/* ══════════════════════════════════════════════════════════════════
   THEME MENU + CUSTOM THEME PANEL (per Big, 2026-11-02)
   ------------------------------------------------------------------
   js/theme.js (menu, colour maths, background layer) and
   js/themePanel.js (the drawer). Everything here is drawn with the
   same tokens as the rest of the app, so the panel itself re-colours
   live as the user picks colours — it is part of the preview.
   ══════════════════════════════════════════════════════════════════ */

/* ── Header menu — reuses .lang-menu / .lang-option (layout.css) ───── */
.theme-pick {
  position: relative;
}
.theme-menu {
  min-width: 200px;
}
.theme-opt-ico {
  display: inline-flex;
  color: var(--muted);
}
.theme-opt-ico svg {
  width: 16px;
  height: 16px;
}
.theme-opt-text {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}
.theme-opt-text small {
  font-size: var(--fs-xs);
  font-weight: 500;
  color: var(--muted);
}
/* The language menu marks its row with aria-selected (a listbox); this one is
   a menu of radio items, so the same look keys off aria-checked. */
.theme-menu .lang-option[aria-checked="true"] {
  background: var(--surface-3);
}
.theme-menu .lang-option[aria-checked="true"] .lang-check {
  visibility: visible;
}
.theme-menu .lang-option[aria-checked="true"] .theme-opt-ico {
  color: var(--ink);
}

/* ── Background image layer ─────────────────────────────────────────
   Fixed behind the whole app. body's own background (var(--bg)) is
   propagated to the canvas, which paints BELOW a z-index:-1 layer, so
   the picture shows wherever the page colour used to. ::after lays the
   page colour back over it at --tw-dim — the readability knob. */
#theme-wall {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}
#theme-wall[hidden] {
  display: none;
}
#theme-wall .tw-img {
  position: absolute;
  inset: 0;
  background-position: center;
  background-size: cover;
  filter: blur(var(--tw-blur, 0px));
  transform: scale(var(--tw-scale, 1));
}
#theme-wall::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--bg);
  opacity: var(--tw-dim, 0.3);
}

/* ── Neon border (.neon-fx) ─────────────────────────────────────────
   Shared by the screen overlay (#theme-neon) and the panel's style chips.
   .tn-band is masked down to its border ring (padding = line width);
   .tn-spin inside is a square the size of the band's diagonal, painted
   per style and ROTATED — transform only, so the GPU animates it without
   repainting. .tn-glow is a blurred, thicker copy underneath. Variables
   come from neonVars() in js/theme.js. */
/* No variable defaults here on purpose: the chips must INHERIT them from the
   panel's fieldset (where syncNeon sets them), and a declaration on the
   element itself would beat inheritance. */
.neon-fx {
  border-radius: var(--r-xl);
  pointer-events: none;
}
#theme-neon {
  position: fixed;
  inset: 0;
  /* Over the header so the frame runs round it too; under the theme panel
     (--z-float) and every modal. */
  z-index: calc(var(--z-header) + 1);
  border-radius: 0; /* the screen's corners are square */
}
#theme-neon[hidden] {
  display: none;
}
.neon-fx .tn-glow,
.neon-fx .tn-band {
  position: absolute;
  inset: 0;
  display: block;
  border-radius: inherit;
}
.neon-fx .tn-glow {
  filter: blur(var(--neon-blur));
  opacity: var(--neon-glow-op);
}
.neon-fx .tn-band {
  overflow: hidden;
  padding: var(--neon-w);
  container-type: size;
  -webkit-mask:
    linear-gradient(#000 0 0) content-box,
    linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask:
    linear-gradient(#000 0 0) content-box exclude,
    linear-gradient(#000 0 0);
}
.neon-fx .tn-glow .tn-band {
  padding: calc(var(--neon-w) * 3);
}
/* A faint full ring under the running styles, so the border reads as a
   border and not just a dot travelling round the screen. */
.neon-fx .tn-sharp {
  background: color-mix(in srgb, var(--neon-c) 22%, transparent);
}
.neon-fx .tn-spin {
  position: absolute;
  left: 50%;
  top: 50%;
  display: block;
  width: 150vmax; /* fallback; hypot() below sizes it to the diagonal */
  /* cqw/cqh measure the band's CONTENT box — the padding (the line itself,
     3× thicker on the glow copy) is outside it. Without the extra the
     rotating square fell ~3px short of the corners at 45°, leaving a dark
     notch where the light should pass (caught by the harness 2026-11-02).
     9 × width covers the 3w padding on both axes (3w·2·√2 ≈ 8.5w). */
  width: calc(hypot(100cqw, 100cqh) + var(--neon-w) * 9 + 4px);
  aspect-ratio: 1;
  translate: -50% -50%;
  background: var(--neon-c);
}

/* Still / breathe / flicker: one solid colour; the whole layer pulses. */
.neon-fx[data-style="breathe"] {
  animation: neon-breathe var(--neon-dur) ease-in-out infinite alternate;
}
.neon-fx[data-style="flicker"] {
  animation: neon-flicker var(--neon-dur) linear infinite;
}
@keyframes neon-breathe {
  from {
    opacity: 1;
  }
  to {
    opacity: 0.3;
  }
}
/* A neon sign with a loose contact: mostly lit, a few soft dips. Kept
   shallow (never below 0.5) and never faster than 2 s a cycle — this is
   decoration, not a strobe. */
@keyframes neon-flicker {
  0%,
  19%,
  23%,
  58%,
  64%,
  100% {
    opacity: 1;
  }
  20% {
    opacity: 0.5;
  }
  22% {
    opacity: 0.85;
  }
  60% {
    opacity: 0.55;
  }
  62% {
    opacity: 0.9;
  }
}

/* Running styles: a conic gradient on the spinning square. */
.neon-fx[data-style="chase"] .tn-spin,
.neon-fx[data-style="dual"] .tn-spin,
.neon-fx[data-style="flow"] .tn-spin,
.neon-fx[data-style="rainbow"] .tn-spin {
  animation: neon-spin var(--neon-dur) linear infinite;
}
/* chase — one comet with a fading tail and a white-hot head */
.neon-fx[data-style="chase"] .tn-spin {
  background: conic-gradient(
    transparent 0deg 230deg,
    color-mix(in srgb, var(--neon-c) 35%, transparent) 290deg,
    var(--neon-c) 348deg,
    #fff 357deg,
    transparent 360deg
  );
}
/* dual — two comets chasing each other from opposite corners */
.neon-fx[data-style="dual"] .tn-spin {
  background: conic-gradient(
    transparent 0deg 110deg,
    var(--neon-c) 172deg,
    #fff 178deg,
    transparent 180deg 290deg,
    var(--neon-c) 352deg,
    #fff 358deg,
    transparent 360deg
  );
}
/* flow — the colour and a neighbouring hue drifting round, no gaps */
.neon-fx[data-style="flow"] .tn-spin {
  background: conic-gradient(
    var(--neon-c),
    var(--neon-c2),
    var(--neon-c),
    var(--neon-c2),
    var(--neon-c)
  );
}
.neon-fx[data-style="flow"] .tn-sharp,
.neon-fx[data-style="rainbow"] .tn-sharp {
  background: none;
}
/* rainbow — the gaming-keyboard RGB loop; ignores the picked colour */
.neon-fx[data-style="rainbow"] .tn-spin {
  background: conic-gradient(
    #ff004c,
    #ff9f00,
    #f5ff00,
    #00ff6a,
    #00e5ff,
    #3d5bff,
    #c400ff,
    #ff004c
  );
}
@keyframes neon-spin {
  to {
    rotate: 360deg;
  }
}
@media (prefers-reduced-motion: reduce) {
  .neon-fx,
  .neon-fx .tn-spin {
    animation: none !important;
  }
}

/* Rings on the frames inside the page (layoutInner in js/theme.js).
   ABSOLUTE at the page's top-left, so the rings scroll with the page in the
   same frame — the fixed version lagged behind on scroll. Zero height and
   overflow-y visible: it adds nothing to the page's height (the rings sit on
   frames that are already there). overflow-x: clip keeps a ring on a card
   half off the right edge from widening the page. Under the sticky header
   (which covers rings scrolled beneath it) and the sidebar fly-out; over
   sticky table headers (--z-sticky). */
#theme-neon-inner {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 0;
  overflow-x: clip;
  overflow-y: visible;
  z-index: calc(var(--z-sidebar) - 1);
  pointer-events: none;
}
#theme-neon-inner[hidden] {
  display: none;
}
/* One sharp band per ring — no blurred copy (dozens of them would cost real
   GPU time); the halo is a plain box-shadow in the neon colour instead. */
.tn-inner {
  position: absolute;
  left: 0;
  top: 0;
  display: block;
  box-shadow: 0 0 calc(var(--neon-blur) * 0.6)
    color-mix(
      in srgb,
      var(--neon-c) calc(var(--neon-glow-op) * 70%),
      transparent
    );
}
.tn-inner[data-style="rainbow"] {
  box-shadow: 0 0 calc(var(--neon-blur) * 0.6)
    color-mix(in srgb, #fff calc(var(--neon-glow-op) * 30%), transparent);
}

/* ── The panel ──────────────────────────────────────────────────────
   A floating drawer, inset from the screen edge like a tool palette.
   No backdrop on purpose: the page behind IS the preview. Sits on the
   --z-float layer — over the page and header, under any modal. */
.tpanel {
  position: fixed;
  top: var(--sp-3);
  right: var(--sp-3);
  bottom: var(--sp-3);
  z-index: var(--z-float);
  width: 344px;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  color: var(--ink-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-xl);
  box-shadow: var(--sh-3);
  animation: tpanel-in var(--dur-3) var(--ease-out);
}
.tpanel[hidden] {
  display: none;
}
@keyframes tpanel-in {
  from {
    opacity: 0;
    transform: translateX(16px);
  }
}
@media (prefers-reduced-motion: reduce) {
  .tpanel {
    animation: none;
  }
}

.tpanel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-4) var(--sp-3);
  border-bottom: 1px solid var(--line);
}
.tpanel-head h2 {
  font-size: var(--fs-lg);
}
.tpanel-sub {
  margin-top: 2px;
  font-size: var(--fs-sm);
  color: var(--muted);
}
.tpanel-x {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
}

.tpanel-body {
  flex: 1;
  overflow-y: auto;
  padding: 0 var(--sp-4) var(--sp-4);
}
.tpanel-sec + .tpanel-sec {
  border-top: 1px solid var(--line);
}
.tpanel-sec {
  padding-bottom: var(--sp-4);
}
.tpanel-h {
  margin: var(--sp-4) 0 var(--sp-3);
  font-family: var(--font-ui);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Presets — each chip is a tiny drawing of the theme it applies:
   page colour, a panel on it, two text lines and a button. */
.tp-presets {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--sp-2);
}
.tp-preset {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px;
  font: inherit;
  color: var(--ink-2);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  cursor: pointer;
  transition:
    border-color var(--dur-1) var(--ease-out),
    box-shadow var(--dur-1) var(--ease-out);
}
.tp-preset:hover {
  border-color: var(--line-strong);
}
.tp-preset[aria-pressed="true"] {
  border-color: var(--ring);
  box-shadow: 0 0 0 1px var(--ring);
}
.tp-preset:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}
.tp-mini {
  display: block;
  height: 46px;
  padding: 7px 8px;
  background: var(--p-bg);
  border-radius: var(--r-sm);
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.08);
}
.tp-mini-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  height: 100%;
  padding: 6px;
  background: var(--p-surface);
  border-radius: 4px;
}
.tp-mini-line {
  height: 3px;
  width: 70%;
  border-radius: 2px;
  background: var(--p-accent);
  opacity: 0.35;
}
.tp-mini-line.short {
  width: 45%;
}
.tp-mini-btn {
  position: absolute;
  right: 5px;
  bottom: 5px;
  width: 14px;
  height: 7px;
  border-radius: 2px;
  background: var(--p-accent);
}
.tp-preset-name {
  font-size: var(--fs-xs);
  font-weight: 600;
  text-align: center;
}

/* Colour rows: swatch (the real colour input, invisible on top) · label ·
   hex box for people who already know the code. */
.tp-colour {
  display: grid;
  grid-template-columns: 34px 1fr 82px;
  align-items: center;
  gap: var(--sp-3);
  padding: 6px 0;
}
.tp-swatch {
  position: relative;
  width: 34px;
  height: 34px;
  background: var(--sw);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  cursor: pointer;
}
.tp-swatch:has(input:focus-visible) {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}
.tp-swatch input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}
.tp-colour-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.3;
}
.tp-colour-text b {
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--ink);
}
.tp-colour-text small {
  font-size: var(--fs-xs);
  color: var(--muted);
}
.tp-hex {
  width: 100%;
  padding: 6px 8px;
  font: inherit;
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
  text-transform: uppercase;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
}
.tp-hex:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 1px;
}
.tp-hex[aria-invalid="true"] {
  border-color: var(--danger);
}

/* Readability check under the colours — green when fine, amber with the
   reason when a pick makes something hard to read. */
.tp-check {
  display: flex;
  gap: var(--sp-2);
  margin-top: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--fs-sm);
  line-height: 1.4;
  color: var(--ok);
  background: var(--ok-bg);
  border-radius: var(--r-md);
}
.tp-check::before {
  content: "✓";
  font-weight: 700;
}
.tp-check.is-warn {
  color: var(--warn);
  background: var(--warn-bg);
}
.tp-check.is-warn::before {
  content: "!";
}

/* Picture drop zone → becomes the thumbnail once a picture is set. */
.tp-drop {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  color: var(--muted);
  background: var(--surface-2);
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--r-lg);
  cursor: pointer;
  transition:
    border-color var(--dur-1) var(--ease-out),
    background-color var(--dur-1) var(--ease-out);
}
.tp-drop:hover,
.tp-drop:focus-visible {
  border-color: var(--muted);
  outline: none;
}
.tp-drop.is-over {
  border-color: var(--ring);
  background: var(--surface-3);
}
.tp-drop.has-img {
  border-style: solid;
  border-color: var(--line-strong);
  cursor: default;
}
.tp-drop-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: var(--sp-3);
  font-size: var(--fs-sm);
  text-align: center;
}
.tp-drop-empty[hidden] {
  display: none;
}
.tp-drop-empty svg {
  width: 26px;
  height: 26px;
  margin-bottom: 2px;
}
.tp-drop-or u {
  color: var(--ink);
  font-weight: 600;
  text-underline-offset: 2px;
}
.tp-thumb {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.tp-drop-busy {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--ink);
  background: color-mix(in srgb, var(--surface) 80%, transparent);
}
.tp-drop-busy[hidden] {
  display: none;
}
.tp-img-actions {
  display: flex;
  gap: var(--sp-2);
  margin-top: var(--sp-2);
}
.tp-img-actions[hidden] {
  display: none;
}

.tp-slider {
  display: block;
  margin-top: var(--sp-3);
  font-size: var(--fs-sm);
}
.tp-slider-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 2px;
  font-weight: 600;
  color: var(--ink-2);
}
.tp-slider output {
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
.tp-slider input {
  width: 100%;
  accent-color: var(--accent);
}
.tp-slider.is-off {
  opacity: 0.45;
}
.tp-note {
  margin-top: var(--sp-3);
  font-size: var(--fs-xs);
  line-height: 1.45;
  color: var(--muted);
}

/* ── Neon section ───────────────────────────────────────────────────── */
.tp-neon-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
/* The shared switch (dialogs.css) only gets its layout inside .modal-field —
   outside one the track is a bare inline span with no size (it simply
   vanished). And it turns red when on, which is NO TRIAL's warning colour;
   here "on" just means on. */
.tp-neon-switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}
.tp-neon-switch input:checked + .cm-switch-track {
  background: var(--accent);
}
.tp-neon-switch:has(input:focus-visible) .cm-switch-track {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}
.tp-neon-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-top: var(--sp-3);
  cursor: pointer;
}
.tp-neon {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}
.tp-neon[disabled] {
  opacity: 0.45;
}
.tp-neon[disabled] .neon-fx,
.tp-neon[disabled] .neon-fx * {
  animation-play-state: paused;
}
.tp-sublabel {
  margin: var(--sp-3) 0 var(--sp-2);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--ink-2);
}
.tp-sublabel:first-child {
  margin-top: 0;
}

/* Colour dots — the picked one gets a ring and its own glow. */
.tp-dots {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}
.tp-dots.is-off {
  opacity: 0.4;
  pointer-events: none;
}
.tp-dot {
  position: relative;
  width: 28px;
  height: 28px;
  padding: 0;
  background: var(--dot);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-full);
  cursor: pointer;
  transition: box-shadow var(--dur-1) var(--ease-out);
}
.tp-dot[aria-pressed="true"],
.tp-dot-pick.is-on {
  box-shadow:
    0 0 0 2px var(--surface),
    0 0 0 4px var(--dot),
    0 0 12px 2px var(--dot);
}
.tp-dot:focus-visible,
.tp-dot-pick:has(input:focus-visible) {
  outline: 2px solid var(--ring);
  outline-offset: 4px;
}
/* "Any colour" — a colour wheel until the user's own colour is in use. */
.tp-dot-pick {
  background: conic-gradient(
    #f43f5e,
    #f59e0b,
    #84cc16,
    #06b6d4,
    #6366f1,
    #d946ef,
    #f43f5e
  );
}
.tp-dot-pick.is-on {
  background: var(--dot);
}
.tp-dot-pick input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}
.tp-rainbow-note {
  margin-top: var(--sp-2);
}

/* Style chips — each one is a live, shrunk copy of the real border, on a
   dark stage whatever the theme (neon only reads against dark). */
.tp-nstyles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--sp-2);
}
.tp-nstyle {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px;
  font: inherit;
  color: var(--ink-2);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  cursor: pointer;
  transition:
    border-color var(--dur-1) var(--ease-out),
    box-shadow var(--dur-1) var(--ease-out);
}
.tp-nstyle:hover {
  border-color: var(--line-strong);
}
.tp-nstyle[aria-pressed="true"] {
  border-color: var(--ring);
  box-shadow: 0 0 0 1px var(--ring);
}
.tp-nstyle:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}
.tp-nmini {
  --neon-w: 2px;
  --neon-blur: 5px;
  position: relative;
  display: block;
  height: 40px;
  overflow: hidden;
  background: #0b111f;
  border-radius: var(--r-sm);
}
.tp-nstyle-name {
  font-size: var(--fs-xs);
  font-weight: 600;
  text-align: center;
  line-height: 1.25;
}

.tpanel-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--line);
}
.tpanel-foot button {
  white-space: nowrap;
}
/* dialogs.css gives .primary-btn width:100% for the login card, unscoped —
   same trap print.css notes for .rp-btn. Here it would crush Reset into two
   lines, so size Done to its label. */
.tpanel-foot .primary-btn {
  width: auto;
  padding: var(--sp-2) var(--sp-6);
}
