/* Layout: full-bleed game canvas; HUD chips pinned to the corners; one centered card for menus. */

/* The fonts come from this server, not a font service, so the page makes no
   requests elsewhere. Bungee and IBM Plex, SIL Open Font License (fonts/OFL-*.txt). */
@font-face { font-family: 'Bungee'; font-weight: 400; font-display: swap; src: url(fonts/bungee-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Bungee'; font-weight: 400; font-display: swap; src: url(fonts/bungee-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: 'IBM Plex Sans'; font-weight: 400 600; font-display: swap; src: url(fonts/plex-sans-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'IBM Plex Sans'; font-weight: 400 600; font-display: swap; src: url(fonts/plex-sans-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: 'IBM Plex Sans'; font-weight: 400 600; font-display: swap; src: url(fonts/plex-sans-greek.woff2) format('woff2');
  unicode-range: U+0370-0377, U+037A-037F, U+0384-038A, U+038C, U+038E-03A1, U+03A3-03FF; }
@font-face { font-family: 'IBM Plex Mono'; font-weight: 500; font-display: swap; src: url(fonts/plex-mono-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'IBM Plex Mono'; font-weight: 500; font-display: swap; src: url(fonts/plex-mono-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF; }

:root {
  --void: #2a2f38;            /* outside the round map */
  --floor: #eef0f3;           /* unclaimed ground */
  --grid: rgba(30, 40, 60, 0.08);
  --edge: rgba(30, 40, 60, 0.35);
  --panel: #ffffff;
  --chip: rgba(255, 255, 255, 0.9);
  --line: #d6dbe2;
  --ink: #1b2129;
  --muted: #5b6573;
  --halo: rgba(255, 255, 255, 0.9);
  --ring: #ffffff;
  --accent: #c2410c;
  --accent-strong: #9a3412;
  --accent-ink: #ffffff;
  --scrim: rgba(18, 21, 27, 0.45);
  --gain: #15803d;            /* "+412 cells" pop-ups */
  --mini: 168px;              /* minimap diameter */
  --land-l: 62;               /* lightness of claimed land, % */
  --trail-l: 72;
  --font-display: 'Bungee', 'Arial Black', Impact, sans-serif;
  --font-body: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-data: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --void: #0d1014; --floor: #232931; --grid: rgba(255, 255, 255, 0.05); --edge: rgba(255, 255, 255, 0.25);
    --panel: #1a1f26; --chip: rgba(26, 31, 38, 0.9); --line: #343b45; --ink: #e8ecf1; --muted: #a0a9b5;
    --halo: rgba(13, 16, 20, 0.85); --ring: #ffffff; --accent: #fb923c; --accent-strong: #fdba74;
    --accent-ink: #1a0f08; --scrim: rgba(0, 0, 0, 0.5); --land-l: 52; --trail-l: 64; --gain: #4ade80;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --void: #0d1014; --floor: #232931; --grid: rgba(255, 255, 255, 0.05); --edge: rgba(255, 255, 255, 0.25);
  --panel: #1a1f26; --chip: rgba(26, 31, 38, 0.9); --line: #343b45; --ink: #e8ecf1; --muted: #a0a9b5;
  --halo: rgba(13, 16, 20, 0.85); --ring: #ffffff; --accent: #fb923c; --accent-strong: #fdba74;
  --accent-ink: #1a0f08; --scrim: rgba(0, 0, 0, 0.5); --land-l: 52; --trail-l: 64; --gain: #4ade80;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; }
body {
  background: var(--void); color: var(--ink); font: 15px/1.45 var(--font-body);
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none;
}
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
[hidden] { display: none !important; }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; font-size: 13px; }
#leaders {
  position: absolute; top: calc(12px + env(safe-area-inset-top, 0px)); right: max(12px, env(safe-area-inset-right, 0px));
  margin: 0; padding: 8px 12px; list-style: none; counter-reset: rank; min-width: 180px; max-width: 46vw;
  background: var(--chip); border-radius: 10px;
}
#leaders:empty { display: none; }
#arena {
  position: absolute; top: calc(12px + env(safe-area-inset-top, 0px)); left: max(12px, env(safe-area-inset-left, 0px));
  min-width: 150px; max-width: calc(54vw - 36px); padding: 8px 12px; border-radius: 10px; background: var(--chip);
  display: flex; flex-direction: column; gap: 6px; user-select: none;
}
.arena-row { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 12px; }
#arena-value, #arena-odds-value { color: var(--ink); font: 500 12px var(--font-data); font-variant-numeric: tabular-nums; }
.arena-bar { position: relative; height: 6px; border-radius: 3px; background: var(--line); }
#arena-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 3px; background: var(--accent); }
.arena-bar::before, .arena-bar::after { content: ''; position: absolute; left: 50%; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; background: var(--ink); opacity: 0.55; }
.arena-bar::after { left: 85%; }
#arena.closed #arena-label { color: var(--accent-strong); font-weight: 600; }
#arena.closed #arena-fill { background: var(--muted); }
#leaders li { display: flex; align-items: center; gap: 8px; counter-increment: rank; padding: 1px 0; }
#leaders li::before { content: counter(rank); width: 1.2em; color: var(--muted); font: 500 12px var(--font-data); }
#leaders i { width: 10px; height: 10px; border-radius: 3px; flex: none; }
#leaders b { font-weight: 400; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#leaders li.me b { font-weight: 600; }
#leaders span { font: 500 12px var(--font-data); font-variant-numeric: tabular-nums; }
#bottom-left {
  position: absolute; left: max(12px, env(safe-area-inset-left, 0px)); bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  max-width: calc(100% - var(--mini) - 48px);
}
#minimap {
  position: absolute; right: max(12px, env(safe-area-inset-right, 0px)); bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  width: var(--mini); height: var(--mini);   /* round chip drawn on the canvas itself */
}
#feed { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
#feed div { background: var(--chip); color: var(--muted); padding: 3px 10px; border-radius: 8px; }
#score {
  background: var(--chip); padding: 8px 12px; border-radius: 10px;
  font: 500 13px var(--font-data); font-variant-numeric: tabular-nums;
}
@media (max-width: 600px) {
  :root { --mini: 112px; }
  #arena { min-width: 124px; }
  #score { font-size: 12px; }
  #leaders li:nth-child(n + 6) { display: none; }
  #leaders { min-width: 150px; }
}

/* Menus */
.overlay {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: var(--scrim);
  padding: calc(16px + env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px))
    calc(16px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
}
.card {
  background: var(--panel); color: var(--ink); border-radius: 18px; padding: 28px;
  width: min(400px, 100%); max-height: 100%; overflow-y: auto;
  display: flex; flex-direction: column; gap: 12px; box-shadow: 0 18px 50px rgba(0, 0, 0, 0.3);
}
.card h1 {
  margin: 0; font: 400 34px/1.02 var(--font-display); letter-spacing: 0.01em; color: var(--accent); text-wrap: balance;
}
.card h2 { margin: 0; font: 600 22px/1.2 var(--font-body); text-wrap: balance; }
.card p { margin: 0; }
.lede { color: var(--ink); }
.hint, .facts, .note { color: var(--muted); font-size: 13px; }
.facts { font-family: var(--font-data); font-size: 12px; }
.note { color: var(--accent-strong); }
label { font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); margin-bottom: -6px; }
input, button { font: inherit; border-radius: 10px; padding: 11px 14px; width: 100%; }
button { touch-action: manipulation; }
button:disabled { opacity: 0.6; cursor: default; }
input { border: 1.5px solid var(--line); background: var(--panel); color: var(--ink); }
input:focus-visible, button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions button { flex: 1 1 140px; }
button { border: 1.5px solid var(--line); background: transparent; color: var(--ink); font-weight: 600; cursor: pointer; }
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 4px 0; }
.stats div { display: flex; flex-direction: column; gap: 2px; }
.stats dt { font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.stats dd { margin: 0; font: 500 20px var(--font-data); font-variant-numeric: tabular-nums; }

/* The round's winner, announced over everything for a few seconds. */
#winner {
  position: fixed; z-index: 10; top: calc(16px + env(safe-area-inset-top, 0px)); left: 50%; transform: translateX(-50%);
  width: max-content; max-width: calc(100% - 32px); display: flex; align-items: center; gap: 14px;
  padding: 14px 20px; border-radius: 16px; border: 2px solid var(--accent);
  background: var(--panel); color: var(--ink); box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35); pointer-events: none;
}
#winner svg { width: 40px; height: 40px; flex: none; color: var(--accent); }
#winner-title { margin: 0; font: 400 22px/1.15 var(--font-display); color: var(--accent); text-wrap: balance; }
#winner-sub { margin: 4px 0 0; color: var(--muted); font: 500 13px var(--font-data); }
#winner-next { margin: 2px 0 0; font-size: 13px; font-weight: 600; }
#winner.mine { background: var(--accent); }
#winner.mine svg, #winner.mine #winner-title, #winner.mine #winner-sub, #winner.mine #winner-next { color: var(--accent-ink); }
@media (max-width: 600px) {
  #winner { gap: 10px; padding: 12px 14px; }
  #winner svg { width: 32px; height: 32px; }
  #winner-title { font-size: 18px; }
}

/* Cloudflare's human check: invisible unless it needs a click. */
#human { display: flex; justify-content: center; }
#human:empty { display: none; }

@media (prefers-reduced-motion: no-preference) {
  button { transition: background-color 0.15s, border-color 0.15s; }
  #winner:not([hidden]) { animation: winner-in 0.45s cubic-bezier(0.2, 1.4, 0.4, 1); }
  @keyframes winner-in { from { opacity: 0; transform: translateX(-50%) scale(0.7); } }
}
