/* ═══════════════════════════════════════════════════════════════
   AMES 01 — "Cool Organism" design system
   Shared CSS: variables, typography, base components
   ═══════════════════════════════════════════════════════════════ */

/* ── Fonts ── */
@import url('https://fonts.googleapis.com/css2?family=Instrument+Serif:ital@0;1&family=Inter:wght@300;400;500;600&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── Root variables ── */
:root {
  /* Surfaces */
  --bg:      #EDEEF1;
  --bg-2:    #E3E5EA;
  --bg-3:    #D9DCE4;
  --paper:   #F7F8FB;

  /* Ink */
  --ink:     #1C2634;
  --ink-2:   rgba(28, 38, 52, 0.82);
  --muted:   rgba(28, 38, 52, 0.62);
  --muted-2: rgba(28, 38, 52, 0.40);

  /* Lines — 1px only, never thicker */
  --line:    rgba(28, 38, 52, 0.10);
  --line-2:  rgba(28, 38, 52, 0.18);
  --line-3:  rgba(28, 38, 52, 0.28);

  /* Accents — slate-teal is primary */
  --terra:       #4A7A8C;
  --terra-soft:  rgba(74, 122, 140, 0.12);
  --terra-line:  rgba(74, 122, 140, 0.35);
  --ochre:       #8DA0B5;
  --clay:        #5A6C84;
  --leaf:        #6B8E7F;
  --leaf-soft:   rgba(107, 142, 127, 0.14);
  --leaf-line:   rgba(107, 142, 127, 0.35);

  /* Status */
  --amber:       #B08A3E;
  --amber-soft:  rgba(176, 138, 62, 0.14);
  --amber-line:  rgba(176, 138, 62, 0.30);
  --danger:      #9E4E3E;
  --danger-soft: rgba(158, 78, 62, 0.12);
  --danger-line: rgba(158, 78, 62, 0.30);
  --info:        #4A7A8C;
  --info-soft:   rgba(74, 122, 140, 0.10);

  /* Font stacks */
  --serif: 'Instrument Serif', serif;
  --sans:  'Inter', system-ui, sans-serif;
  --mono:  'JetBrains Mono', monospace;

  /* Shadows — layered depth system */
  --shadow-card:
    0 1px 0 rgba(247, 248, 251, 1) inset,
    0 2px 4px rgba(28, 38, 52, 0.06),
    0 8px 16px -4px rgba(28, 38, 52, 0.10),
    0 20px 40px -8px rgba(28, 38, 52, 0.14),
    0 40px 72px -12px rgba(28, 38, 52, 0.12);
  --shadow-sm:
    0 1px 0 rgba(247, 248, 251, 0.9) inset,
    0 2px 3px rgba(28, 38, 52, 0.05),
    0 6px 14px -2px rgba(28, 38, 52, 0.09),
    0 16px 36px -8px rgba(28, 38, 52, 0.12),
    0 28px 56px -12px rgba(28, 38, 52, 0.08);

  /* Inner element shadows — for 3D-on-3D nesting */
  --shadow-inner:
    0 1px 0 rgba(247, 248, 251, 0.7) inset,
    0 1px 2px rgba(28, 38, 52, 0.06),
    0 3px 8px -2px rgba(28, 38, 52, 0.08),
    0 6px 16px -4px rgba(28, 38, 52, 0.06);
  --shadow-inner-hover:
    0 1px 0 rgba(247, 248, 251, 0.8) inset,
    0 2px 4px rgba(28, 38, 52, 0.08),
    0 6px 14px -2px rgba(28, 38, 52, 0.10),
    0 10px 24px -6px rgba(28, 38, 52, 0.08);
  --shadow-inset:
    0 2px 6px rgba(28, 38, 52, 0.06) inset,
    0 1px 2px rgba(28, 38, 52, 0.04) inset;
}


/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: var(--sans);
  color: var(--ink);
  font-size: 14.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  background:
    radial-gradient(1200px 700px at 50% -100px, rgba(74, 122, 140, 0.13), transparent 60%),
    radial-gradient(900px 600px at 15% 30%, rgba(141, 160, 181, 0.09), transparent 60%),
    radial-gradient(800px 500px at 90% 80%, rgba(107, 142, 127, 0.08), transparent 60%),
    var(--bg);
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font-family: inherit; color: inherit; }


/* ── Utility ── */
.mono {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}


/* ═══════════════════════════════════════════
   TYPOGRAPHY
   ═══════════════════════════════════════════ */

/* Display headings — Instrument Serif with italic emphasis */
h1, h2, h3 {
  font-family: var(--serif);
  font-weight: 400;
  letter-spacing: -0.015em;
  line-height: 1.15;
  margin: 0;
}
h1 { font-size: clamp(26px, 3.5vw, 36px); letter-spacing: -0.022em; line-height: 1.05; }
h2 { font-size: 22px; }
h3 { font-size: 18px; }
h1 em, h2 em, h3 em {
  font-style: italic;
  color: var(--clay);
}

/* Eyebrow labels — mono, tracked, uppercase */
.eyebrow {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.eyebrow.teal { color: var(--terra); }

/* Body stays Inter (inherited from body) */


/* ═══════════════════════════════════════════
   NAVIGATION — floating pill
   ═══════════════════════════════════════════ */

.nav-spacer { height: 72px; }

nav.top {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 32px);
  max-width: 1280px;
  z-index: 100;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  background: rgba(247, 248, 251, 0.85);
  border: 1px solid var(--line-2);
  border-radius: 100px;
  box-shadow: var(--shadow-card);
}

.nav-inner {
  padding: 8px 8px 8px 20px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Logo: orb + italic wordmark */
.logo {
  font-family: var(--serif);
  font-size: 27px;
  font-style: italic;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  flex-shrink: 0;
  margin-right: 10px;
}
.logo-text {
  display: flex;
  flex-direction: column;
  line-height: 1;
}
.logo-word { line-height: 1; }
.logo-orb {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, var(--ochre), var(--terra) 70%);
  box-shadow: 0 0 12px rgba(74, 122, 140, 0.5);
  animation: pulse 3s ease-in-out infinite;
}
@keyframes pulse {
  50% { box-shadow: 0 0 20px rgba(74, 122, 140, 0.75); }
}
/* Brand mark left of the wordmark — theme-aware square logo pair; .logo is
   align-items:center so it vertically centers. width/height attrs on the
   <img>s prevent CLS. Light asset is the default; the dark asset swaps in for
   the manual html.dark toggle and for system dark, while a manual html.light
   choice beats system dark — mirroring the .theme-icon-sun/-moon rules below. */
.logo-img { width: 32px; height: 32px; }
.logo-img.logo-light { display: block; }
.logo-img.logo-dark  { display: none; }
html.dark .logo-img.logo-light { display: none; }
html.dark .logo-img.logo-dark  { display: block; }
@media (prefers-color-scheme: dark) {
  html:not(.light) .logo-img.logo-light { display: none; }
  html:not(.light) .logo-img.logo-dark  { display: block; }
}
/* Wordmark byline, stacked beneath "AMES" — "AMES / by aetherian labs" (HIM-311) */
.logo-sup {
  font-family: var(--mono);
  font-style: normal;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted-2);
  margin-top: 2px;
}
/* Vertical rule between the brand lockup and the nav links, so the taller
   lockup reads as the visual anchor rather than just another nav item. */
.nav-divider {
  width: 1px;
  align-self: stretch;
  background: var(--line-2);
  margin-right: 8px;
}

/* Nav links — darker text */
.nav-links {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1;
  min-width: 0;
}
.nav-link {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-2);
  padding: 7px 13px;
  border-radius: 100px;
  transition: all 0.15s;
  white-space: nowrap;
  text-decoration: none;
  position: relative;
}
.nav-link:hover {
  color: var(--ink);
  background: rgba(28, 38, 52, 0.06);
}
.nav-link.active {
  color: var(--terra);
  background: var(--terra-soft);
  box-shadow: var(--shadow-inner);
}

/* More dropdown */
.more-wrapper { position: relative; }
.more-btn {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-2);
  background: none;
  border: 1px solid var(--line-2);
  padding: 7px 14px;
  border-radius: 100px;
  cursor: pointer;
  transition: all 0.15s;
}
.more-btn:hover, .more-btn.open {
  color: var(--ink);
  background: rgba(28, 38, 52, 0.06);
}
.more-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--paper);
  border: 1px solid var(--line-2);
  border-radius: 14px;
  box-shadow: var(--shadow-card);
  min-width: 200px;
  z-index: 200;
  overflow: hidden;
  padding: 6px;
}
.more-dropdown.show { display: block; }
.more-dropdown a {
  display: block;
  padding: 9px 14px;
  color: var(--ink-2);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  border-radius: 10px;
  transition: all 0.15s;
}
.more-dropdown a:hover { background: var(--bg-2); color: var(--ink); }
.more-dropdown a.active { color: var(--terra); background: var(--terra-soft); box-shadow: var(--shadow-inner); }
.more-dropdown .divider {
  height: 1px;
  background: var(--line);
  margin: 4px 6px;
}

/* Nav right (search + user) */
.nav-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.nav-search {
  display: flex;
  gap: 0;
}
.nav-search input {
  padding: 6px 12px;
  border: 1px solid var(--line-2);
  border-right: none;
  border-radius: 100px 0 0 100px;
  font-size: 12px;
  background: rgba(255, 255, 255, 0.6);
  color: var(--ink);
  outline: none;
  width: 140px;
  transition: all 0.15s;
}
.nav-search input::placeholder { color: var(--muted-2); }
.nav-search input:focus {
  border-color: var(--terra-line);
  background: var(--paper);
  box-shadow: 0 0 0 3px var(--terra-soft);
}
.nav-search button {
  padding: 6px 12px;
  border: 1px solid var(--line-2);
  border-radius: 0 100px 100px 0;
  background: var(--bg-2);
  color: var(--muted);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  transition: all 0.15s;
}
.nav-search button:hover {
  background: var(--terra-soft);
  color: var(--terra);
  border-color: var(--terra-line);
}

.nav-user {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--ink-2);
  padding: 6px 10px;
  transition: color 0.15s;
}
.nav-user:hover { color: var(--terra); }

/* Theme toggle */
.theme-toggle {
  background: none;
  border: 1px solid var(--line-2);
  border-radius: 100px;
  padding: 5px 7px;
  cursor: pointer;
  color: var(--muted);
  display: flex;
  align-items: center;
  transition: all 0.15s;
  box-shadow: var(--shadow-inner);
}
.theme-toggle:hover {
  color: var(--terra);
  border-color: var(--terra-line);
  background: var(--terra-soft);
}
/* Light mode: show moon, hide sun */
.theme-icon-sun  { display: none; }
.theme-icon-moon { display: block; }
/* Dark mode: show sun, hide moon */
html.dark .theme-icon-sun  { display: block; }
html.dark .theme-icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  html:not(.light) .theme-icon-sun  { display: block; }
  html:not(.light) .theme-icon-moon { display: none; }
}

/* Queue badge */
.nav-queue-badge {
  display: none;
  position: absolute;
  top: -2px;
  right: -4px;
  min-width: 15px;
  height: 15px;
  border-radius: 100px;
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 500;
  line-height: 15px;
  text-align: center;
  padding: 0 4px;
  color: var(--paper);
}
.nav-queue-badge.processing { background: var(--terra); }
.nav-queue-badge.error { background: var(--danger); }


/* ═══════════════════════════════════════════
   CONTENT AREA
   ═══════════════════════════════════════════ */

.content {
  max-width: 1240px;
  margin: 0 auto;
  padding: clamp(24px, 3vw, 40px) clamp(20px, 4vw, 40px);
}


/* ═══════════════════════════════════════════
   CARDS
   ═══════════════════════════════════════════ */



/* ═══════════════════════════════════════════
   BUTTONS — pill-shaped, three variants
   ═══════════════════════════════════════════ */

.btn-05b {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 20px;
  border-radius: 100px;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  line-height: 1.3;
}

/* Primary — slate-teal gradient */
.btn-05b-primary {
  background: linear-gradient(135deg, #4A7A8C, #345C6E);
  color: var(--paper);
  border-color: transparent;
  box-shadow:
    0 1px 0 rgba(255,255,255,0.2) inset,
    0 4px 12px -4px rgba(74, 122, 140, 0.4);
}
.btn-05b-primary:hover {
  transform: translateY(-1px);
  box-shadow:
    0 1px 0 rgba(255,255,255,0.2) inset,
    0 6px 16px -4px rgba(74, 122, 140, 0.5);
  color: var(--paper);
}

/* Default — paper bg with border */
.btn-05b-default {
  background: var(--paper);
  color: var(--ink);
  border-color: var(--line-2);
  box-shadow: var(--shadow-inner);
}
.btn-05b-default:hover {
  border-color: var(--terra);
  color: var(--terra);
  transform: translateY(-1px);
  box-shadow: var(--shadow-inner-hover);
}

/* Ghost — transparent */
.btn-05b-ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--line);
  box-shadow: var(--shadow-inner);
}
.btn-05b-ghost:hover {
  color: var(--terra);
  border-color: var(--terra-line);
  box-shadow: var(--shadow-inner-hover);
}

/* Size variants */
.btn-05b-sm { padding: 6px 14px; font-size: 12px; }
.btn-05b-lg { padding: 12px 28px; font-size: 14px; }


/* ═══════════════════════════════════════════
   CHIPS & TAGS
   ═══════════════════════════════════════════ */



/* ═══════════════════════════════════════════
   FORM INPUTS
   ═══════════════════════════════════════════ */



/* ═══════════════════════════════════════════
   CLINICAL CONTENT — mono, high legibility
   Overrides the serif used elsewhere.
   ═══════════════════════════════════════════ */

.section-textarea {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.7;
  color: var(--ink);
  resize: vertical;
  min-height: 60px;
  padding: 14px 16px;
}
.section-textarea::placeholder {
  color: var(--muted-2);
  font-style: italic;
}

/* Focus on parent card, not the textarea itself */
.section-card:focus-within {
  border-color: var(--terra-line);
  box-shadow: var(--shadow-card), 0 0 0 4px var(--terra-soft);
}

/* Transcript box — mono for clinical accuracy */
.transcript-box {
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.75;
  color: var(--ink-2);
  box-shadow: var(--shadow-inset);
  border-radius: 12px;
}


/* ═══════════════════════════════════════════
   SECTION CARDS (note editor)
   ═══════════════════════════════════════════ */

.section-card {
  background: var(--paper);
  border: 1px solid var(--line-2);
  border-radius: 16px;
  margin-bottom: 14px;
  overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s;
  box-shadow: var(--shadow-sm);
}

.section-body {
  padding: 0;
  background: var(--paper);
  box-shadow: var(--shadow-inset);
}


/* ═══════════════════════════════════════════
   ALERTS & FLASH MESSAGES
   ═══════════════════════════════════════════ */

.flash-messages {
  max-width: 1240px;
  margin: 16px auto 0;
  padding: 0 clamp(20px, 4vw, 40px);
}

.alert {
  padding: 12px 18px;
  border-radius: 14px;
  margin-bottom: 12px;
  font-size: 13.5px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid;
  box-shadow: var(--shadow-inner);
}
.alert-success {
  background: var(--leaf-soft);
  color: #2D5A46;
  border-color: var(--leaf-line);
}
.alert-danger {
  background: var(--danger-soft);
  color: #6B2E24;
  border-color: var(--danger-line);
}
.alert-warning {
  background: var(--amber-soft);
  color: #6B5420;
  border-color: var(--amber-line);
}
.alert-info {
  background: var(--info-soft);
  color: #2A5564;
  border-color: var(--terra-line);
}


/* ═══════════════════════════════════════════
   TOAST NOTIFICATIONS
   ═══════════════════════════════════════════ */

.toast-05b {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  max-width: 400px;
  width: calc(100vw - 40px);
  border-radius: 16px;
  box-shadow: var(--shadow-card);
  overflow: hidden;
  animation: toastSlide 0.3s ease;
  display: none;
  border: 1px solid;
}
.toast-05b.show { display: block; }

.toast-05b.error {
  background: var(--paper);
  border-color: var(--danger-line);
}
.toast-05b.warning {
  background: var(--paper);
  border-color: var(--amber-line);
}

.toast-header {
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.toast-header.error { background: var(--danger-soft); }
.toast-header.warning { background: var(--amber-soft); }

.toast-header-text {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 500;
}
.toast-header.error .toast-header-text { color: var(--danger); }
.toast-header.warning .toast-header-text { color: var(--amber); }

.toast-close {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 2px;
}
.toast-close:hover { color: var(--ink); }

.toast-body {
  padding: 14px 16px;
  font-size: 13px;
  color: var(--ink-2);
}
.toast-actions {
  padding: 8px 16px 14px;
  display: flex;
  gap: 8px;
}

@keyframes toastSlide {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}


/* ═══════════════════════════════════════════
   GDRIVE ALERT BANNER
   ═══════════════════════════════════════════ */

.gdrive-banner {
  padding: 10px clamp(20px, 4vw, 40px);
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid;
}
.gdrive-banner.error {
  background: var(--danger-soft);
  color: #6B2E24;
  border-color: var(--danger-line);
}
.gdrive-banner.warning {
  background: var(--amber-soft);
  color: #6B5420;
  border-color: var(--amber-line);
}
.gdrive-banner a {
  font-weight: 600;
  text-decoration: underline;
  margin-left: 6px;
}
.gdrive-banner.error a { color: #6B2E24; }
.gdrive-banner.warning a { color: #6B5420; }


/* ═══════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════ */

@media (max-width: 900px) {
  nav.top { border-radius: 24px; }
  .nav-links { gap: 0; }
  .nav-link { padding: 6px 8px; font-size: 10px; letter-spacing: 0.1em; }
  .nav-search input { width: 100px; }
}

@media (max-width: 768px) {
  nav.top {
    border-radius: 20px;
    top: 8px;
    width: calc(100% - 16px);
  }
  .nav-inner {
    flex-wrap: wrap;
    padding: 8px 12px;
    gap: 6px;
  }
  .nav-links {
    order: 3;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .nav-links::-webkit-scrollbar { display: none; }
  .nav-right {
    order: 2;
    margin-left: auto;
  }
  .nav-search { display: none; }
  .nav-spacer { height: 100px; }
  /* The tracked-out byline is the widest line in the stacked lockup — drop it
     here to give the (already cramped, pre-existing) scrollable nav-links
     strip back some of the room the taller lockup takes from it. */
  .logo-sup { display: none; }
}


/* ═══════════════════════════════════════════
   DARK MODE
   Activates via OS preference OR .dark class
   on <html> (for manual toggle — Phase 4).
   ═══════════════════════════════════════════ */

@media (prefers-color-scheme: dark) {
  :root:not(.light) {
    /* Surfaces */
    --bg:      #151A22;
    --bg-2:    #1A2030;
    --bg-3:    #212838;
    --paper:   #1E2530;

    /* Ink — warm off-white, not pure white */
    --ink:     #D8DDE6;
    --ink-2:   rgba(216, 221, 230, 0.82);
    --muted:   rgba(200, 210, 225, 0.55);
    --muted-2: rgba(200, 210, 225, 0.35);

    /* Lines — light base, lower opacity */
    --line:    rgba(200, 210, 225, 0.08);
    --line-2:  rgba(200, 210, 225, 0.14);
    --line-3:  rgba(200, 210, 225, 0.22);

    /* Accents — lifted for contrast on dark surfaces */
    --terra:       #6AACBF;
    --terra-soft:  rgba(106, 172, 191, 0.14);
    --terra-line:  rgba(106, 172, 191, 0.30);
    --ochre:       #A3B8CC;
    --clay:        #8599B0;
    --leaf:        #88B5A3;
    --leaf-soft:   rgba(136, 181, 163, 0.14);
    --leaf-line:   rgba(136, 181, 163, 0.30);

    /* Status */
    --amber:       #D4A94E;
    --amber-soft:  rgba(212, 169, 78, 0.14);
    --amber-line:  rgba(212, 169, 78, 0.28);
    --danger:      #C8685A;
    --danger-soft: rgba(200, 104, 90, 0.14);
    --danger-line: rgba(200, 104, 90, 0.28);
    --info:        #6AACBF;
    --info-soft:   rgba(106, 172, 191, 0.12);

    /* Shadows — darker, no white inset highlights */
    --shadow-card:
      0 2px 4px rgba(0, 0, 0, 0.20),
      0 8px 16px -4px rgba(0, 0, 0, 0.28),
      0 20px 40px -8px rgba(0, 0, 0, 0.22);
    --shadow-sm:
      0 2px 3px rgba(0, 0, 0, 0.16),
      0 6px 14px -2px rgba(0, 0, 0, 0.22),
      0 16px 36px -8px rgba(0, 0, 0, 0.18);
    --shadow-inner:
      0 1px 2px rgba(0, 0, 0, 0.18),
      0 3px 8px -2px rgba(0, 0, 0, 0.16);
    --shadow-inner-hover:
      0 2px 4px rgba(0, 0, 0, 0.22),
      0 6px 14px -2px rgba(0, 0, 0, 0.18);
    --shadow-inset:
      0 2px 6px rgba(0, 0, 0, 0.18) inset,
      0 1px 2px rgba(0, 0, 0, 0.12) inset;
  }

  /* Body gradient — same structure, muted for dark */
  html:not(.light) body {
    background:
      radial-gradient(1200px 700px at 50% -100px, rgba(106, 172, 191, 0.08), transparent 60%),
      radial-gradient(900px 600px at 15% 30%, rgba(163, 184, 204, 0.05), transparent 60%),
      radial-gradient(800px 500px at 90% 80%, rgba(136, 181, 163, 0.04), transparent 60%),
      var(--bg);
  }

  /* Nav — dark frosted glass */
  html:not(.light) nav.top {
    background: rgba(30, 37, 48, 0.88);
    border-color: var(--line-2);
  }

  /* Alerts — dark-safe text colors */
  html:not(.light) .alert-success { color: var(--leaf); }
  html:not(.light) .alert-danger  { color: var(--danger); }
  html:not(.light) .alert-warning { color: var(--amber); }
  html:not(.light) .alert-info    { color: var(--terra); }

  /* GDrive banners */
  html:not(.light) .gdrive-banner.error   { color: var(--danger); }
  html:not(.light) .gdrive-banner.warning { color: var(--amber); }
  html:not(.light) .gdrive-banner.error a   { color: var(--danger); }
  html:not(.light) .gdrive-banner.warning a { color: var(--amber); }

  /* Search input — darker field */
  html:not(.light) .nav-search input {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--line-2);
  }
  html:not(.light) .nav-search input:focus {
    background: var(--bg-2);
  }

  /* Form elements — dark backgrounds */
  html:not(.light) input,
  html:not(.light) textarea,
  html:not(.light) select {
    background: var(--bg-2);
    color: var(--ink);
    border-color: var(--line-2);
  }
  html:not(.light) input::placeholder,
  html:not(.light) textarea::placeholder {
    color: var(--muted-2);
  }
  html:not(.light) input:focus,
  html:not(.light) textarea:focus,
  html:not(.light) select:focus {
    background: var(--bg-3);
  }

  /* Audio player — dark controls */
  html:not(.light) audio,
  html:not(.light) .td-audio {
    color-scheme: dark;
    background: var(--bg-2);
    border-radius: 18px;
  }

  /* Scrollbar */
  html:not(.light) ::-webkit-scrollbar { width: 8px; }
  html:not(.light) ::-webkit-scrollbar-track { background: var(--bg); }
  html:not(.light) ::-webkit-scrollbar-thumb { background: var(--line-3); border-radius: 4px; }
  html:not(.light) ::-webkit-scrollbar-thumb:hover { background: var(--muted-2); }
}

/* Manual toggle: html.dark overrides regardless of OS preference */
html.dark {
  /* Surfaces */
  --bg:      #151A22;
  --bg-2:    #1A2030;
  --bg-3:    #212838;
  --paper:   #1E2530;

  --ink:     #D8DDE6;
  --ink-2:   rgba(216, 221, 230, 0.82);
  --muted:   rgba(200, 210, 225, 0.55);
  --muted-2: rgba(200, 210, 225, 0.35);

  --line:    rgba(200, 210, 225, 0.08);
  --line-2:  rgba(200, 210, 225, 0.14);
  --line-3:  rgba(200, 210, 225, 0.22);

  --terra:       #6AACBF;
  --terra-soft:  rgba(106, 172, 191, 0.14);
  --terra-line:  rgba(106, 172, 191, 0.30);
  --ochre:       #A3B8CC;
  --clay:        #8599B0;
  --leaf:        #88B5A3;
  --leaf-soft:   rgba(136, 181, 163, 0.14);
  --leaf-line:   rgba(136, 181, 163, 0.30);

  --amber:       #D4A94E;
  --amber-soft:  rgba(212, 169, 78, 0.14);
  --amber-line:  rgba(212, 169, 78, 0.28);
  --danger:      #C8685A;
  --danger-soft: rgba(200, 104, 90, 0.14);
  --danger-line: rgba(200, 104, 90, 0.28);
  --info:        #6AACBF;
  --info-soft:   rgba(106, 172, 191, 0.12);

  --shadow-card:
    0 2px 4px rgba(0, 0, 0, 0.20),
    0 8px 16px -4px rgba(0, 0, 0, 0.28),
    0 20px 40px -8px rgba(0, 0, 0, 0.22);
  --shadow-sm:
    0 2px 3px rgba(0, 0, 0, 0.16),
    0 6px 14px -2px rgba(0, 0, 0, 0.22),
    0 16px 36px -8px rgba(0, 0, 0, 0.18);
  --shadow-inner:
    0 1px 2px rgba(0, 0, 0, 0.18),
    0 3px 8px -2px rgba(0, 0, 0, 0.16);
  --shadow-inner-hover:
    0 2px 4px rgba(0, 0, 0, 0.22),
    0 6px 14px -2px rgba(0, 0, 0, 0.18);
  --shadow-inset:
    0 2px 6px rgba(0, 0, 0, 0.18) inset,
    0 1px 2px rgba(0, 0, 0, 0.12) inset;
}

html.dark body {
  background:
    radial-gradient(1200px 700px at 50% -100px, rgba(106, 172, 191, 0.08), transparent 60%),
    radial-gradient(900px 600px at 15% 30%, rgba(163, 184, 204, 0.05), transparent 60%),
    radial-gradient(800px 500px at 90% 80%, rgba(136, 181, 163, 0.04), transparent 60%),
    var(--bg);
}

html.dark nav.top {
  background: rgba(30, 37, 48, 0.88);
  border-color: var(--line-2);
}

html.dark .alert-success { color: var(--leaf); }
html.dark .alert-danger  { color: var(--danger); }
html.dark .alert-warning { color: var(--amber); }
html.dark .alert-info    { color: var(--terra); }

html.dark .gdrive-banner.error   { color: var(--danger); }
html.dark .gdrive-banner.warning { color: var(--amber); }
html.dark .gdrive-banner.error a   { color: var(--danger); }
html.dark .gdrive-banner.warning a { color: var(--amber); }

html.dark ::-webkit-scrollbar { width: 8px; }
html.dark ::-webkit-scrollbar-track { background: var(--bg); }
html.dark ::-webkit-scrollbar-thumb { background: var(--line-3); border-radius: 4px; }
html.dark ::-webkit-scrollbar-thumb:hover { background: var(--muted-2); }

html.dark .nav-search input {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--line-2);
}
html.dark .nav-search input:focus {
  background: var(--bg-2);
}

html.dark input,
html.dark textarea,
html.dark select {
  background: var(--bg-2);
  color: var(--ink);
  border-color: var(--line-2);
}
html.dark input::placeholder,
html.dark textarea::placeholder {
  color: var(--muted-2);
}
html.dark input:focus,
html.dark textarea:focus,
html.dark select:focus {
  background: var(--bg-3);
}

html.dark audio,
html.dark .td-audio {
  color-scheme: dark;
  background: var(--bg-2);
  border-radius: 18px;
}
