:root {
  --sky: #05070d;
  --ink: #eef1f8;
  --ink-soft: #c3cbdd;
  --dim: #808aa0;
  --gold: #f1c778;
  --gold-soft: #d8b062;
  --accent: #f1c778;                              /* set per-selection to the field colour */
  --panel: rgba(14, 18, 27, 0.78);
  --panel-solid: rgba(20, 25, 36, 0.95);
  --hair: rgba(255, 255, 255, 0.09);
  --hair-bright: rgba(255, 255, 255, 0.16);
  --shadow: 0 24px 64px rgba(0, 0, 0, 0.62);
  --serif: 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, 'Times New Roman', serif;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --blur: saturate(1.25) blur(18px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  height: 100%; width: 100%;
  overflow: hidden;
  background: var(--sky);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior: none;
}

#sky {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  display: block;
  cursor: grab;
  touch-action: none;
}
#sky.grabbing { cursor: grabbing; }
#sky:focus-visible { outline: 2px solid var(--gold); outline-offset: -3px; }

/* ---------- Accessibility ---------- */
/* Visually hidden, still read by screen readers and seen by crawlers. */
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
/* Honeypot — hidden from people (and from screen readers via aria-hidden), not from bots.
   Deliberately NOT .sr-only: that is meant to be READ by screen readers. */
.honeypot { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; opacity: 0; }
#argue-turnstile:not(:empty) { margin-bottom: 16px; }

.skip-link {
  position: fixed; top: -60px; left: 16px; z-index: 60;
  background: var(--panel-solid); color: var(--ink);
  border: 1px solid var(--gold); border-radius: 0 0 10px 10px;
  padding: 10px 16px; font-size: 14px; text-decoration: none;
  transition: top .15s;
}
.skip-link:focus { top: 0; }

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

.noscript-note {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column; justify-content: center;
  max-width: 620px; margin: 0 auto; padding: 32px;
  background: var(--sky); color: var(--ink-soft);
  font-size: 16px; line-height: 1.65;
}
.noscript-note h1 { font-family: var(--serif); color: var(--ink); font-size: 34px; margin: 0 0 16px; }

/* ---------- Top bar ---------- */
#topbar {
  position: fixed; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
  padding: 16px 22px;
  z-index: 20;
  background: linear-gradient(180deg, rgba(5,7,13,0.94) 0%, rgba(5,7,13,0.55) 62%, rgba(5,7,13,0) 100%);
  pointer-events: none;
}
#topbar > * { pointer-events: auto; }

.brand { display: flex; align-items: baseline; gap: 11px; user-select: none; }
.brand-mark { color: var(--gold); font-size: 20px; transform: translateY(2px); text-shadow: 0 0 14px rgba(241,199,120,0.55); }
.brand-name {
  font-family: var(--serif);
  font-weight: 600;
  letter-spacing: 0.20em;
  font-size: 20px;
  color: var(--ink);
  text-shadow: 0 0 22px rgba(160,180,230,0.25);
}
.brand-tag { color: var(--dim); font-size: 12.5px; font-style: italic; letter-spacing: 0.02em; }

.top-actions { display: flex; align-items: center; gap: 10px; }

.search-wrap { position: relative; }
#search, .pf-input {
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--hair);
  color: var(--ink);
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 14px;
  font-family: var(--sans);
  width: 236px;
  outline: none;
  transition: border-color .18s, background .18s, box-shadow .18s;
}
#search:focus, .pf-input:focus {
  border-color: rgba(241,199,120,0.55);
  background: rgba(255,255,255,0.08);
  box-shadow: 0 0 0 3px rgba(241,199,120,0.12);
}
#search::placeholder, .pf-input::placeholder { color: var(--dim); }

.btn {
  background: linear-gradient(180deg, rgba(241,199,120,0.20), rgba(241,199,120,0.11));
  border: 1px solid rgba(241,199,120,0.38);
  color: var(--gold);
  border-radius: 10px;
  padding: 9px 16px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  letter-spacing: 0.01em;
  transition: background .18s, border-color .18s, transform .06s, box-shadow .18s;
  font-family: var(--sans);
}
.btn:hover { background: linear-gradient(180deg, rgba(241,199,120,0.30), rgba(241,199,120,0.18)); box-shadow: 0 4px 18px rgba(241,199,120,0.14); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: rgba(255,255,255,0.03); color: var(--dim); border-color: var(--hair); box-shadow: none; }
.btn.ghost:hover { color: var(--ink); border-color: var(--hair-bright); background: rgba(255,255,255,0.07); }
.btn.small { padding: 7px 13px; font-size: 12.5px; }
.btn.big { padding: 14px 30px; font-size: 15px; margin-top: 8px; letter-spacing: 0.02em; }

/* ---------- Legend ---------- */
#legend {
  position: fixed; left: 22px; bottom: 22px;
  z-index: 15;
  display: flex; flex-wrap: wrap; gap: 7px 15px;
  max-width: 340px;
  padding: 13px 15px;
  background: var(--panel);
  border: 1px solid var(--hair);
  border-radius: 14px;
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,0.05);
}
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-soft); cursor: pointer; transition: color .15s, opacity .15s; }
.legend-item:hover { color: var(--ink); }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; box-shadow: 0 0 9px currentColor; }
.legend-item.muted { opacity: 0.32; }

/* ---------- Zoom controls ---------- */
#zoom-controls {
  position: fixed; right: 22px; bottom: 22px;
  z-index: 15;
  display: flex; flex-direction: column; gap: 9px;
}
.zbtn {
  width: 42px; height: 42px;
  background: var(--panel);
  border: 1px solid var(--hair);
  color: var(--ink-soft);
  border-radius: 12px;
  font-size: 20px; line-height: 1;
  cursor: pointer;
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,0.05);
  transition: background .15s, color .15s, border-color .15s;
}
.zbtn:hover { background: rgba(38,45,62,0.92); color: var(--ink); border-color: var(--hair-bright); }

/* ---------- Panels ---------- */
.panel {
  position: fixed; top: 74px; right: 22px;
  width: 350px; max-width: calc(100vw - 44px);
  max-height: calc(100vh - 108px);
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--hair);
  border-radius: 20px;
  padding: 24px 24px 22px;
  z-index: 25;
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,0.06);
  animation: slidein .22s cubic-bezier(.2,.8,.2,1);
}
/* field-colour accent along the top of the story card */
.panel::before {
  content: ""; position: absolute; top: 0; left: 26px; right: 26px; height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: 0.75; border-radius: 2px;
}
#pathfinder::before { background: linear-gradient(90deg, transparent, var(--gold), transparent); }
@keyframes slidein { from { opacity: 0; transform: translateY(8px) scale(.99); } to { opacity: 1; transform: none; } }

.panel::-webkit-scrollbar { width: 8px; }
.panel::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 8px; }

.panel-close {
  position: absolute; top: 13px; right: 15px;
  width: 28px; height: 28px; border-radius: 8px;
  background: none; border: none; color: var(--dim);
  font-size: 22px; line-height: 1; cursor: pointer;
  transition: color .15s, background .15s;
}
.panel-close:hover { color: var(--ink); background: rgba(255,255,255,0.06); }

.story-field {
  display: inline-block;
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.11em; text-transform: uppercase;
  padding: 4px 11px; border-radius: 20px; margin-bottom: 12px;
}
.story-title { font-family: var(--serif); font-weight: 600; font-size: 25px; margin: 0 0 5px; line-height: 1.16; letter-spacing: 0.005em; }
.story-who { color: var(--gold-soft); font-size: 13px; margin-bottom: 15px; font-style: italic; }
.story-blurb { font-size: 14.5px; line-height: 1.6; color: var(--ink-soft); margin: 0 0 20px; }

.story-section { margin-bottom: 16px; }
.story-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--dim); margin-bottom: 9px; }
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  font-size: 12.5px;
  padding: 6px 11px;
  border-radius: 8px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--hair);
  color: var(--ink-soft);
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background .14s, border-color .14s, color .14s, transform .06s;
}
.chip:hover { background: rgba(255,255,255,0.11); border-color: var(--hair-bright); color: var(--ink); transform: translateY(-1px); }
.chip:active { transform: none; }
.chip.empty { color: var(--dim); cursor: default; background: none; border: none; padding-left: 0; font-style: italic; }
.chip.empty:hover { transform: none; }
.story-actions { margin-top: 18px; }

/* ---------- Path Finder ---------- */
.pf-heading { font-family: var(--serif); font-weight: 600; font-size: 23px; margin: 0 0 5px; }
.pf-sub { color: var(--dim); font-size: 13px; margin: 0 0 20px; line-height: 1.5; }
.pf-label { display: block; position: relative; font-size: 11px; color: var(--dim); margin-bottom: 15px; text-transform: uppercase; letter-spacing: 0.08em; }
.pf-input { width: 100%; margin-top: 7px; text-transform: none; letter-spacing: normal; font-size: 14px; }
.pf-buttons { display: flex; gap: 9px; margin-bottom: 18px; }
.pf-examples { font-size: 12px; color: var(--dim); display: flex; flex-wrap: wrap; gap: 7px; align-items: center; }
.example {
  background: rgba(241,199,120,0.06); border: 1px dashed rgba(241,199,120,0.32); color: var(--gold-soft);
  border-radius: 7px; padding: 5px 9px; font-size: 12px; cursor: pointer; font-family: var(--sans);
  transition: border-color .15s, color .15s, background .15s;
}
.example:hover { border-color: var(--gold); color: var(--gold); background: rgba(241,199,120,0.12); }

.pf-narration { margin-top: 20px; border-top: 1px solid var(--hair); padding-top: 18px; }
.pf-step { display: flex; gap: 13px; margin-bottom: 4px; position: relative; }
.pf-step-rail { display: flex; flex-direction: column; align-items: center; flex-shrink: 0; }
.pf-step-dot { width: 13px; height: 13px; border-radius: 50%; margin-top: 5px; box-shadow: 0 0 10px currentColor; flex-shrink: 0; transition: transform .2s; }
.pf-step-line { width: 2px; flex: 1; background: linear-gradient(rgba(255,255,255,0.22), rgba(255,255,255,0.06)); margin: 4px 0; min-height: 15px; }
.pf-step:last-child .pf-step-line { display: none; }
.pf-step-body { padding-bottom: 18px; }
.pf-step-title { font-family: var(--serif); font-weight: 600; font-size: 16px; color: var(--ink); transition: color .2s; }
.pf-step-year { font-size: 12px; color: var(--dim); margin-left: 7px; }
.pf-step-note { font-size: 12.5px; color: var(--dim); line-height: 1.45; margin-top: 3px; }
.pf-summary { font-size: 13px; color: var(--gold-soft); margin-bottom: 12px; line-height: 1.55; }
.pf-replay-row { margin-bottom: 16px; }
.pf-fail { color: #efa0ad; font-size: 13.5px; line-height: 1.55; }
.pf-step.active .pf-step-title { color: var(--gold); }
.pf-step.active .pf-step-dot { box-shadow: 0 0 14px var(--gold); outline: 2px solid rgba(241,199,120,0.5); outline-offset: 2px; transform: scale(1.15); }
.pf-step.active .pf-step-note { color: var(--ink-soft); }

/* ---------- Overlay ---------- */
/* [hidden] must always win — .overlay's display:flex would otherwise override it */
.overlay[hidden] { display: none; }

.overlay {
  position: fixed; inset: 0; z-index: 40;
  background: radial-gradient(ellipse 80% 60% at 50% 42%, rgba(10,14,24,0.62), rgba(3,5,10,0.90));
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  animation: fadein .4s ease-out;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.intro-card {
  max-width: 480px; text-align: center;
  background: var(--panel-solid);
  border: 1px solid var(--hair);
  border-radius: 24px;
  padding: 46px 40px 38px;
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,0.07);
  animation: introrise .5s cubic-bezier(.2,.8,.2,1);
}
@keyframes introrise { from { opacity: 0; transform: translateY(16px) scale(.98); } to { opacity: 1; transform: none; } }
.intro-mark { color: var(--gold); font-size: 40px; margin-bottom: 8px; text-shadow: 0 0 30px rgba(241,199,120,0.5); }
.intro-card h1 { font-family: var(--serif); font-weight: 600; font-size: 38px; margin: 0 0 16px; letter-spacing: 0.04em; }
.intro-lead { font-size: 15.5px; line-height: 1.65; color: var(--ink-soft); margin: 0 0 22px; }
.intro-how { text-align: left; font-size: 13.5px; line-height: 1.75; color: var(--dim); margin: 0 auto 12px; padding-left: 20px; max-width: 380px; }
.intro-how b { color: var(--ink); font-weight: 600; }

/* ---------- Argue form ---------- */
.argue-card {
  max-width: 520px; width: 100%;
  max-height: calc(100vh - 48px); overflow-y: auto;
  position: relative;
  background: var(--panel-solid);
  border: 1px solid var(--hair);
  border-radius: 22px;
  padding: 34px 32px 28px;
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,0.07);
  animation: introrise .35s cubic-bezier(.2,.8,.2,1);
}
.argue-card h2 { font-family: var(--serif); font-weight: 600; font-size: 26px; margin: 0 0 8px; }
.argue-sub { color: var(--dim); font-size: 13.5px; line-height: 1.6; margin: 0 0 20px; }
.argue-context {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--hair);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 10px 13px; margin-bottom: 18px;
  font-size: 13px; color: var(--ink-soft); line-height: 1.5;
}
.argue-label {
  display: block; margin-bottom: 16px;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--dim);
}
.argue-input {
  display: block; width: 100%; margin-top: 7px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--hair);
  color: var(--ink);
  border-radius: 10px;
  padding: 10px 13px;
  font-size: 14px; font-family: var(--sans);
  text-transform: none; letter-spacing: normal;
  outline: none;
  transition: border-color .18s, background .18s, box-shadow .18s;
}
textarea.argue-input { resize: vertical; min-height: 84px; line-height: 1.5; }
.argue-input:focus { border-color: rgba(241,199,120,0.55); background: rgba(255,255,255,0.08); box-shadow: 0 0 0 3px rgba(241,199,120,0.12); }
.argue-input::placeholder { color: var(--dim); }
.argue-actions { display: flex; gap: 9px; margin-top: 4px; }
.argue-result { margin-top: 16px; font-size: 13.5px; line-height: 1.6; border-radius: 10px; padding: 12px 14px; }
.argue-result.ok { background: rgba(99,206,124,0.12); border: 1px solid rgba(99,206,124,0.4); color: #b6e8c3; }
.argue-result.warn { background: rgba(239,106,130,0.10); border: 1px solid rgba(239,106,130,0.35); color: #f0b7c1; }
.argue-result textarea {
  width: 100%; margin-top: 10px; min-height: 120px;
  background: rgba(0,0,0,0.35); border: 1px solid var(--hair); border-radius: 8px;
  color: var(--ink-soft); font-size: 12px; font-family: ui-monospace, Menlo, Consolas, monospace; padding: 9px;
}

/* ---------- Search dropdown ---------- */
.dropdown {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  background: var(--panel-solid);
  border: 1px solid var(--hair);
  border-radius: 12px;
  max-height: 320px; overflow-y: auto;
  z-index: 30;
  box-shadow: var(--shadow);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  overflow: hidden;
}
.dropdown-item { padding: 10px 14px; cursor: pointer; font-size: 13.5px; display: flex; align-items: center; gap: 10px; transition: background .12s; }
.dropdown-item:hover, .dropdown-item.active { background: rgba(241,199,120,0.14); }
.dropdown-item .dd-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; box-shadow: 0 0 7px currentColor; }
.dropdown-item .dd-year { color: var(--dim); font-size: 12px; margin-left: auto; }
.dropdown-empty { padding: 12px 14px; color: var(--dim); font-size: 13px; font-style: italic; }

/* ---------- Tooltip ---------- */
#tooltip {
  position: fixed; z-index: 35;
  background: rgba(8,11,18,0.94);
  border: 1px solid var(--hair);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  pointer-events: none;
  max-width: 250px;
  box-shadow: var(--shadow);
  transform: translate(-50%, -120%);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
}
#tooltip .tt-title { font-family: var(--serif); font-weight: 600; font-size: 14px; }
#tooltip .tt-meta { color: var(--dim); font-size: 11.5px; margin-top: 2px; }

@media (max-width: 640px) {
  .brand-tag { display: none; }
  #search { width: 150px; }
  .panel { top: auto; bottom: 0; right: 0; left: 0; width: 100%; max-width: 100%;
           border-radius: 20px 20px 0 0; max-height: 62vh; }
  #legend { max-width: calc(100vw - 44px); bottom: 78px; }
  #zoom-controls { bottom: 78px; }
  .brand-name { font-size: 17px; }
}

@media (prefers-reduced-motion: reduce) {
  .panel, .intro-card, .overlay { animation: none; }
}
