/* Pulsa
   Tokens by intent. Base styles are the phone layout; wider screens layer on. */

:root {
  --void: #0d0b0a;
  --void-2: #16120f;
  --line: #2a231d;
  --line-soft: #201a16;

  --chalk: #f2ece1;
  --chalk-dim: #a79b8a;
  --chalk-faint: #8d8272;

  --pulse: #ffcf5c;
  --pulse-deep: #d9a52c;
  --danger: #e4553b;
  --good: #7bd88f;

  --sans: 'Instrument Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --fast: 150ms;
  --mid: 300ms;

  --pad: clamp(16px, 4.5vw, 32px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  background: var(--void);
  color: var(--chalk);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

.stage {
  position: relative;
  height: 100%;
  height: 100dvh;
  display: grid;
  place-items: center;
  isolation: isolate;
}

#field {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
}

/* ------------------------------------------------------------------- hud */

.hud {
  position: absolute;
  z-index: 3;
  top: 0;
  left: 0;
  right: 0;
  padding: max(var(--pad), env(safe-area-inset-top)) var(--pad) 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: var(--s3);
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--mid) var(--ease);
}

.stage[data-phase='playing'] .hud,
.stage[data-phase='paused'] .hud {
  opacity: 1;
}

.hud-left {
  display: grid;
  gap: 2px;
}

.hud-right {
  justify-self: end;
  display: grid;
  gap: 6px;
  justify-items: end;
}

.hud-label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--chalk-faint);
}

.hud-score {
  font-family: var(--mono);
  font-size: clamp(1.8rem, 7vw, 2.6rem);
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--chalk);
  transition: color var(--fast) var(--ease);
}

.hud-score.is-hit {
  color: var(--pulse);
}

.combo {
  display: block;
  padding-top: 2px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--pulse);
  opacity: 0;
  transform: translateY(-3px);
  transition: opacity var(--fast) var(--ease), transform var(--fast) var(--ease);
  white-space: nowrap;
}

.combo.is-on {
  opacity: 1;
  transform: none;
}

.lives {
  display: flex;
  gap: 5px;
}

.life {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--pulse);
  transition: background var(--mid) var(--ease), transform var(--mid) var(--ease), opacity var(--mid) var(--ease);
}

.life.is-lost {
  background: transparent;
  box-shadow: inset 0 0 0 1px var(--line);
  transform: scale(0.72);
}

/* ----------------------------------------------------------------- panels */

.panel {
  position: relative;
  z-index: 2;
  width: min(520px, 100% - (var(--pad) * 2));
  text-align: center;
  animation: panelIn 420ms var(--ease) both;
}

.panel[hidden] {
  display: none;
}

@keyframes panelIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.kicker {
  margin: 0 0 var(--s3);
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--chalk-faint);
}

.panel-title .title {
  margin: 0 0 var(--s4);
  font-family: var(--mono);
  font-size: clamp(3rem, 17vw, 5.4rem);
  font-weight: 700;
  letter-spacing: -0.045em;
  line-height: 0.86;
  color: var(--chalk);
}

.pitch {
  margin: 0 auto var(--s6);
  max-width: 34ch;
  font-size: 0.98rem;
  line-height: 1.6;
  color: var(--chalk-dim);
}

.panel-over .final-label,
.stats dt {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--chalk-faint);
}

.panel-over .final-label {
  margin: 0 0 2px;
}

.final {
  margin: 0 0 var(--s2);
  font-family: var(--mono);
  font-size: clamp(3.4rem, 20vw, 6rem);
  font-weight: 700;
  line-height: 0.9;
  letter-spacing: -0.05em;
  font-variant-numeric: tabular-nums;
  color: var(--pulse);
}

.verdict {
  margin: 0 0 var(--s5);
  font-size: 0.95rem;
  color: var(--chalk-dim);
  min-height: 1.5em;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  margin: 0 0 var(--s5);
  padding: 0;
  background: var(--line-soft);
  border: 1px solid var(--line-soft);
}

.stats > div {
  background: var(--void);
  padding: var(--s3) var(--s2);
  display: grid;
  gap: 3px;
}

.stats dt {
  font-size: 9px;
  letter-spacing: 0.12em;
}

.stats dd {
  margin: 0;
  font-family: var(--mono);
  font-size: 1.1rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--chalk);
}

.record {
  margin: 0 0 var(--s4);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--pulse);
}

.record[hidden] {
  display: none;
}

.best {
  margin: var(--s5) 0 0;
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: 0.06em;
  color: var(--chalk-faint);
}

.best[hidden] {
  display: none;
}

.best strong {
  color: var(--chalk);
  font-weight: 500;
}

.hint {
  margin: var(--s5) 0 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--chalk-faint);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--s3);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  min-height: 48px;
  padding: 0 var(--s5);
  font-family: var(--sans);
  font-size: 0.95rem;
  font-weight: 500;
  border-radius: 2px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease),
    border-color var(--fast) var(--ease), transform var(--fast) var(--ease), gap var(--mid) var(--ease);
}

.btn-primary {
  background: var(--pulse);
  color: #0d0b0a;
}

.btn-primary:hover {
  background: #ffdb85;
  gap: var(--s3);
}

.btn-primary:active {
  transform: translateY(1px);
}

.btn-quiet {
  background: transparent;
  color: var(--chalk);
  border-color: var(--line);
}

.btn-quiet:hover {
  border-color: var(--chalk-faint);
  background: var(--void-2);
}

.btn-quiet[aria-pressed='true'] {
  color: var(--chalk-dim);
  border-color: var(--line);
}

:where(button):focus-visible {
  outline: 2px solid var(--pulse);
  outline-offset: 3px;
}

/* ------------------------------------------------------------------ toast */

.toast {
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: max(var(--pad), env(safe-area-inset-bottom));
  transform: translate(-50%, 10px);
  margin: 0;
  padding: 8px 14px;
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: 0.04em;
  color: var(--chalk);
  background: var(--void-2);
  border: 1px solid var(--line);
  border-radius: 2px;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--mid) var(--ease), transform var(--mid) var(--ease);
  white-space: nowrap;
  max-width: calc(100% - (var(--pad) * 2));
  overflow: hidden;
  text-overflow: ellipsis;
}

.toast.is-on {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ------------------------------------------------------------- responsive */

@media (max-height: 620px) {
  .panel-title .title {
    font-size: clamp(2.4rem, 12vw, 3.6rem);
  }

  .pitch {
    margin-bottom: var(--s5);
    font-size: 0.9rem;
  }

  .hint {
    margin-top: var(--s4);
  }

  .final {
    font-size: clamp(2.8rem, 14vw, 4rem);
  }
}

@media (min-width: 900px) {
  .panel {
    width: min(560px, 100% - 96px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}