:root {
  --bg-deep: #070b14;
  --bg-surface: #0d1322;
  --bg-elevated: rgba(17, 25, 44, 0.78);
  --border-subtle: rgba(148, 163, 184, 0.14);
  --border-glow: rgba(52, 211, 153, 0.35);

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent-emerald: #34d399;
  --accent-cyan: #22d3ee;
  --accent-amber: #fbbf24;
  --accent-rose: #fb7185;

  --radius-lg: 20px;
  --radius-md: 12px;
  --radius-sm: 8px;

  /* 40x22 widescreen arena sized cleanly for 1920x1080 and smaller viewports */
  --grid-ratio: calc(40 / 22);
  --stage-w: min(1680px, calc(100vw - 56px), calc((100vh - 136px) * var(--grid-ratio)));
  --stage-h: calc(var(--stage-w) / var(--grid-ratio));
}

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

html,
body {
  height: 100%;
  background-color: var(--bg-deep);
  color: var(--text-primary);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  user-select: none;
}

.mono {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* Subtle Ambient Background Orbs */
.ambient-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}

.ambient-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(110px);
  opacity: 0.22;
  transition: transform 0.8s ease;
}

.orb-1 {
  width: 520px;
  height: 520px;
  background: radial-gradient(circle, #10b981 0%, transparent 70%);
  top: -160px;
  left: -120px;
}

.orb-2 {
  width: 480px;
  height: 480px;
  background: radial-gradient(circle, #06b6d4 0%, transparent 70%);
  bottom: -160px;
  right: -120px;
}

/* Main App Layout */
.app-shell {
  position: relative;
  z-index: 1;
  height: 100%;
  width: 100%;
  max-width: 1760px;
  margin: 0 auto;
  padding: 12px 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

/* Top HUD Bar */
.hud-bar {
  width: calc(var(--stage-w) + 12px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  backdrop-filter: blur(14px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

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

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent-emerald);
  box-shadow: 0 0 12px var(--accent-emerald);
}

.brand h1 {
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--text-primary);
}

.version-tag {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(52, 211, 153, 0.14);
  color: var(--accent-emerald);
  border: 1px solid rgba(52, 211, 153, 0.25);
}

.stats-cluster {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stat-pill {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  padding: 4px 10px;
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  min-width: 64px;
  transition: transform 0.16s cubic-bezier(0.22, 1, 0.36, 1), border-color 0.2s ease, box-shadow 0.2s ease;
}

.stat-pill.bump {
  transform: scale(1.1);
  border-color: rgba(52, 211, 153, 0.55);
  box-shadow: 0 0 16px rgba(52, 211, 153, 0.25);
}

.stat-label {
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.stat-value {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.best-pill .stat-value {
  color: var(--accent-amber);
}

.combo-pill {
  min-width: 78px;
}

.combo-pill[data-active="true"] {
  border-color: rgba(251, 191, 36, 0.45);
  background: rgba(251, 191, 36, 0.09);
  box-shadow: 0 0 18px rgba(251, 191, 36, 0.16);
}

.combo-pill[data-active="true"] .stat-value {
  color: var(--accent-amber);
}

.combo-readout {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  width: 100%;
  gap: 3px;
}

.combo-bar-track {
  width: 100%;
  height: 3px;
  background: rgba(148, 163, 184, 0.18);
  border-radius: 99px;
  overflow: hidden;
}

.combo-bar-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--accent-amber), var(--accent-rose));
  border-radius: 99px;
  transition: width 60ms linear;
}

.speed-pill {
  min-width: 92px;
}

.speed-pill[data-tier="slow"] {
  border-color: rgba(56, 189, 248, 0.42);
  background: rgba(56, 189, 248, 0.08);
}

.speed-pill[data-tier="slow"] .stat-value {
  color: #38bdf8;
}

.speed-pill[data-tier="normal"] .stat-value {
  color: var(--accent-emerald);
}

.speed-pill[data-tier="fast"] {
  border-color: rgba(251, 191, 36, 0.42);
}

.speed-pill[data-tier="fast"] .stat-value {
  color: var(--accent-amber);
}

.speed-pill[data-tier="hyper"] {
  border-color: rgba(251, 113, 133, 0.5);
  background: rgba(251, 113, 133, 0.08);
}

.speed-pill[data-tier="hyper"] .stat-value {
  color: var(--accent-rose);
}

.speed-bar-fill {
  width: 35%;
  height: 100%;
  background: linear-gradient(90deg, #38bdf8, #34d399 55%, #fbbf24 80%, #fb7185);
  border-radius: 99px;
  transition: width 220ms cubic-bezier(0.22, 1, 0.36, 1);
}

.controls-cluster {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: rgba(15, 23, 42, 0.7);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
}

.icon-btn svg {
  width: 17px;
  height: 17px;
}

.icon-btn:hover {
  color: var(--text-primary);
  border-color: rgba(148, 163, 184, 0.35);
  background: rgba(30, 41, 59, 0.9);
  transform: translateY(-1px);
}

.icon-btn:active {
  transform: translateY(0);
}

/* Canvas Stage */
.stage-wrapper {
  position: relative;
  width: calc(var(--stage-w) + 12px);
  height: calc(var(--stage-h) + 12px);
  border-radius: var(--radius-lg);
  padding: 6px;
  background: linear-gradient(145deg, rgba(52, 211, 153, 0.22), rgba(34, 211, 238, 0.12) 45%, rgba(15, 23, 42, 0.6));
  box-shadow:
    0 24px 60px rgba(0, 0, 0, 0.65),
    0 0 0 1px rgba(255, 255, 255, 0.05) inset;
  transition: box-shadow 0.25s ease;
}

.stage-wrapper.pulse-glow {
  box-shadow:
    0 24px 60px rgba(0, 0, 0, 0.65),
    0 0 36px rgba(52, 211, 153, 0.32),
    0 0 0 1px rgba(52, 211, 153, 0.35) inset;
}

.stage-wrapper.danger-glow {
  box-shadow:
    0 24px 60px rgba(0, 0, 0, 0.7),
    0 0 42px rgba(251, 113, 133, 0.45),
    0 0 0 1px rgba(251, 113, 133, 0.45) inset;
}

.stage-wrapper.phase-glow {
  background: linear-gradient(145deg, rgba(192, 132, 252, 0.6), rgba(34, 211, 238, 0.4) 50%, rgba(192, 132, 252, 0.6));
  box-shadow:
    0 24px 60px rgba(0, 0, 0, 0.65),
    0 0 38px rgba(192, 132, 252, 0.38),
    0 0 0 1px rgba(216, 180, 254, 0.55) inset;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: calc(var(--radius-lg) - 5px);
  background: #080d18;
}

/* Glassmorphic Overlays */
.overlay {
  position: absolute;
  inset: 6px;
  border-radius: calc(var(--radius-lg) - 5px);
  background: rgba(7, 11, 20, 0.72);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 1;
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.98);
}

.modal-card {
  width: 100%;
  max-width: 390px;
  padding: 28px 26px;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(20, 30, 52, 0.94), rgba(12, 18, 34, 0.96));
  border: 1px solid rgba(148, 163, 184, 0.2);
  box-shadow: 0 24px 50px rgba(0, 0, 0, 0.55);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.modal-card.compact {
  max-width: 320px;
}

.modal-card.wide {
  max-width: 470px;
}

.danger-text {
  color: var(--accent-rose);
  font-weight: 600;
}

.powerup-legend {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.legend-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 8px;
  border-radius: 10px;
  background: rgba(7, 11, 20, 0.58);
  border: 1px solid var(--border-subtle);
}

.legend-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
}

.legend-item.triple {
  border-color: rgba(52, 211, 153, 0.3);
}
.legend-item.triple .legend-dot {
  background: #34d399;
  box-shadow: 0 0 10px #34d399;
}

.legend-item.slow {
  border-color: rgba(56, 189, 248, 0.3);
}
.legend-item.slow .legend-dot {
  background: #38bdf8;
  box-shadow: 0 0 10px #38bdf8;
}

.legend-item.phase {
  border-color: rgba(192, 132, 252, 0.34);
}
.legend-item.phase .legend-dot {
  background: #c084fc;
  box-shadow: 0 0 10px #c084fc;
}

.legend-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.legend-name {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-primary);
}

.legend-desc {
  font-size: 0.65rem;
  color: var(--text-muted);
  line-height: 1.3;
}

.modal-badge {
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(52, 211, 153, 0.14);
  color: var(--accent-emerald);
  border: 1px solid rgba(52, 211, 153, 0.3);
}

.modal-badge.neutral {
  background: rgba(34, 211, 238, 0.14);
  color: var(--accent-cyan);
  border-color: rgba(34, 211, 238, 0.3);
}

.modal-badge.danger {
  background: rgba(251, 113, 133, 0.15);
  color: var(--accent-rose);
  border-color: rgba(251, 113, 133, 0.35);
}

.modal-title {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.modal-desc {
  font-size: 0.9rem;
  line-height: 1.55;
  color: var(--text-secondary);
}

.accent-text {
  color: var(--accent-amber);
  font-weight: 600;
}

/* Speed Selector */
.speed-selector {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  width: 100%;
  padding: 4px;
  background: rgba(7, 11, 20, 0.65);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
}

.speed-btn {
  padding: 8px 10px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.16s ease;
}

.speed-btn:hover {
  color: var(--text-primary);
}

.speed-btn.active {
  background: rgba(52, 211, 153, 0.18);
  color: var(--accent-emerald);
  box-shadow: 0 0 0 1px rgba(52, 211, 153, 0.35) inset;
}

/* Primary & Secondary Buttons */
.primary-btn,
.secondary-btn {
  width: 100%;
  padding: 13px 18px;
  border-radius: 12px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  transition: transform 0.14s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.primary-btn {
  border: none;
  background: linear-gradient(135deg, #10b981, #06b6d4);
  color: #041218;
  box-shadow: 0 10px 26px rgba(16, 185, 129, 0.32);
}

.primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 30px rgba(16, 185, 129, 0.45);
}

.primary-btn:active {
  transform: translateY(0);
}

.primary-btn kbd {
  background: rgba(4, 18, 24, 0.2);
  color: #041218;
  border-color: rgba(4, 18, 24, 0.25);
}

.secondary-btn {
  border: 1px solid var(--border-subtle);
  background: rgba(30, 41, 59, 0.65);
  color: var(--text-primary);
}

.secondary-btn:hover {
  background: rgba(51, 65, 85, 0.8);
  transform: translateY(-1px);
}

.modal-actions {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.action-row {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.action-row .secondary-btn {
  padding: 11px 10px;
  font-size: 0.84rem;
}

/* Name Entry Form */
.name-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.name-input {
  width: 100%;
  padding: 13px 14px;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  background: rgba(7, 11, 20, 0.85);
  color: var(--text-primary);
  font-size: 1.05rem;
  font-weight: 700;
  text-align: center;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.name-input:focus {
  border-color: var(--accent-emerald);
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.18);
}

.gameover-player {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--accent-cyan);
  margin-top: -10px;
}

/* Leaderboard Modal */
.leaderboard-card {
  max-width: 500px;
}

.lb-list {
  width: 100%;
  max-height: 320px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-right: 2px;
}

.lb-row {
  display: grid;
  grid-template-columns: 40px 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 10px;
  background: rgba(7, 11, 20, 0.62);
  border: 1px solid var(--border-subtle);
  text-align: left;
}

.lb-row.highlight {
  border-color: rgba(52, 211, 153, 0.55);
  background: rgba(52, 211, 153, 0.12);
}

.lb-rank {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--text-muted);
}

.lb-rank.gold {
  color: #fbbf24;
}

.lb-rank.silver {
  color: #e2e8f0;
}

.lb-rank.bronze {
  color: #fb923c;
}

.lb-name {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-meta {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.lb-score {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.96rem;
  font-weight: 800;
  color: var(--accent-emerald);
  min-width: 54px;
  text-align: right;
}

.lb-empty {
  padding: 26px 12px;
  font-size: 0.86rem;
  color: var(--text-muted);
  text-align: center;
}

/* Keycap Badges */
kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 6px;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-primary);
  background: rgba(30, 41, 59, 0.9);
  border: 1px solid rgba(148, 163, 184, 0.28);
  border-radius: 5px;
  margin: 0 1px;
}

.key-hints {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 14px;
  font-size: 0.74rem;
  color: var(--text-muted);
  padding-top: 4px;
}

/* Game Over Summary */
.new-best-banner {
  padding: 5px 12px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(251, 191, 36, 0.2), rgba(251, 113, 133, 0.2));
  border: 1px solid rgba(251, 191, 36, 0.45);
  color: var(--accent-amber);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.1em;
}

.summary-grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.summary-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 8px;
  border-radius: 10px;
  background: rgba(7, 11, 20, 0.58);
  border: 1px solid var(--border-subtle);
}

.summary-label {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.summary-value {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text-primary);
}

/* Footer */
.footer-bar {
  width: calc(var(--stage-w) + 12px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.74rem;
  color: var(--text-muted);
  padding: 0 4px;
  min-height: 24px;
}

.active-buffs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.buff-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  border: 1px solid rgba(52, 211, 153, 0.35);
  background: rgba(52, 211, 153, 0.12);
  color: var(--accent-emerald);
}

.buff-chip.hazard {
  border-color: rgba(251, 113, 133, 0.35);
  background: rgba(251, 113, 133, 0.12);
  color: var(--accent-rose);
}

.buff-chip.rift {
  border-color: rgba(167, 139, 250, 0.42);
  background: rgba(139, 92, 246, 0.14);
  color: #c4b5fd;
}

.buff-chip.rift.urgent {
  border-color: rgba(232, 121, 249, 0.72);
  background: rgba(168, 85, 247, 0.24);
  color: #f5d0fe;
  box-shadow: 0 0 14px rgba(168, 85, 247, 0.35);
}

.buff-chip.slow {
  border-color: rgba(56, 189, 248, 0.38);
  background: rgba(56, 189, 248, 0.11);
  color: #7dd3fc;
}

.buff-chip.phase {
  border-color: rgba(192, 132, 252, 0.48);
  background: rgba(168, 85, 247, 0.15);
  color: #e9d5ff;
}

.buff-chip.phase.expiring {
  border-color: rgba(251, 191, 36, 0.65);
  background: rgba(251, 191, 36, 0.18);
  color: #fde68a;
  box-shadow: 0 0 12px rgba(251, 191, 36, 0.25);
}

.buff-chip.timer {
  border-color: rgba(148, 163, 184, 0.28);
  background: rgba(30, 41, 59, 0.65);
  color: var(--text-secondary);
}

.buff-chip.timer.urgent {
  border-color: rgba(251, 113, 133, 0.6);
  background: rgba(251, 113, 133, 0.16);
  color: #fda4af;
}

.buff-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 8px currentColor;
}

.footer-status {
  color: var(--text-secondary);
  font-weight: 600;
  white-space: nowrap;
}

.hidden {
  display: none !important;
}

@media (max-width: 620px) {
  .brand h1,
  .version-tag {
    display: none;
  }

  .stat-pill {
    min-width: 54px;
    padding: 4px 7px;
  }

  .footer-tip {
    display: none;
  }

  .powerup-legend {
    grid-template-columns: 1fr;
  }
}
