/* Shared visual shell: the canvas frame, tools row and controls sidebar every visual page uses
   (see "visual-canvas" and "visual-tools" in openspec/specs/). Plain, unlayered CSS - it must beat
   utilities, same reason visuals/honeycomb/controls.css is unlayered (see docs/styling.md).
   A visual's own controls.css keeps only rules truly specific to it (honeycomb's #vignette). */

main {
  --sidebar-w: 420px;
  --dur: 420ms;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  display: flex;
}

/* padding and gap must match PAD in visual-chrome.js (frameSizes) */
#stage {
  --w: 600px;
  --h: 600px;
  margin: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  transition: transform var(--dur) var(--ease);
}

/* Clipping frame: its size is set from visual-chrome.js; the canvas inside keeps its own size and
   is cropped around its center, so smaller means fewer/less of the drawing, never rescaled.
   position: relative so a visual can anchor its own overlay inside it (honeycomb's #vignette). */
#canvas-host {
  position: relative;
  width: var(--w);
  height: var(--h);
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: width var(--dur) var(--ease), height var(--dur) var(--ease);
}

#canvas-inner {
  position: relative;
  flex: none;
}

#sidebar {
  display: none;
}

/* Keep the 1024px in sync with CONTROLS_MIN_WIDTH in visual-chrome.js and the
   min-[1024px] on the controls button in each visual's index.html */
@media (min-width: 1024px) {
  #sidebar {
    display: flex;
    flex-direction: column;
    position: fixed;
    /* 32px below the header and above the bottom edge; the right gap (16px) must match PAD in
       visual-chrome.js (frameSizes); --header-h is set there */
    top: calc(var(--header-h, 0px) + 32px);
    right: 16px;
    /* height follows the content up to the room left; 64 = the top and bottom gaps */
    max-height: calc(100dvh - var(--header-h, 0px) - 64px);
    width: var(--sidebar-w);
    overflow: hidden;
    --sp-bg: #141414; /* a little lighter than the page; the panel (settings-panel.css) reads it too */
    background: var(--sp-bg);
    color: var(--color-fg);
    font: 12px sans-serif;
    transform: translateX(calc(100% + 16px));
    transition: transform var(--dur) var(--ease);
  }

  main.controls-open #sidebar {
    transform: none;
  }

  /* the sidebar floats over the visual here, so it also stays clear of the tools row: 80 = 32 above, 32 below and PAD between the frame and the tools row */
  main.fill #sidebar {
    max-height: calc(100dvh - var(--header-h, 0px) - var(--tools-h, 0px) - 80px);
  }

  main.controls-open:not(.fill) #stage {
    transform: translateX(calc((var(--sidebar-w) + 16px) / -2));
  }
}

@media (prefers-reduced-motion: reduce) {
  main {
    --dur: 0ms;
  }
}

/* The settings panel (settings-panel.js, styles in assets/settings-panel.css) fills the sidebar
   above a fixed foot; the tab content scrolls inside the panel, not the sidebar. */
#panel { flex: 1; min-height: 0; display: flex; }

#sidebar-foot { flex: none; padding: 8px 16px; color: #8a8a8a; }

/* No native up/down spinner on the auto-randomize popup's seconds field */
#auto-seconds {
  appearance: textfield;
}
#auto-seconds::-webkit-outer-spin-button,
#auto-seconds::-webkit-inner-spin-button {
  appearance: none;
  margin: 0;
}

/* Its own visible box: tint it directly on focus, never an outline (src/tailwind.css kills
   the native ring) - one step up from its resting bg-white/10 (each visual's index.html). */
#auto-seconds:focus {
  background: rgb(255 255 255 / 0.15);
}

/* Fullscreen (class set from visual-chrome.js): the visual alone, no padding. visual-chrome.js
   sizes it. The tools row gets its own floating panel in fullscreen (below), regardless of fill mode. */
html.is-fullscreen header,
html.is-fullscreen #sidebar {
  display: none;
}

/* Toolbar chrome, common to every layout: square windowed (in #stage's own flow), fill windowed
   (fixed centered pill, below) and fullscreen (fixed centered pill, further below) all share one
   background container for the title and the buttons together - not just the buttons, so there is
   no separate background behind the title. width: auto overrides the w-(--w) utility (each
   visual's index.html): the panel sizes to its content and is centered, rather than stretching to
   the frame's width - #stage's own align-items: center then centers it under the canvas in the
   square-windowed case; the fixed-position layouts below center it themselves. Only
   position/inset differs per layout. */
#tools {
  width: auto;
  background: #000;
  padding: 8px 16px;
  border-radius: 9999px;
}

/* Fill mode, windowed only (fullscreen has its own tools treatment below): the canvas is edge to
   edge (no padding). The tools row floats over it instead of sharing #stage's flow, inset by PAD
   (16px, matches visual-chrome.js) from the window edges - same idiom the sidebar already uses in
   fill mode. */
html.is-fullscreen #stage,
main.fill #stage {
  padding: 0;
}

/* Floating centered pill, both fill-mode windowed and fullscreen: fixed to the viewport/screen,
   inset from the bottom, centered horizontally rather than stretched between left and right edges
   (width: auto comes from the shared #tools rule above). */
main.fill #tools,
html.is-fullscreen #tools {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
}

/* Fullscreen only: no title (below), and the idle-fade transition. Ordered after `main.fill
   #tools` so it wins the specificity tie (same shape, element.class #id) when both .fill and
   .is-fullscreen apply - not that centering itself differs between them any more. */
html.is-fullscreen #tools {
  justify-content: center;
  transition: opacity 200ms ease;
}

/* No title, and no Controls / auto-randomize (both non-functional in fullscreen: sidebar is
   force-closed, auto-randomize is force-stopped - see visual-chrome.js's fullscreenchange
   handler) inside the panel. :has(> #auto-toggle) drops only the button's own immediate wrapper
   (each visual's index.html has no id on it) - plain :has(#auto-toggle) would also match the
   outer button-group div, since it too has auto-toggle as a (non-immediate) descendant, hiding
   every other tool along with it. */
html.is-fullscreen #tools h1,
html.is-fullscreen #controls-toggle,
html.is-fullscreen #tools div:has(> #auto-toggle) {
  display: none;
}

/* Idle-fade state, JS-toggled (visual-chrome.js's showTools()/armToolsIdleTimeout()): only
   meaningful in fullscreen, where the panel is a floating overlay rather than part of the page flow. */
html.is-fullscreen #tools.tools-idle {
  opacity: 0;
  pointer-events: none;
}

/* Bare (?bare, visual-chrome.js): the visual alone. The frame is sized by the fill-mode path with a
   header of zero height, so it fills the window. Last in the file so display: none wins the tie with
   the fill-mode #tools rule. */
html.is-bare header,
html.is-bare #tools,
html.is-bare #sidebar {
  display: none;
}

/* The randomize hint (.hint in src/tailwind.css, built by visual-chrome.js) never shows in fullscreen
   (it comes back on exit unless dismissed) or bare (visual-chrome.js doesn't build it there either). */
html.is-fullscreen .hint,
html.is-bare .hint {
  display: none;
}
