@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;450;500;550;600&display=swap');

:root {
  color-scheme: dark;
  font-family: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: #f5f7fa;
  background: #08090b;
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  --ink: #f5f7fa;
  --muted: #a0acb5;
  --cyan: #a8e8f1;
  --space: 32px;
  --control: 56px;
  --ease: cubic-bezier(.16, 1, .3, 1);
}

* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; min-height: 100%; overscroll-behavior: none; }
body { min-height: 100svh; display: grid; place-items: center; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button:disabled { cursor: default; }
button:focus-visible { outline: 2px solid var(--cyan); outline-offset: 6px; }
::selection { color: #000; background: var(--cyan); }

.game {
  position: relative;
  width: min(540px, calc(100% - 64px));
  height: min(800px, calc(100svh - 80px));
  min-height: 400px;
  container-type: inline-size;
  isolation: isolate;
  overflow: hidden;
  border-radius: 16px;
  background: #000;
  user-select: none;
  -webkit-user-select: none;
}

.game canvas {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  transform: scaleX(1.2);
  filter: brightness(1.85) saturate(1.08);
  mask-image: linear-gradient(to bottom, transparent, #000 12%, #000 67%, transparent 97%);
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 12%, #000 67%, transparent 97%);
}

.drag-surface { position: absolute; inset: 0; z-index: 1; touch-action: none; }
.drag-surface:focus-visible { outline: 1px solid var(--cyan); outline-offset: -8px; border-radius: inherit; }
.game[data-phase=match] .drag-surface { cursor: ns-resize; }
.round {
  position: absolute;
  top: calc(var(--space) + env(safe-area-inset-top, 0px));
  left: var(--space);
  z-index: 2;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  pointer-events: none;
}

.score-block {
  position: absolute;
  top: calc(var(--space) - 8px + env(safe-area-inset-top, 0px));
  right: var(--space);
  z-index: 2;
  max-width: 76%;
  text-align: right;
  pointer-events: none;
  animation: arrive 260ms var(--ease) both;
}
.score-line { display: flex; justify-content: flex-end; align-items: baseline; gap: 10px; }
.score { font-size: clamp(64px, 16cqw, 88px); font-weight: 450; letter-spacing: -.04em; line-height: 1; font-variant-numeric: tabular-nums; }
.score-unit { color: var(--muted); font-size: 14px; line-height: 1; white-space: nowrap; }
.score-block p { margin: 10px 0 0; color: var(--muted); font-size: 13px; line-height: 1.5; }

.bottom {
  position: absolute;
  inset: auto var(--space) calc(var(--space) + env(safe-area-inset-bottom, 0px));
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--control);
  align-items: end;
  column-gap: 24px;
  pointer-events: none;
}
.intro, .readings { min-width: 0; grid-column: 1; grid-row: 1; }
.intro .prompt { margin: 0 0 14px; color: var(--ink); font-size: clamp(48px, 12cqw, 64px); font-weight: 450; letter-spacing: -.04em; line-height: 1.05; }
.intro #instruction { margin: 0; max-width: 29ch; color: var(--muted); font-size: 14px; line-height: 1.55; text-wrap: balance; }
.intro #instruction:empty { display: none; }
.game[data-phase=summary] .prompt { margin-bottom: 0; font-size: clamp(34px, 9.5cqw, 52px); }
.game[data-phase=listening] .prompt { margin-bottom: 0; }
.readings { width: fit-content; max-width: 100%; }
.frequency-line { display: flex; align-items: baseline; white-space: nowrap; font-size: var(--reading-size, clamp(40px, 12.5cqw, 64px)); font-weight: 500; line-height: 1.05; letter-spacing: -.04em; font-variant-numeric: tabular-nums; }
.unit { margin-left: 7px; font-size: 15px; font-weight: 400; letter-spacing: 0; color: var(--muted); }
.replay-indicator { display: none; flex: 0 0 auto; align-self: center; margin-left: 12px; color: var(--muted); }
.reading-caption { display: block; margin-top: 7px; color: var(--muted); font-size: 13px; font-weight: 400; line-height: 1.4; letter-spacing: 0; }
.target-reading, .guess-reading { display: block; min-height: 44px; padding: 0; border: 0; border-radius: 4px; background: none; text-align: left; pointer-events: auto; touch-action: manipulation; transition: color 160ms var(--ease), opacity 160ms var(--ease); }
.target-reading { --reading-size: clamp(32px, 10cqw, 48px); margin-bottom: 20px; color: var(--muted); }
.guess-reading { color: var(--ink); }
.game[data-phase=result] .replay-indicator { display: block; }
.game[data-phase=match] .guess-reading { pointer-events: none; }
.game[data-phase=match] .reading-caption { display: none; }
.drag-hint { margin: 12px 0 0; color: var(--muted); font-size: 14px; line-height: 1.5; }

.action {
  display: grid;
  grid-column: 2;
  grid-row: 1;
  place-items: center;
  width: var(--control);
  height: var(--control);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--ink);
  color: #080c10;
  pointer-events: auto;
  transition: background 180ms var(--ease), transform 180ms var(--ease), opacity 180ms var(--ease);
}
.action svg { display: block; }
.action:disabled { opacity: 0; pointer-events: none; }
.action:active { transform: scale(.94); }
.target-reading:active, .guess-reading:active { opacity: .7; }
@media (hover: hover) {
  .action:hover { background: var(--cyan); transform: translateY(-2px); }
  .action:active { transform: scale(.94); }
  .target-reading:hover, .guess-reading:hover { color: var(--cyan); }
  .target-reading:hover .replay-indicator, .guess-reading:hover .replay-indicator { color: var(--cyan); }
}

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.no-script { position: fixed; inset: auto 16px 20px; margin: 0; text-align: center; color: var(--ink); background: #000; font-size: 14px; }
@keyframes arrive { from { opacity: .55; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 600px) {
  :root { background: #000; --space: 24px; }
  .game { width: 100%; height: 100svh; min-height: 0; border-radius: 0; }
  .bottom { column-gap: 20px; }
  .score-block { top: calc(var(--space) + env(safe-area-inset-top, 0px)); }
}
@media (max-width: 350px) {
  :root { --space: 20px; --control: 48px; }
  .bottom { column-gap: 16px; }
  .frequency-line { font-size: 40px; }
  .target-reading .frequency-line { font-size: 32px; }
  .replay-indicator { margin-left: 8px; }
  .score-line { gap: 7px; }
  .score { font-size: 64px; }
}
@media (max-height: 600px) and (min-width: 601px) {
  :root { --space: 24px; --control: 52px; }
  .game { width: min(760px, calc(100% - 32px)); height: calc(100svh - 32px); min-height: 280px; }
  .intro .prompt { font-size: 48px; }
  .score { font-size: 64px; }
  .game[data-phase=result] .readings { display: flex; gap: 32px; align-items: end; }
  .target-reading { margin-bottom: 0; }
  .frequency-line, .target-reading .frequency-line { font-size: 40px; }
}
@media (max-height: 500px) and (max-width: 600px) {
  .intro .prompt { font-size: 40px; }
  .score { font-size: 56px; }
  .target-reading { margin-bottom: 12px; }
  .frequency-line { font-size: 36px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
