:root {
  color-scheme: dark;
  --bg: #0a0a0a;
  --fg: #f3efe6;
  --fg-dim: rgba(243, 239, 230, 0.55);
  --fg-faint: rgba(243, 239, 230, 0.28);
  --line: rgba(243, 239, 230, 0.18);
  --panel: rgba(14, 14, 14, 0.82);
  --serif: "Didot", "Bodoni 72", "Bodoni MT", "Times New Roman", serif;
  --sans: "Avenir Next", "Avenir", "Helvetica Neue", Helvetica, Arial, system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  max-width: 100%;
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  overflow: hidden;
}

body {
  font-family: var(--sans);
  min-height: 100svh;
  min-height: 100dvh;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
  cursor: grab;
}

body.is-holding {
  cursor: grabbing;
}

body.is-results {
  cursor: auto;
  touch-action: auto;
}

.grain,
.trails,
.stage,
.hud,
.end-card {
  position: fixed;
  inset: 0;
}

.grain {
  z-index: 40;
  pointer-events: none;
  opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)' opacity='0.7'/%3E%3C/svg%3E");
  mix-blend-mode: overlay;
}

.trails {
  z-index: 2;
  width: 100%;
  height: 100svh;
  pointer-events: none;
}

.stage {
  z-index: 3;
  pointer-events: auto;
}

.letters {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.letter {
  position: absolute;
  display: grid;
  place-items: center;
  color: var(--fg);
  font-family: var(--serif);
  font-weight: 400;
  line-height: 1;
  letter-spacing: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  transform: translate3d(-50%, -50%, 0);
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease;
}

.letter.is-hit {
  background: var(--fg);
  border-color: var(--fg);
  color: var(--bg);
  animation: letter-hit 420ms cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes letter-hit {
  0% { transform: translate3d(-50%, -50%, 0) scale(0.92); }
  35% { transform: translate3d(-50%, -50%, 0) scale(1.08); }
  100% { transform: translate3d(-50%, -50%, 0) scale(1); }
}

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

.puck {
  position: absolute;
  top: 0;
  left: 0;
  width: 22px;
  height: 22px;
  margin: 0;
  border-radius: 50%;
  background: var(--fg);
  box-shadow:
    0 0 0 1px rgba(10, 10, 10, 0.2),
    0 6px 18px rgba(0, 0, 0, 0.35);
  transform: translate3d(-50%, -50%, 0);
  will-change: transform;
  pointer-events: none;
  z-index: 4;
}

.puck.is-held {
  box-shadow:
    0 0 0 1px rgba(10, 10, 10, 0.2),
    0 0 0 8px rgba(243, 239, 230, 0.08),
    0 8px 22px rgba(0, 0, 0, 0.4);
}

.hint {
  position: absolute;
  left: 50%;
  bottom: max(36px, calc(24px + env(safe-area-inset-bottom)));
  margin: 0;
  color: var(--fg-faint);
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: lowercase;
  transform: translate3d(-50%, 0, 0);
  transition: opacity 280ms ease;
  pointer-events: none;
}

body.is-playing .hint,
body.is-results .hint {
  opacity: 0;
}

.hud {
  z-index: 8;
  display: flex;
  width: min(220px, 70vw);
  height: auto;
  inset: 18px auto auto 50%;
  align-items: baseline;
  justify-content: space-between;
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  letter-spacing: -0.01em;
  pointer-events: none;
  opacity: 0;
  transform: translate3d(-50%, -8px, 0);
  transition: opacity 200ms ease, transform 240ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

body.is-playing .hud,
body.is-results .hud {
  opacity: 0.78;
  transform: translate3d(-50%, 0, 0);
}

.score-burst {
  position: fixed;
  top: 48px;
  left: 50%;
  z-index: 9;
  font-size: 26px;
  font-weight: 500;
  pointer-events: none;
  opacity: 0;
  transform: translate3d(-50%, 8px, 0);
}

.score-burst.is-visible {
  animation: burst 680ms cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes burst {
  0% { opacity: 0; transform: translate3d(-50%, 12px, 0) scale(0.7); }
  22% { opacity: 1; transform: translate3d(-50%, 0, 0) scale(1.14); }
  100% { opacity: 0; transform: translate3d(-50%, -22px, 0) scale(0.94); }
}

.end-card {
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  pointer-events: none;
  visibility: hidden;
  opacity: 0;
  transition: opacity 220ms ease, visibility 0s linear 220ms;
}

body.is-results .end-card {
  pointer-events: auto;
  visibility: visible;
  opacity: 1;
  transition-delay: 0s;
}

.end-panel {
  width: min(372px, 100%);
  max-height: calc(100svh - 36px);
  padding: 28px 22px 20px;
  overflow-x: hidden;
  overflow-y: auto;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  transform: translate3d(0, 16px, 0) scale(0.97);
  transition: transform 280ms cubic-bezier(0.16, 1, 0.3, 1);
}

body.is-results .end-panel {
  transform: none;
}

.end-panel h2 {
  display: flex;
  flex-direction: column;
  margin: 0;
  font-weight: 400;
}

.final-score {
  font-family: var(--serif);
  font-size: clamp(64px, 18vw, 92px);
  line-height: 0.9;
  letter-spacing: -0.03em;
}

.final-label,
.end-subtitle,
.board-heading,
.board-form label,
.board-status,
.done {
  color: var(--fg-dim);
}

.final-label {
  margin-top: 8px;
  font-size: 15px;
  letter-spacing: 0.04em;
}

.end-subtitle {
  margin: 6px 0 28px;
  font-size: 14px;
}

.leaderboard {
  text-align: left;
}

.board-heading,
.board-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.board-heading {
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: lowercase;
}

.board-heading h3 {
  flex: 1;
  margin: 0;
  font-size: inherit;
  font-weight: 500;
  color: var(--fg);
  letter-spacing: inherit;
  text-transform: inherit;
}

.board-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.board-row {
  padding: 6px 0;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.board-row.is-new {
  color: var(--fg);
}

.board-rank {
  width: 1.4em;
  color: var(--fg-dim);
}

.board-initials {
  flex: 1;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.board-form {
  margin-top: 16px;
}

.board-form label {
  display: block;
  margin-bottom: 10px;
  font-size: 12px;
  letter-spacing: 0.08em;
}

.initials-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.initials {
  display: flex;
  gap: 6px;
}

.initials input {
  width: 42px;
  height: 48px;
  padding: 0;
  color: var(--fg);
  font-family: var(--serif);
  font-size: 22px;
  line-height: 48px;
  text-align: center;
  text-transform: uppercase;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  caret-color: var(--fg);
}

.initials input:focus {
  border-color: var(--fg);
}

.board-submit,
.replay,
.done,
.save-settings,
.reset-settings {
  font-family: inherit;
  color: var(--fg);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}

.board-submit,
.replay {
  padding: 10px 18px;
  font-size: 14px;
}

.board-submit:hover,
.replay:hover,
.done:hover,
.save-settings:hover,
.reset-settings:hover,
.board-submit:focus-visible,
.replay:focus-visible,
.done:focus-visible,
.save-settings:focus-visible,
.reset-settings:focus-visible,
.settings summary:focus-visible {
  border-color: var(--fg);
  outline: none;
}

.board-status {
  min-height: 1.2em;
  margin: 10px 0 0;
  font-size: 12px;
  text-align: center;
}

.end-actions {
  margin-top: 24px;
}

.replay {
  min-width: 140px;
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
}

.done {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 8px;
  font-size: 13px;
  background: none;
  border: 0;
}

.settings {
  position: fixed;
  right: 16px;
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 25;
  width: min(230px, calc(100vw - 28px));
  color: var(--fg-dim);
  font-size: 12px;
}

.settings summary {
  width: max-content;
  margin-left: auto;
  padding: 6px 10px;
  letter-spacing: 0.08em;
  list-style: none;
  cursor: pointer;
  border-radius: 999px;
  border: 1px solid transparent;
}

.settings summary::-webkit-details-marker {
  display: none;
}

.settings[open] summary {
  color: var(--fg);
}

.control-grid {
  display: grid;
  gap: 14px;
  margin-top: 8px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.control-grid label {
  display: grid;
  gap: 6px;
  letter-spacing: 0.04em;
}

.control-grid output {
  color: var(--fg);
  font-variant-numeric: tabular-nums;
}

.control-grid input[type="range"] {
  width: 100%;
  accent-color: var(--fg);
}

.control-actions {
  display: flex;
  gap: 8px;
}

.save-settings,
.reset-settings {
  flex: 1;
  padding: 7px 8px;
  font-size: 12px;
}

.audio-start {
  position: fixed;
  left: 50%;
  top: max(18px, env(safe-area-inset-top));
  z-index: 12;
  color: var(--fg-faint);
  font-size: 12px;
  letter-spacing: 0.08em;
  pointer-events: none;
  transform: translate3d(-50%, 0, 0);
}

body.is-playing .audio-start,
body.is-results .audio-start {
  display: none;
}

@media (max-width: 480px) {
  .settings {
    right: 10px;
    left: auto;
  }

  .final-score {
    font-size: 72px;
  }
}
