:root {
  --bg: #1a1140;
  --bg2: #2a1a66;
  --ink: #fdf4ff;
  --muted: #b9a8e6;
  --accent: #ffd166;
  --panel: rgba(255, 255, 255, 0.07);
  --panel-border: rgba(255, 255, 255, 0.14);
  --font: 'Baloo 2', 'Fredoka', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background:
    radial-gradient(1200px 700px at 15% -10%, #3a1f7a 0%, transparent 55%),
    radial-gradient(1000px 800px at 110% 120%, #6a2db8 0%, transparent 50%),
    linear-gradient(160deg, var(--bg) 0%, var(--bg2) 100%);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  touch-action: manipulation;
}

.back-link {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  left: max(16px, env(safe-area-inset-left));
  z-index: 50;
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
  font-size: 15px;
  padding: 7px 13px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(6px);
  transition: transform 0.12s ease, background 0.12s ease;
}
.back-link:hover { transform: translateY(-1px); background: rgba(255, 255, 255, 0.14); }

.stage {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.hud {
  display: flex;
  gap: 10px;
  width: min(94vw, 480px);
  flex-wrap: wrap;
  justify-content: center;
}
.hud-item {
  flex: 1 1 0;
  min-width: 72px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 8px 12px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.hud-label {
  font-size: 11px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}
.hud-value {
  font-size: 21px;
  font-weight: 800;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.combo-item .hud-value { color: var(--accent); }
.combo-item.flash { animation: comboPop 0.45s ease; }
@keyframes comboPop {
  0% { transform: scale(1); }
  40% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

.canvas-wrap {
  position: relative;
  width: min(94vw, 480px);
  aspect-ratio: 1 / 1;
  border-radius: 24px;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45), inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

canvas#game {
  display: block;
  width: 100%;
  height: 100%;
  background: radial-gradient(120% 120% at 50% 0%, #241653 0%, #160d36 100%);
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  padding: 28px;
  background: radial-gradient(120% 120% at 50% 30%, rgba(40, 22, 90, 0.82), rgba(14, 8, 34, 0.94));
  backdrop-filter: blur(3px);
  transition: opacity 0.25s ease;
}
.overlay.hidden { opacity: 0; pointer-events: none; }

.title {
  font-size: clamp(40px, 13vw, 66px);
  line-height: 0.95;
  margin: 0;
  font-weight: 800;
  letter-spacing: -0.01em;
  background: linear-gradient(120deg, #ff8fd8, #ffd166 60%, #6ee7ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 6px 20px rgba(255, 122, 200, 0.3));
}
.title span { display: block; }

.toast-title { font-size: 34px; margin: 0; font-weight: 800; }
.toast-sub { color: var(--muted); margin: 0; font-size: 15px; min-height: 1em; }
.score-line { font-size: 20px; margin: 0; color: var(--muted); }
.score-line strong { color: var(--ink); font-size: 30px; margin-left: 6px; }
.best { color: var(--muted); margin: 0; font-size: 16px; font-weight: 600; }
.best span { color: var(--accent); }

.howto {
  color: var(--muted);
  font-size: 14px;
  max-width: 300px;
  margin: 4px 0 0;
  line-height: 1.4;
}

.btn {
  font-family: var(--font);
  font-size: 20px;
  font-weight: 800;
  color: #20114a;
  border: none;
  border-radius: 999px;
  padding: 13px 38px;
  cursor: pointer;
  background: linear-gradient(120deg, #ffd166, #ff8fd8);
  box-shadow: 0 10px 26px rgba(255, 143, 216, 0.4);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 14px 32px rgba(255, 143, 216, 0.5); }
.btn:active { transform: translateY(0); }

.sound-toggle {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 12;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--ink);
  font-size: 17px;
  cursor: pointer;
  display: grid;
  place-items: center;
  backdrop-filter: blur(6px);
}
.sound-toggle:hover { background: rgba(255, 255, 255, 0.16); }

/* Push fullscreen button below the sound toggle to avoid overlap.
   Sound toggle is 44px tall at top:10px = 54px from the board edge.
   On phones the board sits near the top, so offset the fixed fs button. */
.arcade-ui-fs {
  top: max(64px, calc(env(safe-area-inset-top) + 64px)) !important;
}

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