/* ═══════════════════════════════════════════════════════════════
   Nitesh Upreti — themes.css  (shared by every page)

   ONE source of truth for colour. Each palette defines the same raw
   tokens for dark + light; everything derived (glows, prose, bento)
   is computed once from --accent-rgb in the "derived tokens" block.

   Selector map (all on <html>):
     :root / html[data-theme="light"]              → Rosé Pine (default)
     html[data-palette="x"]                        → palette x, dark
     html[data-palette="x"][data-theme="light"]    → palette x, light

   To add a palette: copy a block below, change the values, then add
   the same id/name/preview colours to PALETTES in /theme.js.
   Keep this file and the PALETTES array in /theme.js in sync
   (README → "Adding a theme").
   ═══════════════════════════════════════════════════════════════ */

/* ── Rosé Pine — Dusk lavender & warm gold ─────────────────────── */
:root,
html[data-palette="rose-pine"] {
  color-scheme: dark;
  --bg: #16141d;
  --bg-alt: #1e1c28;
  --bg-card: #23212f;
  --bg-glass: rgba(30, 28, 40, 0.72);
  --border: rgba(255, 255, 255, 0.07);
  --border-soft: rgba(255, 255, 255, 0.04);
  --text: #e8e3f0;
  --text-muted: #8b85a1;
  --text-faint: #504a63;
  --accent: #c4a0d0;
  --accent-secondary: #e8a87c;
  --accent-rgb: 196, 160, 208;
  --rain-3: #7ad69a;
  --ok: #4ade80;
  --ok-rgb: 74, 222, 128;
  --term-bg: #0d0c14;
  --term-text: #e8e3f0;
  --term-a: #c4a0d0;
  --term-b: #e8a87c;
  --term-ok: #4ade80;
  --scrim-rgb: 13, 12, 20;
  --veil-rgb: 10, 9, 16;
  --bg-rgb: 22, 20, 29;
}

html[data-theme="light"],
html[data-palette="rose-pine"][data-theme="light"] {
  color-scheme: light;
  --bg: #f5f0eb;
  --bg-alt: #ede8e2;
  --bg-card: #ffffff;
  --bg-glass: rgba(245, 240, 235, 0.82);
  --border: rgba(0, 0, 0, 0.08);
  --border-soft: rgba(0, 0, 0, 0.04);
  --text: #1a1625;
  --text-muted: #6b6478;
  --text-faint: #b0a8c0;
  --accent: #8b5c9e;
  --accent-secondary: #c4752a;
  --accent-rgb: 139, 92, 158;
  --rain-3: #2e7a4a;
  --ok: #4ade80;
  --ok-rgb: 74, 222, 128;
  --term-bg: #1a1625;
  --term-text: #e8e3f0;
  --term-a: #c4a0d0;
  --term-b: #e8a87c;
  --term-ok: #4ade80;
  --scrim-rgb: 13, 12, 20;
  --veil-rgb: 10, 9, 16;
  --bg-rgb: 245, 240, 235;
}

/* ── Mandarin Forest — Forest green, mandarin & crest yellow ─────────────────────── */
html[data-palette="mandarin-forest"] {
  color-scheme: dark;
  --bg: #0d1b12;
  --bg-alt: #12251a;
  --bg-card: #173023;
  --bg-glass: rgba(18, 37, 26, 0.72);
  --border: rgba(220, 255, 230, 0.08);
  --border-soft: rgba(220, 255, 230, 0.045);
  --text: #eef3e2;
  --text-muted: #94ab9b;
  --text-faint: #4d6656;
  --accent: #f28500;
  --accent-secondary: #ffd23f;
  --accent-rgb: 242, 133, 0;
  --rain-3: #5fd37a;
  --ok: #3fb558;
  --ok-rgb: 63, 181, 88;
  --term-bg: #07120b;
  --term-text: #eef3e2;
  --term-a: #f28500;
  --term-b: #ffd23f;
  --term-ok: #3fb558;
  --scrim-rgb: 6, 16, 10;
  --veil-rgb: 5, 13, 8;
  --bg-rgb: 13, 27, 18;
}

html[data-palette="mandarin-forest"][data-theme="light"] {
  color-scheme: light;
  --bg: #f7f3e3;
  --bg-alt: #eee8d0;
  --bg-card: #fffdf6;
  --bg-glass: rgba(247, 243, 227, 0.82);
  --border: rgba(18, 38, 26, 0.10);
  --border-soft: rgba(18, 38, 26, 0.05);
  --text: #12261a;
  --text-muted: #4f6556;
  --text-faint: #9fb1a3;
  --accent: #1f6f35;
  --accent-secondary: #c25e00;
  --accent-rgb: 31, 111, 53;
  --rain-3: #a87a00;
  --ok: #3fb558;
  --ok-rgb: 63, 181, 88;
  --term-bg: #0f2418;
  --term-text: #eef3e2;
  --term-a: #f28500;
  --term-b: #ffd23f;
  --term-ok: #3fb558;
  --scrim-rgb: 6, 16, 10;
  --veil-rgb: 5, 13, 8;
  --bg-rgb: 247, 243, 227;
}

/* ── Midnight Electric — Midnight black, electric blue & cantaloupe ─────────────────────── */
html[data-palette="midnight-electric"] {
  color-scheme: dark;
  --bg: #05070d;
  --bg-alt: #0a0e18;
  --bg-card: #0f1524;
  --bg-glass: rgba(10, 14, 24, 0.72);
  --border: rgba(140, 170, 255, 0.11);
  --border-soft: rgba(140, 170, 255, 0.055);
  --text: #e7ecfb;
  --text-muted: #8a95b5;
  --text-faint: #444d6a;
  --accent: #4a86ff;
  --accent-secondary: #ffa571;
  --accent-rgb: 74, 134, 255;
  --rain-3: #6fe3ff;
  --ok: #35e0a1;
  --ok-rgb: 53, 224, 161;
  --term-bg: #02040a;
  --term-text: #e7ecfb;
  --term-a: #4a86ff;
  --term-b: #ffa571;
  --term-ok: #35e0a1;
  --scrim-rgb: 2, 4, 10;
  --veil-rgb: 1, 3, 8;
  --bg-rgb: 5, 7, 13;
}

html[data-palette="midnight-electric"][data-theme="light"] {
  color-scheme: light;
  --bg: #fff4ea;
  --bg-alt: #ffe8d6;
  --bg-card: #fffaf5;
  --bg-glass: rgba(255, 244, 234, 0.82);
  --border: rgba(10, 18, 48, 0.10);
  --border-soft: rgba(10, 18, 48, 0.05);
  --text: #0a1230;
  --text-muted: #55608a;
  --text-faint: #a9b1cf;
  --accent: #1f4fe0;
  --accent-secondary: #c94f12;
  --accent-rgb: 31, 79, 224;
  --rain-3: #0f8aa8;
  --ok: #16a97a;
  --ok-rgb: 22, 169, 122;
  --term-bg: #0a1230;
  --term-text: #e7ecfb;
  --term-a: #4a86ff;
  --term-b: #ffa571;
  --term-ok: #35e0a1;
  --scrim-rgb: 2, 4, 10;
  --veil-rgb: 1, 3, 8;
  --bg-rgb: 255, 244, 234;
}

/* ── Mocha Silver — Mocha brown, platinum silver & pale lavender ─────────────────────── */
html[data-palette="mocha-silver"] {
  color-scheme: dark;
  --bg: #17110f;
  --bg-alt: #201816;
  --bg-card: #2a201d;
  --bg-glass: rgba(32, 24, 22, 0.72);
  --border: rgba(236, 232, 244, 0.08);
  --border-soft: rgba(236, 232, 244, 0.045);
  --text: #ece8f2;
  --text-muted: #a79d9f;
  --text-faint: #6a5d5c;
  --accent: #d9dbe3;
  --accent-secondary: #c9b8ee;
  --accent-rgb: 217, 219, 227;
  --rain-3: #b08968;
  --ok: #9bd8b4;
  --ok-rgb: 155, 216, 180;
  --term-bg: #0e0908;
  --term-text: #ece8f2;
  --term-a: #d9dbe3;
  --term-b: #c9b8ee;
  --term-ok: #9bd8b4;
  --scrim-rgb: 14, 9, 8;
  --veil-rgb: 10, 6, 5;
  --bg-rgb: 23, 17, 15;
}

html[data-palette="mocha-silver"][data-theme="light"] {
  color-scheme: light;
  --bg: #f3eff8;
  --bg-alt: #e8e2f1;
  --bg-card: #fbf9fd;
  --bg-glass: rgba(243, 239, 248, 0.82);
  --border: rgba(61, 42, 36, 0.10);
  --border-soft: rgba(61, 42, 36, 0.05);
  --text: #2b1d19;
  --text-muted: #6e5f5c;
  --text-faint: #b3a9b8;
  --accent: #5c4033;
  --accent-secondary: #7c62b8;
  --accent-rgb: 92, 64, 51;
  --rain-3: #8a8f9c;
  --ok: #3f9b6a;
  --ok-rgb: 63, 155, 106;
  --term-bg: #241815;
  --term-text: #ece8f2;
  --term-a: #d9dbe3;
  --term-b: #c9b8ee;
  --term-ok: #9bd8b4;
  --scrim-rgb: 14, 9, 8;
  --veil-rgb: 10, 6, 5;
  --bg-rgb: 243, 239, 248;
}


/* ── Aubergine Marigold — ice silver, deep aubergine & marigold ─────────────────────── */
html[data-palette="aubergine-marigold"] {
  color-scheme: dark;
  --bg: #120e16;
  --bg-alt: #1a1420;
  --bg-card: #241b2c;
  --bg-glass: rgba(26, 20, 32, 0.74);
  --border: rgba(184, 196, 212, 0.12);
  --border-soft: rgba(184, 196, 212, 0.06);
  --text: #ebe8f0;
  --text-muted: #9a93ab;
  --text-faint: #5c556e;
  --accent: #f0b429;
  --accent-secondary: #b8c4d4;
  --accent-rgb: 240, 180, 41;
  --rain-3: #c4a0e0;
  --ok: #6ed9a0;
  --ok-rgb: 110, 217, 160;
  --term-bg: #0a080f;
  --term-text: #ebe8f0;
  --term-a: #f0b429;
  --term-b: #b8c4d4;
  --term-ok: #6ed9a0;
  --scrim-rgb: 10, 8, 15;
  --veil-rgb: 8, 6, 12;
  --bg-rgb: 18, 14, 22;
}

html[data-palette="aubergine-marigold"][data-theme="light"] {
  color-scheme: light;
  --bg: #f3f5f9;
  --bg-alt: #e6eaf2;
  --bg-card: #ffffff;
  --bg-glass: rgba(243, 245, 249, 0.84);
  --border: rgba(42, 24, 48, 0.10);
  --border-soft: rgba(42, 24, 48, 0.05);
  --text: #2a1830;
  --text-muted: #5c4d66;
  --text-faint: #a89ab0;
  --accent: #6b2a78;
  --accent-secondary: #c9920c;
  --accent-rgb: 107, 42, 120;
  --rain-3: #8a96a8;
  --ok: #2a9a62;
  --ok-rgb: 42, 154, 98;
  --term-bg: #1e1424;
  --term-text: #ebe8f0;
  --term-a: #f0b429;
  --term-b: #b8c4d4;
  --term-ok: #6ed9a0;
  --scrim-rgb: 10, 8, 15;
  --veil-rgb: 8, 6, 12;
  --bg-rgb: 243, 245, 249;
}

/* ── Derived tokens (never edit per palette) ─────────────────── */
:root {
  --accent-glow: rgba(var(--accent-rgb), 0.15);
  --accent-glow-strong: rgba(var(--accent-rgb), 0.25);
  --bento-glow-rgb: var(--accent-rgb);
  --bento-glow: rgba(var(--accent-rgb), 0.5);
  --bento-glow-soft: rgba(var(--accent-rgb), 0.22);
  --prose-code-bg: rgba(var(--accent-rgb), 0.08);
  --prose-pre-bg: var(--term-bg);
  --prose-border: rgba(var(--accent-rgb), 0.2);
  --prose-quote-bg: rgba(var(--accent-rgb), 0.06);
}

html[data-theme="light"] {
  --accent-glow: rgba(var(--accent-rgb), 0.1);
  --accent-glow-strong: rgba(var(--accent-rgb), 0.2);
  --bento-glow: rgba(var(--accent-rgb), 0.4);
  --bento-glow-soft: rgba(var(--accent-rgb), 0.16);
  --prose-code-bg: rgba(var(--accent-rgb), 0.08);
  --prose-border: rgba(var(--accent-rgb), 0.25);
  --prose-quote-bg: rgba(var(--accent-rgb), 0.05);
}

/* ═══════════════════════════════════════════════════════════════
   Theme switcher UI (button in the navbar + popover / bottom sheet)
   Built by /theme.js — styled entirely from the palette tokens above,
   so it re-skins itself with whichever palette is active.
   ═══════════════════════════════════════════════════════════════ */

/* Circular reveal when the palette / mode changes (View Transitions) */
::view-transition-old(root),
::view-transition-new(root) {
  animation: none;
  mix-blend-mode: normal;
}
::view-transition-old(root) { z-index: 1; }
::view-transition-new(root) { z-index: 2; }

/* While a transition snapshot is taken, don't let colour transitions fight it */
html.theme-switching *,
html.theme-switching *::before,
html.theme-switching *::after {
  transition: none !important;
}

/* ── Navbar button ───────────────────────────────────────────────
   A minimal hanging scroll: a flat paper tab held between two hairline rods, a half-moon mark and a
   label (mark only on phones). No ring, no swatches, no brass. /theme.js drives its position. */

/* the paper stock, shared by the tab and the sheet. Its colour comes FROM the selected palette (the
   palette's own surface colour with a measured dose of its accent), so every palette gets its own paper:
   dusk-lavender, forest-green, midnight-blue... */
.palette-btn,
.theme-panel {
  --paper: color-mix(in srgb, var(--bg-alt) 93%, var(--accent));
  --rod: color-mix(in srgb, var(--accent) 38%, var(--text-muted));
  --tex-grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n' x='0' y='0' width='100%25' height='100%25'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='2.6 0 0 0 -.8 2.6 0 0 0 -.8 2.6 0 0 0 -.8 0 0 0 0 1'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  --tex-fibre: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='360' height='260'%3E%3Cfilter id='f' x='0' y='0' width='100%25' height='100%25'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.012 .5' numOctaves='2' seed='7' stitchTiles='stitch'/%3E%3CfeColorMatrix values='2.4 0 0 0 -.7 2.4 0 0 0 -.7 2.4 0 0 0 -.7 0 0 0 0 1'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23f)'/%3E%3C/svg%3E");
  /* a hanging sheet curves away at its two edges, so they are in shade */
  --edge-shade: linear-gradient(90deg, rgba(0, 0, 0, 0.13) 0%, rgba(0, 0, 0, 0.04) 3.5%, transparent 10%, transparent 90%, rgba(0, 0, 0, 0.04) 96.5%, rgba(0, 0, 0, 0.13) 100%);
}
html[data-theme="dark"] .palette-btn,
html[data-theme="dark"] .theme-panel {
  --paper: color-mix(in srgb, var(--bg-card) 88%, var(--accent));
  --tex-grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n' x='0' y='0' width='100%25' height='100%25' color-interpolation-filters='sRGB'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' seed='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .94  0 0 0 0 .94  0 0 0 0 .94  1.6 0 0 0 -.62'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  --tex-fibre: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='360' height='260'%3E%3Cfilter id='f' x='0' y='0' width='100%25' height='100%25' color-interpolation-filters='sRGB'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.01 .55' numOctaves='2' seed='7' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .95  0 0 0 0 .95  0 0 0 0 .95  1.8 0 0 0 -.78'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23f)'/%3E%3C/svg%3E");
  --edge-shade: linear-gradient(90deg, rgba(0, 0, 0, 0.30) 0%, rgba(0, 0, 0, 0.10) 3.5%, transparent 10%, transparent 90%, rgba(0, 0, 0, 0.10) 96.5%, rgba(0, 0, 0, 0.30) 100%);
}

.palette-btn {
  position: relative;
  isolation: isolate;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  height: 34px;                       /* = PULL.BTN_H in theme.js */
  padding: 0 0.85rem 0 0.7rem;
  margin: 0 5px;                      /* room for the rods' overhang */
  border-radius: 4px;                 /* paper between two rods: nearly square */
  border: 1px solid var(--border);
  /* the faintest curl where the paper turns round each rod, and the same edge shade as the sheet */
  background-image: var(--edge-shade), linear-gradient(180deg, rgba(0, 0, 0, 0.1) 0%, transparent 24%, transparent 76%, rgba(0, 0, 0, 0.1) 100%);
  background-color: color-mix(in srgb, var(--paper) 55%, transparent);
  transform-origin: 50% 0;            /* it hangs from its hanger: swings and stretches from the top */
  --pp: 0;                            /* 0..1 how close the pull is to the point of no return (set by /theme.js) */
  color: var(--text-muted);
  font: 500 0.72rem/1 var(--font-mono, monospace);
  letter-spacing: 0.05em;
  cursor: grab;
  touch-action: none;                 /* dragging the tab must never scroll the page */
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  /* NB: no transform transition: /theme.js positions the tab every frame while it is pulled */
  transition: color 0.25s, background-color 0.25s, border-color 0.25s, box-shadow 0.25s;
}
.palette-btn[data-grabbing] { cursor: grabbing; }
.palette-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }

/* a roomier place to grab: an invisible zone around the tab (kept a little shorter on the right so
   the hamburger beside it still gets its own taps) */
.pal-hit { position: absolute; inset: -16px -8px -20px -16px; }

/* the two rods: thin, flat, a hair wider than the paper */
.pal-rod {
  position: absolute;
  left: -3px;
  right: -3px;
  height: 3px;
  z-index: 1;
  border-radius: 2px;
  background: var(--rod);
  pointer-events: none;
  transition: background 0.25s;
}
.pal-rod-t { top: -2px; transition: opacity 0.2s, background 0.25s; }
.pal-rod-b { bottom: -2px; }

.pal-mark {
  width: 14px;
  height: 14px;
  flex: none;
  color: var(--accent);
  transition: transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* hover / open / pulled: the rods and the border pick up the accent, nothing else moves */
.palette-btn:hover,
.palette-btn[aria-expanded="true"],
.palette-btn[data-grabbing] { color: var(--text); }
.palette-btn:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.palette-btn:hover .pal-rod,
.palette-btn[aria-expanded="true"] .pal-rod,
.palette-btn[data-grabbing] .pal-rod { background: var(--accent); }
.palette-btn:hover .pal-mark { transform: rotate(25deg); }

/* once the tab leaves the header it is solid paper with the sheet's own grain, hanging in front of the page */
.palette-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;                        /* above the paper, under the mark and the label */
  border-radius: inherit;
  pointer-events: none;
  background: var(--tex-grain) 0 0 / 200px 200px;
  opacity: 0;
  transition: opacity 0.25s;
}
.palette-btn[data-pulled],
.palette-btn[data-grabbing],
.palette-btn[aria-expanded="true"] {
  background-color: var(--paper);
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
}
.palette-btn[data-pulled]::before,
.palette-btn[data-grabbing]::before,
.palette-btn[aria-expanded="true"]::before { opacity: 0.16; }
html[data-theme="light"] .palette-btn[data-pulled]::before,
html[data-theme="light"] .palette-btn[data-grabbing]::before,
html[data-theme="light"] .palette-btn[aria-expanded="true"]::before { opacity: 0.45; mix-blend-mode: overlay; }

/* the scroll is out: the tab is the sheet's own tail, hanging straight from the sheet's rod. Same paper,
   no seam: its own top rod and top border go, and the rod above casts a little shade onto it. */
.palette-btn[aria-expanded="true"] {
  border-top-color: transparent;
  border-radius: 0 0 4px 4px;
  background-image: var(--edge-shade), linear-gradient(180deg, rgba(0, 0, 0, 0.22) 0%, transparent 34%, transparent 76%, rgba(0, 0, 0, 0.1) 100%);
}
.palette-btn[aria-expanded="true"] .pal-rod-t { opacity: 0; }
.palette-btn[data-grabbing] {
  box-shadow:
    0 0 0 calc(var(--pp) * 3px) rgba(var(--accent-rgb), calc(var(--pp) * 0.18)),
    0 10px 20px -12px rgba(0, 0, 0, 0.7);
}
/* past the point of no return (release now and the scroll finishes the job) */
.palette-btn[data-armed] {
  color: var(--text);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.2), 0 10px 22px -12px rgba(0, 0, 0, 0.7);
}
.palette-btn[data-armed] .pal-mark { animation: pal-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes pal-pop { 0% { transform: scale(1); } 35% { transform: scale(1.25); } 100% { transform: scale(1); } }

/* first visit only: the lower rod dips like a tug on a cord, to say "pull me" */
.palette-btn.is-new .pal-rod-b { animation: pal-tug 2.4s ease-in-out 1.2s infinite; }
@keyframes pal-tug { 0%, 55%, 100% { transform: translateY(0); } 70% { transform: translateY(3px); } 85% { transform: translateY(0.5px); } }

/* a little tip under the tab: says what to do, then "release" once the pull has gone far enough */
.pal-tip {
  position: absolute;
  z-index: 3;
  left: 50%;
  top: calc(100% + 14px);
  padding: 0.3rem 0.55rem;
  border-radius: 5px;
  background: var(--paper);
  border: 1px solid var(--border);
  box-shadow: 0 6px 14px -8px rgba(0, 0, 0, 0.55);
  color: var(--text);
  font: 500 0.64rem/1 var(--font-mono, monospace);
  letter-spacing: 0.06em;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -4px);
  transition: opacity 0.2s, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.pal-tip b { font-weight: 500; }
.pal-tip-pull::after { content: ' \2193'; color: var(--accent); }     /* ↓ */
.pal-tip-rel { display: none; color: var(--accent); }
.palette-btn[data-armed] .pal-tip-pull { display: none; }
.palette-btn[data-armed] .pal-tip-rel { display: inline; }
.palette-btn[data-hint] .pal-tip,
.palette-btn[data-grabbing]:not([data-was-open]) .pal-tip { opacity: 1; transform: translate(-50%, 0); }
@media (hover: hover) and (pointer: fine) {
  .palette-btn:hover:not([data-pulled]):not([aria-expanded="true"]) .pal-tip { opacity: 1; transform: translate(-50%, 0); }
}

/* the chain the tab hangs from while it is pulled out of the header: it comes down from the top edge of
   the screen. Alternating links, one face-on and one edge-on, drawn as a mask so it takes the accent
   colour. (/theme.js places it and reveals it with clip-path + opacity; it sits behind the tab) */
.theme-strap {
  position: absolute;
  z-index: 0;
  width: 10px;
  pointer-events: none;
  opacity: 0;
  clip-path: inset(0 0 100% 0);
  background: color-mix(in srgb, var(--accent) 60%, var(--text-muted));
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 24' width='10' height='24'%3E%3Crect x='1' y='1' width='8' height='13' rx='4' fill='none' stroke='%23000' stroke-width='1.6'/%3E%3Crect x='3.7' y='9' width='2.6' height='15' rx='1.3'/%3E%3Crect x='3.7' y='0' width='2.6' height='2'/%3E%3C/svg%3E") repeat-y 0 0 / 10px 24px;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 24' width='10' height='24'%3E%3Crect x='1' y='1' width='8' height='13' rx='4' fill='none' stroke='%23000' stroke-width='1.6'/%3E%3Crect x='3.7' y='9' width='2.6' height='15' rx='1.3'/%3E%3Crect x='3.7' y='0' width='2.6' height='2'/%3E%3C/svg%3E") repeat-y 0 0 / 10px 24px;
}

/* phones: just the mark, a clean 34 × 34 tab (the hamburger sits right beside it) */
@media (max-width: 767px) {
  .palette-btn { width: 34px; padding: 0; gap: 0; margin: 0 4px; }
  .pal-btn-label { display: none; }
}

/* Keep the navbar clear of the pull-rope that hangs at the far right */
@media (max-width: 1240px) {
  .navbar .nav-inner { padding-right: 3.2rem; }
}

/* Compact navbar (hamburger visible): logo left, controls grouped right */
.nav-inner.nav-compact { gap: 0.55rem; }
.nav-inner.nav-compact .palette-btn { margin-left: auto; }
.nav-inner.nav-compact .hamburger { margin-left: 0.2rem; }

/* ── Scrim + scroll ──────────────────────────────────────────────
   While the scroll is out the header is lifted above it (so the tab hangs in
   front) and the rope stays in front of everything. */
html.theme-live .navbar,
html.theme-open .navbar { z-index: 1210; }
html.theme-live .rope-switch,
html.theme-open .rope-switch { z-index: 1215; }

.theme-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1190;
  opacity: 0;                       /* phones: /theme.js fades it in with the scroll */
  pointer-events: none;
}
.theme-backdrop.open { pointer-events: auto; }

/* The "window" the scroll unrolls out of. Its top edge is the bottom of the header, so the
   sheet is hidden above that line. overflow:hidden (not clip-path) keeps backdrop-filter working;
   the generous side/bottom gutters just let the sheet's big soft shadow show. */
.theme-panel {
  --tp-ext: 46px;                   /* = PULL.EXT in theme.js */
  --tp-gx: 130px;
  --tp-gb: 190px;
  position: fixed;
  z-index: 1200;
  top: var(--tp-top, 64px);
  right: calc(var(--tp-right, 16px) - var(--tp-gx));
  width: calc(var(--tp-w, 720px) + var(--tp-gx) * 2);
  height: calc(var(--tp-fh, 520px) + var(--tp-gb));
  padding: 0 var(--tp-gx);
  box-sizing: border-box;
  overflow: hidden;
  pointer-events: none;
  visibility: hidden;
}
.theme-panel.is-live { visibility: visible; }

/* the sheet itself: a hanging paper scroll. Square-cornered (paper has no radius), opaque, coloured by the
   selected palette (--paper), curved away at both edges, with a faint aged shade at its margins. */
.tp-sheet {
  position: relative;
  padding: calc(var(--tp-ext) + 1.5rem) 1.2rem 1.6rem;   /* .tp-body below relies on these exact paddings */
  border-radius: 0 0 2px 2px;
  color: var(--text);
  --paper-grain: 0.5;               /* strength of the paper texture */
  --paper-fibre: 0.32;
  background:
    var(--edge-shade),
    linear-gradient(180deg, rgba(var(--accent-rgb), 0.06) 0%, rgba(var(--accent-rgb), 0) 30%, rgba(0, 0, 0, 0) 74%, rgba(0, 0, 0, 0.07) 100%),
    var(--paper);
  border: 1px solid color-mix(in srgb, var(--accent) 22%, var(--border));
  border-top: none;
  box-shadow:
    0 26px 50px -22px rgba(0, 0, 0, 0.55),
    inset 0 0 26px -8px rgba(0, 0, 0, 0.16);
  overflow: hidden;
  overflow: clip;                   /* the sheet clips its own text: the paper is uncovered while the text stays put */
}
/* paper tooth and long fibres (light mode: neutral grey blended over the palette colour, so the hue is
   always the selected palette's). They live on the sheet, so they travel with the paper. */
.tp-sheet::before,
.tp-sheet::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  mix-blend-mode: overlay;
}
.tp-sheet::before { background: var(--tex-grain) 0 0 / 220px 220px; opacity: var(--paper-grain); }
.tp-sheet::after  { background: var(--tex-fibre) 0 0 / 360px 260px; opacity: var(--paper-fibre); }

/* Dark mode: dark paper in the palette's colour. Pale specks and fibres in normal blend read as paper
   tooth rather than dirt; the margins are a little deeper. */
html[data-theme="dark"] .tp-sheet {
  background:
    var(--edge-shade),
    radial-gradient(120% 70% at 50% 0%, rgba(var(--accent-rgb), 0.09), transparent 62%),
    linear-gradient(180deg, transparent 68%, rgba(0, 0, 0, 0.2) 100%),
    var(--paper);
  box-shadow:
    0 24px 48px -20px rgba(0, 0, 0, 0.75),
    inset 0 0 34px -8px rgba(0, 0, 0, 0.4);
}
html[data-theme="dark"] .tp-sheet::before { mix-blend-mode: normal; background-size: 200px 200px; opacity: 0.16; }
html[data-theme="dark"] .tp-sheet::after  { mix-blend-mode: normal; opacity: 0.12; }

/* /theme.js moves this (sheet + rod) down as one piece and counter-moves the body inside, so the rod leads
   and the paper unrolls beneath it without the text sliding */
.tp-move {
  position: relative;
  transform-origin: 50% 0;          /* the sheet hangs from the header line and swings from there */
  transform: translate3d(0, -110%, 0);
  pointer-events: none;
}
.theme-panel.is-live .tp-move { pointer-events: auto; will-change: transform; }
.tp-body { position: relative; z-index: 1; will-change: transform; }   /* text sits above the paper texture */

/* the part of the scroll that is still rolled up, at the leading edge: a paper cylinder that shrinks as the
   sheet comes off it (/theme.js scales it) */
.tp-roll {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 26px;
  transform-origin: 50% 100%;
  background:
    var(--edge-shade),
    repeating-linear-gradient(180deg, rgba(0, 0, 0, 0.1) 0 1px, transparent 1px 4px),       /* the layers of paper wound on the rod */
    linear-gradient(180deg, rgba(0, 0, 0, 0.16) 0%, rgba(255, 255, 255, 0.12) 28%, rgba(255, 255, 255, 0.02) 55%, rgba(0, 0, 0, 0.34) 100%),
    var(--paper);
  pointer-events: none;
}

/* where the paper turns round the rod: a soft shadow that is strongest while the scroll is mostly rolled */
.tp-curl {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 30px;
  transform-origin: 50% 100%;
  background: linear-gradient(0deg, rgba(0, 0, 0, 0.30) 0%, rgba(0, 0, 0, 0.10) 45%, transparent 100%);
  pointer-events: none;
}

/* on a short screen the content scrolls inside the sheet (the rod and tab stay put) */
.tp-body {
  margin: 0 -1.2rem;                /* full sheet width, so the clipping edge is the sheet's edge */
  padding: 0 1.2rem;
  max-height: calc(var(--tp-cap, 640px) - 1.5rem - 1.6rem);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* soft shadow where the sheet slips out from under the header */
.tp-slot {
  position: absolute;
  left: var(--tp-gx);
  right: var(--tp-gx);
  top: 0;
  height: 24px;
  z-index: 3;
  pointer-events: none;
  opacity: 0;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.42), rgba(0, 0, 0, 0.16) 42%, transparent);
  border-top: 1px solid rgba(var(--accent-rgb), 0.35);
}

/* the rod along the bottom edge: a slim dowel in the same tone as the tab's rods; grab it to roll the scroll back up */
.tp-rod {
  transform-origin: 50% 0;
  position: absolute;
  left: -6px;
  right: -6px;
  bottom: -5px;
  height: 10px;
  border-radius: 5px;
  cursor: grab;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  background: linear-gradient(180deg,
    color-mix(in srgb, var(--rod) 82%, #fff) 0%,
    var(--rod) 45%,
    color-mix(in srgb, var(--rod) 72%, #000) 100%);
  box-shadow: 0 6px 12px -6px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(0, 0, 0, 0.18);
}
.tp-rod::before,
.tp-rod::after {
  content: '';
  position: absolute;
  top: -1.5px;
  width: 5px;
  height: 13px;
  border-radius: 3px;
  background: color-mix(in srgb, var(--rod) 76%, #000);
}
.tp-rod::before { left: -3px; }
.tp-rod::after  { right: -3px; }
html.theme-live .tp-rod:active { cursor: grabbing; }
/* …and a roomier place to grab the rod too */
.tp-rod-hit { position: absolute; left: -6px; right: -6px; top: -14px; bottom: -16px; }

.tp-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin: 0.1rem 0.15rem 1rem;
  padding-bottom: 0.7rem;
  border-bottom: 1px solid rgba(var(--accent-rgb), 0.24);    /* a ruled line under the heading, like ink on the scroll */
}
.tp-title {
  font-family: 'Iowan Old Style', 'Palatino Linotype', Palatino, 'Book Antiqua', Georgia, serif;
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: 0;
}
.tp-sub {
  font: 400 0.68rem/1.3 var(--font-mono, monospace);
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

/* Light / Dark segmented control with a sliding thumb */
.tp-modes {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 4px;
  margin-bottom: 1.1rem;
  border-radius: 14px;
  background: rgba(var(--accent-rgb), 0.07);
  border: 1px solid var(--border-soft);
}
.tp-thumb {
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: 4px;
  width: calc(50% - 4px);
  border-radius: 10px;
  background: color-mix(in srgb, var(--paper) 70%, var(--bg-card));
  border: 1px solid var(--border);
  box-shadow: 0 6px 18px -6px rgba(var(--accent-rgb), 0.55), 0 0 0 1px rgba(var(--accent-rgb), 0.12);
  transition: transform 0.5s var(--spring, cubic-bezier(0.34, 1.56, 0.64, 1));
}
.tp-modes[data-mode="dark"] .tp-thumb { transform: translateX(100%); }

.tp-mode {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 0.5rem;
  border: none;
  background: none;
  border-radius: 10px;
  color: var(--text-muted);
  font: 500 0.78rem/1 var(--font-body, system-ui);
  cursor: pointer;
  transition: color 0.3s;
  -webkit-tap-highlight-color: transparent;
}
.tp-mode svg { width: 15px; height: 15px; transition: transform 0.5s var(--spring, ease), color 0.3s; }
.tp-mode[aria-checked="true"] { color: var(--text); }
.tp-mode[aria-checked="true"] svg { color: var(--accent); transform: rotate(-12deg) scale(1.1); }
.tp-mode:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.tp-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0.15rem 0.6rem;
  font: 400 0.66rem/1 var(--font-mono, monospace);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.tp-label b { font-weight: 500; color: var(--accent); }

/* ── Spotlight Frames palette picker ─────────────────────────── */
.sf { padding: 26px 0; }          /* room for the selector's guide lines */

.sf-track {
  position: relative;
  height: 250px;
  --sf-ew: 210px;
}

.sf-slat {
  position: absolute;
  top: 0;
  height: 100%;
  padding: 0;
  overflow: hidden;
  border: none;
  border-radius: 14px;
  background: var(--bg-card);
  color: #fff;
  font: inherit;
  text-align: left;
  cursor: pointer;
  box-shadow: 0 0 0 1px rgba(128, 128, 128, 0.25), 0 14px 26px -16px rgba(0, 0, 0, 0.7);
  -webkit-tap-highlight-color: transparent;
}
.sf-slat:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* long circular ease-out — the whole character of the motion */
.sf-track.sf-ready .sf-slat,
.sf-track.sf-ready .sf-sel {
  transition: left 0.75s cubic-bezier(0.075, 0.82, 0.165, 1), width 0.75s cubic-bezier(0.075, 0.82, 0.165, 1);
}

/* the artwork is always drawn at the open width and centred, so a closed slat
   shows the middle strip of it and the picture holds still while it opens */
.sf-art {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: var(--sf-ew);
  margin-left: calc(var(--sf-ew) / -2);
  overflow: hidden;
  filter: brightness(0.6) saturate(0.85);
  transition: filter 0.6s cubic-bezier(0.075, 0.82, 0.165, 1);
}
.sf-slat.is-open .sf-art { filter: none; }
.sf-slat:hover:not(.is-open) .sf-art { filter: brightness(0.8) saturate(0.95); }

.sf-shade {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(var(--scrim-rgb), 0.94) 0%, rgba(var(--scrim-rgb), 0.78) 30%, rgba(var(--scrim-rgb), 0.3) 52%, transparent 72%);
  opacity: 0;
  transition: opacity 0.5s 0.1s;
}
.sf-slat.is-open .sf-shade { opacity: 1; }

/* the SAME mini screen in both modes, split on a diagonal */
.pv {
  position: absolute;
  inset: 0;
  background: var(--pv-bg);
  transition: clip-path 0.7s cubic-bezier(0.075, 0.82, 0.165, 1);
}
.pv-light { clip-path: polygon(60% 0, 100% 0, 100% 100%, 34% 100%); }
.sf-slat.is-open .pv-light { clip-path: polygon(48% 0, 100% 0, 100% 100%, 22% 100%); }
.pv i { position: absolute; display: block; }
.pv-bar   { left: 8%; right: 8%; top: 7%; height: 4px; border-radius: 3px; background: var(--pv-text); opacity: 0.16; }
.pv-dot   { left: 8%; top: 7%; width: 6px; height: 4px; border-radius: 3px; background: var(--pv-a); opacity: 1; }
.pv-l1    { left: 8%; top: 22%; width: 54%; height: 9px; border-radius: 5px; background: var(--pv-text); }
.pv-l2    { left: 8%; top: 33%; width: 38%; height: 6px; border-radius: 3px; background: var(--pv-b); }
.pv-btn   { left: 8%; top: 46%; width: 26%; height: 12px; border-radius: 6px; background: var(--pv-a); }
.pv-btn2  { left: 38%; top: 46%; width: 20%; height: 12px; border-radius: 6px; box-shadow: inset 0 0 0 1.5px var(--pv-text); opacity: 0.35; }
.pv-card  { left: 8%; right: 8%; top: 62%; height: 15%; border-radius: 7px; background: var(--pv-card); box-shadow: 0 0 0 1px rgba(128, 128, 128, 0.25); }

/* name + note appear only on the open slat */
.sf-label {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: var(--sf-ew);
  margin-left: calc(var(--sf-ew) / -2);
  padding: 0 0.85rem 0.8rem;
  display: block;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.25s, transform 0.45s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
}
.sf-slat.is-open .sf-label { opacity: 1; transform: none; transition-delay: 0.22s; }
.sf-label b { display: block; font-size: 0.9rem; font-weight: 600; letter-spacing: -0.01em; line-height: 1.2; }
.sf-label small { display: block; margin-top: 0.2rem; font-size: 0.66rem; line-height: 1.35; color: rgba(255, 255, 255, 0.78); }
.sf-dots { display: flex; gap: 5px; margin-top: 0.5rem; }
.sf-dots i { width: 10px; height: 10px; border-radius: 50%; box-shadow: 0 0 0 1.5px rgba(255, 255, 255, 0.55); }

/* applied palette badge */
.sf-check {
  position: absolute;
  top: 9px;
  left: 50%;
  width: 22px;
  height: 22px;
  margin-left: -11px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: var(--bg);
  box-shadow: 0 4px 12px -2px rgba(0, 0, 0, 0.55), 0 0 0 2px rgba(255, 255, 255, 0.35);
  transform: scale(0);
  transition: transform 0.5s var(--spring, cubic-bezier(0.34, 1.56, 0.64, 1));
}
.sf-check svg { width: 12px; height: 12px; }
.sf-slat[aria-checked="true"] .sf-check { transform: scale(1); }

/* selector: hairline box around the open slat + a guide line out of its top and bottom */
.sf-sel {
  position: absolute;
  top: 0;
  height: 100%;
  border: 2px solid var(--accent);
  border-radius: 14px;
  pointer-events: none;
  z-index: 5;
  box-shadow: 0 0 22px -4px rgba(var(--accent-rgb), 0.7), inset 0 0 14px -6px rgba(var(--accent-rgb), 0.5);
}
.sf-sel::before,
.sf-sel::after {
  content: '';
  position: absolute;
  left: 50%;
  width: 2px;
  height: 18px;
  margin-left: -1px;
  background: var(--accent);
  box-shadow: 0 0 10px rgba(var(--accent-rgb), 0.8);
}
.sf-sel::before { bottom: 100%; border-radius: 2px 2px 0 0; }
.sf-sel::after  { top: 100%;    border-radius: 0 0 2px 2px; }

/* ── Phones: same scroll, just full width, with a dimming scrim behind it ── */
@media (max-width: 640px) {
  .theme-backdrop { background: rgba(var(--scrim-rgb), 0.58); }
  .sf-track { height: 270px; }
}

html.theme-sheet-open { overflow: hidden; }

@media (prefers-reduced-motion: reduce) {
  .palette-btn .pal-rod, .palette-btn .pal-mark { animation: none !important; }
  .tp-thumb, .pv, .pal-mark, .sf-slat, .sf-sel, .sf-art, .sf-label, .sf-check { transition-duration: 0.01ms !important; }
}