:root {
  --ink: #0b0d1c;
  --panel: #14172e;
  --rule: #2a2e52;
  --paper: #fff;
  --smoke: #a9adc8;
  --cyan: #00d8ef;
  --magenta: #ed27c2;
  --gold: #ffd438;
  --display: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", "Nunito", "Varela Round", system-ui, sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--ink); color: var(--paper); }
body { font-family: var(--body); font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

.top { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; height: 48px; padding: 10px 16px 0; max-width: 860px; margin: 0 auto; }
.top h1 { margin: 0; font: 700 20px/1 var(--display); letter-spacing: .02em; }
.top nav { display: flex; align-items: baseline; gap: 18px; }
.top a, #board-open { color: var(--cyan); text-decoration: none; font-weight: 600; }
#board-open, #board-close { display: none; border: 0; padding: 0; background: none; cursor: pointer; }
.top a:hover { text-decoration: underline; }

.layout { display: flex; flex-wrap: wrap; justify-content: center; align-items: flex-start; gap: 24px; padding: 0 0 32px; }

/* The playfield is 390 x 640 and scales to whatever fits */
.stage {
  position: relative;
  width: min(100vw, calc((100dvh - 56px) * 390 / 640), 468px);
  aspect-ratio: 390 / 640;
  container-type: inline-size;
  overflow: hidden;
  background: #11152f;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
@media (min-width: 480px) { .stage { border-radius: 14px; } }
canvas { display: block; width: 100%; height: 100%; }

.controls { position: absolute; z-index: 1; top: 3cqw; right: 3cqw; display: flex; gap: 2cqw; }
.controls button { width: 11cqw; height: 11cqw; min-width: 40px; min-height: 40px; padding: 0; border: 0; border-radius: 50%; background: rgba(11, 13, 28, .7); color: var(--paper); cursor: pointer; }
.controls svg { width: 55%; height: 55%; fill: currentColor; vertical-align: middle; }

.overlay { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 12px; padding: 0 7cqw 12cqw; text-align: center; }
.overlay.shade { justify-content: center; padding-bottom: 0; background: rgba(11, 13, 28, .82); }
.overlay h2 { margin: 0; font: 800 9cqw/1.1 var(--display); }
.overlay p { margin: 0; }
.hint { font-weight: 600; text-shadow: 0 1px 6px #000, 0 0 2px #000; }
#over-cause { color: var(--smoke); }
.result { display: flex; gap: 28px; font-family: var(--display); color: var(--smoke); }
.result b { display: block; font-size: 10cqw; line-height: 1; color: var(--paper); }
.pose { background-repeat: no-repeat; animation: bob 1.4s ease-in-out infinite alternate; }
@keyframes bob { from { transform: translateY(-4px); } to { transform: translateY(4px); } }
@media (prefers-reduced-motion: reduce) { .pose { animation: none; } }

button { font: inherit; }
button.main, #save-btn, #reload { border: 0; border-radius: 999px; padding: 12px 28px; font: 700 17px/1 var(--display); background: var(--cyan); color: #06222a; cursor: pointer; }
#save-btn { padding: 12px 16px; font-size: 15px; background: var(--gold); color: #2a2100; white-space: nowrap; }
button:focus-visible, input:focus-visible, a:focus-visible { outline: 3px solid var(--magenta); outline-offset: 2px; }
button:disabled { opacity: .5; cursor: default; }

#save { width: 100%; max-width: 320px; text-align: left; }
#save label { display: block; margin-bottom: 6px; font-size: 13px; color: var(--smoke); }
.row { display: flex; gap: 8px; }
#name { flex: 1; min-width: 0; padding: 10px 12px; border: 1px solid var(--rule); border-radius: 10px; background: var(--panel); color: var(--paper); font: 600 16px var(--body); }
#save-msg { min-height: 1.45em; font-size: 14px; color: var(--gold); }

.side { width: min(100vw, 320px); padding: 0 16px; }
.side section { margin-bottom: 24px; }
.side h2 { margin: 0 0 10px; font: 700 13px/1 var(--display); letter-spacing: .12em; text-transform: uppercase; color: var(--cyan); }
/* The kit's medal, cut from the icons sheet (1254 px square; the medal is 342 x 439 at 165, 699) */
.medal::before { content: ""; display: inline-block; width: 18px; height: 23px; margin-right: 8px; vertical-align: -6px; background: url(../assets/icons-atlas.webp) -8.7px -36.8px / 66px 66px no-repeat; }
#board { margin: 0; padding: 0; list-style: none; counter-reset: rank; }
#board li { counter-increment: rank; display: flex; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--rule); font-variant-numeric: tabular-nums; }
#board li::before { content: counter(rank); width: 1.5em; color: var(--smoke); }
#board li span:first-child { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#board li.me { color: var(--gold); font-weight: 700; }
#board-msg { margin: 8px 0 0; font-size: 14px; color: var(--smoke); }
.how { margin: 0; padding-left: 18px; color: var(--smoke); }
.how li { margin-bottom: 6px; }
.how b { color: var(--paper); }

/* Phones: the page itself never scrolls, so a tap can't drag it about. The game fills the screen
   and the leaderboard opens over it. svh is the height with the browser's bars showing, so the
   playfield doesn't change size when they slide away. */
@media (max-width: 819px) {
  html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
  body { position: fixed; inset: 0; }
  .top { padding-top: env(safe-area-inset-top); height: calc(48px + env(safe-area-inset-top)); align-items: center; }
  .layout { padding: 0; }
  .stage { width: min(100vw, calc((100svh - 48px - env(safe-area-inset-top)) * 390 / 640)); }
  #board-open { display: inline; font-size: 15px; }
  #board-close { display: block; margin: 0 0 24px; padding: 12px 22px; border-radius: 999px; background: var(--cyan); color: #06222a; font: 700 16px/1 var(--display); }
  .side { display: none; position: fixed; inset: 0; z-index: 5; width: auto; overflow-y: auto; overscroll-behavior: contain; padding: calc(20px + env(safe-area-inset-top)) 20px calc(20px + env(safe-area-inset-bottom)); background: var(--ink); }
  .side.open { display: block; }
}
