/* Tarsier — a night forest exhibit. Design system: deep nocturnal teal-blue,
   moon silver, and one warm amber accent, over a live WebGL understory. */

@font-face {
  font-family: "Fraunces";
  src: url("../lib/fraunces-400.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Fraunces";
  src: url("../lib/fraunces-italic.woff2") format("woff2");
  font-weight: 100 900;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: "Inter";
  src: url("../lib/inter-400.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Inter";
  src: url("../lib/inter-500.woff2") format("woff2");
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: "Inter";
  src: url("../lib/inter-600.woff2") format("woff2");
  font-weight: 600;
  font-display: swap;
}

:root {
  --ink: #eef3f4;
  --ink-dim: #b9c8cb;
  --ink-faint: #8fa3a7;
  --night: #060b0e;
  --panel: rgba(7, 15, 18, 0.78);
  --panel-edge: rgba(190, 224, 226, 0.13);
  --panel-edge-bright: rgba(190, 224, 226, 0.28);
  --moon: #cfe3f2;
  --amber: #e8b34b;
  --amber-soft: rgba(232, 179, 75, 0.16);
  --leaf: #7fae8f;
  --teal: #6fc4bd;
  --danger: #d98a7a;
  --serif: "Fraunces", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --r: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--night);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* ---------- boot ---------- */
#boot {
  position: fixed; inset: 0; z-index: 60;
  background: radial-gradient(120% 100% at 50% 30%, #0c1a20 0%, #060b0e 70%);
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.9s ease, visibility 0.9s;
}
#boot.gone { opacity: 0; visibility: hidden; pointer-events: none; }
.boot-inner { text-align: center; }
.boot-eye {
  width: 54px; height: 54px; margin: 0 auto 18px;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 35%, #f4d9a0 0%, #c98f3d 34%, #59390f 72%, #1c1104 100%);
  box-shadow: 0 0 34px rgba(232, 179, 75, 0.35), inset 0 0 12px rgba(0,0,0,0.5);
  position: relative;
  animation: boot-breathe 2.6s ease-in-out infinite;
}
.boot-pupil {
  position: absolute; inset: 31%;
  border-radius: 50%; background: #04070a;
  box-shadow: inset 2px 2px 4px rgba(120,160,170,0.25);
}
@keyframes boot-breathe {
  0%, 100% { transform: scale(1); } 50% { transform: scale(1.05); }
}
.boot-word {
  font-family: var(--serif); font-weight: 340; font-size: 44px;
  letter-spacing: 0.04em; color: var(--moon);
}
.boot-sub { color: var(--ink-faint); font-size: 13px; margin-top: 6px; font-style: italic; font-family: var(--serif); }
.boot-bar {
  width: 180px; height: 2px; margin: 20px auto 0;
  background: rgba(190, 224, 226, 0.14); border-radius: 2px; overflow: hidden;
}
.boot-fill {
  height: 100%; width: 4%;
  background: linear-gradient(90deg, var(--teal), var(--moon));
  border-radius: 2px; transition: width 0.4s ease;
}

.skip-link {
  position: fixed; top: -60px; left: 12px; z-index: 90;
  background: var(--amber); color: #1a1206; padding: 8px 14px; border-radius: 8px;
  font-weight: 600; font-size: 13px; text-decoration: none;
  transition: top 0.15s ease;
}
.skip-link:focus-visible { top: 12px; }

/* ---------- stage ---------- */
#stage, #scene { position: fixed; inset: 0; }
#scene { width: 100%; height: 100%; display: block; outline: none; cursor: grab; touch-action: none; }
#scene:active { cursor: grabbing; }
#scene:focus-visible { box-shadow: inset 0 0 0 2px var(--amber); }

#hotspots { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
.hotspot {
  position: absolute; transform: translate(-50%, -50%);
  pointer-events: auto;
  width: 30px; height: 30px; margin: 0; padding: 0;
  border: none; background: none; cursor: pointer;
}
.hotspot::before {
  content: ""; position: absolute; inset: 9px;
  border-radius: 50%; background: var(--amber);
  box-shadow: 0 0 10px rgba(232,179,75,0.8);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.hotspot::after {
  content: ""; position: absolute; inset: 4px;
  border-radius: 50%; border: 1px solid rgba(232,179,75,0.55);
  animation: hs-pulse 2.8s ease-out infinite;
}
@keyframes hs-pulse {
  0% { transform: scale(0.6); opacity: 0.9; }
  70% { transform: scale(1.6); opacity: 0; }
  100% { transform: scale(1.6); opacity: 0; }
}
.hotspot:hover::before, .hotspot:focus-visible::before { transform: scale(1.35); box-shadow: 0 0 16px rgba(232,179,75,1); }
.hotspot:focus-visible { outline: 2px solid var(--amber); outline-offset: 3px; border-radius: 50%; }
.hotspot.occluded { opacity: 0.25; }
.hotspot .hs-tip {
  position: absolute; bottom: 130%; left: 50%; transform: translateX(-50%) translateY(4px);
  white-space: nowrap;
  background: var(--panel); border: 1px solid var(--panel-edge-bright);
  color: var(--ink); font-size: 12px; font-weight: 500;
  padding: 5px 10px; border-radius: 8px;
  opacity: 0; pointer-events: none; transition: opacity 0.15s ease, transform 0.15s ease;
}
.hotspot:hover .hs-tip, .hotspot:focus-visible .hs-tip { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- masthead ---------- */
#masthead {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px;
  padding: 12px 16px;
  pointer-events: none;
}
#masthead > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 10px; margin-right: 4px; }
.brand-eye {
  width: 26px; height: 26px; border-radius: 50%;
  background: radial-gradient(circle at 38% 35%, #f4d9a0 0%, #c98f3d 38%, #59390f 76%, #160d03 100%);
  box-shadow: 0 0 14px rgba(232,179,75,0.45);
  position: relative; flex: none;
}
.brand-eye::after {
  content: ""; position: absolute; inset: 33%;
  border-radius: 50%; background: #04070a;
}
.brand-words { display: flex; flex-direction: column; line-height: 1.15; }
.brand-words strong {
  font-family: var(--serif); font-weight: 400; font-size: 19px; letter-spacing: 0.06em; color: var(--moon);
}
.brand-words span { font-size: 10.5px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-faint); }

#chapter-nav { flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; mask-image: linear-gradient(90deg, transparent, #000 16px, #000 calc(100% - 16px), transparent); }
#chapter-nav::-webkit-scrollbar { display: none; }
#chapter-list {
  display: flex; gap: 2px; margin: 0; padding: 0 8px; list-style: none;
}
#chapter-list button {
  border: none; background: none; cursor: pointer;
  color: var(--ink-faint); font-family: var(--sans); font-size: 12px; font-weight: 500;
  padding: 7px 10px; border-radius: 8px; white-space: nowrap;
  transition: color 0.15s ease, background 0.15s ease;
}
#chapter-list button:hover { color: var(--ink); background: rgba(190,224,226,0.07); }
#chapter-list button:focus-visible { outline: 2px solid var(--amber); outline-offset: -1px; }
#chapter-list button[aria-current="true"] { color: var(--amber); background: var(--amber-soft); }

.mast-actions { display: flex; gap: 8px; }
.chip-btn {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--panel-edge); border-radius: 999px;
  background: var(--panel); color: var(--ink-dim);
  font-family: var(--sans); font-size: 12.5px; font-weight: 500;
  padding: 7px 13px; cursor: pointer;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.chip-btn:hover { color: var(--ink); border-color: var(--panel-edge-bright); }
.chip-btn:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
.chip-btn[aria-pressed="true"] { color: var(--amber); border-color: rgba(232,179,75,0.4); background: var(--amber-soft); }
#sound-toggle .snd-off { display: none; }
#sound-toggle[aria-pressed="false"] .snd-waves { display: none; }
#sound-toggle[aria-pressed="false"] .snd-off { display: initial; }

/* ---------- chapter panel ---------- */
#chapter-panel {
  position: fixed; z-index: 15;
  left: 16px; top: 72px; bottom: 88px;
  width: min(392px, calc(100vw - 32px));
  display: flex; flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: var(--r);
  backdrop-filter: blur(14px) saturate(1.1); -webkit-backdrop-filter: blur(14px) saturate(1.1);
  box-shadow: 0 18px 50px rgba(0,0,0,0.45);
  outline: none;
}
#chapter-panel:focus-visible { border-color: rgba(232,179,75,0.5); }
.cp-scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 22px 22px 10px; scrollbar-width: thin; scrollbar-color: rgba(190,224,226,0.25) transparent; }
.cp-kicker {
  display: flex; align-items: center; gap: 10px;
  font-size: 11px; letter-spacing: 0.22em; text-transform: uppercase;
  color: var(--teal); font-weight: 600;
}
.cp-kicker-line { flex: 0 0 28px; height: 1px; background: currentColor; opacity: 0.5; }
#cp-title {
  font-family: var(--serif); font-weight: 350; font-size: 32px; line-height: 1.08;
  margin: 10px 0 4px; color: var(--moon); letter-spacing: 0.01em;
}
#cp-title em { font-style: italic; }
.cp-hook {
  font-family: var(--serif); font-style: italic; font-weight: 340;
  font-size: 16.5px; line-height: 1.5; color: var(--ink-dim);
  margin: 8px 0 14px;
}
.cp-hook::before { content: ""; display: block; width: 34px; height: 1px; background: var(--amber); opacity: 0.6; margin-bottom: 12px; }

#cp-body p { margin: 0 0 12px; color: var(--ink-dim); }
#cp-body strong { color: var(--ink); font-weight: 600; }
#cp-body em { color: var(--moon); }

details.cp-fact {
  border: 1px solid var(--panel-edge); border-radius: 10px;
  margin: 0 0 8px; overflow: hidden;
  background: rgba(10, 22, 26, 0.4);
}
details.cp-fact[open] { border-color: var(--panel-edge-bright); background: rgba(12, 26, 31, 0.55); }
details.cp-fact summary {
  cursor: pointer; list-style: none;
  padding: 10px 14px;
  font-weight: 600; font-size: 13.5px; color: var(--ink);
  display: flex; align-items: center; gap: 9px;
}
details.cp-fact summary::-webkit-details-marker { display: none; }
details.cp-fact summary::before {
  content: ""; flex: none; width: 7px; height: 7px; border-radius: 50%;
  background: var(--teal); opacity: 0.85;
}
details.cp-fact summary::after {
  content: "+"; margin-left: auto; color: var(--ink-faint);
  font-size: 16px; font-weight: 400; transition: transform 0.2s ease;
}
details.cp-fact[open] summary::after { transform: rotate(45deg); color: var(--amber); }
details.cp-fact summary:hover { background: rgba(190,224,226,0.05); }
details.cp-fact summary:focus-visible { outline: 2px solid var(--amber); outline-offset: -2px; border-radius: 10px; }
details.cp-fact .fact-body { padding: 2px 14px 12px 30px; color: var(--ink-dim); font-size: 13.5px; }
details.cp-fact .fact-body p { margin: 0 0 8px; }
details.cp-fact .fact-body p:last-child { margin-bottom: 2px; }

.src {
  display: inline; color: var(--teal); font-size: 11.5px; font-weight: 500;
  letter-spacing: 0.01em; opacity: 0.9;
}
.src::before { content: "· "; opacity: 0.6; }

.uncertain {
  display: inline-block;
  font-size: 10.5px; font-weight: 600; letter-spacing: 0.09em; text-transform: uppercase;
  color: var(--amber); border: 1px solid rgba(232,179,75,0.45);
  padding: 1px 7px; border-radius: 999px; vertical-align: 1px; margin-left: 6px;
}
.uncertain.blue { color: var(--teal); border-color: rgba(111,196,189,0.45); }
.uncertain.red { color: var(--danger); border-color: rgba(217,138,122,0.5); }

.myth {
  border: 1px solid rgba(217,138,122,0.35);
  background: rgba(217, 138, 122, 0.07);
  border-radius: 10px; padding: 12px 14px; margin: 10px 0;
}
.myth h4 {
  margin: 0 0 6px; font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--danger); font-family: var(--sans); font-weight: 600;
}
.myth p { margin: 0 0 8px; font-size: 13.5px; }
.myth p:last-child { margin-bottom: 0; }

/* widgets inside chapters */
.widget { margin: 14px 0 6px; border: 1px solid var(--panel-edge); border-radius: 12px; padding: 12px 14px; background: rgba(9, 19, 23, 0.5); }
.widget h4 { margin: 0 0 8px; font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--teal); font-weight: 600; }
.widget svg { display: block; width: 100%; height: auto; }
.widget .w-note { font-size: 12px; color: var(--ink-faint); margin: 8px 0 0; }

/* generic buttons */
.btn {
  border: 1px solid var(--panel-edge-bright); border-radius: 999px;
  background: rgba(14, 28, 33, 0.6); color: var(--ink);
  font-family: var(--sans); font-size: 13px; font-weight: 600;
  padding: 9px 16px; cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}
.btn:hover { border-color: var(--amber); color: var(--amber); }
.btn:active { transform: scale(0.97); }
.btn:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
.btn.solid { background: var(--amber); border-color: var(--amber); color: #1d1305; }
.btn.solid:hover { background: #f2c463; color: #1d1305; }
.btn[aria-pressed="true"] { background: var(--amber-soft); border-color: rgba(232,179,75,0.55); color: var(--amber); }

.cp-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 6px 0 14px; }

.cp-footer {
  flex: none; display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-top: 1px solid var(--panel-edge);
}
.nav-arrow {
  flex: none; width: 38px; height: 38px; border-radius: 50%;
  border: 1px solid var(--panel-edge-bright); background: none;
  color: var(--ink); font-size: 20px; line-height: 1; cursor: pointer;
  transition: all 0.15s ease;
}
.nav-arrow:hover { border-color: var(--amber); color: var(--amber); }
.nav-arrow:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
.nav-arrow.next { background: var(--amber); border-color: var(--amber); color: #1d1305; font-weight: 700; }
.nav-arrow.next:hover { background: #f2c463; }
.cp-progress { flex: 1; display: flex; gap: 4px; align-items: center; }
.cp-progress i {
  flex: 1; height: 3px; border-radius: 2px;
  background: rgba(190,224,226,0.14); transition: background 0.3s ease;
}
.cp-progress i.done { background: var(--teal); }
.cp-progress i.now { background: var(--amber); box-shadow: 0 0 6px rgba(232,179,75,0.6); }

/* ---------- action bar ---------- */
#actionbar {
  position: fixed; z-index: 15;
  left: 50%; bottom: 22px; transform: translateX(-50%);
  display: flex; gap: 8px; align-items: center;
  padding: 8px 10px;
  background: var(--panel); border: 1px solid var(--panel-edge); border-radius: 999px;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 12px 34px rgba(0,0,0,0.42);
  max-width: calc(100vw - 32px);
  overflow-x: auto; scrollbar-width: none;
}
#actionbar::-webkit-scrollbar { display: none; }
.ab-btn {
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
  border: 1px solid transparent; border-radius: 999px; background: none;
  color: var(--ink-dim); font-family: var(--sans); font-size: 12.5px; font-weight: 600;
  padding: 8px 13px; cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.ab-btn:hover { color: var(--ink); background: rgba(190,224,226,0.08); }
.ab-btn:focus-visible { outline: 2px solid var(--amber); outline-offset: 1px; }
.ab-btn[aria-pressed="true"] { color: var(--amber); background: var(--amber-soft); border-color: rgba(232,179,75,0.4); }
.ab-btn.primary { color: #1d1305; background: var(--amber); }
.ab-btn.primary:hover { background: #f2c463; }
.ab-btn:disabled { opacity: 0.4; cursor: default; }
.ab-btn svg { flex: none; }
.ab-sep { width: 1px; height: 20px; background: var(--panel-edge-bright); flex: none; }

/* ---------- hint toast ---------- */
#hint {
  position: fixed; z-index: 30;
  left: 50%; bottom: 84px; transform: translateX(-50%) translateY(8px);
  background: var(--panel); border: 1px solid var(--panel-edge-bright);
  border-radius: 10px; color: var(--ink);
  padding: 9px 16px; font-size: 13px;
  opacity: 0; pointer-events: none;
  transition: opacity 0.35s ease, transform 0.35s ease;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  max-width: min(90vw, 480px); text-align: center;
}
#hint.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#hint em { color: var(--amber); font-style: normal; font-weight: 600; }

/* ---------- help overlay ---------- */
#help-overlay {
  position: fixed; inset: 0; z-index: 55;
  background: rgba(4, 9, 11, 0.72);
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
#help-overlay[hidden] { display: none; }
.help-card {
  width: min(640px, calc(100vw - 40px)); max-height: 84vh; overflow-y: auto;
  background: #0a1518; border: 1px solid var(--panel-edge-bright); border-radius: 16px;
  padding: 26px 28px;
}
.help-card h2 { font-family: var(--serif); font-weight: 400; color: var(--moon); margin: 0 0 14px; font-size: 24px; }
.help-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 26px; margin-bottom: 18px; }
.help-card h3 { font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--teal); margin: 12px 0 6px; }
.help-card ul { margin: 0; padding-left: 18px; color: var(--ink-dim); font-size: 13.5px; }
.help-card li { margin-bottom: 6px; }
kbd {
  font-family: var(--sans); font-size: 11px; font-weight: 600;
  background: rgba(190,224,226,0.1); border: 1px solid var(--panel-edge-bright);
  border-bottom-width: 2px; border-radius: 5px; padding: 1px 5px; color: var(--ink);
}

/* ---------- fatal / nojs ---------- */
#fatal {
  position: fixed; inset: 0; z-index: 70;
  background: var(--night); display: flex; align-items: center; justify-content: center;
  text-align: center; padding: 30px;
}
#fatal[hidden] { display: none; }
#fatal h2, .nojs h2 { font-family: var(--serif); color: var(--moon); font-weight: 400; }
#fatal p, .nojs p { color: var(--ink-dim); max-width: 52ch; margin: 10px auto; }
.nojs { position: fixed; inset: 0; z-index: 70; background: var(--night); padding: 40px; display: flex; flex-direction: column; justify-content: center; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  #chapter-nav { display: none; }
}
@media (max-width: 640px) {
  body { font-size: 14px; }
  .brand-words span { display: none; }
  #chapter-panel {
    left: 10px; right: 10px; top: auto; bottom: 84px;
    width: auto; max-height: 46vh;
  }
  #cp-title { font-size: 24px; }
  .cp-hook { font-size: 14.5px; }
  #actionbar {
    bottom: 14px; left: 10px; right: 10px; transform: none;
    max-width: none; width: auto;
    justify-content: flex-start;
  }
  .cp-scroll { padding: 16px 16px 8px; }
  .help-cols { grid-template-columns: 1fr; }
  #masthead { padding: 10px 10px; }
  .chip-btn span { display: none; }
  .chip-btn { padding: 8px 10px; }
  .cp-footer { padding: 8px 10px; }
  #hint { bottom: 148px; }
}
@media (max-width: 640px) and (orientation: landscape) {
  #chapter-panel { max-height: 56vh; bottom: 10px; width: min(360px, 52vw); left: 10px; right: auto; }
  #actionbar { bottom: 10px; left: auto; right: 120px; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .hotspot::after { animation: none; opacity: 0; }
  .boot-eye { animation: none; }
  * { transition-duration: 0.01s !important; }
}
