:root {
  --bg: #07090d;
  --panel: rgba(12, 16, 24, 0.86);
  --line: rgba(255, 255, 255, 0.12);
  --text: #eef2f7;
  --muted: #94a3b8;
  --accent: #ffd166;
  --good: #06d6a0;
  --bad: #ef476f;
  --home: #e63950;
  --away: #3d8bff;
  /* system fonts only: nothing is downloaded from third-party font hosts */
  --font-display: Impact, Haettenschweiler, "Arial Narrow Bold", "Franklin Gothic Bold", "Arial Black", sans-serif;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: var(--font-body); }
canvas#view { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; }
button { font: inherit; cursor: pointer; }

/* ---------- overlays & menu ---------- */
.overlay { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; padding: 16px; z-index: 20;
  background: radial-gradient(ellipse at 50% 30%, rgba(30, 60, 110, 0.55), rgba(5, 7, 11, 0.94) 70%); overflow-y: auto; }
.overlay.show { display: flex; }
#pause, #end, #help { background: rgba(5, 7, 11, 0.72); backdrop-filter: blur(4px); z-index: 30; }
#help { z-index: 40; }
.menu-card { width: min(1060px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 28px 30px; box-shadow: 0 30px 80px rgba(0,0,0,0.5); margin: auto; }
.menu-card.narrow { width: min(720px, 100%); }
.menu-card.center { text-align: center; width: min(360px, 100%); }
header { text-align: center; margin-bottom: 18px; }
/* Logo: a manga title card — heavy slanted letters, ink outline, offset shadow */
.logo { margin: 0; font-family: var(--font-display); font-weight: 400; font-size: clamp(52px, 10vw, 104px); letter-spacing: 3px; line-height: 0.9; transform: skewX(-10deg); display: inline-flex; gap: 0; }
.logo span { -webkit-text-stroke: 3px #07090d; paint-order: stroke fill; text-shadow: 5px 5px 0 #07090d, 7px 7px 0 rgba(230, 57, 80, 0.85); }
.logo .l1 { color: #ffffff; }
.logo .l2 { color: var(--accent); }

/* accessibility */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
button:focus-visible, input:focus-visible, [tabindex]:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; } }

/* legal footer, dialogs */
.legal-links { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; justify-content: center; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); font-size: 13px; }
.legal-links button { background: none; border: none; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; padding: 4px 2px; }
.legal-links button:hover { color: var(--text); }
.legal-links .muted { flex-basis: 100%; text-align: center; font-size: 12px; }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.tabs button { background: rgba(255,255,255,0.05); border: 1px solid var(--line); color: var(--muted); border-radius: 999px; padding: 6px 14px; font-weight: 600; }
.tabs button[aria-selected="true"] { color: #1a1a1a; background: var(--accent); border-color: var(--accent); }
.doc { max-height: min(56vh, 520px); overflow-y: auto; padding-right: 6px; line-height: 1.6; font-size: 14px; }
.doc h4 { margin: 16px 0 4px; font-size: 15px; }
.doc p, .doc li { color: #d5dde8; max-width: 68ch; }
.doc .meta { color: var(--muted); font-size: 12px; margin: 0; }
.doc .licence { white-space: pre-wrap; font: 12px/1.5 ui-monospace, Consolas, monospace; background: rgba(0,0,0,0.35); padding: 12px; border-radius: 8px; overflow-x: auto; }
.doc a { color: var(--accent); }
.doc .notice, .notice { background: rgba(6, 214, 160, 0.14); border: 1px solid rgba(6, 214, 160, 0.4); padding: 8px 12px; border-radius: 8px; }
.sel-text { user-select: all; color: var(--text); }
.opt-grid { display: grid; grid-template-columns: 1fr auto; gap: 14px 18px; align-items: center; margin: 10px 0 6px; }
.opt-grid label small { display: block; color: var(--muted); font-size: 12px; }
.opt-grid input[type=range] { width: min(220px, 40vw); accent-color: var(--accent); }
.opt-grid input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); }
.tablewrap { overflow-x: auto; }
.tag { color: var(--muted); margin: 8px 0 0; }
h2 { font-family: var(--font-display); font-size: 34px; margin: 0 0 12px; letter-spacing: 1px; }
h3 { font-family: var(--font-display); font-weight: 800; text-transform: uppercase; letter-spacing: 2px; color: var(--muted); font-size: 15px; margin: 14px 0 8px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.choices { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.choices.small { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
.choices button { text-align: left; background: rgba(255,255,255,0.04); color: var(--text); border: 1px solid var(--line); border-radius: 12px; padding: 12px; font-weight: 700; transition: transform .12s, border-color .12s, background .12s; }
.choices button:hover { transform: translateY(-2px); border-color: rgba(255,255,255,0.35); }
.choices button.sel { border-color: var(--accent); background: rgba(255, 209, 102, 0.12); box-shadow: 0 0 0 1px var(--accent) inset; }
.choices small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; margin-top: 6px; line-height: 1.35; }
.badge { display: inline-block; font-family: var(--font-display); font-weight: 900; font-size: 22px; background: var(--home); color: #fff; border-radius: 8px; padding: 0 8px; margin-right: 8px; }
.actions { display: flex; gap: 12px; justify-content: center; margin-top: 22px; flex-wrap: wrap; }
.actions.col { flex-direction: column; }
.actions button, .btns button { background: rgba(255,255,255,0.06); border: 1px solid var(--line); color: var(--text); padding: 12px 26px; border-radius: 12px; font-weight: 700; }
.actions button.primary, .btns button:first-child { background: var(--accent); color: #1a1a1a; border: none; font-family: var(--font-display); font-weight: 900; font-size: 22px; letter-spacing: 2px; padding: 10px 46px; }
.keys { width: 100%; border-collapse: collapse; margin: 12px 0; }
.keys td { padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; font-size: 14px; }
.keys td:first-child { white-space: nowrap; width: 1%; }
kbd, .k { display: inline-block; min-width: 22px; text-align: center; padding: 1px 6px; border-radius: 6px; background: rgba(255,255,255,0.12); border: 1px solid rgba(255,255,255,0.25); font-family: ui-monospace, Consolas, monospace; font-size: 12px; font-weight: 700; }
.muted { color: var(--muted); }
p { line-height: 1.55; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; display: none; z-index: 10; font-family: var(--font-body); }
#hud.show { display: block; }
#scorebug { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); display: flex; align-items: stretch; filter: drop-shadow(0 6px 18px rgba(0,0,0,0.5)); }
#scorebug .team { display: flex; align-items: center; gap: 0; background: var(--panel); border-top: 4px solid var(--tc); }
#scorebug .t0 { border-radius: 10px 0 0 10px; }
#scorebug .t1 { border-radius: 0 10px 10px 0; }
#scorebug .name { font-family: var(--font-display); font-weight: 800; font-size: 20px; letter-spacing: 1px; text-transform: uppercase; padding: 6px 14px; min-width: 92px; text-align: center; }
#scorebug .sets { font-weight: 700; color: var(--muted); padding: 0 8px; font-size: 15px; }
#scorebug .pts { font-family: var(--font-display); font-weight: 900; font-size: 34px; min-width: 52px; text-align: center; background: rgba(255,255,255,0.06); padding: 0 8px; }
#scorebug .srv { width: 10px; height: 10px; border-radius: 50%; margin: 0 8px; background: transparent; }
#scorebug .srv.on { background: var(--accent); box-shadow: 0 0 10px var(--accent); }
#scorebug .mid { background: #0b0f16; display: flex; align-items: center; padding: 0 10px; font-size: 11px; font-weight: 700; color: var(--muted); letter-spacing: 1px; }
#info { position: absolute; top: 14px; left: 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; font-size: 13px; line-height: 1.5; max-width: 46vw; }
#keys { position: absolute; top: 14px; right: 16px; font-size: 12px; color: var(--muted); background: var(--panel); padding: 6px 10px; border-radius: 8px; }
#callout { position: absolute; top: 88px; left: 50%; transform: translateX(-50%) translateY(-6px); font-family: var(--font-display); font-weight: 800; font-size: 22px; letter-spacing: 2px; color: var(--accent); text-shadow: 0 2px 10px rgba(0,0,0,0.8); opacity: 0; transition: opacity .2s, transform .2s; white-space: nowrap; }
#callout.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast { position: absolute; top: 34%; left: 50%; transform: translate(-50%, -50%) scale(0.85); font-family: var(--font-display); font-weight: 900; font-style: italic; font-size: clamp(34px, 6vw, 72px); letter-spacing: 3px; opacity: 0; transition: opacity .2s, transform .25s cubic-bezier(.2,1.6,.4,1); text-shadow: 0 4px 24px rgba(0,0,0,0.85); white-space: nowrap; text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
#toast.good { color: #fff; } #toast.good::after { content: ''; display: block; height: 5px; background: var(--home); margin-top: 4px; border-radius: 3px; }
#toast.bad { color: #cbd5e1; } #toast.bad::after { content: ''; display: block; height: 5px; background: var(--away); margin-top: 4px; border-radius: 3px; }
#toast.info { color: var(--accent); font-size: 44px; }
#toast.big { font-size: clamp(30px, 5vw, 60px); }
#cue { position: absolute; top: 56%; left: 50%; transform: translate(-50%, -50%); font-family: var(--font-display); font-weight: 900; font-size: 46px; color: #fff; background: rgba(239, 71, 111, 0.85); padding: 2px 22px; border-radius: 12px; opacity: 0; transition: opacity .08s; letter-spacing: 3px; }
#cue.show { opacity: 1; }
#minimap { position: absolute; left: 16px; bottom: 16px; border-radius: 10px; border: 1px solid var(--line); width: 136px; height: 240px; }
#ctx { position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 16px; font-size: 14px; line-height: 1.9; text-align: center; max-width: min(860px, calc(100vw - 340px)); }
#ctx:empty { display: none; }
#ctx .sel { color: var(--accent); font-weight: 700; }
#ctx .sel .k { border-color: var(--accent); background: rgba(255, 209, 102, 0.25); }
#ctx > span { margin: 0 4px; white-space: nowrap; }
#meter { position: absolute; left: 50%; bottom: 112px; transform: translateX(-50%); width: min(420px, 80vw); height: 22px; background: rgba(0,0,0,0.55); border: 1px solid var(--line); border-radius: 11px; overflow: hidden; display: none; }
#meter .fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--accent); }
#meter .sweet { position: absolute; top: 0; bottom: 0; border-left: 2px solid var(--good); border-right: 2px solid var(--good); background: rgba(6, 214, 160, 0.18); }
#meter .lbl { position: absolute; inset: 0; text-align: center; font-size: 11px; font-weight: 800; letter-spacing: 2px; line-height: 22px; color: #fff; text-shadow: 0 1px 3px #000; }

/* ---------- end screen ---------- */
#end h1 { font-family: var(--font-display); font-size: 64px; margin: 0; text-align: center; letter-spacing: 4px; font-style: italic; }
#end h1.good { color: var(--accent); } #end h1.bad { color: #cbd5e1; }
#end .sets { text-align: center; color: var(--muted); font-size: 20px; margin: 4px 0 16px; }
#end table { width: 100%; border-collapse: collapse; font-size: 14px; }
#end th, #end td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: center; }
#end th:first-child, #end td:first-child { text-align: left; }
#end tr.me { background: rgba(255, 209, 102, 0.12); }
#end .btns { display: flex; gap: 12px; justify-content: center; margin-top: 20px; }

#end .tablewrap { overflow-x: auto; }
#netstatus { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px 22px; max-width: min(560px, calc(100vw - 32px)); display: none; z-index: 50; line-height: 1.6; }
#netstatus.show { display: block; }
#netstatus button { margin-left: 8px; background: var(--accent); border: none; border-radius: 8px; padding: 6px 14px; font-weight: 800; }
.spinner { width: 46px; height: 46px; border: 4px solid rgba(255,255,255,0.15); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 820px) {
  .choices { grid-template-columns: repeat(2, 1fr); }
  .row { grid-template-columns: 1fr; }
  .menu-card { padding: 20px 16px; }
  #info { font-size: 11px; max-width: 60vw; }
  #keys { display: none; }
  #ctx { max-width: calc(100vw - 32px); font-size: 12px; bottom: 270px; }
  #minimap { width: 100px; height: 176px; }
}
