:root {
  --neon-primary: #00f5ff;
  --neon-secondary: #ff2e97;
  --neon-accent: #ffe600;
  --neon-bumper: #38bdf8;
  --bg-top: #060a18;
  --bg-bottom: #0b1026;
  --panel-bg: rgba(9, 14, 30, 0.82);
  --panel-border: rgba(255, 255, 255, 0.11);
  --text-main: #f3f7ff;
  --text-muted: #93a4c7;
  --font-sans: 'SF Pro Display', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', system-ui, -apple-system, sans-serif;
  --font-mono: 'SF Mono', 'JetBrains Mono', 'Menlo', ui-monospace, monospace;
}

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

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at 20% 0%, color-mix(in srgb, var(--neon-primary) 12%, var(--bg-top)), var(--bg-bottom));
  color: var(--text-main);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

.app-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100dvh;
  max-width: 1360px;
  margin: 0 auto;
  padding: 10px 18px 8px;
  gap: 8px;
}

/* Top HUD Bar */
.top-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.36), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.brand-icon {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  font-size: 16px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--neon-primary) 28%, transparent), color-mix(in srgb, var(--neon-secondary) 28%, transparent));
  border: 1px solid color-mix(in srgb, var(--neon-primary) 55%, transparent);
  box-shadow: 0 0 14px color-mix(in srgb, var(--neon-primary) 35%, transparent);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.brand-text h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.04em;
  background: linear-gradient(90deg, #ffffff, var(--neon-primary));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.brand-sub {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  color: var(--text-muted);
}

/* Level Switcher */
.level-switcher {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px;
  background: rgba(4, 7, 16, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
}

.level-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.16s ease;
}

.level-btn:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.06);
}

.level-btn.is-active {
  color: #ffffff;
  background: color-mix(in srgb, var(--neon-primary) 18%, rgba(12, 20, 42, 0.9));
  border-color: color-mix(in srgb, var(--neon-primary) 70%, transparent);
  box-shadow: 0 0 14px color-mix(in srgb, var(--neon-primary) 30%, transparent);
}

.key-tag {
  display: inline-grid;
  place-items: center;
  width: 17px;
  height: 17px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.1);
  color: var(--neon-primary);
}

.level-btn.is-active .key-tag {
  background: var(--neon-primary);
  color: #050a14;
}

/* Mode & Action Buttons */
.controls-cluster {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mode-switcher {
  display: flex;
  padding: 3px;
  background: rgba(4, 7, 16, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 9px;
}

.mode-btn {
  padding: 5px 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.16s ease;
}

.mode-btn:hover {
  color: #ffffff;
}

.mode-btn.is-active {
  color: #ffffff;
  background: color-mix(in srgb, var(--neon-secondary) 22%, rgba(16, 12, 34, 0.92));
  border-color: color-mix(in srgb, var(--neon-secondary) 68%, transparent);
  box-shadow: 0 0 12px color-mix(in srgb, var(--neon-secondary) 28%, transparent);
}

.action-buttons {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: color-mix(in srgb, var(--neon-primary) 50%, rgba(255, 255, 255, 0.2));
}

.icon-btn.is-muted {
  color: var(--text-muted);
  border-color: rgba(255, 255, 255, 0.07);
  background: rgba(255, 255, 255, 0.02);
}

/* Scoreboard Bar */
.scoreboard-bar {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 14px;
  padding: 7px 18px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  backdrop-filter: blur(10px);
}

.player-panel {
  display: flex;
  align-items: center;
  gap: 14px;
}

.player-left {
  justify-content: flex-start;
}

.player-right {
  justify-content: flex-end;
}

.player-meta {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.player-right .player-meta {
  align-items: flex-end;
}

.player-name {
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.player-left .player-name {
  color: var(--neon-primary);
}

.player-right .player-name {
  color: var(--neon-secondary);
}

.score-pips {
  display: flex;
  align-items: center;
  gap: 5px;
}

.score-pip {
  width: 14px;
  height: 5px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.12);
  transition: all 0.2s ease;
}

.player-left .score-pip.is-filled {
  background: var(--neon-primary);
  box-shadow: 0 0 10px var(--neon-primary);
}

.player-right .score-pip.is-filled {
  background: var(--neon-secondary);
  box-shadow: 0 0 10px var(--neon-secondary);
}

.score-value {
  font-family: var(--font-mono);
  font-size: 32px;
  font-weight: 800;
  line-height: 1;
  min-width: 34px;
  text-align: center;
}

.player-left .score-value {
  color: #ffffff;
  text-shadow: 0 0 14px var(--neon-primary);
}

.player-right .score-value {
  color: #ffffff;
  text-shadow: 0 0 14px var(--neon-secondary);
}

.center-telemetry {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.level-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.pill-tag {
  padding: 1px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 800;
  color: #060a18;
  background: var(--neon-accent);
}

.pill-title {
  color: #ffffff;
  font-weight: 700;
}

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

.metric-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.09);
  font-size: 11px;
  transition: all 0.2s ease;
}

.metric-chip.is-hot {
  border-color: color-mix(in srgb, var(--neon-accent) 75%, transparent);
  background: color-mix(in srgb, var(--neon-accent) 16%, rgba(16, 16, 28, 0.8));
  box-shadow: 0 0 12px color-mix(in srgb, var(--neon-accent) 30%, transparent);
}

.metric-label {
  color: var(--text-muted);
}

.metric-val {
  font-family: var(--font-mono);
  font-weight: 700;
  color: #ffffff;
}

/* Main Stage & Canvas */
.stage-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.arena-frame {
  position: relative;
  aspect-ratio: 960 / 580;
  height: 100%;
  max-height: 100%;
  max-width: 100%;
  width: auto;
  border-radius: 14px;
  overflow: hidden;
  border: 1.5px solid color-mix(in srgb, var(--neon-primary) 42%, rgba(255, 255, 255, 0.14));
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.04),
    0 0 34px color-mix(in srgb, var(--neon-primary) 16%, transparent),
    0 18px 46px rgba(0, 0, 0, 0.55);
  background: var(--bg-top);
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

/* Overlays & Modals */
.overlay-backdrop {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(4, 7, 18, 0.62);
  backdrop-filter: blur(6px);
  z-index: 10;
  transition: opacity 0.2s ease;
}

.overlay-backdrop.is-hidden {
  display: none;
}

.modal-card {
  width: min(510px, 92%);
  padding: 24px 28px;
  border-radius: 16px;
  background: linear-gradient(160deg, rgba(11, 17, 38, 0.94), rgba(8, 10, 24, 0.96));
  border: 1px solid color-mix(in srgb, var(--neon-primary) 48%, rgba(255, 255, 255, 0.16));
  box-shadow:
    0 0 36px color-mix(in srgb, var(--neon-primary) 22%, transparent),
    0 20px 52px rgba(0, 0, 0, 0.65);
  text-align: center;
}

.compact-card {
  width: min(390px, 90%);
}

.modal-eyebrow {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.badge-neon {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 99px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--neon-primary);
  background: color-mix(in srgb, var(--neon-primary) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--neon-primary) 55%, transparent);
}

.badge-ghost {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.modal-title {
  margin: 0 0 6px;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #ffffff;
  text-shadow: 0 0 18px color-mix(in srgb, var(--neon-primary) 45%, transparent);
}

.modal-desc {
  margin: 0 0 18px;
  font-size: 13.5px;
  color: var(--text-muted);
  line-height: 1.5;
}

.guide-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 20px;
}

.guide-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 8px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.guide-label {
  font-size: 11px;
  color: var(--text-muted);
}

.guide-val {
  font-size: 12px;
  font-weight: 700;
  color: #ffffff;
  line-height: 1.35;
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.stat-box {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 11px 8px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid rgba(255, 255, 255, 0.09);
}

.stat-label {
  font-size: 11px;
  color: var(--text-muted);
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 17px;
  font-weight: 800;
  color: #ffffff;
}

.modal-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.primary-cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 11px 26px;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--neon-primary) 80%, #ffffff);
  background: linear-gradient(135deg, var(--neon-primary), color-mix(in srgb, var(--neon-primary) 55%, var(--neon-secondary)));
  color: #050a14;
  font-family: inherit;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.04em;
  cursor: pointer;
  box-shadow: 0 0 24px color-mix(in srgb, var(--neon-primary) 45%, transparent);
  transition: transform 0.14s ease, box-shadow 0.14s ease;
}

.primary-cta:hover {
  transform: translateY(-1px);
  box-shadow: 0 0 32px color-mix(in srgb, var(--neon-primary) 65%, transparent);
}

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

.primary-cta kbd {
  padding: 2px 6px;
  border-radius: 5px;
  background: rgba(5, 10, 20, 0.24);
  border: 1px solid rgba(5, 10, 20, 0.3);
  color: #050a14;
  font-size: 11px;
}

.secondary-cta {
  padding: 11px 22px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.06);
  color: #ffffff;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.14s ease;
}

.secondary-cta:hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: color-mix(in srgb, var(--neon-secondary) 60%, rgba(255, 255, 255, 0.25));
}

/* Footer Hints */
.footer-hints {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 12px;
  font-size: 12px;
  color: var(--text-muted);
}

.hint-group {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
}

.hint-group.is-hidden {
  display: none;
}

.hint-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.hint-item strong {
  color: var(--text-main);
  font-weight: 600;
}

.hint-sep {
  opacity: 0.4;
}

kbd {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 700;
  color: #e6f2ff;
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid rgba(255, 255, 255, 0.16);
}

/* Narrow viewport adaptation */
@media (max-width: 1040px) {
  .top-bar {
    flex-wrap: wrap;
    justify-content: center;
    padding: 7px 10px;
    gap: 8px;
  }

  .brand-sub {
    display: none;
  }

  .arena-frame {
    height: auto;
    width: 100%;
    max-height: 100%;
  }
}

@media (max-width: 720px) {
  html,
  body {
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100dvh;
    padding: 8px 10px;
  }

  .guide-grid,
  .result-stats {
    grid-template-columns: 1fr;
  }
}
