:root {
  --bg: #10151c;
  --panel: rgba(14, 20, 28, .88);
  --line: rgba(255, 255, 255, .14);
  --ink: #eef3f8;
  --dim: #93a2b4;
  --grass: #4caf50;
  --offside: #ff3b4e;
  --onside: #22c55e;
  --violet: #7b5cff;
  --topbar: 68px;
  font-synthesis-weight: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
}

/* ---------------------------------------------------------------- topbar */
#topbar {
  height: var(--topbar);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 18px;
  background: linear-gradient(180deg, #16202c, #0d131a);
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 5;
}

.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }

.brand-flag {
  height: 30px;
  width: auto;
  flex: none;
  align-self: center;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, .5));
}

h1 {
  font-size: 27px;
  letter-spacing: -.5px;
  margin: 0;
  font-weight: 800;
}
h1 .excl { color: var(--offside); }

.tagline {
  margin: 0;
  color: var(--dim);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-tools { display: flex; align-items: center; gap: 8px; flex: none; }

.tool {
  width: 36px; height: 34px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0c1219;
  color: var(--ink);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.tool:hover { background: #1a2531; }
.tool svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tool .spk { fill: currentColor; stroke-width: 1.2; }
.tool .cross { display: none; }
.tool[aria-pressed="true"] { color: var(--dim); }
.tool[aria-pressed="true"] .wave { display: none; }
.tool[aria-pressed="true"] .cross { display: block; }

/* language dropdown */
.dropdown { position: relative; }
#lang-btn {
  display: flex; align-items: center; gap: 8px;
  height: 34px;
  padding: 0 10px;
  font: inherit; font-size: 13px;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0c1219;
  cursor: pointer;
  transition: background .15s;
}
#lang-btn:hover { background: #1a2531; }
.flag {
  width: 24px; height: 17px; flex: none;
  border-radius: 3px; overflow: hidden;
  box-shadow: 0 0 0 1px #0006;
  display: block;
}
.flag svg { display: block; width: 100%; height: 100%; }
.caret {
  width: 0; height: 0; margin-left: 1px;
  border: 4px solid transparent;
  border-top-color: currentColor;
  transform: translateY(2px);
  opacity: .7;
}
#lang-btn[aria-expanded="true"] .caret { transform: translateY(-2px) rotate(180deg); }

#lang-list {
  position: absolute; top: calc(100% + 6px); right: 0;
  min-width: 168px;
  margin: 0; padding: 5px;
  list-style: none;
  background: #101821;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 16px 40px #000b;
  z-index: 20;
}
#lang-list button {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 8px 9px;
  font: inherit; font-size: 13.5px;
  color: var(--ink);
  background: none; border: none; border-radius: 7px;
  cursor: pointer;
  text-align: left;
}
#lang-list button:hover { background: #1d2a38; }
#lang-list button[aria-selected="true"] { background: #24384d; font-weight: 600; }

/* ----------------------------------------------------------------- stage */
#stage {
  position: relative;
  height: calc(100% - var(--topbar));
  overflow: hidden;
}
/* the explicit height above would otherwise leave a topbar-sized gap */
#stage:fullscreen { width: 100%; height: 100%; }
#scene { display: block; width: 100%; height: 100%; }

/* fullscreen toggle, bottom right of the playing area */
.corner-btn {
  position: absolute; right: 14px; bottom: 14px;
  z-index: 6;
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: background .15s, transform .12s;
}
.corner-btn:hover { background: #223041; transform: translateY(-2px); }
.corner-btn svg {
  width: 19px; height: 19px;
  fill: none; stroke: currentColor;
  stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round;
}
.corner-btn .fs-out { display: none; }
.corner-btn[aria-pressed="true"] .fs-in { display: none; }
.corner-btn[aria-pressed="true"] .fs-out { display: block; }

/* ------------------------------------------------------------------- hud */
#hud {
  position: absolute; top: 14px; left: 14px; right: 14px;
  display: flex; align-items: flex-start; justify-content: space-between;
  pointer-events: none;
}
.hud-row { display: flex; gap: 8px; }
.chip {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 15px;
  font-size: 13px;
  backdrop-filter: blur(6px);
}
.chip-k { color: var(--dim); text-transform: uppercase; letter-spacing: .9px; font-size: 11px; }
.chip b { font-size: 15px; font-variant-numeric: tabular-nums; }

.icon-btn {
  pointer-events: auto;
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font-size: 16px; font-weight: 700;
  cursor: pointer;
  backdrop-filter: blur(6px);
}
.icon-btn:hover { background: #223041; }

#phase-label {
  /* top aligned with the round/score chips */
  position: absolute; top: 14px; left: 0; right: 0;
  display: flex;
  justify-content: center;
  padding: 0 12px;
  pointer-events: none;
  animation: fade .4s;
}
.phase-card {
  background: rgba(6, 9, 13, .86);
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 10px 24px 12px;
  text-align: center;
  max-width: min(560px, 92vw);
  backdrop-filter: blur(6px);
  box-shadow: 0 12px 34px #0008;
}
#phase-main {
  display: block;
  font-size: 13px;
  letter-spacing: 2.4px;
  text-transform: uppercase;
  color: #fff;
  text-shadow: 0 2px 12px #000a;
}
#phase-sub {
  display: block;
  margin-top: 5px;
  font-size: 14px;
  color: #dbe6f2;
  text-shadow: 0 2px 12px #000c;
}
#phase-sub:empty { display: none; }

#phase-team {
  display: block;
  margin-top: 4px;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: .3px;
}
#phase-team:empty { display: none; }
#phase-team.team-blue { color: #7ea8ff; }
#phase-team.team-red { color: #ff8a80; }

/* -------------------------------------------------------------- controls */
#controls {
  position: absolute; bottom: 26px; left: 0; right: 0;
  display: flex; justify-content: center; align-items: center; gap: 12px;
  padding: 0 12px;
  animation: rise .35s cubic-bezier(.2,.9,.3,1.2);
}
#controls button {
  font: inherit;
  font-weight: 700;
  border-radius: 12px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: transform .12s, filter .12s, background .12s;
}
#controls button:hover { transform: translateY(-2px); filter: brightness(1.12); }
#controls button:active { transform: translateY(0); }

.answer {
  padding: 15px 30px;
  font-size: 17px;
  color: #fff;
  letter-spacing: .3px;
  box-shadow: 0 8px 26px #0008;
  display: inline-flex; align-items: center; gap: 9px;
}
/*
 * Both buttons carry a mark as well as a colour, and both clear 4.5:1 at this
 * size. The red is a little deeper than it looks like it wants to be: white on
 * the old #ff5468 measured 3.5:1. The green keeps its brightness instead and
 * takes near-black text, which measures 8.3:1 — better than white ever could
 * on a colour that light.
 */
.answer.offside { background: linear-gradient(180deg, #d0384c, #b31f30); }
.answer.onside  { background: linear-gradient(180deg, #35d17a, #12a355); color: #04240f; }
.answer .mark { font-size: 1.05em; line-height: 1; }

.ghost {
  padding: 13px 20px;
  font-size: 14px;
  background: var(--panel);
  color: var(--ink);
  border-color: var(--line) !important;
  backdrop-filter: blur(6px);
  display: inline-flex; align-items: center; gap: 9px;
}
.ghost .eye {
  width: 17px; height: 11px; flex: none;
  border: 1.6px solid currentColor;
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  position: relative;
}
.ghost .eye::after {
  content: ""; position: absolute; inset: 2px; margin: auto;
  width: 4px; height: 4px; border-radius: 50%; background: currentColor;
}

#view-name {
  position: absolute; bottom: 96px; left: 0; right: 0;
  text-align: center;
  font-size: 12px; letter-spacing: 1.8px; text-transform: uppercase;
  color: #cfe0f0;
  text-shadow: 0 2px 10px #000a;
  pointer-events: none;
}

/* --------------------------------------------------------------- verdict */
#verdict {
  position: absolute; inset: auto 0 0 0;
  display: flex; justify-content: center;
  padding: 0 14px 24px;
  pointer-events: none;
}
.verdict-card {
  pointer-events: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px 26px 20px;
  text-align: center;
  min-width: min(460px, 92vw);
  backdrop-filter: blur(10px);
  box-shadow: 0 18px 50px #000a;
  animation: rise .4s cubic-bezier(.2,.9,.3,1.2);
}
.v-judgement { font-size: 30px; font-weight: 800; letter-spacing: -.5px; }
.v-judgement.is-offside { color: var(--offside); }
.v-judgement.is-onside  { color: var(--onside); }
.v-margin { color: var(--dim); font-size: 13px; margin-top: 2px; font-variant-numeric: tabular-nums; }
.v-outcome { margin-top: 10px; font-size: 16px; font-weight: 700; }
.v-outcome.ok  { color: var(--onside); }
.v-outcome.bad { color: var(--offside); }
.v-explain { color: #c3cfdc; font-size: 13px; line-height: 1.5; margin: 8px auto 14px; max-width: 46ch; }
.v-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.ghost-btn {
  font: inherit; font-weight: 600;
  padding: 12px 20px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .06);
  color: var(--ink);
  cursor: pointer;
  transition: transform .12s, background .12s;
}
.ghost-btn:hover { transform: translateY(-2px); background: rgba(255, 255, 255, .12); }

/* --------------------------------------------------------- panels/screens */
#loader, #start, #end, #help, #about {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 14px;
  background: radial-gradient(ellipse at 50% 40%, #16202c 0%, #080b10 100%);
  z-index: 4;
}
#help, #about { background: rgba(6, 9, 13, .82); backdrop-filter: blur(4px); }

.panel h3 { margin: 18px 0 8px; font-size: 15px; letter-spacing: .2px; }
.credits { text-align: left; margin: 0 0 18px; font-size: 13px; line-height: 1.5; }
.credits dt { color: var(--dim); font-size: 11.5px; text-transform: uppercase; letter-spacing: .8px; margin-top: 10px; }
.credits dd { margin: 2px 0 0; color: #c3cfdc; }
.credits b { color: #fff; font-weight: 600; }
.credits a { color: #7ea8ff; text-decoration: none; }
.credits a:hover { text-decoration: underline; }

/* which commit this copy was built from: wanted when a bug report comes in,
   and of no interest at all the rest of the time */
.build {
  margin: 16px 0 0 !important;
  font-size: 11.5px !important;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 30px 34px;
  max-width: min(560px, 92vw);
  text-align: center;
  box-shadow: 0 24px 70px #000b;
}
.panel h2 { margin: 0 0 10px; font-size: 25px; letter-spacing: -.4px; }
.panel p { color: #c3cfdc; font-size: 14px; line-height: 1.6; margin: 0 0 14px; }

.rules { text-align: left; margin: 0 0 18px; padding-left: 20px; color: #c3cfdc; font-size: 13.5px; line-height: 1.65; }
.rules li { margin-bottom: 5px; }
.rules b { color: #fff; }

.primary {
  font: inherit; font-weight: 700;
  padding: 12px 26px;
  border-radius: 11px;
  border: none;
  background: linear-gradient(180deg, #4a71cf, #3559b4);   /* white text, 4.6:1 */
  color: #fff;
  cursor: pointer;
  transition: transform .12s, filter .12s;
}
.primary:hover { transform: translateY(-2px); filter: brightness(1.1); }
.primary.big { padding: 15px 40px; font-size: 17px; }

.final-score { font-size: 15px; color: var(--dim); }
.final-score b { font-size: 46px; color: #fff; display: block; line-height: 1.05; font-variant-numeric: tabular-nums; }
.grade { font-size: 16px; font-weight: 700; color: #ffd166 !important; }

.recap {
  text-align: left;
  margin: 4px 0 20px;
  padding: 0;
  list-style: none;
  font-size: 13px;
  /* eleven rows: taller and tighter, still scrolling on a short window */
  max-height: min(44vh, 380px);
  overflow: auto;
}
.recap li {
  display: flex; align-items: center; gap: 10px;
  padding: 5px 4px;
  border-bottom: 1px solid rgba(255,255,255,.07);
  color: #c3cfdc;
}
.recap .n { color: var(--dim); width: 22px; font-variant-numeric: tabular-nums; }
.recap .mark { width: 20px; font-size: 15px; text-align: center; }
.recap .mark.ok { color: var(--onside); }
.recap .mark.bad { color: var(--offside); }
.recap .body { flex: 1; display: flex; flex-direction: column; gap: 1px; }
.recap .txt { line-height: 1.25; }
/* the rule the round was teaching: present, but never louder than the result */
.recap .lesson { color: var(--dim); font-size: 12.5px; line-height: 1.35; }
.recap .cm { color: var(--dim); font-variant-numeric: tabular-nums; }

/* -------------------------------------------------------------- loading */
.spinner {
  width: 42px; height: 42px;
  border: 3px solid rgba(255,255,255,.16);
  border-top-color: var(--grass);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
#loader p { color: var(--dim); font-size: 14px; margin: 0; }
.bar { width: min(280px, 60vw); height: 4px; border-radius: 2px; background: rgba(255,255,255,.12); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--grass); transition: width .25s; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }
@keyframes fade { from { opacity: 0; } }

[hidden] { display: none !important; }

/* ------------------------------------------------------- keyboard controls */
/* The shortcuts, listed and rebindable, at the bottom of the rules panel. */
.keys-hint { font-size: 12.5px; color: var(--dim); margin: 0 0 8px !important; text-align: left; }
.keys { margin: 0 0 18px; padding: 0; list-style: none; text-align: left; }
.keys li {
  display: flex; align-items: center; gap: 10px;
  padding: 5px 2px;
  font-size: 13px;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.keys .what { flex: 1; color: #c3cfdc; }
.keys button {
  font: inherit; font-size: 12px; font-weight: 600;
  min-width: 84px;
  padding: 6px 10px;
  color: var(--ink);
  background: rgba(255,255,255,.07);
  border: 1px solid var(--line);
  border-radius: 7px;
  cursor: pointer;
}
.keys button:hover { background: rgba(255,255,255,.13); }
/* while waiting for the next key press, so it is obvious the game is listening */
.keys button[aria-pressed="true"] {
  background: #24384d;
  border-color: #7ea8ff;
  color: #cfe0f0;
}
.keys-reset {
  font: inherit; font-size: 12px;
  display: block;
  margin: 0 auto 18px;      /* its own line, above the panel's own button */
  padding: 7px 12px;
  color: var(--dim);
  background: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}
.keys-reset:hover { color: var(--ink); background: rgba(255,255,255,.07); }

/* ---------------------------------------------------------------- a11y */
/*
 * One visible focus ring for everything, drawn outside the element so it
 * survives the dark gradients and the busy 3D behind the overlay. Only
 * :focus-visible, so a mouse click does not leave a ring behind.
 */
:focus-visible {
  outline: 3px solid #8ab4ff;
  outline-offset: 2px;
  border-radius: 6px;
}

/* Everything that moves here is decoration: the panels rising, the spinner,
   the button lifts. The camera drift is switched off in views.js. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
  #controls button:hover, .primary:hover, .ghost-btn:hover { transform: none; }
}

/* Reader's setting, not ours: firmer borders, brighter secondary text and
   solid panels, since the translucent ones sit over whatever is on the pitch. */
@media (prefers-contrast: more) {
  :root {
    --dim: #c2ceda;
    --line: rgba(255, 255, 255, .5);
    --panel: #0b1017;
  }
  .recap .lesson, #loader p { color: #c2ceda; }
  .panel, .verdict-card, .phase-card, .chip { border: 1px solid var(--line); }
  .answer.offside { background: #a3162a; }
  .answer.onside { background: #2fd177; color: #001a08; }
  .primary { background: #2f5fe0; }
  :focus-visible { outline-width: 4px; outline-color: #fff; }
}

@media (max-width: 700px) {
  :root { --topbar: 58px; }
  h1 { font-size: 21px; }
  .tagline { display: none; }
  .answer { padding: 13px 18px; font-size: 15px; }
  .ghost { padding: 12px 14px; font-size: 13px; }
  #controls { gap: 8px; bottom: 16px; }
  /* the card is nearly full width here, so it cannot share a line with the chips */
  #phase-label { top: 56px; }
}

/* On a phone the three controls do not fit side by side: "Not offside" wraps
   and runs under the full-screen button. The view toggle drops to its icon,
   which is what the button is recognised by anyway (its name stays
   in title/aria-label), and that buys back enough room for the two answers. */
@media (max-width: 560px) {
  .answer { padding: 13px 15px; font-size: 14.5px; white-space: nowrap; }
  .ghost { padding: 12px; gap: 0; }
  .ghost span:not(.eye) { display: none; }
  .corner-btn { width: 34px; height: 34px; bottom: 12px; right: 12px; }
}
