/* The Theme button and its panel (templates/_theme_picker.html, portal/docs/themes.md).

   Its own file so aperture.css is untouched. Every colour is a role token from
   portal/docs/themes-tokens.md (--surface-*, --text-*, --border*, --accent, --warning,
   --shadow-*), so a theme that re-points the roles restyles the picker with no rule of its
   own here. Motion is transform/opacity only.

   Layers: the panel sits in `.wrap`'s stacking context at 58, under the review viewer (60)
   and the phone app bar (70) - it can never draw over a render or the verdict bar, and
   `body.viewer-open` hides it outright besides. */

.theme-picker { position: relative; }

/* `.sidebar` is position: sticky, which makes it a stacking context of its own - so the
   panel's z-index only counts inside it, and the page's cards (transformed, positioned)
   painted over the panel. While the panel is open the sidebar itself is lifted, still
   under the viewer (60). On a phone the drawer already sits at 80. */
@media (min-width: 761px) {
  .sidebar:has(.theme-picker[open]) { z-index: 58; }

  /* The sidebar scrolls on its own. It is sticky and exactly 100vh tall, so scrolling the
     page never moves it, and anything below its bottom edge could not be reached at all:
     the staff footer (Sign out, View as, Change password) sat at y~1650 on every desktop,
     and the Theme button pushed the artist footer past 900px too. Now the sidebar is a
     scroll container: nothing moves when it fits; when it does not, a thin scrollbar
     appears at its right edge and the wheel over it scrolls it. The Theme button stays at
     the top, never scrolled out of reach on load. The phone drawer already scrolls.
     Checked by `sidebar_reach` in portal/tools/ui_harness/. */
  .sidebar {
    overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--border-hover) transparent;
  }
}

.theme-toggle {
  display: flex; align-items: center; gap: 11px;
  min-height: 52px; padding: 10px 13px;
  border-radius: var(--radius);
  border: 1px solid var(--accent);
  background: var(--surface-raised);
  color: var(--text-primary);
  font-weight: 700; font-size: 15px;
  cursor: pointer; list-style: none; user-select: none;
  transition: transform var(--speed) var(--ease), border-color var(--speed);
}
.theme-toggle::-webkit-details-marker { display: none; }
.theme-toggle::marker { content: ""; }
.theme-toggle:hover { transform: translateX(4px); }
.theme-toggle:focus-visible,
.theme-option:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.theme-toggle-icon { font-size: 22px; line-height: 1; }
.theme-toggle-text { flex: 1 1 auto; line-height: 1.2; }
.theme-toggle-text small { display: block; font-weight: 400; font-size: 11px; color: var(--text-muted); }

.theme-swatch { display: inline-flex; flex: 0 0 auto; border-radius: 6px; overflow: hidden;
                border: 1px solid var(--border); }
.theme-swatch i { display: block; width: 9px; height: 22px; }

.theme-panel {
  position: fixed; z-index: 58;
  left: 280px; top: 18px;
  width: min(420px, calc(100vw - 300px));
  max-height: calc(100vh - 36px); overflow-y: auto; overscroll-behavior: contain;
  padding: 14px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface-popover);
  color: var(--text-primary);
  box-shadow: 0 24px 60px var(--shadow-soft);
  animation: theme-panel-in 180ms var(--ease) both;
}
@keyframes theme-panel-in { from { opacity: 0; transform: translateY(-6px); } }

.theme-panel-head { font-size: 12px; color: var(--text-muted); margin: 0 2px 10px; }
.theme-locked { font-size: 13px; margin: 0 2px 10px; color: var(--warning); }

.theme-list { display: flex; flex-direction: column; gap: 8px; margin: 0; }
.theme-option {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 10px 12px; text-align: left; font: inherit; cursor: pointer;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-glass);
  color: var(--text-primary);
  transition: transform var(--speed) var(--ease), border-color var(--speed);
}
.theme-option:hover:not(:disabled) { transform: translateX(3px); border-color: var(--text-muted); }
.theme-option.current { border-color: var(--accent); }
.theme-option:disabled { cursor: not-allowed; opacity: .6; }
.theme-option .theme-swatch i { width: 10px; height: 34px; }
.theme-option-text { min-width: 0; line-height: 1.3; }
.theme-option-text small { display: block; font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.theme-tag { display: inline-block; margin-left: 6px; padding: 0 7px; border-radius: 999px;
             font-size: 10px; letter-spacing: .6px; text-transform: uppercase; vertical-align: 2px;
             border: 1px solid currentColor; }
.theme-tag.current { color: var(--accent); }
.theme-tag.soon { color: var(--text-muted); }

/* The phone app bar's copy of the button, added by theme_picker.js (only exists ≤760px). */
.appbar-theme { display: none; }

@media (max-width: 760px) {
  /* The sidebar is a transformed drawer here, and a transform makes it the containing
     block of anything fixed inside it - so the panel would be pinned off-screen with it.
     Inside the drawer the panel is simply part of the list. */
  .theme-panel {
    position: static; width: auto; max-height: none; margin-top: 8px;
    box-shadow: none; padding: 10px;
  }
  /* ...and as wide as the drawer, whatever a theme says. The rule above is 0,1,0 and every
     theme file's `.theme-panel` is 0,3,0, so a theme that gave the panel a desktop `left` or
     `width` outside a desktop media query won on a phone: Darkroom, Blueprint and Neon
     Sanctuary drew it 112px wide at 390, one letter per line, and the drawer scrolled
     through a list twenty screens long. This one is 0,4,0, so only the geometry is pinned
     here; padding, border and shadow stay each theme's own. `theme_panel_phone` in the UI
     harness measures it.

     Nor is the panel a scroll container here: the drawer is the one that scrolls. With the
     desktop `overflow-y: auto` and `overscroll-behavior: contain` it still was one, with
     nothing to scroll, and Chrome stops a touch drag at such a box - so a finger on the
     theme list never scrolled the drawer, and the themes below the screen edge could not
     be reached. */
  :root .sidebar .theme-picker > .theme-panel {
    position: static; left: auto; top: auto; width: auto; max-width: none; max-height: none;
    overflow: visible; overscroll-behavior: auto;
  }
  .appbar-theme {
    display: inline-flex; align-items: center; gap: 6px; flex: 0 0 auto;
    height: 40px; padding: 0 12px; margin-left: auto;
    border-radius: 12px; border: 1px solid var(--accent);
    background: transparent; color: var(--text-primary);
    font: inherit; font-weight: 700; font-size: 14px; cursor: pointer;
  }
  .appbar-theme + .appbar-brand { margin-left: 8px; }
  .appbar-theme:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
}

/* Never inside the review viewer: the button, its panel and its app-bar copy all go. */
body.viewer-open .theme-picker,
body.viewer-open .appbar-theme { display: none; }

@media (prefers-reduced-motion: reduce) {
  .theme-panel { animation: none; }
  .theme-toggle, .theme-option { transition: none; }
  .theme-toggle:hover, .theme-option:hover:not(:disabled) { transform: none; }
}
