:root {
  --ink: #08080f;
  --ink-2: #0d0d1a;
  --player: #34e2d4;      /* electric teal */
  --player-dim: rgba(52,226,212,0.18);
  --bot: #ff5ca8;         /* magenta */
  --bot-dim: rgba(255,92,168,0.18);
  --amber: #ffc24b;
  --strike: #ff4d4d;
  --fog: rgba(160,170,210,0.55);
  --display: "Fraunces", Georgia, serif;
  --mono: "Space Mono", ui-monospace, monospace;
}

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

html, body { height: 100%; }

body {
  font-family: var(--mono);
  color: #e8e9f3;
  background: var(--ink);
  overflow: hidden;
  position: relative;
}

/* ── Atmospheric layered background ── */
.bg {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(900px 700px at 22% 18%, rgba(52,226,212,0.15), transparent 60%),
    radial-gradient(800px 800px at 82% 78%, rgba(255,92,168,0.15), transparent 60%),
    radial-gradient(1200px 900px at 50% 50%, #11112200, var(--ink) 75%),
    var(--ink);
}
.bg::after {
  content: ""; position: absolute; inset: -50%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.4'/%3E%3C/svg%3E");
  opacity: 0.035; mix-blend-mode: screen;
  animation: drift 40s linear infinite;
}
@keyframes drift { from { transform: translate(0,0); } to { transform: translate(-80px,-60px); } }

/* ── SVG edge canvas ── */
svg#edges { position: fixed; inset: 0; z-index: 1; pointer-events: none; width: 100%; height: 100%; }
.edge {
  fill: none; stroke-width: 1.4; stroke-linecap: round; opacity: 0.5;
  stroke-dasharray: 1; stroke-dashoffset: 1;
  transition: stroke-dashoffset 0.7s ease;
}
.edge.player { stroke: var(--player); }
.edge.bot    { stroke: var(--bot); }

/* Provisional (learning) edge — dashed amber, visually distinct from confirmed */
.edge.provisional { stroke: var(--amber); stroke-dasharray: 6 6; opacity: 0.7; }
.edge.provisional.graduated {
  stroke-dasharray: 1; opacity: 1;
  filter: drop-shadow(0 0 6px var(--amber));
}

/* ── HUD ── */
.hud {
  position: fixed; z-index: 5; top: 28px; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: center;
  padding: 0 40px; font-size: 12px; letter-spacing: 0.22em; text-transform: uppercase;
}
.brand { color: var(--fog); }
.brand b { color: #fff; font-weight: 700; }
.strikes { display: flex; gap: 10px; align-items: center; }
.pip {
  width: 11px; height: 11px; border-radius: 50%; border: 1.5px solid var(--strike);
  opacity: 0.45; transition: all .35s;
}
.pip.on { background: var(--strike); opacity: 1; box-shadow: 0 0 16px var(--strike); }
.score { color: var(--fog); display: flex; align-items: center; gap: 10px; }
.score b { color: var(--player); }
.daily-link {
  color: var(--player); text-decoration: none;
  border: 1px solid var(--player-dim); border-radius: 2px;
  padding: 3px 8px; letter-spacing: 0.18em; transition: all .25s;
}
.daily-link:hover { background: var(--player-dim); }
.share-btn {
  font-family: var(--mono); font-size: 12px; letter-spacing: 0.18em;
  text-transform: uppercase; cursor: pointer;
  color: var(--player); background: var(--player-dim);
  border: 1px solid var(--player); border-radius: 2px;
  padding: 3px 10px; transition: all .25s;
}
.share-btn:hover { background: var(--player); color: var(--ink); }

/* Countdown clock — teal normally, amber when time is low */
.clock {
  font-variant-numeric: tabular-nums;
  color: var(--player); letter-spacing: 0.18em;
  border: 1px solid var(--player-dim); border-radius: 2px;
  padding: 3px 8px; min-width: 44px; text-align: center;
}
.clock.low {
  color: var(--amber); border-color: var(--amber);
  box-shadow: 0 0 12px rgba(255,194,75,0.4);
}

/* ── Pre-game picker (mode / category / timed) ── */
.picker {
  position: fixed; z-index: 5; top: 64px; left: 0; right: 0;
  display: flex; flex-wrap: wrap; justify-content: center; gap: 18px;
  padding: 0 40px; font-size: 11px;
  letter-spacing: 0.18em; text-transform: uppercase;
}
.picker-group { display: flex; align-items: center; gap: 8px; }
.picker-label { color: var(--fog); }
.picker-opt {
  color: var(--fog); text-decoration: none;
  border: 1px solid var(--player-dim); border-radius: 2px;
  padding: 2px 8px; transition: all .25s;
}
.picker-opt:hover { color: var(--player); background: var(--player-dim); }
.picker-opt:focus-visible { outline: 2px solid var(--player); outline-offset: 2px; }
.picker-opt.active {
  color: var(--ink); background: var(--player); border-color: var(--player);
}

@media (max-width: 640px) {
  .picker { gap: 10px; top: 58px; padding: 0 12px; font-size: 10px; }
}

/* ── Constellation field ── */
.field { position: fixed; inset: 0; z-index: 2; }
.node {
  position: absolute; transform: translate(-50%,-50%);
  font-family: var(--display); font-weight: 400; white-space: nowrap;
  transition: opacity .8s, filter .8s;
  /* cue 2: node spring pop on mount */
  animation: pop .55s cubic-bezier(.2,1.3,.4,1) both;
}
.node .word { display: block; }
.node.player .word { color: var(--player); text-shadow: 0 0 22px var(--player-dim), 0 0 60px var(--player-dim); }
.node.bot .word    { color: var(--bot);    text-shadow: 0 0 22px var(--bot-dim), 0 0 60px var(--bot-dim); }
.node.old { opacity: 0.32; filter: blur(0.3px); }
@keyframes pop {
  from { opacity: 0; transform: translate(-50%,-50%) scale(.6); }
  to   { opacity: 1; transform: translate(-50%,-50%) scale(1); }
}

/* ── Center stage ── */
.stage {
  position: fixed; z-index: 3; left: 50%; top: 42%;
  transform: translate(-50%,-50%); text-align: center;
}
.turnlabel {
  font-size: 11px; letter-spacing: 0.3em; text-transform: uppercase;
  color: var(--fog); margin-bottom: 14px;
}
.turnlabel .who { color: var(--player); }
.turnlabel.botturn .who { color: var(--bot); }

/* cue 3: stage word change — scale+opacity with CSS transition */
.current {
  font-family: var(--display); font-size: clamp(56px, 11vw, 150px);
  line-height: 0.9; font-weight: 300; letter-spacing: -0.02em;
  transition: opacity 0.25s, transform 0.25s;
}
.current.player { color: #eafffb; text-shadow: 0 0 40px var(--player-dim); }
.current.bot    { color: #ffeaf4; text-shadow: 0 0 40px var(--bot-dim); }

/* cue 3: stage word swap animation — fades/scales in on each new word */
@keyframes stageSwap {
  0%   { opacity: 0; transform: scale(0.9); }
  100% { opacity: 1; transform: scale(1); }
}
.current.swap { animation: stageSwap 0.25s ease; }

/* cue: rejected word dissolve animation */
@keyframes dissolve {
  0%   { opacity: 0.9; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0;   transform: translate(-50%, -50%) scale(1.4); }
}
.node.dissolve { animation: dissolve 0.7s ease forwards; }

/* cue 1: page-load reveal — seed node + underline draw-in */
@keyframes reveal { from { opacity: 0; transform: translate(-50%,-50%) scale(.85); } to { opacity: 1; transform: translate(-50%,-50%) scale(1); } }
.stage { animation: reveal 0.6s 0.1s ease both; }

/* cue 4: bot thinking — pulsing dots */
.thinking { display: inline-flex; gap: 8px; margin-top: 8px; }
.thinking i {
  width: 9px; height: 9px; border-radius: 50%; background: var(--bot);
  display: inline-block; animation: blink 1s infinite both;
}
.thinking i:nth-child(2) { animation-delay: .15s; }
.thinking i:nth-child(3) { animation-delay: .3s; }
@keyframes blink {
  0%, 100% { opacity: .2; transform: scale(.8); }
  50%       { opacity: 1;  transform: scale(1); }
}

/* ── Input wrap — directly beneath the stage word ── */
.inputwrap {
  position: fixed; z-index: 6; left: 50%; top: 58%;
  transform: translateX(-50%); width: min(560px, 80vw); text-align: center;
}
.prompt {
  font-size: 12px; letter-spacing: 0.2em; text-transform: uppercase;
  color: var(--fog); margin-bottom: 12px;
}
.prompt b { color: var(--player); }
.field-line { position: relative; }
input#input {
  width: 100%; background: transparent; border: none; outline: none;
  text-align: center; font-family: var(--display); font-weight: 300;
  font-size: 38px; color: #fff; padding: 6px 2px; caret-color: var(--player);
}
/* cue 1: underline draw-in on page load */
.underline {
  height: 2px; background: rgba(255,255,255,0.12);
  position: relative; overflow: hidden;
}
.underline::after {
  content: ""; position: absolute; inset: 0; width: 0;
  background: linear-gradient(90deg, var(--player), var(--amber));
  animation: drawline 1s 0.3s ease forwards;
}
@keyframes drawline { to { width: 100%; } }
input#input:focus ~ .underline { background: rgba(52,226,212,0.25); }
.hint { margin-top: 10px; font-size: 11px; letter-spacing: .08em; color: rgba(255,255,255,0.3); }
.hint kbd { color: var(--amber); }

/* ── Toast notification ── */
.toast {
  position: fixed; z-index: 7; left: 50%; top: 72%;
  transform: translateX(-50%); font-size: 13px; letter-spacing: .1em;
  padding: 9px 16px; border-radius: 2px;
  opacity: 0; transition: opacity .3s, transform .3s; pointer-events: none;
}
.toast.show { opacity: 1; }
.toast.bad  { color: var(--strike); border: 1px solid rgba(255,77,77,.4); background: rgba(255,77,77,.08); }
.toast.good { color: var(--player); border: 1px solid var(--player-dim); }

/* ── Progression stats panel (revealed on game over) ── */
.stats {
  position: fixed; z-index: 6; left: 50%; bottom: 132px;
  transform: translateX(-50%);
  padding: 14px 22px; border-radius: 4px;
  background: rgba(13,13,26,0.72);
  border: 1px solid var(--player-dim);
  backdrop-filter: blur(6px);
}
.stats[hidden] { display: none; }
.stats-row { display: flex; gap: 26px; align-items: flex-end; }
.stat { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.stat b {
  font-family: var(--display); font-weight: 600; font-size: 28px;
  color: var(--player); line-height: 1;
}
.stat span {
  font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--fog);
}

/* ── Daily leaderboard (revealed on a daily game over) ── */
.leaderboard {
  position: fixed; z-index: 6; right: 40px; top: 96px;
  width: 280px; max-width: 80vw;
  padding: 18px 20px; border-radius: 4px;
  background: rgba(13,13,26,0.78);
  border: 1px solid var(--bot-dim);
  backdrop-filter: blur(6px);
}
.leaderboard[hidden] { display: none; }
.leaderboard-title {
  font-family: var(--display); font-weight: 600; font-size: 16px;
  letter-spacing: 0.04em; color: var(--bot); margin-bottom: 12px;
}
.leaderboard-form { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.handle-label {
  flex: 1 0 100%;
  font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--fog);
}
.handle-in {
  flex: 1 1 auto; min-width: 0;
  font-family: var(--mono); font-size: 13px; color: #e8e9f3;
  background: rgba(8,8,15,0.6);
  border: 1px solid var(--bot-dim); border-radius: 2px;
  padding: 6px 9px; outline: none;
}
.handle-in:focus { border-color: var(--bot); }
.handle-in::placeholder { color: rgba(160,170,210,0.4); }
.submitscore-btn {
  font-family: var(--mono); font-size: 12px; letter-spacing: 0.16em;
  text-transform: uppercase; cursor: pointer;
  color: var(--bot); background: var(--bot-dim);
  border: 1px solid var(--bot); border-radius: 2px;
  padding: 6px 12px; transition: all .25s;
}
.submitscore-btn:hover { background: var(--bot); color: var(--ink); }
.submitscore-btn:disabled { opacity: 0.5; cursor: default; }
.board {
  list-style: none; display: flex; flex-direction: column; gap: 6px;
  counter-reset: rank; max-height: 320px; overflow-y: auto;
}
.board-row {
  counter-increment: rank;
  display: flex; align-items: baseline; gap: 10px;
  font-size: 13px; color: #e8e9f3;
}
.board-row::before {
  content: counter(rank);
  font-family: var(--mono); font-size: 11px; color: var(--amber);
  min-width: 18px; text-align: right;
}
.board-name { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-score {
  font-variant-numeric: tabular-nums; color: var(--player); font-weight: 700;
}

/* ── First-run onboarding overlay ── */
.onboarding {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: rgba(8,8,15,0.82);
  backdrop-filter: blur(4px);
}
.onboarding[hidden] { display: none; }
.onboarding-card {
  width: min(480px, 92vw);
  padding: 28px 30px 30px;
  border-radius: 6px;
  background: rgba(13,13,26,0.96);
  border: 1px solid var(--player-dim);
  box-shadow: 0 0 60px rgba(52,226,212,0.18), 0 0 40px rgba(255,92,168,0.12);
}
.onboarding-card h2 {
  font-family: var(--display); font-weight: 600; font-size: 28px;
  letter-spacing: 0.01em; color: var(--player);
  margin-bottom: 18px;
}
.onboarding-card ul {
  list-style: none; display: flex; flex-direction: column; gap: 12px;
  margin-bottom: 24px;
}
.onboarding-card li {
  font-family: var(--mono); font-size: 14px; line-height: 1.5;
  color: #e8e9f3;
  padding-left: 18px; position: relative;
}
.onboarding-card li::before {
  content: ""; position: absolute; left: 0; top: 9px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--bot);
  box-shadow: 0 0 8px var(--bot-dim);
}
.onboarding-card strong { color: var(--player); font-weight: 700; }
.onboarding-card em { color: var(--bot); font-style: normal; font-weight: 700; }
.onboarding-btn {
  font-family: var(--mono); font-size: 13px; letter-spacing: 0.2em;
  text-transform: uppercase; cursor: pointer;
  color: var(--ink); background: var(--player);
  border: 1px solid var(--player); border-radius: 2px;
  padding: 10px 22px; transition: filter .25s, box-shadow .25s;
}
.onboarding-btn:hover { filter: brightness(1.1); box-shadow: 0 0 20px var(--player-dim); }
.onboarding-btn:focus-visible { outline: 2px solid var(--player); outline-offset: 3px; }

/* cue 6: strike flash — red screen-edge pulse */
.flash {
  position: fixed; inset: 0; z-index: 8; pointer-events: none;
  box-shadow: inset 0 0 200px 40px var(--strike); opacity: 0;
}
.flash.go { animation: redflash .5s ease; }
@keyframes redflash { 0% { opacity: 0; } 25% { opacity: .55; } 100% { opacity: 0; } }

/* ── End states on the root [data-over] ── */

/* cue 7: win — bright pulse flourish */
[data-over="win"] .field { animation: winPulse 1.2s ease; }
@keyframes winPulse {
  0%, 100% { filter: none; }
  40% { filter: brightness(1.6) drop-shadow(0 0 20px var(--player)); }
}

/* cue 8: loss — dim constellation */
[data-over="loss"] .field  { opacity: 0.18; transition: opacity 1s; }
[data-over="loss"] #edges  { opacity: 0.1;  transition: opacity 1s; }

/* cue 8: halted — freeze + grayscale */
[data-over="halted"] .field { filter: grayscale(0.6); opacity: 0.5; transition: all 1s; }

/* ── Reduced motion: instant states, no looping/transition animations ── */
@media (prefers-reduced-motion: reduce) {
  .bg::after            { animation: none; }
  .node                 { animation: none; }
  .stage                { animation: none; }
  .thinking i           { animation: none; opacity: 0.6; }
  .edge                 { animation: none; stroke-dashoffset: 0 !important; }
  .flash.go             { animation: none; opacity: 0.3; }
  .underline::after     { animation: none; width: 100%; }
  [data-over] .field    { transition: none; animation: none; }
  .current.swap         { animation: none; }
  .node.dissolve        { animation: none; opacity: 0; }
}

/* ── Responsive: keep stage + input co-axial on narrow screens ── */
@media (max-width: 640px) {
  .current    { font-size: clamp(40px, 16vw, 72px); }
  .inputwrap  { width: 88vw; }
  .hud        { padding: 0 16px; }
  .leaderboard {
    position: fixed; right: 50%; top: auto; bottom: 16px;
    transform: translateX(50%); width: 90vw;
  }
  .stats      { bottom: auto; top: 96px; }
  .stats-row  { gap: 18px; }
}

/* ── Accessibility: visually-hidden live region, skip-link, focus rings ── */
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Skip-link: hidden off-screen until focused, then anchored top-left. */
.skip-link {
  position: absolute;
  top: -100px; left: 8px;
  z-index: 1000;
  padding: 8px 14px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--ink);
  background: var(--player);
  border-radius: 6px;
  text-decoration: none;
  transition: top 0.15s ease;
}
.skip-link:focus,
.skip-link:focus-visible {
  top: 8px;
  outline: 2px solid var(--player);
  outline-offset: 2px;
}

/* Visible focus rings for keyboard users only (mouse users see no persistent ring). */
#input:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--player);
  outline-offset: 2px;
}

/* ── Broad reduced-motion neutralizer: gate motion-heavy effects ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
