/*
 * hyd-window-resize.css - the grow box, the zoom button and each window's growth rule (desk round T8, and
 * round 2 lane R2-5 for the photo viewer, dialogs and the green zoom).
 *
 * hyd-window-resize.js adds a grow box (.window-grow) and a zoom button ([data-zoom-window]) to start here,
 * about me, the photo viewer, stickers, wishes and guestbook (not the time machine: the owner removed its sizing option). The zoom button is the classic
 * green disc (--hyd-zoom-fill, --hyd-zoom-rim and --hyd-zoom-ink below). While a window has a size of its own it carries the
 * class is-resized with --hyd-window-w (its width), --hyd-window-h (its minimum height) and --hyd-window-sx (its
 * content box's width over the base width). Everything here applies at 901 px and over only: the 621-900 px
 * layout and the phone sheets keep their sizes, and there the grow box and the zoom button are hidden.
 *
 * Loaded after the desktop window sheets. The window ids inside :is() give the size rule one id more than each
 * window's own width and height rules, so no !important is needed.
 */

/* The zoom disc: the site's disc style, in green, with a darker rim like the gold and red discs (the
   gold and red ones are in hyd-classic-desktop.css and hyd-mobile-desktop.css). */
:root {
  --hyd-zoom-fill: radial-gradient(ellipse at 40% 15%, #f0fbe8, #9ed48a 55%, #5ea35a);
  --hyd-zoom-rim: #4a7e47;
  --hyd-zoom-ink: #1f4a22;
}

/* Below 901 px windows keep their size: no grow box, no zoom button. */
@media (max-width: 900px) {
  html[data-theme] #world #home .desktop-window .desktop-titlebar > div > [data-zoom-window],
  html[data-theme] #world #home .desktop-window > .window-grow,
  html[data-theme] body button.dialog-zoom[data-zoom-dialog],
  html[data-theme] body :is(#hyd-solitaire, #hyd-pinball, #hyd-bookcricket, #hyd-flyovers) button.dialog-zoom[data-zoom-dialog],
  html[data-theme] body dialog > .window-grow.dialog-grow {
    display: none;
  }
}

@media (min-width: 901px) {
  /* The title clears three round buttons instead of two: the 8 px inset, 3 x 24 px buttons and two 7 px
     gaps end 90 px into the title button. */
  html[data-theme]
    #world
    #home
    :is(#desk-entry, #desk-notes, #desk-stickers, #desk-wishes, #desk-guestbook, #desk-view)
    .window-grab {
    padding-inline: 90px;
  }

  /* The photo viewer is 246 px wide: its title ("photo viewer", 79 px) cannot clear 90 px on both sides, so it centres
     in what is left of the bar to the right of the discs. */
  html[data-theme] #world #home #desk-view .window-grab {
    padding-inline: 90px 8px;
  }

  /* Zoom takes every rule of the minimise button beside it (they share the titlebar button rules) and
     draws a plus for its mark. */
  html[data-theme]
    #world
    #home
    .desktop-window
    .desktop-titlebar
    > div
    > [data-zoom-window]::before {
    width: 10px;
    height: 10px;
    background:
      linear-gradient(currentColor, currentColor) center / 10px 2px no-repeat,
      linear-gradient(currentColor, currentColor) center / 2px 10px no-repeat;
  }

  /* Green, like the gold minimise and red close discs beside it. */
  html[data-theme]
    #world
    #home
    .desktop-window
    .desktop-titlebar
    > div
    > [data-zoom-window] {
    border-color: var(--hyd-zoom-rim);
    background: var(--hyd-zoom-fill);
    color: var(--hyd-zoom-ink);
  }

  /* The grow box: a 32 px target in the window's bottom-right corner, drawn as the period diagonal ridges in
     the titlebar buttons' gold and cream. Its top-left corner is cut off (clip-path also cuts the pointer
     target), so a control that ends just inside the box's square, such as start here's browse all places,
     keeps its pointer target. */
  html[data-theme] #world #home .desktop-window > .window-grow {
    position: absolute;
    right: 0;
    bottom: 0;
    z-index: 3;
    display: block;
    box-sizing: border-box;
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0 0 3px 0;
    background: transparent;
    box-shadow: none;
    font-size: 0;
    cursor: nwse-resize;
    touch-action: none;
    appearance: none;
    -webkit-appearance: none;
    clip-path: polygon(81.25% 0, 100% 0, 100% 100%, 0 100%, 0 81.25%);
  }

  html[data-theme] #world #home .desktop-window > .window-grow::before {
    content: '';
    position: absolute;
    right: 3px;
    bottom: 3px;
    width: 15px;
    height: 15px;
    background: repeating-linear-gradient(
      135deg,
      transparent 0 2px,
      #947844 2px 3px,
      #fff9d9 3px 4px
    );
    clip-path: polygon(100% 0, 100% 100%, 0 100%);
    pointer-events: none;
  }

  html[data-theme] #world #home .desktop-window > .window-grow:hover::before {
    filter: brightness(1.12);
  }

  /* Inside the box: the window clips anything drawn past its edge. */
  html[data-theme] #world #home .desktop-window > .window-grow:focus-visible {
    outline: 2px solid #4d386b;
    outline-offset: -3px;
  }

  html[data-theme] #world #home .desktop-window.is-growing {
    -webkit-user-select: none;
    user-select: none;
  }

  /* The size the visitor chose: a width, and a minimum height, so content that needs more room still grows
     the window as it does today. It keeps the left edge of its base place, so a window placed from the right
     grows to the right as well, under the pointer. */
  html[data-theme]
    #world
    #home
    .desktop-window.is-resized:is(
      #desk-entry,
      #desk-notes,
      #desk-stickers,
      #desk-wishes,
      #desk-guestbook
    ) {
    left: var(--hyd-window-left);
    right: auto;
    width: var(--hyd-window-w);
    min-height: var(--hyd-window-h);
  }

  /* The extra height goes to each window's content. */
  html[data-theme]
    #world
    #home
    .desktop-window.is-resized:is(
      #desk-entry,
      #desk-notes,
      #desk-stickers,
      #desk-wishes
    )
    > .desktop-window-body {
    display: flex;
    flex-direction: column;
  }

  /* Start here and about me: the text reflows into the extra width, and their panels fill the height. */
  html[data-theme] #world #home #desk-entry.is-resized .visual-entry,
  html[data-theme] #world #home #desk-notes.is-resized .about-manad {
    flex: 1 0 auto;
  }

  /* About me's paragraph is held to 36ch at its base size; resized, it takes the window's width. */
  html[data-theme] #world #home #desk-notes.is-resized .about-manad p {
    max-width: none;
  }

  /* Stickers: the sheet fills the window and scrolls inside it; the tray adds whole columns, each sticker
     keeping its base size (the 294 px tray holds three columns with two 7 px gaps). */
  html[data-theme] #world #home #desk-stickers.is-resized .sticker-play {
    flex: 1 1 0;
    min-height: 0;
    max-height: none;
  }

  /* The grow box covers the window's bottom-right 32 px, at the base size as well as resized. The scroll areas
     that reach that corner (the sticker sheet always, the guestbook's scroll area once resized) end above it,
     by a bottom margin the box's height, so no control, at rest or scrolled, sits under the box; the window's
     own paper shows in that strip. Start here's browse all places link, which ends just inside the box's cut
     corner, gets a margin instead. The phone sheets and the 621-900 px layout keep their layout. */
  html[data-theme] #world #home #desk-stickers .sticker-play,
  html[data-theme] #world #home #desk-guestbook.is-resized > .desktop-window-body {
    margin-bottom: 32px;
  }

  html[data-theme] #world #home #desk-entry .finder-all-areas {
    margin-bottom: 10px;
  }

  /* The sticker sheet's base cap (460 px, or the viewport less 160 px) gives up the same 32 px, so the window
     keeps its base height; resized, the sheet fills the window instead. */
  html[data-theme] #world #home #desk-stickers:not(.is-resized) .sticker-play {
    max-height: min(428px, calc(100svh - 192px));
  }

  html[data-theme] #world #home #desk-stickers.is-resized .sticker-tray {
    grid-template-columns: repeat(auto-fill, calc((294px - 14px) / 3));
    justify-content: center;
  }

  /* Wishes: the rock keeps its proportions as it widens. The star field keeps its base size (514 x 310 px)
     and is zoomed by the same factor, so each star stays on the same spot of the rock, and the wishes
     script's row arithmetic stays in base px. The label sits outside the zoom, placed from screen
     positions. */
  html[data-theme] #world #home #desk-wishes.is-resized .wishes-body {
    flex: 1 0 auto;
  }

  html[data-theme] #world #home #desk-wishes.is-resized .wishes-sky {
    height: auto;
    min-height: 0;
    aspect-ratio: 514 / 310;
  }

  html[data-theme] #world #home #desk-wishes.is-resized .wishes-scroll {
    zoom: var(--hyd-window-sx, 1);
  }

  /* Stars stay tiny: their 44 px targets and 16 px marks are divided by the zoom, so they keep their size. */
  html[data-theme] #world #home #desk-wishes.is-resized .wishes-star {
    width: calc(44px / var(--hyd-window-sx, 1));
    height: calc(44px / var(--hyd-window-sx, 1));
    min-width: calc(44px / var(--hyd-window-sx, 1));
    min-height: calc(44px / var(--hyd-window-sx, 1));
  }

  html[data-theme] #world #home #desk-wishes.is-resized .wishes-star svg {
    width: calc(16px / var(--hyd-window-sx, 1));
    height: calc(16px / var(--hyd-window-sx, 1));
  }

  /* Photo viewer: it scales as one piece. Its width is the chosen one; everything under the titlebar (the
     photo, the editor, the thumbnails and the tools row) is zoomed by --hyd-window-sx, so the photo keeps its
     shape and each button keeps its place. hyd-window-resize.js moves the window into view when it grows. The
     window's base height cap (the viewport less the dock) grows with it: the dock top less both 8 px gaps. */
  html[data-theme] #world #home #desk-view.is-resized {
    left: var(--hyd-window-left);
    right: auto;
    width: var(--hyd-window-w);
    max-height: calc(100dvh - 78px);
  }

  html[data-theme]
    #world
    #home
    #desk-view.is-resized
    > :is(.desktop-photo-scroll, .desktop-photo-tools) {
    zoom: var(--hyd-window-sx, 1);
  }

  /* The grow box covers the window's bottom-right 32 px, where the next picture button sat. The tools row
     keeps a strip as wide as the box on its right (in the row's own px, so zoomed it is still 36 px on screen),
     so the buttons end before the box. */
  html[data-theme] #world #home #desk-view .desktop-photo-tools {
    padding-right: 36px;
  }

  html[data-theme] #world #home #desk-view.is-resized .desktop-photo-tools {
    padding-right: calc(36px / var(--hyd-window-sx, 1));
  }

  /* Dialogs (hyd-window-resize.js attachDialog): scaled as one piece with zoom. The dialog's layout stays the one
     it has at scale 1. A dialog's own sheet keeps its max-height inside the viewport by dividing by the scale. */
  html[data-theme] body .is-dialog-scaled {
    zoom: var(--hyd-dialog-scale, 1);
  }

  /* The grow box of a dialog: the same ridges as the desk windows', at 32 px on screen whatever the scale. */
  html[data-theme] body dialog > .window-grow.dialog-grow {
    position: absolute;
    right: 0;
    bottom: 0;
    z-index: 30;
    display: block;
    box-sizing: border-box;
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0 0 3px 0;
    background: transparent;
    box-shadow: none;
    font-size: 0;
    cursor: nwse-resize;
    touch-action: none;
    appearance: none;
    -webkit-appearance: none;
    clip-path: polygon(81.25% 0, 100% 0, 100% 100%, 0 100%, 0 81.25%);
    zoom: calc(1 / var(--hyd-dialog-scale, 1));
  }

  html[data-theme] body dialog > .window-grow.dialog-grow::before {
    content: '';
    position: absolute;
    right: 3px;
    bottom: 3px;
    width: 15px;
    height: 15px;
    background: repeating-linear-gradient(135deg, transparent 0 2px, #6a6d74 2px 3px, #fdfdfe 3px 4px);
    clip-path: polygon(100% 0, 100% 100%, 0 100%);
    pointer-events: none;
  }

  html[data-theme] body dialog > .window-grow.dialog-grow:hover::before {
    filter: brightness(1.12);
  }

  html[data-theme] body dialog > .window-grow.dialog-grow:focus-visible {
    outline: 2px solid #4d386b;
    outline-offset: -3px;
  }

  html[data-theme] body dialog.is-growing {
    -webkit-user-select: none;
    user-select: none;
  }

  /* The dialog's zoom disc: the same green disc as the desk windows', 24 px like its neighbours. The marks are
     drawn by ::before, as for the other discs. #hyd-pinball and #hyd-bookcricket are listed for those windows to use. */
  html[data-theme] body :is(#hyd-solitaire, #hyd-pinball, #hyd-bookcricket, #hyd-flyovers) button.dialog-zoom[data-zoom-dialog] {
    position: relative;
    box-sizing: border-box;
    flex: none;
    display: block;
    width: 24px !important;
    height: 24px !important;
    min-width: 24px !important;
    min-height: 24px !important;
    margin: 0;
    padding: 0;
    border: 1px solid var(--hyd-zoom-rim);
    border-radius: 50%;
    background: var(--hyd-zoom-fill);
    box-shadow:
      inset 0 1px #fff8,
      0 1px #fff7;
    color: var(--hyd-zoom-ink);
    font-size: 0 !important;
    line-height: 0;
    cursor: pointer;
  }

  html[data-theme] body :is(#hyd-solitaire, #hyd-pinball, #hyd-bookcricket, #hyd-flyovers) button.dialog-zoom[data-zoom-dialog]::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    width: 10px;
    height: 10px;
    margin: 0;
    transform: translate(-50%, -50%);
    background:
      linear-gradient(currentColor, currentColor) center / 10px 2px no-repeat,
      linear-gradient(currentColor, currentColor) center / 2px 10px no-repeat;
    pointer-events: none;
  }

  html[data-theme] body :is(#hyd-solitaire, #hyd-pinball, #hyd-bookcricket, #hyd-flyovers) button.dialog-zoom[data-zoom-dialog]:hover {
    filter: brightness(1.08);
  }

  html[data-theme] body :is(#hyd-solitaire, #hyd-pinball, #hyd-bookcricket, #hyd-flyovers) button.dialog-zoom[data-zoom-dialog]:focus-visible {
    outline: 2px solid #4d386b;
    outline-offset: 3px;
  }

  html[data-theme] body :is(#hyd-solitaire, #hyd-pinball, #hyd-bookcricket, #hyd-flyovers) button.dialog-zoom[data-zoom-dialog]:active {
    box-shadow: inset 0 1px 3px #0007;
  }

  /* Solitaire's titlebar: three discs, 3 x 24 px and two 6 px gaps, so the controls and the spacer that
     balances them are 84 px, and the title stays in the middle. */
  html[data-theme] body #hyd-solitaire .solitaire-window-controls:has(> .dialog-zoom),
  html[data-theme] body #hyd-solitaire .solitaire-titlebar:has(.dialog-zoom) .solitaire-title-spacer {
    width: 84px;
  }

  /* Book cricket’s titlebar is a three-column grid (hyd-bookcricket.css), so the zoom disc needs no width
     here. Scaled, its viewport cap (24 px of margin in hyd-bookcricket.css) is divided by the scale. */
  html[data-theme] body #hyd-bookcricket.is-dialog-scaled {
    max-height: calc((100dvh - 24px) / var(--hyd-dialog-scale, 1));
  }
  html[data-theme] body #hyd-flyovers.is-dialog-scaled {
    max-height: calc((100vh - 24px) / var(--hyd-dialog-scale, 1));
    max-height: calc((100dvh - 24px) / var(--hyd-dialog-scale, 1));
  }
}

/* Touch screens at 901 px and over: the titlebar buttons are 44 px targets with no gap (hyd-mobile-desktop.css),
   so the title clears 3 x 44 px from a 2 px inset, and the grow box is a 44 px target too. */
@media (min-width: 901px) and (any-pointer: coarse) {
  html[data-theme]
    #world
    #home
    :is(#desk-entry, #desk-notes, #desk-stickers, #desk-wishes, #desk-guestbook, #desk-view)
    .window-grab {
    padding-inline: 134px 8px;
  }

  html[data-theme] #world #home .desktop-window > .window-grow {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
  }

  html[data-theme] #world #home #desk-stickers .sticker-play,
  html[data-theme] #world #home #desk-guestbook.is-resized > .desktop-window-body {
    margin-bottom: 44px;
  }

  html[data-theme] #world #home #desk-entry .finder-all-areas {
    margin-bottom: 21px;
  }

  html[data-theme] #world #home #desk-stickers:not(.is-resized) .sticker-play {
    max-height: min(416px, calc(100svh - 204px));
  }
}

/* Touch screens at 901 px and over, continued: the discs of the touch titlebars are drawn by ::after (see
   hyd-mobile-desktop.css), so the zoom disc takes its green there; the viewer's tools strip clears the 44 px
   box; solitaire's three 44 px targets take 144 px. */
@media (min-width: 901px) and (any-pointer: coarse) {
  html[data-theme]
    #world
    #home
    .desktop-window
    .desktop-titlebar
    > div
    > [data-zoom-window]::after {
    border-color: var(--hyd-zoom-rim);
    background: var(--hyd-zoom-fill);
  }

  html[data-theme]
    #world
    #home
    .desktop-window
    .desktop-titlebar
    > div
    > [data-zoom-window] {
    background: none;
    border-color: transparent;
  }

  html[data-theme] #world #home #desk-view .desktop-photo-tools {
    padding-right: 48px;
  }

  html[data-theme] #world #home #desk-view.is-resized .desktop-photo-tools {
    padding-right: calc(48px / var(--hyd-window-sx, 1));
  }

  html[data-theme] body dialog > .window-grow.dialog-grow {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
  }

  html[data-theme] body :is(#hyd-solitaire, #hyd-pinball, #hyd-bookcricket, #hyd-flyovers) button.dialog-zoom[data-zoom-dialog] {
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    min-height: 44px !important;
    border: 0;
    background: none;
    box-shadow: none;
  }

  html[data-theme] body :is(#hyd-solitaire, #hyd-pinball, #hyd-bookcricket, #hyd-flyovers) button.dialog-zoom[data-zoom-dialog]::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    translate: -50% -50%;
    width: 24px;
    height: 24px;
    box-sizing: border-box;
    border: 1px solid var(--hyd-zoom-rim);
    border-radius: 50%;
    background: var(--hyd-zoom-fill);
    pointer-events: none;
  }

  html[data-theme] body :is(#hyd-solitaire, #hyd-pinball, #hyd-bookcricket, #hyd-flyovers) button.dialog-zoom[data-zoom-dialog]::before {
    z-index: 1;
  }

  /* Book cricket’s sideways layout gives each title-bar control a 44 px ::after target moved by a transform; here
     ::after is the drawn zoom disc, centred by translate alone. */
  html[data-theme] body #hyd-bookcricket button.dialog-zoom[data-zoom-dialog]::after,
  html[data-theme] body #hyd-flyovers button.dialog-zoom[data-zoom-dialog]::after {
    transform: none;
  }

  html[data-theme] body #hyd-solitaire .solitaire-window-controls:has(> .dialog-zoom) {
    width: 144px;
  }

  html[data-theme] body #hyd-solitaire .solitaire-titlebar:has(.dialog-zoom) {
    grid-template-columns: 144px minmax(0, 1fr);
  }
}
