:root {
  --page-bg: #5b6b8a;       /* neutral slate blue */
  --stage-bg: #2c323d;      /* dark slate gray, same family */
  --stage-glow: #3a4250;
  --pipe-light: #eef0f3;
  --pipe-mid: #c9ced6;
  --pipe-dark: #8f96a2;
}

* { box-sizing: border-box; }

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

body {
  background: var(--page-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

/* Light gray "piping": a rounded tube with a bevel highlight and shadow */
.frame {
  padding: 14px;
  border-radius: 28px;
  background: linear-gradient(145deg, var(--pipe-light) 0%, var(--pipe-mid) 45%, var(--pipe-dark) 100%);
  box-shadow:
    inset 2px 2px 3px rgba(255, 255, 255, 0.9),
    inset -2px -2px 4px rgba(0, 0, 0, 0.25),
    0 12px 30px rgba(0, 0, 0, 0.35);
}

/* Play area is exactly 600x800, shrinking proportionally on small screens */
.stage {
  position: relative;       /* anchors the game-over overlay */
  width: min(600px, calc((100vh - 60px) * 0.75), calc(100vw - 60px));
  aspect-ratio: 600 / 800;
  border-radius: 16px;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 35%, var(--stage-glow) 0%, var(--stage-bg) 75%);
  box-shadow:
    inset 0 3px 8px rgba(0, 0, 0, 0.55),
    0 0 0 1px rgba(0, 0, 0, 0.25);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;       /* finger drags move the paddle instead of scrolling */
}

/* Hide the system cursor while playing; the paddle is the cursor */
.stage.playing canvas {
  cursor: none;
}

/* ---------- Overlays (end screens, title, high scores) ---------- */

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: safe center;   /* centered, but scrolls instead of clipping if too tall */
  gap: clamp(10px, 2.2vmin, 18px);
  overflow-y: auto;
  background: rgba(28, 32, 40, 0.72);
  backdrop-filter: blur(3px);
  color: var(--pipe-light);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  text-align: center;
  padding: 16px 28px;       /* keeps long titles off the frame edges */
}

.overlay[hidden] {
  display: none;
}

/* Victory: lighter veil so the celebration fireworks show through */
.overlay.win {
  background: rgba(28, 32, 40, 0.15);
  backdrop-filter: none;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
}

.overlay.win h1 {
  background: linear-gradient(90deg, #f7a8b8, #f9c89b, #f6e59a, #a8e6b0, #9fd3f2, #c3a8f0);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: none;
  filter: drop-shadow(0 3px 10px rgba(0, 0, 0, 0.45));
}

.overlay h1 {
  margin: 0;
  font-size: clamp(30px, 8vmin, 48px);
  line-height: 1.1;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-shadow: 0 3px 12px rgba(0, 0, 0, 0.5);
}

.overlay p {
  margin: 0;
  font-size: 18px;
  color: var(--pipe-mid);
}

/* Button styled like the frame's piping */
.button {
  margin-top: 8px;
  padding: 12px 34px;
  border: none;
  border-radius: 999px;
  font: inherit;
  font-size: 18px;
  font-weight: 700;
  color: var(--stage-bg);
  background: linear-gradient(145deg, var(--pipe-light) 0%, var(--pipe-mid) 50%, var(--pipe-dark) 100%);
  box-shadow:
    inset 1px 1px 2px rgba(255, 255, 255, 0.9),
    inset -1px -1px 3px rgba(0, 0, 0, 0.25),
    0 6px 16px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  transition: transform 0.08s ease, filter 0.15s ease;
}

.button:hover {
  filter: brightness(1.06);
}

.button:active {
  transform: translateY(1px) scale(0.98);
}

.button:focus-visible {
  outline: 3px solid #a9bbe0;
  outline-offset: 3px;
}

/* ---------- Sound controls (top-right of the page, outside the frame) ---------- */

.controls {
  position: fixed;
  top: 16px;
  right: 16px;
  display: flex;
  gap: 10px;
  z-index: 10;
}

.round-button {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  border: none;
  border-radius: 50%;
  color: #3a4250;
  background: linear-gradient(145deg, var(--pipe-light) 0%, var(--pipe-mid) 50%, var(--pipe-dark) 100%);
  box-shadow:
    inset 1px 1px 2px rgba(255, 255, 255, 0.9),
    inset -1px -1px 3px rgba(0, 0, 0, 0.25),
    0 4px 12px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  transition: transform 0.08s ease, filter 0.15s ease, opacity 0.15s ease;
}

.round-button:hover {
  filter: brightness(1.06);
}

.round-button:active {
  transform: scale(0.94);
}

.round-button:focus-visible {
  outline: 3px solid #a9bbe0;
  outline-offset: 3px;
}

/* "On" parts show by default; "off" parts show when the button is pressed (turned off) */
.round-button .icon-off,
.round-button[aria-pressed="true"] .icon-on {
  display: none;
}

.round-button[aria-pressed="true"] .icon-off {
  display: inline;
}

/* Music button looks dimmed while everything is muted (music can't play then anyway) */
.round-button.dimmed {
  opacity: 0.55;
}

/* ---------- Title screen ---------- */

.overlay.title-screen {
  gap: clamp(10px, 2.4vmin, 18px);
  background: rgba(28, 32, 40, 0.78);
  backdrop-filter: blur(4px);
}

.game-title {
  font-size: clamp(34px, 9vmin, 60px) !important;
  background: linear-gradient(90deg, #f7a8b8, #f9c89b, #f6e59a, #a8e6b0, #9fd3f2, #c3a8f0);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: none !important;
  filter: drop-shadow(0 3px 10px rgba(0, 0, 0, 0.45));
}

.tagline {
  margin-top: -6px !important;
  font-size: clamp(13px, 2.2vmin, 17px) !important;
}

.play-button {
  margin-top: clamp(4px, 1.5vmin, 12px);
  padding: clamp(12px, 2.2vmin, 16px) clamp(48px, 9vmin, 72px);
  font-size: clamp(20px, 3.6vmin, 26px);
  letter-spacing: 0.04em;
}

.title-toggles {
  display: flex;
  gap: 10px;
}

.button.small {
  margin-top: 0;
  padding: 7px 16px;
  font-size: 14px;
  font-weight: 600;
}

/* A toggle that's switched off looks pressed in and dimmer */
.button.small[aria-pressed="true"] {
  opacity: 0.6;
  box-shadow:
    inset 1px 1px 3px rgba(0, 0, 0, 0.3),
    0 2px 6px rgba(0, 0, 0, 0.25);
}

.scores {
  width: min(320px, 100%);
  margin-top: clamp(4px, 1.5vmin, 12px);
  padding: clamp(10px, 2vmin, 16px) clamp(14px, 3vmin, 22px);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.06);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}

.scores h2 {
  margin: 0 0 8px;
  font-size: clamp(13px, 2.2vmin, 16px);
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--pipe-mid);
}

.scores ol {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: clamp(14px, 2.4vmin, 18px);
}

.scores li,
.board-list li {
  display: grid;
  grid-template-columns: 2ch 1fr auto;
  gap: 10px;
  padding: clamp(3px, 0.7vmin, 5px) 0;
  text-align: left;
  font-variant-numeric: tabular-nums;
}

.scores li + li,
.board-list li + li {
  border-top: 1px solid rgba(255, 255, 255, 0.07);
}

.scores .rank,
.board-list .rank {
  color: var(--pipe-dark);
  font-weight: 700;
}

.scores li.empty {
  color: rgba(238, 240, 243, 0.3);
}

.scores .text-button {
  margin-top: 6px;
}

/* ---------- Buttons used by the high score screens ---------- */

.overlay-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}

.overlay-actions[hidden] {
  display: none;
}

.overlay-actions .button {
  margin-top: 0;
}

/* Outlined companion to the main pill button */
.button.secondary {
  color: var(--pipe-light);
  background: rgba(255, 255, 255, 0.1);
  box-shadow:
    inset 0 0 0 1.5px rgba(255, 255, 255, 0.35),
    0 6px 16px rgba(0, 0, 0, 0.25);
}

.text-button {
  padding: 6px 10px;
  border: none;
  background: none;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--pipe-mid);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.text-button:hover {
  color: var(--pipe-light);
}

.text-button:focus-visible {
  outline: 2px solid #a9bbe0;
  outline-offset: 2px;
  border-radius: 6px;
}

.overlay .score-status {
  font-size: 16px;
  font-weight: 600;
  color: #f6e59a;
}

.score-status[hidden] {
  display: none;
}

/* ---------- High score name entry ---------- */

.entry {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(6px, 1.4vmin, 10px);
}

.entry[hidden] {
  display: none;
}

.overlay .entry-heading {
  font-size: clamp(18px, 3.4vmin, 24px);
  font-weight: 800;
  color: #f6e59a;
}

.overlay .entry-hint {
  margin-top: -4px;
  font-size: 14px;
}

.entry-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.entry-actions .button {
  margin-top: 0;
}

.name-picker {
  --item: clamp(32px, 6.2vmin, 46px);   /* height of one letter slot */
  display: flex;
  gap: clamp(8px, 2vmin, 14px);
}

.wheel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

/* Three slots tall; the middle one is the selected letter */
.wheel-view {
  position: relative;
  width: calc(var(--item) * 1.4);
  height: calc(var(--item) * 3);
  overflow: hidden;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.3);
  box-shadow:
    inset 0 3px 8px rgba(0, 0, 0, 0.5),
    inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  touch-action: none;       /* a finger drag turns the wheel instead of scrolling */
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
  outline: none;
}

.wheel-view:active {
  cursor: grabbing;
}

/* Selection band in the middle, styled like the piping */
.wheel-view::before {
  content: "";
  position: absolute;
  left: 4px;
  right: 4px;
  top: var(--item);
  height: var(--item);
  border-radius: 10px;
  background: linear-gradient(145deg, var(--pipe-light) 0%, var(--pipe-mid) 55%, var(--pipe-dark) 100%);
  box-shadow: inset 1px 1px 2px rgba(255, 255, 255, 0.9), 0 2px 6px rgba(0, 0, 0, 0.35);
}

/* The wheel being edited gets a soft blue ring */
.wheel-view:focus::before {
  box-shadow:
    inset 1px 1px 2px rgba(255, 255, 255, 0.9),
    0 0 0 3px #a9bbe0;
}

.wheel-letter {
  position: absolute;
  left: 0;
  right: 0;
  top: var(--item);
  height: var(--item);
  line-height: var(--item);
  text-align: center;
  font-size: calc(var(--item) * 0.66);
  font-weight: 800;
  color: var(--pipe-light);
  pointer-events: none;
}

.wheel-letter.selected {
  color: var(--stage-bg);
}

.wheel-arrow {
  width: calc(var(--item) * 1.4);
  height: 26px;
  display: grid;
  place-items: center;
  padding: 0;
  border: none;
  border-radius: 8px;
  color: var(--pipe-mid);
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
}

.wheel-arrow:hover {
  color: var(--pipe-light);
  background: rgba(255, 255, 255, 0.16);
}

.wheel-arrow::before {
  content: "";
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
}

.wheel-arrow.up::before   { border-bottom: 8px solid currentColor; }
.wheel-arrow.down::before { border-top: 8px solid currentColor; }

/* ---------- Full high score list ---------- */

.overlay.board-screen {
  z-index: 5;
  padding: clamp(12px, 3vmin, 28px);
  background: rgba(28, 32, 40, 0.6);
}

.board {
  width: min(380px, 100%);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 18px 16px 16px;
  border-radius: 18px;
  background: rgba(44, 50, 61, 0.95);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.1),
    0 10px 30px rgba(0, 0, 0, 0.45);
}

.board h2 {
  margin: 0;
  font-size: clamp(20px, 3.6vmin, 26px);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: linear-gradient(90deg, #f7a8b8, #f9c89b, #f6e59a, #a8e6b0, #9fd3f2, #c3a8f0);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.overlay .board-status {
  font-size: 13px;
}

.board-list {
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  padding: 0 6px;
  overflow-y: auto;
  overscroll-behavior: contain;
  list-style: none;
  font-size: clamp(15px, 2.6vmin, 18px);
}

.board-list li {
  grid-template-columns: 3.2ch 1fr auto;
  padding: 5px 8px;
}

.board-list .rank {
  text-align: right;
}

/* The score the player just saved */
.board-list li.me {
  color: #f6e59a;
  background: rgba(246, 229, 154, 0.14);
  border-radius: 8px;
}

.board-list li.note {
  display: block;
  padding: 24px 0;
  text-align: center;
  color: rgba(238, 240, 243, 0.5);
}

.board .button {
  margin-top: 6px;
}
