:root {
  color-scheme: dark;
  --ink: #1b1030;
  --cream: #fff6da;
  --gold: #ffe36b;
  --pink: #e4517a;
  --night: #120c26;
  --edge: #ffe2a3;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-family: var(--mono);
  background: var(--night);
  color: var(--cream);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(ellipse at 50% -10%, #3a2a78 0%, transparent 60%),
    radial-gradient(ellipse at 50% 120%, #4a1f4f 0%, transparent 55%),
    repeating-linear-gradient(0deg, transparent 0 3px, rgba(255, 255, 255, 0.015) 3px 4px),
    var(--night);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

.stage {
  /* Fit a 2:3 cabinet into whatever space the viewport offers. */
  --pad: max(10px, env(safe-area-inset-top));
  --hint: 26px;
  --avail-h: calc(100vh - var(--pad) - max(10px, env(safe-area-inset-bottom)) - var(--hint));
  --avail-w: calc(100vw - max(10px, env(safe-area-inset-left)) - max(10px, env(safe-area-inset-right)));
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: var(--pad) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
}

@supports (height: 100dvh) {
  .stage {
    height: 100dvh;
    --avail-h: calc(100dvh - var(--pad) - max(10px, env(safe-area-inset-bottom)) - var(--hint));
  }
}

.cabinet {
  position: relative;
  width: min(var(--avail-w), calc(var(--avail-h) * 2 / 3), 600px);
  aspect-ratio: 2 / 3;
  border: 4px solid var(--edge);
  border-radius: 16px;
  overflow: hidden;
  isolation: isolate;
  container-type: inline-size;
  background: #2c2f78;
  box-shadow: 0 18px 50px #000a, 7px 7px 0 var(--pink), 0 0 0 1px #000;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  outline: none;
}

.hint {
  margin: 0;
  height: var(--hint);
  line-height: var(--hint);
  font-size: 10px;
  letter-spacing: 2px;
  color: #9d97c9;
  text-align: center;
  white-space: nowrap;
}
.hint span { color: var(--pink); }

.icon-btn {
  position: absolute;
  top: 10px;
  z-index: 3;
  width: 44px;
  height: 44px;
  width: clamp(30px, 9.5cqw, 46px);
  height: clamp(30px, 9.5cqw, 46px);
  display: grid;
  place-items: center;
  padding: 0;
  border: 2.5px solid var(--ink);
  border-radius: 10px;
  background: rgba(255, 246, 218, 0.9);
  color: var(--ink);
  box-shadow: 3px 3px 0 var(--pink);
  cursor: pointer;
  touch-action: manipulation;
}
.icon-btn svg { width: 45%; height: 45%; fill: currentColor; }
.icon-btn:hover { background: #fff; }
.icon-btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--pink); }
.icon-btn:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.icon-btn[hidden] { display: none; }
.pause-btn { left: 10px; }
.sound-btn { right: 10px; }
.sound-btn .off { display: none; }
.sound-btn.muted .on { display: none; }
.sound-btn.muted .off { display: block; }

.settings {
  position: absolute;
  z-index: 4;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(86%, 340px);
  padding: 18px 18px 14px;
  background: #171033;
  border: 3px solid var(--edge);
  border-radius: 12px;
  box-shadow: 6px 7px 0 var(--pink);
  touch-action: manipulation;
}
.settings[hidden] { display: none; }
.settings h2 {
  margin: 0 0 12px;
  text-align: center;
  font-size: 18px;
  letter-spacing: 3px;
  color: var(--gold);
  text-shadow: 2px 2px 0 var(--pink);
}
.settings .row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 1px;
  cursor: pointer;
}
.settings .slider { justify-content: space-between; }
.settings input[type='checkbox'] {
  width: 22px;
  height: 22px;
  accent-color: var(--pink);
}
.settings input[type='range'] {
  width: 58%;
  accent-color: var(--gold);
}
.settings button {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 11px;
  border: 2.5px solid var(--ink);
  border-radius: 8px;
  background: var(--gold);
  color: var(--ink);
  font: 700 16px var(--mono);
  letter-spacing: 2px;
  box-shadow: 3px 4px 0 var(--pink);
  cursor: pointer;
}
.settings button:hover { background: #fff0ae; }
.settings .keys {
  margin: 12px 0 0;
  font-size: 10px;
  color: #9d97c9;
  text-align: center;
  line-height: 1.5;
}

.error {
  position: absolute;
  z-index: 5;
  left: 12px;
  right: 12px;
  bottom: 20px;
  margin: 0;
  padding: 12px;
  border-radius: 8px;
  background: #740f29;
  color: #fff;
  font-size: 12px;
}
.error[hidden] { display: none; }

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

@media (max-width: 520px) {
  .cabinet { border-width: 3px; border-radius: 12px; box-shadow: 0 10px 30px #000a, 4px 4px 0 var(--pink); }
  .icon-btn { top: 8px; }
  .pause-btn { left: 8px; }
  .sound-btn { right: 8px; }
}

/* Short landscape phones: drop the hint line to give the cabinet every pixel. */
@media (max-height: 500px) {
  .stage { --hint: 0px; gap: 0; }
  .hint { display: none; }
}
/* Touch-only devices: keyboard hints are noise; the canvas already says TAP. */
@media (hover: none) and (pointer: coarse) {
  .stage { --hint: 0px; }
  .hint { display: none; }
}

/* Arcade marquee: only on tall screens where there is spare height above the cabinet. */
.marquee { display: none; }
@media (max-aspect-ratio: 5/8) and (min-height: 640px) {
  .stage { --marquee: 64px; --avail-h: calc(100dvh - var(--pad) - max(10px, env(safe-area-inset-bottom)) - var(--hint) - var(--marquee) - 8px); }
  .marquee {
    display: flex;
    align-items: baseline;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0 10px;
    height: var(--marquee);
    font-weight: 800;
    font-size: 30px;
    letter-spacing: 3px;
    line-height: 1;
  }
  .marquee .m1 { color: var(--gold); text-shadow: 3px 3px 0 var(--pink), -1px -1px 0 var(--ink); }
  .marquee .m2 { color: #8ff0dc; text-shadow: 3px 3px 0 var(--pink), -1px -1px 0 var(--ink); }
  .marquee small { flex-basis: 100%; text-align: center; font-size: 10px; letter-spacing: 4px; color: #b9a8d8; margin-top: 8px; }
}

.settings .audio-status { margin-top: 4px; color: #6f6a9a; text-transform: uppercase; }
