:root {
  --bg: #000;
  --fg: #f4f4f4;
  --mute: #6b6f80;
  --green: #39ff88;
  --red: #ff3b5c;
  --gold: #ffd700;
  --blue: #4aa8ff;
  --k: min(48px, calc((100vw - 24px) / 11));
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: "Press Start 2P", ui-monospace, monospace;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

canvas#game {
  position: fixed;
  inset: 0 auto auto 0;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* scanlines + vignette (static layer, no per-frame cost) */
.fx {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  background:
    repeating-linear-gradient(to bottom, rgba(0,0,0,0) 0 2px, rgba(0,0,0,.18) 2px 3px),
    radial-gradient(ellipse at center, rgba(0,0,0,0) 55%, rgba(0,0,0,.65) 100%);
}

/* ---------- screens ---------- */
.screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 16px;
  text-align: center;
  background: #000;
}
.screen.dim { background: rgba(0,0,0,.78); }
[hidden] { display: none !important; }

.logo {
  font-size: clamp(30px, 9vw, 84px);
  font-weight: 400;
  letter-spacing: .04em;
  color: #fff;
  text-shadow:
    .06em .06em 0 var(--red),
    .12em .12em 0 var(--blue),
    .18em .18em 0 #1b1d26;
  animation: float 3s steps(6) infinite;
}
.tag { font-size: clamp(9px, 2.2vw, 14px); color: var(--green); letter-spacing: .3em; }
.how { list-style: none; display: grid; gap: 12px; font-size: clamp(8px, 1.8vw, 11px); line-height: 1.6; color: #c8cad4; text-align: left; }
.how b { color: #000; background: var(--fg); padding: 2px 5px; margin-right: 8px; font-weight: 400; }
.how em, .r, .g, .gold { font-style: normal; }
.g { color: var(--green); }
.r { color: var(--red); }
.gold { color: var(--gold); }
.best { font-size: 11px; color: var(--gold); min-height: 1em; }
.note { font-size: 8px; color: var(--mute); line-height: 1.8; }
.big { font-size: clamp(28px, 7vw, 56px); font-weight: 400; text-shadow: .08em .08em 0 #1b1d26; }
.sub { font-size: clamp(9px, 2vw, 12px); line-height: 1.8; color: #d5d7e0; }

.btn {
  font: inherit;
  font-size: clamp(14px, 3vw, 20px);
  color: #000;
  background: var(--green);
  border: 0;
  padding: 16px 28px 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 14px;
  box-shadow:
    0 -4px 0 0 #000 inset,
    4px 0 0 0 var(--green), -4px 0 0 0 var(--green),
    0 4px 0 0 var(--green), 0 -4px 0 0 var(--green),
    0 8px 0 0 #138a45;
  transition: transform 60ms steps(1);
}
.btn:hover, .btn:focus-visible { background: #7dffb3; outline: none; }
.btn:active { transform: translateY(4px); box-shadow: 0 -4px 0 0 #000 inset, 4px 0 0 0 var(--green), -4px 0 0 0 var(--green), 0 4px 0 0 var(--green), 0 -4px 0 0 var(--green); }
.btn.ghost { background: transparent; color: var(--fg); box-shadow: 0 0 0 4px #333; font-size: 12px; padding: 12px 20px; }
.btn.ghost:hover, .btn.ghost:focus-visible { background: #222; }
#play { animation: pulse 1.2s steps(2) infinite; }
.tri { width: 0; height: 0; border-left: 14px solid #000; border-top: 9px solid transparent; border-bottom: 9px solid transparent; }

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  z-index: 6;
  top: 0; left: 0; right: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) 16px 0;
  pointer-events: none;
}
.hud-r { justify-self: end; text-align: right; display: grid; gap: 8px; justify-items: end; }
.hud-c { display: grid; gap: 6px; justify-items: center; }
.grade { font-size: clamp(22px, 4vw, 36px); text-shadow: 3px 3px 0 #000; }
.small { font-size: 9px; color: #c8cad4; margin-top: 6px; text-shadow: 2px 2px 0 #000; }
.bar { width: clamp(110px, 22vw, 220px); height: 12px; background: #111; box-shadow: 0 0 0 2px #000, 0 0 0 4px #444; overflow: hidden; }
.fill { height: 100%; width: 100%; background: var(--green); transform-origin: left center; will-change: transform; }
.bar.low .fill { background: var(--red); animation: blink .25s steps(2) infinite; }
.timer { height: 6px; }
.timer .fill { background: var(--gold); }
.icon { pointer-events: auto; font: inherit; font-size: 8px; color: var(--fg); background: #111; border: 0; box-shadow: 0 0 0 2px #444; padding: 6px 7px; cursor: pointer; }
.icon[aria-pressed="true"] { color: var(--mute); text-decoration: line-through; }

.banner {
  position: fixed;
  z-index: 7;
  left: 0; right: 0; top: 13%;
  text-align: center;
  font-size: clamp(22px, 6vw, 52px);
  text-shadow: 4px 4px 0 #000, -2px -2px 0 #000;
  pointer-events: none;
  opacity: 0;
}
.banner.show { animation: banner 1.6s steps(16) forwards; }

.prompt {
  position: fixed;
  z-index: 6;
  left: 0; right: 0;
  bottom: calc(var(--k) * 4 + 64px + env(safe-area-inset-bottom));
  text-align: center;
  font-size: clamp(10px, 2vw, 14px);
  line-height: 2.4;
  text-shadow: 2px 2px 0 #000;
  pointer-events: none;
}
.prompt kbd { font: inherit; color: #000; padding: 4px 7px 3px; margin: 0 3px; background: var(--fg); box-shadow: 0 3px 0 #777; }
.prompt kbd.lift { background: var(--red); box-shadow: 0 3px 0 #8a1023; }
.prompt kbd.grab { background: var(--green); box-shadow: 0 3px 0 #138a45; }

/* ---------- keyboard ---------- */
.kb {
  position: fixed;
  z-index: 6;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: grid;
  gap: 6px;
  touch-action: none;
  padding: 10px;
  background: rgba(0,0,0,.72);
  box-shadow: 0 0 0 2px #222;
}
.kb.shake { animation: shake .2s steps(4); }
.row { display: flex; gap: 4px; }
.key {
  width: calc(var(--k) - 4px);
  height: calc(var(--k) - 4px);
  display: grid;
  place-items: center;
  font-size: clamp(8px, calc(var(--k) * .28), 13px);
  color: #777;
  background: #121318;
  box-shadow: 0 0 0 2px #2a2c36, 0 4px 0 2px #0a0a0d;
  cursor: pointer;
  touch-action: none;
}
.key.dim { opacity: .2; }
.key.held { background: var(--fg); color: #000; box-shadow: 0 0 0 2px #fff, 0 1px 0 2px #777; transform: translateY(3px); }
.key.need { background: #0f2d1c; color: var(--green); box-shadow: 0 0 0 2px var(--green), 0 4px 0 2px #0a0a0d; animation: blink .5s steps(2) infinite; }
.key.grab { background: var(--green); color: #000; box-shadow: 0 0 0 2px #b8ffd6, 0 4px 0 2px #138a45; animation: pop .4s steps(2) infinite; }
.key.lift { background: var(--red); color: #fff; box-shadow: 0 0 0 2px #ffb3c0, 0 1px 0 2px #8a1023; transform: translateY(3px); animation: blink .3s steps(2) infinite; }
.key.extra { background: #3a3c48; color: #bbb; transform: translateY(3px); }
.key[data-flash] { background: var(--red) !important; color: #fff !important; }

@keyframes blink { 50% { opacity: .45; } }
@keyframes pop { 50% { transform: translateY(-2px); } }
@keyframes pulse { 50% { filter: brightness(1.25); } }
@keyframes float { 50% { transform: translateY(-6px); } }
@keyframes shake { 25% { transform: translateX(calc(-50% - 4px)); } 75% { transform: translateX(calc(-50% + 4px)); } }
@keyframes banner {
  0% { opacity: 0; transform: scale(.6); }
  12% { opacity: 1; transform: scale(1.1); }
  20% { transform: scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-20px); }
}

@media (max-height: 560px) {
  :root { --k: min(36px, calc((100vw - 24px) / 11)); }
  .screen { gap: 12px; }
  .how { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; }
  .banner.show { animation-duration: 1.6s !important; }
}
