:root {
  --bg-0: #0d0b1a;
  --bg-1: #171233;
  --ink: #f4f1ff;
  --ink-dim: #b7b0d8;
  --accent: #ff3b6b;
  --accent-2: #ffb63b;
  --accent-3: #7b5cff;
  --good: #34e0a1;
  --panel: rgba(20, 16, 44, 0.82);
  --panel-border: rgba(123, 92, 255, 0.35);
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg-0);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

/* ------------------------------------------------------------------ HUD */
.hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  padding: max(16px, env(safe-area-inset-top)) 18px 0;
  z-index: 5;
}

.hud-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  max-width: 900px;
  margin: 0 auto;
}

.hud-stat { display: flex; flex-direction: column; min-width: 76px; }
.hud-stat--right { align-items: flex-end; text-align: right; }

.hud-label {
  font-size: 11px;
  letter-spacing: 0.18em;
  font-weight: 700;
  color: var(--ink-dim);
}

.hud-value {
  font-size: clamp(26px, 6vw, 40px);
  font-weight: 900;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.hud-timer { text-align: center; display: flex; flex-direction: column; }
.hud-timer-value {
  font-size: clamp(30px, 8vw, 52px);
  font-weight: 900;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.hud-timer-value.is-low { color: var(--accent); animation: pulseWarn 0.6s ease-in-out infinite; }
.hud-timer-label { font-size: 10px; letter-spacing: 0.16em; color: var(--ink-dim); }

@keyframes pulseWarn {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.12); }
}

.hud-rage {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 900px;
  margin: 14px auto 0;
}
.hud-rage-track {
  flex: 1;
  height: 12px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.4);
}
.hud-rage-fill {
  height: 100%;
  width: 0%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--accent-3), var(--accent), var(--accent-2));
  transition: width 0.12s linear;
}
.hud-rage-fill.is-full {
  animation: rageGlow 0.5s ease-in-out infinite alternate;
}
@keyframes rageGlow {
  from { box-shadow: 0 0 6px var(--accent); }
  to { box-shadow: 0 0 22px var(--accent-2); }
}
.hud-rage-label {
  font-size: 11px;
  letter-spacing: 0.18em;
  font-weight: 800;
  color: var(--ink-dim);
}

.combo {
  position: absolute;
  top: 34%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(30px, 11vw, 84px);
  font-weight: 900;
  letter-spacing: -0.02em;
  color: var(--accent-2);
  text-shadow: 0 4px 24px rgba(255, 182, 59, 0.5);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
}
.combo.show { animation: comboPop 0.5s cubic-bezier(0.2, 1.4, 0.4, 1); }
@keyframes comboPop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.4) rotate(-6deg); }
  40% { opacity: 1; transform: translate(-50%, -50%) scale(1.05) rotate(2deg); }
  100% { opacity: 0; transform: translate(-50%, -60%) scale(1) rotate(0); }
}

/* ------------------------------------------------------------- Overlays */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(ellipse at 50% 30%, rgba(123, 92, 255, 0.18), transparent 60%),
              rgba(8, 6, 18, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: fadeIn 0.35s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.overlay[hidden] { display: none; }

.overlay-card {
  width: min(440px, 100%);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 22px;
  padding: 30px 26px 26px;
  text-align: center;
  box-shadow: var(--shadow);
  animation: cardIn 0.4s cubic-bezier(0.2, 1.1, 0.4, 1);
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(18px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.logo {
  font-size: clamp(64px, 20vw, 108px);
  font-weight: 900;
  line-height: 0.9;
  margin: 0 0 6px;
  letter-spacing: -0.04em;
  background: linear-gradient(180deg, #fff, var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 6px 26px rgba(255, 59, 107, 0.4));
}
.logo-bang { color: var(--accent); -webkit-text-fill-color: var(--accent); }

.tagline {
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink-dim);
  margin: 0 0 22px;
}

.how-to {
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
  margin: 0 auto 24px;
  max-width: 320px;
}
.how-to-summary {
  list-style: none;
  cursor: pointer;
  align-self: center;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-dim);
  padding: 4px 2px;
}
.how-to-summary::-webkit-details-marker { display: none; }
.how-to-summary::after { content: " ▾"; opacity: 0.7; }
.how-to[open] .how-to-summary::after { content: " ▴"; }
.how-to-summary:hover { color: var(--ink); }
.how-to-item {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  padding: 10px 14px;
}
.how-to-emoji { font-size: 20px; }

/* ------------------------------------------------------------- Setup form */
.setup {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
  margin: 0 auto 22px;
  max-width: 320px;
}
.setup[hidden] { display: none; }
.setup-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--ink-dim);
  margin-top: 8px;
}
.setup-opt {
  font-weight: 500;
  opacity: 0.7;
  font-style: italic;
}
.setup-input {
  width: 100%;
  font-family: inherit;
  font-size: 16px; /* >=16px avoids iOS zoom-on-focus */
  font-weight: 600;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.setup-input::placeholder { color: rgba(183, 176, 216, 0.55); }
.setup-input:focus {
  border-color: var(--accent-3);
  box-shadow: 0 0 0 3px rgba(123, 92, 255, 0.25);
}

.btn--primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 14px;
  font-family: inherit;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.2s ease, background 0.2s ease;
  user-select: none;
}
.btn:active { transform: translateY(1px) scale(0.98); }

.btn--primary {
  width: 100%;
  padding: 16px 20px;
  font-size: 18px;
  letter-spacing: 0.04em;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-3));
  box-shadow: 0 12px 30px rgba(255, 59, 107, 0.4);
}
.btn--primary:hover { box-shadow: 0 16px 40px rgba(255, 59, 107, 0.55); transform: translateY(-1px); }

.btn--ghost {
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink-dim);
  padding: 12px 18px;
  font-size: 14px;
  margin-top: 12px;
}
.btn--ghost:hover { color: var(--ink); background: rgba(255, 255, 255, 0.1); }

.btn--sound { width: 100%; }

.menu-link {
  display: block;
  margin-top: 16px;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-2);
  text-decoration: none;
  opacity: 0.9;
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.menu-link:hover { opacity: 1; transform: translateY(-1px); text-decoration: underline; }

/* Sound toggle state (label swapping) */
.sound-off { display: none; }
.btn--sound[aria-pressed="true"] .sound-on,
.mute-toggle[aria-pressed="true"] .sound-on { display: none; }
.btn--sound[aria-pressed="true"] .sound-off,
.mute-toggle[aria-pressed="true"] .sound-off { display: inline; }

.mute-toggle {
  position: absolute;
  bottom: max(34px, calc(env(safe-area-inset-bottom) + 30px));
  left: 14px;
  z-index: 8;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  background: rgba(20, 16, 44, 0.7);
  color: var(--ink);
  font-size: 20px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
}
.mute-toggle:not([hidden]) { display: flex; }

/* --------------------------------------------------------- Game over */
.gameover-title {
  font-size: clamp(30px, 9vw, 46px);
  font-weight: 900;
  margin: 0;
  letter-spacing: 0.02em;
}
.gameover-rank {
  font-size: 20px;
  font-weight: 800;
  color: var(--accent-2);
  margin: 6px 0 22px;
}
.gameover-scores {
  display: flex;
  justify-content: center;
  gap: 34px;
  margin-bottom: 8px;
}
.gameover-score { display: flex; flex-direction: column; gap: 2px; }
.gameover-big {
  font-size: clamp(40px, 12vw, 58px);
  font-weight: 900;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.gameover-big--muted { color: var(--ink-dim); }
.gameover-newbest {
  color: var(--good);
  font-weight: 800;
  margin: 10px 0 0;
  animation: pulseWarn 0.9s ease-in-out infinite;
}
.gameover-stats {
  display: flex;
  justify-content: center;
  gap: 18px;
  flex-wrap: wrap;
  margin: 18px 0 22px;
  font-size: 13px;
  color: var(--ink-dim);
}
.gameover-stats b { color: var(--ink); }

/* ------------------------------------------------------------- Footer */
.footer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 6;
  text-align: center;
  padding: 8px 14px calc(8px + env(safe-area-inset-bottom));
  font-size: 11px;
  color: rgba(183, 176, 216, 0.6);
  pointer-events: none;
  line-height: 1.4;
}
.footer strong { color: rgba(244, 241, 255, 0.85); font-weight: 700; }
.footer a { color: inherit; }
.footer a:hover { color: rgba(244, 241, 255, 0.95); }

@media (max-width: 380px) {
  .how-to-item { font-size: 13px; padding: 9px 12px; }
  .gameover-scores { gap: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; }
}
