/* =========================================================
   Tokens — Duolingo-style: bold flat saturated colors, thick dark
   ink outlines, chunky pressable shapes. No soft gradients/glows.
   Dark-only (no light/dark toggle).
   ========================================================= */
:root {
  color-scheme: dark;
  --page: #14141f;
  --surface: #1e1e2e;
  --surface-2: #292940;
  --text-primary: #ffffff;
  --text-secondary: #c7c3dd;
  --text-muted: #8d89a8;
  --ink: #14121f;
  --border: rgba(255,255,255,0.14);
  --gridline: #38344f;

  /* Categorical (data encoding) — bold, distinct, always paired with a
     text label (never color-alone identification). Order below is the
     CVD-safe adjacency order validated for the filter-chip row — don't
     reorder without re-running scripts/validate_palette.js (dataviz skill). */
  --cat-dopamine_protectors: #0b7fc4;
  --cat-dopamine_boosters: #d9720b;
  --cat-dopamine_hunting: #d55181;
  --cat-stabilisers: #008300;
  --cat-lifestyle: #c98500;
  --cat-devices: #8b4fd9;
  --cat-dopamine_blockers: #d6304a;
  --cat-investigational: #0f9488;
  --cat-uncategorized: #5b5a72;

  /* Status (reserved — never a categorical slot; admin danger/error UI) */
  --danger: #d6304a;

  --ev-rct: #0b5fa8;
  --ev-observational: #1678c2;
  --ev-mixed: #2a8fd6;
  --ev-anecdotal: #5fafe0;
  --ev-animal: #9ecdec;

  /* Bold flat accent set (chrome/buttons/brain — not data encoding) */
  --brand-green: #4cbb17;
  --brand-blue: #1cb0f6;
  --brand-red: #ff4b4b;
  --brand-yellow: #ffc700;
  --brand-purple: #b06cff;
  --brand-orange: #ff9600;
  --brand-pink: #ff6dc6;

  --accent: var(--brand-green);
  --focus-ring: var(--brand-blue);
  --radius: 18px;
  --radius-lg: 24px;
  --bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; overflow-anchor: none; }
body {
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.5;
  display: flex; flex-direction: column; min-height: 100vh;
}

.skip-link {
  position: absolute; left: -999px; top: 0;
  background: var(--surface); color: var(--text-primary);
  padding: 8px 14px; border-radius: 0 0 8px 0; z-index: 100;
}
.skip-link:focus { left: 0; }

:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* =========================================================
   Pressable "sticker button" base — thick ink border + hard offset
   shadow that collapses on press. The core Duolingo motif.
   ========================================================= */
.pressable {
  border: 3px solid var(--ink);
  border-radius: 999px;
  box-shadow: 0 4px 0 var(--ink);
  transition: transform 0.12s var(--bounce), box-shadow 0.12s var(--bounce);
}
.pressable:hover { transform: translateY(-2px); box-shadow: 0 6px 0 var(--ink); }
.pressable:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }

/* =========================================================
   Layout
   ========================================================= */
.site-header {
  display: flex; flex-wrap: wrap; gap: 16px;
  align-items: center; justify-content: space-between;
  padding: 18px 24px; border-bottom: 3px solid var(--ink);
  background: var(--surface);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 14px; text-decoration: none; color: inherit; }
.logo { width: 46px; height: 46px; border-radius: 14px; border: 3px solid var(--ink); }
.site-title {
  margin: 0; font-weight: 900; font-size: 1.3rem; letter-spacing: -0.01em;
  color: var(--brand-green);
}
.site-tagline { margin: 0; color: var(--text-secondary); font-size: 0.92rem; }

main {
  max-width: 1080px; margin: 0 auto; padding: 28px 24px;
  flex: 1 1 auto; width: 100%;
  display: flex; flex-direction: column;
}
section { margin-bottom: 56px; }
h1, h2 { letter-spacing: -0.02em; }
h2 { font-size: 1.7rem; font-weight: 900; }
.section-sub { color: var(--text-secondary); margin-top: -6px; }
.muted { color: var(--text-muted); }

/* =========================================================
   Hub — click-through home screen
   ========================================================= */
.hub-stage {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 0;
}
.hub-stage[hidden] { display: none !important; }

/* Transient "curtain" transition — built and torn down entirely in JS
   (animateToView). The incoming panel is placed in its normal resting
   position immediately (a one-time layout cost, paid once up front, same
   as any ordinary navigation). #hub-stage itself is lifted out of flow
   into this fixed-position, opaque overlay — sized/positioned to exactly
   where the stage already was — and only the overlay's `transform` is
   animated, sliding it up and off-screen to reveal the panel underneath.
   Because the overlay only contains the (small, cheap) hub tiles, not the
   panel, its layer promotion/paint cost is independent of how heavy the
   panel is — unlike animating the panel's own container, where a heavy
   panel (e.g. the substances grid) made layer prep expensive enough to
   stall the animation and show up as a jump partway through. */
.hub-slide-overlay {
  position: fixed;
  background: var(--page);
  overflow: hidden;
  will-change: transform;
  z-index: 20;
}
.hub-slide-overlay .hub-stage { width: 100%; height: 100%; }

.hub {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px;
  max-width: 820px; margin: 0 auto;
}
.hub-tile:last-child:nth-child(odd) { grid-column: 1 / -1; }
@media (max-width: 640px) {
  .hub { grid-template-columns: 1fr; }
  .hub-stage { flex: 0 0 auto; justify-content: flex-start; }
}

.hub-tile {
  display: flex; flex-direction: column; gap: 10px; align-items: flex-start;
  text-align: left; text-decoration: none; color: var(--text-primary);
  background: var(--surface); border: 3px solid var(--ink); border-radius: var(--radius-lg);
  padding: 20px 26px; border-top-width: 8px;
  box-shadow: 0 5px 0 var(--ink);
  transition: transform 0.15s var(--bounce), box-shadow 0.15s var(--bounce);
}
.hub-tile:hover { transform: translateY(-4px); box-shadow: 0 8px 0 var(--ink); }
.hub-tile:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.hub-tile[data-accent="green"] { border-top-color: var(--brand-green); }
.hub-tile[data-accent="red"] { border-top-color: var(--brand-red); }
.hub-tile[data-accent="pink"] { border-top-color: var(--brand-pink); }
.hub-tile[data-accent="blue"] { border-top-color: var(--brand-blue); }
.hub-tile[data-accent="yellow"] { border-top-color: var(--brand-yellow); }
.hub-tile .tile-icon { font-size: 2.3rem; line-height: 1; }
.hub-tile h2 { margin: 0; font-size: 1.25rem; }
.hub-tile p { margin: 0; color: var(--text-secondary); font-size: 0.92rem; }

/* =========================================================
   View panels — one full "page" shown at a time, no scroll-through
   ========================================================= */
.view-panel[hidden] { display: none !important; }
.view-panel { animation: panel-in 0.22s var(--bounce); }
@keyframes panel-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.panel-back {
  font: inherit; font-weight: 800; font-size: 0.9rem; cursor: pointer;
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2); color: var(--text-primary);
  border: 3px solid var(--brand-blue); border-radius: 999px;
  box-shadow: 0 4px 0 var(--brand-blue);
  padding: 9px 22px 9px 18px; margin: 0 auto 22px;
  transition: transform 0.15s var(--bounce), box-shadow 0.15s var(--bounce), background-color 0.15s ease;
}
.panel-back span {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; font-size: 0.7rem; line-height: 1;
  background: var(--brand-blue); color: var(--ink); border-radius: 50%;
}
.panel-back:hover {
  background: var(--brand-blue); color: var(--ink);
  transform: translateY(-2px);
  box-shadow: 0 6px 0 var(--brand-blue);
}
.panel-back:hover span { background: var(--ink); color: var(--brand-blue); }
.panel-back:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--brand-blue); }

/* Brain explorer */
.brain-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 16px; }
@media (max-width: 760px) { .brain-layout { grid-template-columns: 1fr; } }

.brain-diagram-wrap {
  background: var(--surface); border: 3px solid var(--ink);
  border-radius: var(--radius-lg); padding: 16px;
}
#brain-svg { width: 100%; height: auto; }

.brain-shape { fill: #f5e6d3; stroke: var(--ink); stroke-width: 5; stroke-linejoin: round; }
.brain-shape.dim { fill: #e8d0b0; }
.fissure-line { fill: none; stroke: var(--ink); stroke-width: 3; stroke-linecap: round; opacity: 0.4; }

.region {
  stroke: var(--ink); stroke-width: 3;
  cursor: pointer; transition: transform 0.18s var(--bounce);
  transform-box: fill-box; transform-origin: center;
}
#region-pfc { fill: var(--brand-red); }
#region-acc { fill: var(--brand-purple); }
#region-striatum { fill: var(--brand-blue); }
#region-accumbens { fill: var(--brand-yellow); }
#region-amygdala { fill: var(--brand-orange); }
#region-locus-coeruleus { fill: var(--brand-pink); }

.region:hover { transform: scale(1.08); }
.region.active { transform: scale(1.15); stroke-width: 4; }
.region:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }

.region-list {
  list-style: none; margin: 0 0 16px; padding: 0;
  display: flex; flex-wrap: wrap; gap: 10px;
}
.region-list button {
  font: inherit; font-size: 0.9rem; font-weight: 700;
  background: var(--surface-2); color: var(--text-primary);
  padding: 9px 18px; cursor: pointer;
}
.region-list button[aria-pressed="true"] {
  background: var(--brand-green); color: var(--ink);
}

.region-detail {
  background: var(--surface); border: 3px solid var(--ink);
  border-radius: var(--radius); padding: 18px 22px; min-height: 120px;
}
.region-detail h3 { margin-top: 0; }
.region-detail .effect-list { list-style: none; margin: 12px 0 0; padding: 0; }
.region-detail .effect-list li {
  padding: 10px 0; border-top: 2px dashed var(--gridline);
  display: flex; flex-direction: column; gap: 2px;
}

/* =========================================================
   ADHD explanation + reels carousel
   ========================================================= */
.adhd-explainer p { max-width: 70ch; color: var(--text-secondary); }

.reel-carousel {
  display: flex; gap: 16px; overflow-x: auto; padding: 12px 4px 16px;
  scroll-snap-type: x mandatory;
}
.reel-card {
  flex: 0 0 200px; aspect-ratio: 9 / 16; scroll-snap-align: start;
  background: var(--surface); border: 3px solid var(--ink); border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center; text-align: center;
  padding: 16px; color: var(--text-muted); font-size: 0.85rem;
  position: relative; overflow: hidden;
}
.reel-card iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.reel-card .placeholder-badge {
  position: absolute; top: 10px; left: 10px; background: var(--brand-pink); color: var(--ink);
  font-size: 0.7rem; font-weight: 800; padding: 3px 9px; border-radius: 999px; border: 2px solid var(--ink);
}

/* =========================================================
   Content creators grid
   ========================================================= */
.creators-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 16px; margin-top: 8px;
}
.creator-card {
  aspect-ratio: 1 / 1; border-radius: var(--radius); border: 3px solid var(--ink);
  background: var(--surface-2); position: relative; overflow: hidden;
  display: flex; align-items: flex-end; text-decoration: none;
}
.creator-card img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.creator-card .creator-name {
  position: relative; z-index: 1; background: rgba(20,18,31,0.75); color: #fff;
  font-weight: 700; font-size: 0.85rem; padding: 8px 10px; width: 100%;
}
.creator-card .platform-badge {
  position: absolute; top: 8px; right: 8px; width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; border: 2px solid var(--ink);
}
.platform-badge.instagram { background: var(--brand-pink); }
.platform-badge.youtube { background: var(--brand-red); }
.platform-badge svg { width: 16px; height: 16px; }
.creator-card.placeholder {
  align-items: center; justify-content: center; color: var(--text-muted); font-size: 0.8rem; text-align: center; padding: 10px;
}

/* =========================================================
   Filters
   ========================================================= */
.filters {
  display: flex; flex-wrap: wrap; gap: 20px; align-items: end;
  margin: 16px 0;
}
.filter-group { display: flex; flex-direction: column; gap: 6px; }
.filter-group label { font-size: 0.85rem; color: var(--text-secondary); font-weight: 700; }
#category-filters { flex-direction: row; flex-wrap: wrap; align-self: end; gap: 14px; }
.cat-chip {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 168px;
  font: inherit; font-size: 0.92rem; font-weight: 800; letter-spacing: 0.15px;
  padding: 13px 26px 13px 82px; cursor: pointer;
  background: color-mix(in srgb, var(--chip-accent, var(--brand-blue)) 50%, white 50%);
  color: #fff;
  text-shadow:
    -1px -1px 0 var(--ink), 1px -1px 0 var(--ink),
    -1px 1px 0 var(--ink), 1px 1px 0 var(--ink),
    0 2px 3px rgba(0,0,0,0.35);
  border: 3px solid var(--ink); border-radius: 999px;
  box-shadow: 0 4px 0 var(--ink);
  transition: transform 0.15s var(--bounce), box-shadow 0.15s var(--bounce),
    border-color 0.15s ease, background-color 0.15s ease, outline-color 0.15s ease;
}
/* Capsule cap: a fixed-width colored half with a seam, like a two-tone pill */
.cat-chip::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 64px;
  background: var(--chip-accent, var(--brand-blue));
  border-radius: 999px 0 0 999px;
  border-right: 2px solid var(--ink);
}
.cat-chip:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 0 var(--ink);
  border-color: var(--chip-accent, var(--brand-blue));
}
.cat-chip:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.cat-chip[aria-pressed="true"] {
  background: color-mix(in srgb, var(--chip-accent, var(--brand-green)) 82%, white 18%);
  outline: 3px solid var(--chip-accent, var(--brand-green));
  outline-offset: 2px;
}
.cat-chip[aria-pressed="true"]::before { background: var(--chip-accent, var(--brand-green)); }

select, input[type="search"] {
  font: inherit; padding: 10px 12px; border-radius: 12px;
  border: 3px solid var(--ink); background: var(--surface); color: var(--text-primary);
}
select:focus, input[type="search"]:focus { border-color: var(--focus-ring); }

.legend { font-size: 0.85rem; color: var(--text-secondary); padding: 12px 0; }
.ev-badge {
  display: inline-block; font-size: 0.75rem; font-weight: 800;
  color: #fff; border-radius: 8px; padding: 3px 9px; margin-right: 4px;
  border: 2px solid var(--ink);
}
.ev-rct { background: var(--ev-rct); }
.ev-observational { background: var(--ev-observational); }
.ev-mixed { background: var(--ev-mixed); }
.ev-animal { background: var(--ev-animal); color: var(--ink); }
.ev-anecdotal { background: var(--ev-anecdotal); color: var(--ink); }
.ev-badge[data-tooltip] { cursor: help; }

/* =========================================================
   Tooltips — small CSS-only popovers for anything with a
   [data-tooltip] attribute (evidence badges, category chips).
   ========================================================= */
[data-tooltip] { position: relative; }
[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute; left: 50%; bottom: calc(100% + 10px);
  transform: translate(-50%, 4px);
  background: var(--surface-2); color: var(--text-primary);
  border: 2px solid var(--ink); border-radius: 10px; box-shadow: 0 3px 0 var(--ink);
  font-size: 0.78rem; font-weight: 700; line-height: 1.35; letter-spacing: 0.1px;
  padding: 8px 12px; width: max-content; max-width: 220px; text-align: center;
  white-space: normal;
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
  z-index: 30;
}
[data-tooltip]:hover::after, [data-tooltip]:focus-visible::after {
  opacity: 1; visibility: visible; transform: translate(-50%, 0);
}

/* =========================================================
   Substance namecards — colored by category (header band), not
   just a small dot next to text.
   ========================================================= */
.substance-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 28px; margin-top: 8px;
}
.substance-card {
  background: var(--surface); border: 3px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: 0 6px 0 var(--ink), 0 14px 28px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.08);
  display: flex; flex-direction: column;
  transition: transform 0.15s var(--bounce), box-shadow 0.15s var(--bounce);
}
.substance-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 9px 0 var(--ink), 0 20px 34px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.08);
}

.card-header {
  padding: 10px 18px; display: flex;
  background: var(--surface-2); border-bottom: 3px solid var(--ink);
  border-radius: calc(var(--radius) - 3px) calc(var(--radius) - 3px) 0 0;
}
.cat-pill {
  display: inline-flex; align-items: center;
  font-weight: 800; font-size: 0.72rem; letter-spacing: 0.03em;
  text-transform: uppercase; color: #fff;
  padding: 5px 14px; border: 2px solid var(--ink); border-radius: 999px;
  box-shadow: 0 2px 0 var(--ink);
  text-shadow: 0 1px 0 rgba(0,0,0,0.4);
}
.cat-pill.uncategorized { color: var(--text-primary); text-shadow: none; }
.card-body { padding: 16px 18px 18px; display: flex; flex-direction: column; gap: 10px; flex: 1; }
.substance-card h3 { margin: 0; font-size: 1.08rem; }

.mech-tags { display: flex; flex-wrap: wrap; gap: 6px; font-size: 0.78rem; color: var(--text-secondary); }
.mech-tags span { background: var(--surface-2); border-radius: 8px; padding: 3px 9px; }

.card-detail { border-top: 2px dashed var(--gridline); padding-top: 10px; margin-top: 4px; }
.card-detail { display: none; }
.substance-card.expanded .card-detail { display: block; }
.expand-btn {
  align-self: stretch; display: flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--surface-2); color: var(--text-primary);
  border: 3px solid var(--ink); border-radius: 999px;
  box-shadow: 0 3px 0 var(--ink);
  cursor: pointer; font: inherit; font-weight: 800; font-size: 0.85rem;
  padding: 9px 16px; margin-top: auto;
  transition: transform 0.15s var(--bounce), box-shadow 0.15s var(--bounce), background-color 0.15s ease, color 0.15s ease;
}
.expand-btn:hover {
  background: var(--brand-blue); color: var(--ink);
  transform: translateY(-2px); box-shadow: 0 5px 0 var(--ink);
}
.expand-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }

.site-footer {
  border-top: 3px solid var(--ink); padding: 24px; margin-top: 20px;
  color: var(--text-muted); font-size: 0.85rem; text-align: center;
}
@media (max-width: 640px) {
  .site-footer { margin-top: 0; }
}
.footer-ref { margin-top: 6px; }
.footer-ref a { color: var(--brand-blue); }

/* =========================================================
   About panel
   ========================================================= */
.about-content { max-width: 70ch; }
.about-content h3 { margin-top: 40px; font-size: 1.25rem; }
.about-content p { color: var(--text-secondary); }
