/* =========================================================
   Cannabis & the Brain — interactive 3D atlas
   Palette and type shared with the About page:
   cream / navy / azure / sky, Fraunces over Hanken Grotesk.

   Performance note: cream cards composite over a canvas that repaints every
   frame, so there are deliberately no backdrop-filters and no blend modes
   here — both forced a full-viewport re-raster on every single frame.
   ========================================================= */

:root {
  --studio: #93a9c0; /* matches the WebGL clear colour */
  --card: #f7f2e4;
  --card-soft: #fbf7ec;
  --cream: #faf6ea;
  --ink: #1c2a3a;
  --ink-2: #2f4257;
  --muted: #64798f;
  --line: rgba(28, 42, 58, 0.12);
  --navy: #1f4568;
  --azure: #2d6ea3;
  --sky: #c3dcef;
  --sky-soft: #e2eef8;
  --thc: #c9603a;
  --cbd: #2b7d8c;

  --font: "Hanken Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Fraunces", Georgia, serif;

  --radius: 18px;
  --radius-lg: 26px;
  --shadow: 0 2px 4px rgba(16, 28, 40, 0.06), 0 18px 40px rgba(16, 28, 40, 0.16);
  --shadow-lg: 0 30px 70px rgba(16, 28, 40, 0.24);
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

* { box-sizing: border-box; margin: 0; }

body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--studio);
  -webkit-font-smoothing: antialiased;
  min-height: 100%;
}

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.06;
}

button { font: inherit; border: none; background: none; color: inherit; }
a { color: inherit; text-decoration: none; }

/* ---------- 3D layer ---------- */
#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 1;
  touch-action: none;
}

.grain {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  opacity: 0.22;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------- loader ---------- */
#loader {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: grid;
  place-items: center;
  background: var(--navy);
  transition: opacity 0.6s var(--ease), visibility 0.6s;
}
body.ready #loader { opacity: 0; visibility: hidden; }

.loader-ring {
  display: block;
  width: 50px;
  height: 50px;
  margin: 0 auto 1rem;
  border: 2px solid rgba(250, 246, 234, 0.25);
  border-top-color: var(--cream);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loader-core p {
  font-size: 0.78rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(250, 246, 234, 0.72);
  text-align: center;
}

/* ---------- top bar ---------- */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: clamp(0.9rem, 2vw, 1.4rem) clamp(1rem, 3vw, 2rem);
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }

.brand { display: flex; align-items: center; gap: 0.7rem; }
.brand-mark { width: 36px; height: 36px; flex: none; }
.brand-text { display: grid; }
.brand-text .t1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.12rem;
  line-height: 1.1;
}
.brand-text .t2 {
  font-size: 0.68rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

.topbar-actions { display: inline-flex; align-items: center; gap: 0.6rem; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.6rem 1.05rem;
  border-radius: 100px;
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, 0.65);
  box-shadow: var(--shadow);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s var(--ease), color 0.2s var(--ease);
}
.pill:hover { transform: translateY(-1px); color: var(--azure); }
.pill svg { width: 15px; height: 15px; }

/* ---------- scrolling content ---------- */
.scroll {
  position: relative;
  z-index: 3;
  pointer-events: none; /* drags between cards reach the canvas */
}
.scroll .card, .scroll a, .scroll button, .scroll input { pointer-events: auto; }

.section {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(5rem, 10vh, 8rem) clamp(1.2rem, 4vw, 3.5rem);
}

.card {
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, 0.65);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.eyebrow {
  font-size: 0.72rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--azure);
  font-weight: 700;
}

/* hero */
.hero { align-items: flex-start; }
.hero-card { max-width: 520px; padding: clamp(1.8rem, 3.5vw, 2.8rem); }
.hero-card h1 { font-size: clamp(2.3rem, 5vw, 3.4rem); margin: 0.8rem 0 1rem; }
.lede { font-size: 1.1rem; line-height: 1.6; color: var(--ink-2); }

.search {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  margin-top: 1.6rem;
  padding: 0.85rem 1.2rem;
  border-radius: 100px;
  background: var(--card-soft);
  border: 1px solid var(--line);
  box-shadow: inset 0 1px 2px rgba(16, 28, 40, 0.05);
}
.search svg { width: 20px; height: 20px; color: var(--muted); flex: none; }
.search input {
  flex: 1;
  border: none;
  background: none;
  outline: none;
  font-size: 1rem;
  font-weight: 500;
  color: var(--ink);
  font-family: inherit;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1.4rem;
  margin-top: 1.3rem;
  font-size: 0.92rem;
  color: var(--ink-2);
}
.legend span { display: inline-flex; align-items: center; gap: 0.5rem; }
.sw { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.sw.thc { background: var(--thc); }
.sw.cbd { background: var(--cbd); }

.cue {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1.6rem;
  font-weight: 600;
  font-size: 0.95rem;
}
.cue span { transition: transform 0.25s var(--ease); }
.cue:hover span { transform: translateY(3px); }

/* region grid */
.head-card {
  max-width: 520px;
  padding: clamp(1.6rem, 3vw, 2.2rem);
  margin-bottom: 1.4rem;
}
.head-card h2 { font-size: clamp(1.8rem, 3.4vw, 2.4rem); margin-bottom: 0.6rem; }
.head-card p { color: var(--ink-2); line-height: 1.6; }

.region-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
  max-width: 620px;
}
.rcard {
  text-align: left;
  padding: 1.15rem 1.25rem;
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, 0.65);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  cursor: pointer;
  transition: transform 0.28s var(--ease), box-shadow 0.28s var(--ease);
}
.rcard:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }
.rcard.active { outline: 2px solid var(--c, var(--azure)); outline-offset: 2px; }
.rcard.hide { display: none; }
.rcard-top { display: flex; align-items: center; gap: 0.55rem; }
.rcard-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--c);
  flex: none;
}
.rcard h3 { font-size: 1.05rem; }
.rcard .fn { font-size: 0.85rem; color: var(--muted); line-height: 1.45; }
.rcard .go { margin-top: 0.3rem; font-size: 0.85rem; font-weight: 600; color: var(--azure); }

/* note card */
.note-card { max-width: 620px; padding: clamp(1.8rem, 3.5vw, 2.6rem); }
.note-card h2 { font-size: clamp(1.8rem, 3.4vw, 2.4rem); margin: 0.7rem 0 1rem; }
.note { color: var(--ink-2); line-height: 1.65; }
.note-rows { display: grid; gap: 0.9rem; margin-top: 1.5rem; }
.note-rows > div { display: flex; gap: 0.8rem; align-items: flex-start; }
.note-rows dd { margin: 0; font-size: 0.92rem; color: var(--ink-2); line-height: 1.55; }
.tag {
  flex: none;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 0.25rem 0.55rem;
  border-radius: 7px;
  color: #fff;
}
.tag.thc { background: var(--thc); }
.tag.cbd { background: var(--cbd); }

/* footer */
.foot {
  margin: 0 clamp(1.2rem, 4vw, 3.5rem) clamp(2rem, 5vh, 4rem);
  padding: 1.3rem 1.6rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1.6rem;
  justify-content: space-between;
  font-size: 0.82rem;
  color: var(--muted);
}

/* ---------- floating info panel ---------- */
.panel {
  position: fixed;
  z-index: 30;
  top: clamp(5rem, 9vh, 6.5rem);
  right: clamp(1rem, 3vw, 2rem);
  width: min(400px, calc(100vw - 2rem));
  padding: 1.6rem 1.7rem 1.4rem;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px) scale(0.98);
  transform-origin: top right;
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease), visibility 0.3s;
}
.panel.open { opacity: 1; visibility: visible; transform: translateY(0) scale(1); }

.panel-close {
  position: absolute;
  top: 0.9rem;
  right: 0.9rem;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 1.15rem;
  line-height: 1;
  color: var(--muted);
  background: var(--card-soft);
  cursor: pointer;
  transition: color 0.2s var(--ease);
}
.panel-close:hover { color: var(--ink); }

.panel-kicker {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  padding-right: 2rem;
}
.panel-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: none;
  background: var(--accent, var(--azure));
}
.panel h2 { font-size: clamp(1.7rem, 3vw, 2.15rem); margin: 0.5rem 0 1rem; }

.cb1-row { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.cb1-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.cb1-val { font-size: 0.85rem; font-weight: 700; color: var(--accent, var(--azure)); }
.cb1-track {
  height: 5px;
  border-radius: 100px;
  background: rgba(28, 42, 58, 0.1);
  margin-top: 0.45rem;
  overflow: hidden;
}
.cb1-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--accent, var(--azure));
  transition: width 0.7s var(--ease);
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.25rem;
  margin: 1.2rem 0 1rem;
  padding: 0.25rem;
  background: rgba(28, 42, 58, 0.06);
  border-radius: 12px;
}
.tab {
  padding: 0.55rem 0.4rem;
  border-radius: 9px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.22s var(--ease), color 0.22s var(--ease);
}
.tab:hover { color: var(--ink); }
.tab.is-active { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(16, 28, 40, 0.12); }
.tab.tab-thc.is-active { color: var(--thc); }
.tab.tab-cbd.is-active { color: var(--cbd); }

.tab-body p { font-size: 1rem; line-height: 1.6; color: var(--ink-2); min-height: 5.6em; }
.panel-foot {
  margin-top: 1rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--line);
  font-size: 0.75rem;
  color: var(--muted);
}

/* ---------- tooltip ---------- */
#tooltip {
  position: fixed;
  z-index: 60;
  padding: 0.35rem 0.65rem;
  border-radius: 8px;
  background: var(--ink);
  color: var(--cream);
  font-size: 0.8rem;
  font-weight: 600;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -190%);
  transition: opacity 0.18s var(--ease);
  white-space: nowrap;
}
#tooltip.show { opacity: 1; }

.noscript {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: sans-serif;
}

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .region-grid { grid-template-columns: 1fr; }
  .panel { top: auto; bottom: 1rem; right: 1rem; left: 1rem; width: auto; }
  .brand-text .t1 { font-size: 1rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.12ms !important;
  }
}
