@font-face {
  font-family: 'PressStart';
  src: url('assets/ui/press-start-2p.woff2') format('woff2');
  font-display: block;
}

:root {
  --bg: #0b0d1f;
  --bg2: #141838;
  --ink: #fbf5ea;
  --muted: #a9a6c8;
  --gold: #ffd23f;
  --gold-d: #b8861e;
  --navy: #0b0e22;
  --line: #e8e4d8;
  --sel: #ffd23f;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: 'PressStart', ui-monospace, monospace;
  -webkit-font-smoothing: none;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none; user-select: none;
}
body { overflow: hidden; }
canvas, .pixel-art, img.pixel {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
button { font-family: inherit; }

#app { position: fixed; inset: 0; height: 100dvh; width: 100vw; }
.screen { position: absolute; inset: 0; display: none; }
.screen.active { display: block; }

/* ===================== MENU ===================== */
#menu {
  overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  background:
    linear-gradient(var(--bg), var(--bg)) padding-box;
}
.menu-inner {
  max-width: 980px; margin: 0 auto;
  padding: 28px 16px 24px;
  text-align: center;
}
.title-block { margin: 8px 0 28px; }
h1 {
  font-size: 32px; line-height: 1.35; margin: 0;
  color: var(--gold);
  text-shadow: 4px 4px 0 #8a3a1e, 8px 8px 0 #1b1426;
  letter-spacing: 1px;
}
.tagline { margin: 18px 0 0; font-size: 12px; color: var(--ink); opacity: .85; }
h2 {
  font-size: 16px; margin: 28px 0 14px; color: var(--ink);
  letter-spacing: 1px;
}
.grid { display: grid; gap: 12px; }
.chars { grid-template-columns: repeat(5, 1fr); }
.cities { grid-template-columns: repeat(4, 1fr); }

.card {
  position: relative;
  background: var(--bg2);
  border: 4px solid #2c3160;
  color: var(--ink);
  padding: 12px 6px 10px;
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  font-size: 10px; line-height: 1.3;
  transition: none;
}
.card:hover { border-color: #5a63b0; }
.card:focus-visible { outline: 4px solid #5ae0f2; outline-offset: 2px; }
.card[aria-checked="true"] {
  border-color: var(--sel);
  background: #252a5a;
  box-shadow: 0 0 0 4px #1b1426, 6px 6px 0 4px #8a6a10;
}
.card[aria-checked="true"]::after {
  content: ''; position: absolute; left: 7px; top: 7px; width: 0; height: 0;
  border-left: 6px solid var(--gold); border-top: 5px solid transparent; border-bottom: 5px solid transparent;
}
.tri { display: inline-block; width: 0; height: 0; margin-left: 14px; vertical-align: -1px;
  border-left: 14px solid currentColor; border-top: 10px solid transparent; border-bottom: 10px solid transparent; }
.card canvas { width: 168px; max-width: 100%; height: auto; aspect-ratio: 56 / 54; }
.card[aria-checked="true"] .cname { color: var(--gold); }
.card canvas { display: block; }
.card .thumb { display: block; width: 176px; max-width: 100%; height: auto; image-rendering: pixelated; }
.cities .card { padding: 8px 8px 10px; }

.run-bar {
  position: sticky; bottom: 0; z-index: 2;
  margin: 30px -16px 0; padding: 16px 16px 20px;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  background: linear-gradient(rgba(11,13,31,0), var(--bg) 28%);
}
.btn {
  font-size: 16px; padding: 18px 26px; cursor: pointer;
  border: 4px solid #1b1426;
  line-height: 1.2;
}
.btn:focus-visible { outline: 4px solid #5ae0f2; outline-offset: 3px; }
.btn-gold {
  background: var(--gold); color: #1b1426;
  box-shadow: inset -4px -4px 0 var(--gold-d), inset 4px 4px 0 #fff1a8, 6px 6px 0 #1b1426;
}
.btn-gold:active { transform: translate(3px, 3px); box-shadow: inset -4px -4px 0 var(--gold-d), 3px 3px 0 #1b1426; }
.btn-gold:disabled { background: #6a6a7a; color: #e8e4d8; box-shadow: none; cursor: wait; }
.btn-run { font-size: 24px; padding: 20px 44px; min-width: 260px; }
.btn-ghost {
  background: var(--navy); color: #ffffff;
  border: 4px solid #ffffff;
  box-shadow: 6px 6px 0 #000;
}
.btn-ghost:hover { background: #1e2456; }
.best { font-size: 10px; color: var(--muted); margin: 0; min-height: 12px; line-height: 1.6; }
.controls-hint { font-size: 10px; color: var(--muted); margin-top: 22px; }
.touch-only { display: none; }
@media (hover: none) and (pointer: coarse) {
  .touch-only { display: block; }
  .desktop-only { display: none; }
}

@media (max-width: 760px) {
  h1 { font-size: 22px; text-shadow: 3px 3px 0 #8a3a1e, 6px 6px 0 #1b1426; }
  .tagline { font-size: 10px; }
  h2 { font-size: 12px; margin: 24px 0 12px; }
  .chars { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .cities { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .card { font-size: 8px; padding: 10px 4px 8px; border-width: 3px; }
  .btn-run { font-size: 20px; min-width: 0; width: 100%; max-width: 340px; }
}

/* ===================== GAME ===================== */
#game { background: #05060f; touch-action: none; overflow: hidden; }
#stage { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
#frame { position: relative; }
#cv { display: block; }

#hud { position: absolute; left: 0; right: 0; top: 0; padding: 10px; pointer-events: none; }
.hud-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.hud-row.second { justify-content: flex-start; margin-top: 8px; min-height: 0; }
.box {
  background: var(--navy);
  border: 3px solid var(--line);
  box-shadow: 3px 3px 0 #000;
  padding: 8px 10px 7px;
  font-size: 16px; line-height: 1; white-space: nowrap;
}
.lbl { color: #ffffff; }
.num { color: var(--gold); }
.who .lbl { color: #ffffff; }
.rampage { border-color: var(--gold); background: #000; display: inline-flex; align-items: center; gap: 10px; }
.rampage[hidden] { display: none; }
.rampage .lbl { color: var(--gold); }
.rampage .bar { width: 80px; height: 8px; background: #3a2a10; display: inline-block; position: relative; }
.rampage .bar i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--gold); width: 100%; }
.mute {
  pointer-events: auto;
  position: absolute; right: 10px; top: 58px;
  width: 40px; height: 40px; padding: 8px;
  background: var(--navy); color: #fff; border: 3px solid var(--line); box-shadow: 3px 3px 0 #000;
  cursor: pointer;
}
.mute svg { width: 100%; height: 100%; display: block; shape-rendering: crispEdges; }
.mute .cross { display: none; }
.mute.off .waves { display: none; }
.mute.off .cross { display: inline; }

.hint {
  position: absolute; left: 50%; top: 30%; transform: translateX(-50%);
  background: rgba(11, 14, 34, .88); border: 3px solid var(--line);
  padding: 10px 12px; font-size: 12px; color: #fff; white-space: nowrap;
  pointer-events: none; opacity: 0;
}
.hint.show { opacity: 1; }

.overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(5, 6, 15, .55);
}
.overlay[hidden] { display: none; }
.panel {
  background: var(--navy); border: 4px solid var(--line); box-shadow: 6px 6px 0 #000;
  padding: 26px 22px; display: flex; flex-direction: column; align-items: stretch; gap: 14px;
  text-align: center; max-width: 92%;
}
.over-title { font-size: 16px; line-height: 1.5; margin: 0 0 6px; color: #fff; }
.over-new { font-size: 16px; color: var(--gold); margin: 0; animation: blink .5s steps(1) infinite; }
.over-score { font-size: 16px; margin: 0; }
.panel .btn { font-size: 14px; padding: 14px 16px; }
@keyframes blink { 50% { opacity: 0; } }

/* small frames (phones): HUD scales with the frame */
#frame.small .hud-row:first-child { flex-wrap: wrap; row-gap: 6px; }
#frame.small .who { order: 3; flex: 1 0 100%; text-align: center; }
#frame.small .box { font-size: 10px; padding: 6px 6px 5px; border-width: 2px; }
#frame.small .who .lbl { font-size: 8px; }
#frame.small .hud-row.second { margin-top: 6px; }
#frame.small .rampage .bar { width: 48px; height: 6px; }
#frame.small #hud { padding: 6px; }
#frame.small .mute { top: 74px; width: 32px; height: 32px; padding: 6px; right: 6px; border-width: 2px; }
#frame.small .over-title, #frame.small .over-new, #frame.small .over-score { font-size: 12px; }
#frame.small .panel .btn { font-size: 11px; padding: 12px 10px; }
#frame.small .hint { font-size: 9px; }
