:root {
  --bg: #0F1226;
  --bg-2: #1a1f3d;
  --ink: #FAF7F2;
  --muted: rgba(250, 247, 242, 0.7);
  --accent: #22D3EE;
  --accent-2: #FF4D6D;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
}

body {
  background:
    radial-gradient(1200px 600px at 20% -10%, #2a2160 0%, transparent 60%),
    radial-gradient(1000px 500px at 100% 110%, #0c2a3a 0%, transparent 55%),
    var(--bg);
  color: var(--ink);
  font-family: 'Fredoka', system-ui, -apple-system, sans-serif;
  display: grid;
  place-items: start center;
  align-content: center;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.back-link {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  left: 16px;
  z-index: 50;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 15px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  transition: background 0.15s, color 0.15s;
}
.back-link:hover { background: rgba(255, 255, 255, 0.12); color: var(--ink); }

.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: min(96vw, 480px);
  margin-top: max(44px, env(safe-area-inset-top));
}

.hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 0 4px;
}
.hud-item { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.hud-label { font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.hud-value { font-family: 'Baloo 2', system-ui, sans-serif; font-weight: 800; font-size: 22px; line-height: 1; }
.hearts { font-size: 18px; letter-spacing: 1px; }

.canvas-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 480 / 720;
  /* P1 fix: on short viewports (iPhone SE etc.) the board was taller than the
     screen, clipping the paddle. Constrain to the available height so the
     entire play field is always visible. The aspect-ratio then makes it
     narrower automatically. 116px = stage margin-top(44) + HUD(~46) + gap(12)
     + a small breathing room; env() covers the home-indicator on notch phones. */
  max-height: calc(100dvh - 116px - env(safe-area-inset-bottom, 0px));
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5), inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(180deg, #141938 0%, #0d1024 100%);
  cursor: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 14px;
  padding: 24px;
  background: rgba(10, 12, 30, 0.78);
  backdrop-filter: blur(6px);
  z-index: 20;
  animation: fade-in 0.25s ease;
}
.overlay.hidden { display: none; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.title {
  font-family: 'Baloo 2', system-ui, sans-serif;
  font-weight: 800;
  font-size: clamp(38px, 11vw, 56px);
  line-height: 0.95;
  background: linear-gradient(135deg, #22D3EE, #F6C453 55%, #FF4D6D);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 6px 16px rgba(255, 77, 109, 0.25));
}
.title span { display: block; }

.toast-title {
  font-family: 'Baloo 2', system-ui, sans-serif;
  font-weight: 800;
  font-size: clamp(28px, 8vw, 40px);
}
.toast-sub { color: var(--muted); font-size: 16px; }

.best { color: var(--muted); font-size: 16px; font-weight: 600; }
.best span { color: var(--accent); }
.score-line { font-size: 18px; }
.score-line strong { font-family: 'Baloo 2', sans-serif; font-size: 30px; color: var(--accent); display: block; margin-top: 2px; }

.howto { color: var(--muted); font-size: 13px; max-width: 280px; line-height: 1.4; margin-top: 6px; }

.btn {
  font-family: 'Baloo 2', system-ui, sans-serif;
  font-weight: 800;
  font-size: 20px;
  color: #0F1226;
  border: none;
  cursor: pointer;
  padding: 14px 44px;
  border-radius: 999px;
  background: linear-gradient(135deg, #22D3EE, #10B981);
  box-shadow: 0 10px 28px rgba(34, 211, 238, 0.35);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.btn:hover { transform: translateY(-2px) scale(1.03); box-shadow: 0 14px 34px rgba(34, 211, 238, 0.45); }
.btn:active { transform: translateY(0) scale(0.99); }

.sound-toggle {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 30;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
  font-size: 17px;
  display: grid;
  place-items: center;
  transition: background 0.15s;
}
.sound-toggle:hover { background: rgba(255, 255, 255, 0.16); }

@media (prefers-reduced-motion: reduce) {
  .overlay { animation: none; }
  .btn { transition: none; }
}
