html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--navy-900); color: var(--ink);
  font: 500 15px/1.4 var(--font-ui);
  touch-action: none; -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
canvas { display: block; width: 100%; height: 100%; }
b { font-weight: 600; font-variant-numeric: tabular-nums; }

.panel {
  background: var(--panel); border: 1px solid var(--panel-edge);
  border-radius: var(--r-m); box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}

/* ---- HUD (hidden until playing) ---------------------------------------- */
.hud, #hpw, #fire, #net { transition: opacity .25s; }
body:not(.playing) .hud, body:not(.playing) #hpw, body:not(.playing) #fire, body:not(.playing) #net { opacity: 0; pointer-events: none; }

.hud {
  position: fixed; left: 0; right: 0; top: 0; pointer-events: none;
  padding: calc(var(--safe-t) + 10px) calc(var(--safe-r) + 10px) 0 calc(var(--safe-l) + 10px);
  display: flex; justify-content: space-between; align-items: flex-start; gap: var(--gap);
}
.stats { display: flex; gap: 14px; padding: 7px 14px; font-size: 18px; }
.stat { display: inline-flex; align-items: center; gap: 6px; }
.stat svg { width: 20px; height: 20px; }

.board { min-width: 150px; max-width: 46vw; padding: 8px 12px 7px; font-size: 13px; }
.board-title { font-size: 11px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--gold); margin-bottom: 3px; }
.board ol { list-style: none; margin: 0; padding: 0; }
.board li { display: flex; gap: 6px; line-height: 1.55; }
.board .rk { width: 1.4em; color: var(--ink-dim); font-variant-numeric: tabular-nums; }
.board .nm { flex: 1; min-width: 0; display: flex; align-items: center; gap: 5px; }
.board .nm-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  flex: none; padding: 0 5px; border-radius: 5px; line-height: 15px;
  font-size: 9.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
}
.badge.ai { color: var(--ink-dim); background: rgba(253, 246, 227, .12); border: 1px solid rgba(253, 246, 227, .2); }
.badge.you { color: #3a2506; background: var(--gold); }
.board .sc { font-weight: 600; font-variant-numeric: tabular-nums; }
.board li.me { color: var(--gold); }
.board li.me .rk { color: var(--gold); }
.board li.gap { border-top: 1px dashed rgba(253, 246, 227, .2); margin-top: 2px; padding-top: 2px; }
.board-foot { margin-top: 4px; font-size: 11px; color: var(--ink-dim); }

#hpw {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--safe-b) + 24px); width: 40%; max-width: 280px; height: 14px;
  background: rgba(6, 23, 38, .7); border: 2px solid rgba(253, 246, 227, .25);
  border-radius: 999px; overflow: hidden; pointer-events: none;
}
#hp { height: 100%; width: 100%; background: var(--good); border-radius: 999px; transition: width .2s, background-color .2s; }
#hp.low { background: var(--bad); }

#fire {
  position: fixed; right: calc(var(--safe-r) + 18px); bottom: calc(var(--safe-b) + 18px);
  width: 96px; height: 96px; border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  border: 3px solid var(--gold); background: var(--panel); color: var(--gold);
  box-shadow: 0 5px 0 var(--gold-deep), var(--shadow);
  font: 700 14px var(--font-ui); letter-spacing: .1em; text-transform: uppercase;
  touch-action: none; transition: transform .06s, box-shadow .06s;
}
#fire svg { width: 38px; height: 38px; }
#fire.on { background: var(--gold); color: var(--navy-800); transform: translateY(4px); box-shadow: 0 1px 0 var(--gold-deep), var(--shadow); }
/* Desktop players fire with Space; the button would fight the mouse for steering. */
@media (hover: hover) and (pointer: fine) { #fire { display: none; } }

#net { position: fixed; left: calc(var(--safe-l) + 12px); bottom: calc(var(--safe-b) + 14px); font-size: 11px; color: var(--ink-dim); pointer-events: none; }

/* ---- Overlay card ---------------------------------------------------------- */
#ov {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: 20px; box-sizing: border-box;
  background: radial-gradient(ellipse at center, rgba(6, 23, 38, .35), rgba(6, 23, 38, .85));
}
body.playing #ov { display: none; }
.card {
  width: 100%; max-width: 360px; box-sizing: border-box; text-align: center;
  padding: 26px 24px 20px; border-radius: var(--r-l);
  background: linear-gradient(180deg, rgba(14, 46, 72, .94), rgba(8, 28, 46, .94));
  border: 1px solid var(--panel-edge); box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, .06);
}
.logo {
  margin: 0; font: 400 76px/0.9 var(--font-display); color: var(--gold); letter-spacing: 1px;
  text-shadow: 0 3px 0 var(--gold-deep), 0 8px 24px rgba(0, 0, 0, .45);
}
.tag { margin: 8px 0 20px; font-size: 13px; color: var(--ink-dim); letter-spacing: .02em; }
.dead .logo, .dead .tag { display: none; }

#result { margin-bottom: 18px; }
.result-title { font: 400 60px/1 var(--font-display); color: var(--bad); text-shadow: 0 3px 0 rgba(0, 0, 0, .35); }
.result-by { margin-top: 4px; color: var(--ink-dim); min-height: 1.4em; }
.result-stats { display: flex; gap: 10px; margin-top: 14px; }
.result-stats div { flex: 1; padding: 10px 6px; border-radius: var(--r-m); background: rgba(6, 23, 38, .55); }
.result-stats b { display: block; font-size: 28px; color: var(--gold); }
.result-stats span { font-size: 12px; color: var(--ink-dim); text-transform: uppercase; letter-spacing: .08em; }

.msg { margin: -6px 0 16px; color: var(--ink); }

.pick { display: flex; align-items: center; gap: 12px; margin: 0 0 14px; }
#preview { flex: none; width: 76px; height: 76px; border-radius: var(--r-m); background: #0f5d8f; box-shadow: inset 0 0 0 1px rgba(253, 246, 227, .12); }
.swatches { flex: 1; display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.swatch {
  aspect-ratio: 1; width: 100%; max-width: 40px; justify-self: center; padding: 0; cursor: pointer;
  border-radius: 50%; border: 2px solid rgba(6, 23, 38, .6); touch-action: manipulation;
  box-shadow: 0 0 0 2px transparent; transition: transform .1s, box-shadow .1s;
}
.swatch[aria-checked="true"] { box-shadow: 0 0 0 3px var(--gold); transform: scale(1.08); }
.swatch:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }

/* 16px stops iOS zooming into the field; inputs need text selection to be typeable in Safari */
#name {
  display: block; width: 100%; box-sizing: border-box; margin: 0 0 12px; padding: 13px 16px;
  font: 500 16px var(--font-ui); color: var(--ink); text-align: center;
  background: rgba(6, 23, 38, .7); border: 2px solid rgba(253, 246, 227, .16); border-radius: var(--r-m);
  outline: none; -webkit-user-select: text; user-select: text; touch-action: manipulation;
}
#name::placeholder { color: rgba(253, 246, 227, .4); }
#name:focus { border-color: var(--gold); }

#go {
  width: 100%; padding: 14px; border: 0; border-radius: var(--r-m); cursor: pointer;
  font: 700 20px var(--font-ui); letter-spacing: .03em; color: #3a2506;
  background: linear-gradient(180deg, #ffd666, var(--gold));
  box-shadow: 0 4px 0 var(--gold-deep), 0 8px 18px rgba(0, 0, 0, .3);
  touch-action: manipulation; transition: transform .06s, box-shadow .06s;
}
#go:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--gold-deep), 0 4px 10px rgba(0, 0, 0, .3); }
#go:disabled { opacity: .65; }

.controls { margin-top: 16px; display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 14px; font-size: 12px; color: var(--ink-dim); }
.controls kbd {
  display: inline-block; min-width: 1.5em; padding: 1px 6px; margin-right: 3px; border-radius: 6px;
  font: 600 11px var(--font-ui); color: var(--ink); background: rgba(253, 246, 227, .1); border: 1px solid rgba(253, 246, 227, .18);
}
.online { margin-top: 12px; font-size: 12px; color: var(--good); min-height: 1.2em; }
.online::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: currentColor; margin-right: 6px; vertical-align: 1px; }
.online:empty::before { display: none; }
.more {
  display: inline-block; margin-top: 10px; padding: 4px 8px; font-size: 13px;
  color: var(--ink-dim); text-decoration: underline; text-underline-offset: 3px; touch-action: manipulation;
}
.more:hover, .more:focus-visible { color: var(--gold); }
.dead .more { display: none; }

.noscript {
  position: fixed; inset: auto 0 0; padding: 16px 20px calc(var(--safe-b) + 16px);
  background: var(--navy-800); color: var(--ink); text-align: center; font-size: 15px;
}
.noscript a { color: var(--gold); }

@media (max-height: 520px) {
  .logo { font-size: 54px; }
  .tag { margin-bottom: 12px; }
  .card { padding: 16px 20px 14px; }
  .controls { margin-top: 10px; }
  .more { margin-top: 4px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
