:root {
  --bg: #060609;
  --accent: #e8be66;
  --accent-strong: #ffe29a;
  --accent-rgb: 232, 190, 102;
  --accent-sec: #c9923b;
  --glass: rgba(12, 12, 17, 0.62);
  --glass-strong: rgba(14, 14, 20, 0.84);
  --border: rgba(232, 190, 102, 0.24);
  --border-subtle: rgba(255, 255, 255, 0.1);
  --text: #f5f2ea;
  --text-dim: rgba(245, 242, 234, 0.56);
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC", "Helvetica Neue", system-ui, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html[data-theme="nebula"] {
  --bg: #050712;
  --accent: #56d6ff;
  --accent-strong: #c4b5fd;
  --accent-rgb: 86, 214, 255;
  --accent-sec: #a855f7;
  --glass: rgba(10, 14, 30, 0.64);
  --glass-strong: rgba(11, 16, 36, 0.86);
  --border: rgba(125, 211, 252, 0.26);
  --text: #eef6ff;
  --text-dim: rgba(226, 238, 255, 0.56);
}

html[data-theme="crimson"] {
  --bg: #090506;
  --accent: #fb7185;
  --accent-strong: #fdba74;
  --accent-rgb: 251, 113, 133;
  --accent-sec: #e06b42;
  --glass: rgba(20, 11, 14, 0.65);
  --glass-strong: rgba(24, 12, 15, 0.86);
  --border: rgba(251, 146, 120, 0.26);
  --text: #fff2ef;
  --text-dim: rgba(255, 234, 229, 0.56);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.app-shell {
  position: relative;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: radial-gradient(circle at 50% 42%, rgba(var(--accent-rgb), 0.08), transparent 62%), var(--bg);
}

.webgl-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}

.webgl-canvas:active {
  cursor: grabbing;
}

/* Bullet-Time Edge Vignette */
.bt-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 220ms ease;
  background: radial-gradient(circle at 50% 50%, transparent 45%, rgba(var(--accent-rgb), 0.16) 85%, rgba(4, 6, 14, 0.72) 100%);
  box-shadow: inset 0 0 64px rgba(var(--accent-rgb), 0.28);
  z-index: 4;
}

.bt-vignette.active {
  opacity: 1;
}

/* Top HUD */
.hud-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  padding: calc(8px + var(--safe-top)) 10px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}

.hud-bar {
  width: 100%;
  max-width: 620px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 12px;
  background: var(--glass);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  pointer-events: auto;
}

.metric {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
}

.metric-score {
  align-items: flex-start;
  flex: 1.45;
}

.metric-combo,
.metric-mult {
  flex: 0.72;
}

.metric-balls {
  flex: 0.85;
}

.metric-best {
  align-items: flex-end;
  flex: 1.05;
}

.metric-label {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  line-height: 1;
  margin-bottom: 3px;
}

.metric-value {
  font-size: 16px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  line-height: 1.05;
  color: var(--text);
  white-space: nowrap;
}

.metric-score .metric-value {
  font-size: 19px;
  color: var(--accent-strong);
  text-shadow: 0 0 18px rgba(var(--accent-rgb), 0.32);
}

.metric-combo .metric-value.hot {
  color: var(--accent);
}

.metric-mult .metric-value.boosted {
  color: var(--accent-strong);
}

.hud-sep {
  width: 1px;
  height: 22px;
  background: var(--border-subtle);
  flex-shrink: 0;
  margin: 0 4px;
}

.ball-pips {
  display: flex;
  align-items: center;
  gap: 5px;
  height: 18px;
}

.ball-pip {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1px solid rgba(var(--accent-rgb), 0.35);
  background: rgba(255, 255, 255, 0.06);
  transition: transform 240ms ease, background 240ms ease, box-shadow 240ms ease;
}

.ball-pip.active {
  background: radial-gradient(circle at 32% 32%, #ffffff 0%, var(--accent-strong) 45%, var(--accent-sec) 100%);
  border-color: rgba(255, 255, 255, 0.65);
  box-shadow: 0 0 8px rgba(var(--accent-rgb), 0.65);
}

/* Floating Controls Strip */
.hud-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  max-width: 100%;
  pointer-events: auto;
}

.seg-group {
  display: inline-flex;
  align-items: center;
  padding: 2px;
  background: var(--glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  gap: 2px;
}

.ctrl-btn {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.03em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 26px;
  padding: 0 8px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 180ms ease, color 180ms ease, border-color 180ms ease, transform 120ms ease;
  white-space: nowrap;
}

.ctrl-btn:active {
  transform: scale(0.95);
}

.theme-btn.active {
  background: rgba(var(--accent-rgb), 0.18);
  border-color: rgba(var(--accent-rgb), 0.44);
  color: var(--text);
}

.pill-btn,
.icon-btn {
  background: var(--glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-subtle);
  color: var(--text);
  height: 30px;
}

.pill-btn {
  padding: 0 10px;
}

.pill-btn:hover,
.icon-btn:hover,
.theme-btn:hover {
  border-color: var(--border);
  color: var(--text);
}

.pill-btn[aria-expanded="true"] {
  border-color: rgba(var(--accent-rgb), 0.55);
  background: rgba(var(--accent-rgb), 0.16);
}

.icon-btn {
  width: 30px;
  padding: 0;
}

.icon-btn.active {
  color: var(--accent-strong);
}

.ctrl-svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.swatch {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.55);
}

.swatch-obsidian {
  background: linear-gradient(135deg, #ffe7a8, #c48d30);
}

.swatch-nebula {
  background: linear-gradient(135deg, #67e8f9, #8b5cf6);
}

.swatch-crimson {
  background: linear-gradient(135deg, #fda4af, #dc2626);
}

.swatch-chrome {
  background: radial-gradient(circle at 30% 30%, #ffffff, #9ca3af 55%, #374151 100%);
}

.swatch-crystal {
  background: linear-gradient(135deg, #e0f2fe, #38bdf8 55%, #c084fc);
}

.swatch-gold {
  background: radial-gradient(circle at 30% 30%, #fff4cc, #f5b942 55%, #9a5d10 100%);
}

.swatch-plasma {
  background: radial-gradient(circle at 35% 35%, #f0abfc, #7c3aed 55%, #0ea5e9 100%);
}

/* Collapsible Ball Skin Picker */
.skin-drawer {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px;
  background: var(--glass-strong);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.55);
  pointer-events: auto;
  animation: fadeSlideDown 160ms ease;
}

@keyframes fadeSlideDown {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.skin-opt {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 11px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 150ms ease;
}

.skin-opt.active {
  background: rgba(var(--accent-rgb), 0.18);
  border-color: rgba(var(--accent-rgb), 0.45);
  color: var(--text);
}

/* Center Event Callout */
.callout {
  position: absolute;
  top: 25%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.92);
  z-index: 8;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 240ms ease, transform 280ms cubic-bezier(0.22, 1, 0.36, 1);
}

.callout.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.callout-sub {
  display: inline-block;
  padding: 3px 12px;
  border-radius: 999px;
  background: rgba(6, 7, 13, 0.72);
  border: 1px solid rgba(var(--accent-rgb), 0.38);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.26em;
  color: var(--accent-strong);
  text-transform: uppercase;
  margin-bottom: 6px;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.98), 0 0 12px rgba(0, 0, 0, 0.9);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.55);
}

.callout-main {
  font-size: clamp(22px, 5vw, 34px);
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--text);
  text-shadow: 0 0 26px rgba(var(--accent-rgb), 0.55), 0 4px 18px rgba(0, 0, 0, 0.95);
  white-space: nowrap;
}

/* Bottom HUD */
.hud-bottom {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  padding: 0 12px calc(10px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.energy-strip {
  width: 100%;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px 12px 7px;
  background: var(--glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  pointer-events: none;
}

.energy-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.energy-tag {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--accent);
  flex-shrink: 0;
}

.hint-pill {
  font-size: 10.5px;
  color: var(--text-dim);
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.energy-pct {
  font-size: 10px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  flex-shrink: 0;
  min-width: 30px;
  text-align: right;
}

.energy-track {
  width: 100%;
  height: 3px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  overflow: hidden;
}

.energy-fill {
  height: 100%;
  width: 65%;
  background: linear-gradient(90deg, var(--accent-sec), var(--accent), var(--accent-strong));
  border-radius: 999px;
  box-shadow: 0 0 10px rgba(var(--accent-rgb), 0.75);
  transition: width 80ms linear;
}

.flipper-dock {
  width: 100%;
  max-width: 560px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
}

.flip-pad {
  pointer-events: auto;
  flex: 1;
  height: 52px;
  border-radius: 15px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(0, 0, 0, 0.34)), var(--glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  color: var(--text);
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  transition: transform 70ms ease, background 100ms ease, border-color 100ms ease, box-shadow 100ms ease;
  touch-action: none;
}

.flip-pad.pressed,
.flip-pad:active {
  transform: scale(0.97);
  border-color: rgba(var(--accent-rgb), 0.8);
  background: linear-gradient(180deg, rgba(var(--accent-rgb), 0.28), rgba(var(--accent-rgb), 0.1)), var(--glass);
  box-shadow: 0 0 22px rgba(var(--accent-rgb), 0.38), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.flip-chevron {
  width: 16px;
  height: 12px;
  color: var(--accent-strong);
}

.flip-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.16em;
}

.flip-key {
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 0.06em;
}

.dock-center-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  min-width: 72px;
}

.prism-status {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  opacity: 0.88;
  white-space: nowrap;
}

/* Game Over Modal */
.modal-backdrop {
  position: absolute;
  inset: 0;
  z-index: 30;
  background: rgba(4, 4, 8, 0.72);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 220ms ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  width: 100%;
  max-width: 370px;
  background: var(--glass-strong);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 24px 22px 20px;
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.7), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  text-align: center;
}

.modal-kicker {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.24em;
  color: var(--accent);
  margin-bottom: 4px;
}

.modal-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--text);
  margin-bottom: 16px;
}

.modal-score-block {
  padding: 14px 12px;
  border-radius: 14px;
  background: rgba(var(--accent-rgb), 0.08);
  border: 1px solid rgba(var(--accent-rgb), 0.2);
  margin-bottom: 14px;
}

.modal-score-label {
  font-size: 9px;
  letter-spacing: 0.2em;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.modal-score-val {
  font-size: 36px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent-strong);
  letter-spacing: 0.02em;
  line-height: 1.1;
}

.record-badge {
  display: inline-block;
  margin-top: 8px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: #09080a;
  background: linear-gradient(90deg, var(--accent), var(--accent-strong));
}

.modal-stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.stat-cell {
  padding: 9px 6px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.stat-k {
  font-size: 8.5px;
  letter-spacing: 0.12em;
  color: var(--text-dim);
}

.stat-v {
  font-size: 16px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.leaderboard-section {
  text-align: left;
  margin-bottom: 18px;
}

.lb-head {
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.18em;
  color: var(--text-dim);
  margin-bottom: 8px;
  padding-left: 2px;
}

.lb-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.lb-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 11px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.lb-item.current {
  border-color: rgba(var(--accent-rgb), 0.45);
  background: rgba(var(--accent-rgb), 0.1);
}

.lb-rank {
  width: 22px;
  font-weight: 700;
  color: var(--accent);
}

.lb-score {
  flex: 1;
  font-weight: 600;
  color: var(--text);
}

.lb-meta {
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 0.04em;
}

.btn-primary {
  width: 100%;
  height: 46px;
  border-radius: 13px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #09080c;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.14em;
  cursor: pointer;
  box-shadow: 0 10px 28px rgba(var(--accent-rgb), 0.34);
  transition: transform 120ms ease, filter 150ms ease;
}

.btn-primary:hover {
  filter: brightness(1.06);
}

.btn-primary:active {
  transform: scale(0.98);
}

.hidden {
  display: none !important;
}

/* Mobile Portrait Tight Tuning (390x844 and smaller) */
@media (max-width: 520px) {
  .hud-bar {
    padding: 6px 10px;
    border-radius: 12px;
  }

  .metric-value {
    font-size: 14px;
  }

  .metric-score .metric-value {
    font-size: 17px;
  }

  .hud-controls {
    gap: 4px;
  }

  .ctrl-btn {
    padding: 0 7px;
    font-size: 10.5px;
  }

  .pill-btn {
    padding: 0 8px;
    height: 28px;
  }

  .icon-btn {
    width: 28px;
    height: 28px;
  }

  .skin-opt {
    padding: 5px 8px;
    font-size: 10.5px;
  }

  .flip-pad {
    height: 50px;
  }

  .flip-key {
    display: none;
  }

  .dock-center-badge {
    min-width: 62px;
  }

  .energy-tag {
    display: none;
  }

  .hint-pill {
    text-align: left;
    font-size: 10px;
  }
}

/* Desktop spacious enhancements */
@media (min-width: 900px) {
  .hud-top {
    padding-top: 14px;
    gap: 8px;
  }

  .hud-bar {
    max-width: 680px;
    padding: 9px 18px;
  }

  .metric-score .metric-value {
    font-size: 22px;
  }

  .metric-value {
    font-size: 17px;
  }

  .hud-bottom {
    padding-bottom: 14px;
  }

  .flipper-dock,
  .energy-strip {
    max-width: 620px;
  }
}
