/*
 * Wikipedia Speedrun — visual design.
 *
 * Direction: the encyclopedia (blue hyperlink, reference authority, Fraunces
 * serif) meets the speedrun (instrument cluster + step numbers in JetBrains
 * Mono, a race-amber live timer). Signature element: the "path trail" — your
 * route rendered as a numbered chain of nodes.
 *
 * Cool screen-paper, not vintage cream. Encyclopedia blue is the primary; amber
 * marks the live/now; gold marks a win. Boldness is spent on the trail and the
 * timer; everything else stays quiet.
 */

:root {
  --ink: #16181d;
  --ink-soft: #3c4250;
  --muted: #6b7280;
  --paper: #f4f5f7;          /* page background (cool, screen-like) */
  --surface: #ffffff;        /* cards, article, inputs */
  --surface-2: #f9fafb;      /* subtle fills */
  --line: #e3e6ec;           /* hairlines */
  --line-strong: #c9ced8;

  --link: #3a5be0;           /* encyclopedia blue — primary/interactive (the "Speedrun" blue) */
  --link-bright: #5274f4;    /* gradient top / highlight */
  --link-deep: #2440b0;      /* hover / pressed */
  --link-tint: #eaefff;      /* hover wash */
  --accent: #e8590c;         /* race amber — the live timer / "now" */
  --gold: #e7a11a;           /* a win */
  --danger: #c5283d;

  --font-display: 'Fraunces', Georgia, 'Times New Roman', serif;
  --font-body: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 60, .05), 0 14px 34px -22px rgba(20, 30, 60, .30);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--paper);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }

h1, h2, h3 { font-family: var(--font-display); font-weight: 600; line-height: 1.12; }
.muted { color: var(--muted); }
.error { color: var(--danger); margin: .5rem 0 0; }
.accent-text { color: var(--link); }

/* ── Controls ────────────────────────────────────────────────────────────── */
button {
  font-family: var(--font-body);
  font-size: .95rem;
  font-weight: 600;
  color: var(--ink);
  background: linear-gradient(180deg, #ffffff, #eef0f5);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: .55rem .95rem;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s, transform .05s;
}
button:hover { border-color: var(--ink-soft); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .55; cursor: default; transform: none; }
button:focus-visible,
input:focus-visible,
.segmented label:focus-within span,
.wiki-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.primary {
  background: linear-gradient(180deg, var(--link-bright), var(--link));
  border-color: var(--link-deep);
  color: #fff;
  box-shadow: 0 1px 1px rgba(20, 30, 80, .25), inset 0 1px 0 rgba(255, 255, 255, .25);
}
.primary:hover { background: linear-gradient(180deg, var(--link), var(--link-deep)); border-color: var(--link-deep); }
.ghost-btn {
  background: none;
  border: 1px dashed var(--line-strong);
  color: var(--muted);
  font-weight: 500;
  box-shadow: none;
}
.ghost-btn:hover { color: var(--ink); border-color: var(--ink-soft); }
#btn-giveup:hover { color: var(--danger); border-color: var(--danger); }

input[type="text"] {
  width: 100%;
  font-family: var(--font-mono);
  font-size: .92rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: .58rem .7rem;
}
input[type="text"]:focus { outline: none; border-color: var(--link); box-shadow: 0 0 0 3px var(--link-tint); }
input::placeholder { color: #9aa1ad; }

fieldset { border: 1px solid var(--line); border-radius: var(--radius); margin: 0 0 1.1rem; padding: .9rem 1.05rem 1.1rem; background: var(--surface); }
legend { font-family: var(--font-mono); font-size: .68rem; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); padding: 0 .4rem; }

/* ── Screens ─────────────────────────────────────────────────────────────── */
.screen { animation: screen-in .4s ease both; }
@keyframes screen-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.screen-centered { max-width: 44rem; margin: 0 auto; padding: clamp(1.5rem, 5vw, 3.5rem) 1.25rem 4rem; }
.screen-game { display: flex; flex-direction: column; height: 100vh; }

/* ── Setup: masthead ─────────────────────────────────────────────────────── */
.masthead { margin-bottom: 2rem; }
.masthead-eyebrow {
  font-family: var(--font-mono);
  font-size: .72rem;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 .6rem;
}
.masthead-title { font-size: clamp(2.4rem, 7vw, 3.6rem); letter-spacing: -.02em; margin: 0; }
.masthead-sub { color: var(--muted); margin: .65rem 0 0; max-width: 32rem; }

/* ── Setup: players ──────────────────────────────────────────────────────── */
.player-row { display: flex; gap: .5rem; margin-bottom: .55rem; }
.player-row .player-name { flex: 1; }
.remove-player { padding: .4rem .65rem; color: var(--muted); }

/* ── Setup: mode (segmented control) ─────────────────────────────────────── */
.segmented { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.segmented label { position: relative; display: block; }
.segmented input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.segmented span { display: block; padding: .5rem 1.4rem; font-weight: 600; color: var(--muted); transition: background .15s, color .15s; }
.segmented input:checked + span { background: linear-gradient(180deg, var(--link-bright), var(--link)); color: #fff; }
.hint { color: var(--muted); font-size: .9rem; margin: .7rem 0 0; }

/* ── Setup: challenge route (From ↓ To) ──────────────────────────────────── */
.route { position: relative; }
.route .field { margin: 0; }
.route-arrow {
  width: 2rem; height: 2rem; margin: .45rem 0;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: var(--link);
  background: var(--link-tint); border-radius: 50%;
}
.ac-field > label { display: block; margin-bottom: .35rem; font-weight: 600; font-size: .9rem; }
.ac-row { display: flex; gap: .5rem; align-items: flex-start; }
.ac-wrap { position: relative; flex: 1; }
.random-btn { padding: .55rem .7rem; font-size: 1.05rem; line-height: 1; }

/* ── Autocomplete dropdown ───────────────────────────────────────────────── */
.ac-list {
  position: absolute; left: 0; right: 0; top: calc(100% + .25rem); z-index: 30;
  margin: 0; padding: .25rem; list-style: none;
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--radius); max-height: 16rem; overflow: auto; box-shadow: var(--shadow);
}
.ac-item { padding: .45rem .6rem; border-radius: 7px; cursor: pointer; font-family: var(--font-mono); font-size: .88rem; }
.ac-item.ac-active, .ac-item:hover { background: var(--link-tint); color: var(--link-deep); }

/* ── Options ─────────────────────────────────────────────────────────────── */
.check { display: flex; align-items: center; gap: .55rem; margin: .45rem 0; cursor: pointer; }
.check input { width: 1.05rem; height: 1.05rem; accent-color: var(--link); }

#setup-submit { width: 100%; padding: .8rem; font-size: 1.05rem; }

/* ── Game: header (challenge + instrument cluster) ───────────────────────── */
.game-header {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: .6rem 1.5rem; padding: .7rem clamp(1rem, 4vw, 2rem);
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.challenge { font-family: var(--font-display); font-size: 1.05rem; min-width: 0; }
.challenge-start { color: var(--muted); }
.challenge-arrow { color: var(--accent); margin: 0 .4rem; }
.challenge-target { font-weight: 700; }

.stats { display: flex; gap: 1.4rem; }
.stat { display: flex; flex-direction: column; line-height: 1.1; }
.stat-label { font-family: var(--font-mono); font-size: .6rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.stat-value { font-family: var(--font-mono); font-weight: 700; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.stat-timer .stat-value { color: var(--accent); }

/* ── Game: search bar ────────────────────────────────────────────────────── */
.search-bar {
  display: flex; align-items: center; gap: .45rem;
  padding: .5rem clamp(1rem, 4vw, 2rem);
  background: var(--surface-2); border-bottom: 1px solid var(--line);
}
.search-bar input { flex: 1; }
.search-bar button { padding: .45rem .6rem; }
.search-count { font-family: var(--font-mono); font-size: .8rem; color: var(--muted); min-width: 5.5rem; text-align: right; }

/* ── Game: article reading column ────────────────────────────────────────── */
.article-scroll { flex: 1; overflow: auto; display: flex; justify-content: center; padding: clamp(1rem, 4vw, 2.25rem); background: var(--paper); }
.article-scroll:focus { outline: none; }
.article-message { max-width: 46rem; width: 100%; margin-top: 2rem; text-align: center; color: var(--muted); font-family: var(--font-mono); font-size: .95rem; }

.article-body {
  max-width: 46rem; width: 100%; align-self: flex-start;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: var(--shadow);
  padding: clamp(1.25rem, 4vw, 2.5rem);
  font-size: 1.02rem; line-height: 1.72;
}
.article-body h1, .article-body h2, .article-body h3, .article-body h4 { font-family: var(--font-display); line-height: 1.2; }
.article-body h1 { font-size: 1.9rem; margin: 0 0 .8rem; }
.article-body h2 { font-size: 1.45rem; margin: 1.8rem 0 .6rem; padding-bottom: .25rem; border-bottom: 1px solid var(--line); }
.article-body h3 { font-size: 1.18rem; margin: 1.3rem 0 .5rem; }
.article-body p { margin: .85rem 0; }
.article-body ul, .article-body ol { padding-left: 1.5rem; }
.article-body li { margin: .2rem 0; }
.article-body img { max-width: 100%; height: auto; border-radius: 6px; }
.article-body table, .article-body .infobox, .article-body .sidebar {
  border-collapse: collapse; font-size: .88rem; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 8px; margin: 1rem 0; max-width: 100%; display: block; overflow: auto;
}
.article-body td, .article-body th { padding: .35rem .55rem; border: 1px solid var(--line); vertical-align: top; text-align: left; }
.article-body figure { margin: 1rem 0; }
.article-body figcaption { font-size: .82rem; color: var(--muted); }

/* Link affordances: valid moves are confident blue underlines; dead links recede. */
.wiki-link { color: var(--link); text-decoration: none; border-bottom: 1px solid color-mix(in srgb, var(--link) 32%, transparent); cursor: pointer; transition: background .12s, border-color .12s; border-radius: 2px; }
.wiki-link:hover { color: var(--link-deep); background: var(--link-tint); border-bottom-color: var(--link); }
.wiki-link-disabled { color: var(--ink); opacity: .55; text-decoration: none; cursor: default; }

mark.search-hit { background: #ffe9a8; color: inherit; border-radius: 2px; }
mark.search-hit-active { background: var(--accent); color: #fff; }

/* ── Game: footer + the path trail (signature) ───────────────────────────── */
.game-footer {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: .6rem 1rem; padding: .65rem clamp(1rem, 4vw, 2rem);
  background: var(--surface); border-top: 1px solid var(--line);
}
.actions { display: flex; gap: .5rem; }

.trail { display: flex; flex-wrap: wrap; align-items: center; gap: .55rem; margin: 0; max-height: 5.5rem; overflow: auto; }
.trail-node { display: inline-flex; align-items: center; gap: .4rem; font-size: .82rem; }
.trail-node:not(.is-start)::before {
  content: ''; width: .9rem; height: 2px; border-radius: 2px;
  background: var(--line-strong); margin-right: .15rem;
}
.trail-step {
  font-family: var(--font-mono); font-size: .58rem; font-weight: 700; letter-spacing: .04em;
  color: #fff; background: var(--link); border-radius: 99px; padding: .12rem .42rem;
}
.trail-node.is-start .trail-step { background: var(--ink); }
.trail-node.is-current .trail-step { background: var(--accent); }
.trail.is-won .trail-node.is-current .trail-step { background: var(--gold); color: var(--ink); }
.trail-title { color: var(--ink-soft); }
.trail-node.is-current .trail-title { color: var(--ink); font-weight: 700; }

/* Large hero trail on results, with a staggered reveal. */
.trail-lg { gap: .7rem .8rem; margin: .5rem 0 1.5rem; max-height: none; }
.trail-lg .trail-node { font-size: 1rem; animation: node-in .4s ease both; animation-delay: calc(var(--i, 0) * 55ms); }
.trail-lg .trail-step { font-size: .68rem; padding: .18rem .5rem; }
@keyframes node-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ── Results ─────────────────────────────────────────────────────────────── */
.result-headline { font-size: clamp(1.8rem, 5vw, 2.6rem); letter-spacing: -.015em; margin: 0 0 1.25rem; }
.section-label { font-family: var(--font-mono); font-size: .7rem; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); font-weight: 500; margin: 1.5rem 0 .4rem; }

.result-summary { display: flex; gap: 2.5rem; margin: 0 0 .5rem; }
.result-summary dt { font-family: var(--font-mono); font-size: .65rem; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.result-summary dd { margin: .1rem 0 0; font-family: var(--font-mono); font-weight: 700; font-size: 2rem; font-variant-numeric: tabular-nums; }

.result-actions { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1.75rem; }

/* ── Scoreboard ──────────────────────────────────────────────────────────── */
.scoreboard-wrap { margin: 1.75rem 0; padding: 1.1rem 1.2rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.scoreboard-wrap h2 { font-size: 1.05rem; margin: 0 0 .6rem; }
.scoreboard-wrap h3 { font-family: var(--font-mono); font-size: .7rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); font-weight: 500; margin: 1.25rem 0 .5rem; }

table.scoreboard { width: 100%; border-collapse: collapse; }
table.scoreboard th, table.scoreboard td { padding: .45rem .5rem; border-bottom: 1px solid var(--line); }
table.scoreboard thead th { font-family: var(--font-mono); font-size: .62rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 500; }
table.scoreboard tbody tr:first-child td { font-weight: 700; }
table.scoreboard td:first-child, table.scoreboard th:first-child { text-align: left; }
table.scoreboard td:not(:first-child), table.scoreboard th:not(:first-child) { text-align: center; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

.mini-scores { list-style: none; padding: 0; margin: .4rem 0 0; }
.mini-scores li { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .25rem 1rem; padding: .4rem 0; border-bottom: 1px solid var(--line); }
.mini-rank { font-family: var(--font-mono); font-size: .85rem; color: var(--muted); min-width: 2rem; }
.mini-name { font-weight: 700; }
.mini-leg { flex: 1; color: var(--muted); font-size: .9rem; }
.mini-score { font-family: var(--font-mono); font-size: .9rem; font-variant-numeric: tabular-nums; }
.mini-legend { font-size: .78rem; margin: .6rem 0 0; }

/* ── Handoff ─────────────────────────────────────────────────────────────── */
.handoff { margin: 1.75rem 0; padding: 1.1rem 1.2rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); }
.handoff h2 { margin: 0 0 .8rem; font-size: 1.1rem; }
.handoff .ac-field { margin-bottom: .9rem; }
#handoff-submit { width: 100%; }

/* ── Motion preference ───────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}

/* ── Small screens ───────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .game-header { gap: .5rem 1rem; }
  .stats { gap: 1rem; width: 100%; justify-content: space-between; }
  .challenge { width: 100%; }
  .result-summary { gap: 1.5rem; }
}
