:root {
  color-scheme: dark;
  --ink: #eef2ff;
  --dim: #97a3c4;
  --accent: #ff8a3d;
  --accent-2: #ffd166;
  --panel: rgba(12, 17, 32, 0.88);
  --line: rgba(255, 255, 255, 0.14);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background:
    radial-gradient(120% 90% at 50% -10%, #1b2545 0%, #0b1020 55%, #070a14 100%);
  color: var(--ink);
  font: 400 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(8px, 2vmin, 24px);
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

.wrap {
  width: min(100%, 1400px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

/* The stage letterboxes at a fixed 16:9. Everything layered on top sizes in
   container units so the chrome keeps its proportions on any viewport shape. */
.stage {
  position: relative;
  width: 100%;
  max-height: calc(100dvh - 72px);
  aspect-ratio: 16 / 9;
  container-type: size;
  border-radius: clamp(6px, 1.4cqw, 18px);
  overflow: hidden;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55), 0 0 0 1px var(--line);
  background: #0a0e1a;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

/* ---------------------------------------------------------------- overlays */
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 4cqh;
  background: radial-gradient(90% 70% at 50% 40%, rgba(8, 12, 24, 0.78), rgba(5, 8, 16, 0.94));
  backdrop-filter: blur(3px);
  text-align: center;
}

.overlay[data-screen="playing"] {
  opacity: 0;
  pointer-events: none;
}

.card {
  max-width: 78cqw;
  animation: rise 0.28s ease-out both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(2cqh); }
}

@media (prefers-reduced-motion: reduce) {
  .card { animation: none; }
}

h1 {
  margin: 0 0 1.2cqh;
  font-size: clamp(22px, 8.4cqh, 62px);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.05;
}

h1 .ball { filter: drop-shadow(0 0.4cqh 1cqh rgba(255, 138, 61, 0.5)); }

h2 {
  margin: 0 0 1cqh;
  font-size: clamp(16px, 4.6cqh, 30px);
  font-weight: 700;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

.tag {
  margin: 0 0 3cqh;
  color: var(--dim);
  font-size: clamp(11px, 3cqh, 19px);
}

.final {
  margin: 0 0 1.4cqh;
  font-size: clamp(34px, 15cqh, 110px);
  font-weight: 800;
  line-height: 1;
  color: var(--accent-2);
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.3em;
}

.final small {
  font-size: clamp(10px, 3cqh, 18px);
  font-weight: 600;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: 0.16em;
}

.stats, .best {
  margin: 0 0 1.4cqh;
  color: var(--dim);
  font-size: clamp(10px, 2.9cqh, 18px);
}

.best b { color: var(--accent); }

.btn {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 1.8cqh 6cqh;
  font: inherit;
  font-size: clamp(13px, 3.6cqh, 22px);
  font-weight: 700;
  color: #241000;
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  box-shadow: 0 0.8cqh 2.4cqh rgba(255, 138, 61, 0.34);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }

.how {
  margin: 3cqh auto 0;
  padding: 0;
  list-style: none;
  max-width: 62cqw;
  color: var(--dim);
  font-size: clamp(9px, 2.6cqh, 16px);
  display: grid;
  gap: 0.9cqh;
}

.how b { color: var(--ink); }

.sound {
  position: absolute;
  bottom: 2cqh;
  right: 1.6cqw;
  width: 6cqh;
  height: 6cqh;
  min-width: 26px;
  min-height: 26px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(10, 14, 26, 0.6);
  color: var(--ink);
  font-size: clamp(11px, 3cqh, 18px);
  cursor: pointer;
  padding: 0;
}

.sound:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }

.hint {
  margin: 0;
  color: var(--dim);
  font-size: clamp(10px, 1.4vw, 14px);
  text-align: center;
}

kbd {
  font: inherit;
  font-size: 0.92em;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 0 5px;
  color: var(--ink);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.rotate { display: none; }

/* a device-shape decision, not a stage-size one — so this one asks the
   viewport rather than the container */
@media (orientation: portrait) and (pointer: coarse) {
  .rotate {
    display: block;
    margin: 0;
    color: var(--accent-2);
    font-size: 13px;
    text-align: center;
  }
}

@media (max-width: 620px) {
  .hint { display: none; }
}
