/* ==========================================================
   GREEDY SNAKE PWA — Design System & Styles
   ========================================================== */

/* ── Google Fonts ────────────────────────────────────────── */
/* Loaded via HTML link tag */

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

html {
  height: 100%;
  font-size: 16px;
}

body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  font-family: 'Inter', system-ui, sans-serif;
  background: #050510;
  color: #e2e8f0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Design Tokens ───────────────────────────────────────── */
:root {
  /* Colors */
  --c-bg:           #050510;
  --c-bg2:          #090918;
  --c-card:         rgba(255, 255, 255, 0.04);
  --c-card-h:       rgba(255, 255, 255, 0.075);
  --c-green:        #39ff14;
  --c-green-dim:    #22c40c;
  --c-green-glow:   rgba(57, 255, 20, 0.22);
  --c-green-glow2:  rgba(57, 255, 20, 0.08);
  --c-red:          #ff2244;
  --c-red-glow:     rgba(255, 34, 68, 0.28);
  --c-gold:         #ffd700;
  --c-gold-glow:    rgba(255, 215, 0, 0.22);
  --c-blue:         #00c8ff;
  --c-purple:       #a855f7;
  --c-mint:         #6ee7b7;

  --c-text:         #e2e8f0;
  --c-text2:        #8892b0;
  --c-muted:        #3d4a66;
  --c-border:       rgba(255, 255, 255, 0.07);
  --c-border-green: rgba(57, 255, 20, 0.28);

  /* Typography */
  --f-head: 'Orbitron', sans-serif;
  --f-body: 'Inter', system-ui, sans-serif;

  /* Radii */
  --r-xs:  6px;
  --r-sm:  10px;
  --r-md:  18px;
  --r-lg:  28px;
  --r-xl:  40px;

  /* Transitions */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ── Light / Cream Theme ─────────────────────────────────── */
html[data-theme="light"] {
  --c-bg:           #f5ede0;
  --c-bg2:          #ede5d6;
  --c-card:         rgba(100, 65, 20, 0.07);
  --c-card-h:       rgba(100, 65, 20, 0.12);
  --c-green:        #2e7d1a;
  --c-green-dim:    #246014;
  --c-green-glow:   rgba(46, 125, 26, 0.22);
  --c-green-glow2:  rgba(46, 125, 26, 0.10);
  --c-red:          #c0392b;
  --c-red-glow:     rgba(192, 57, 43, 0.22);
  --c-gold:         #b8860b;
  --c-gold-glow:    rgba(184, 134, 11, 0.20);
  --c-blue:         #0e6d9e;
  --c-purple:       #6d28d9;
  --c-text:         #2c1d0a;
  --c-text2:        #5a4030;
  --c-muted:        #8a7060;
  --c-border:       rgba(100, 65, 20, 0.18);
  --c-border-green: rgba(46, 125, 26, 0.32);
}

html[data-theme="light"] body {
  background: var(--c-bg);
  color: var(--c-text);
}

/* Light theme — game title "SNAKE" in mint + dark-green glow */
html[data-theme="light"] .game-title span {
  color: #2e7d1a;
  text-shadow:
    0 0 8px  rgba(46, 125, 26, 0.45),
    0 0 26px rgba(46, 125, 26, 0.28),
    0 0 52px rgba(46, 125, 26, 0.12);
}

html[data-theme="light"] .logo-emoji {
  filter: drop-shadow(0 0 12px rgba(46, 125, 26, 0.45));
}

/* Light theme — mode badge in mint green + dark text */
html[data-theme="light"] .mode-badge {
  background: var(--c-mint);
  color: #0a2e14;
  box-shadow: 0 0 10px rgba(110, 231, 183, 0.35);
}

/* Light theme — play-again button in grass green + black text */
html[data-theme="light"] #btnPlayAgain {
  background: #5aab3f;
  color: #0a2e0a;
  box-shadow: 0 0 14px rgba(90, 171, 63, 0.22), 0 4px 12px rgba(0, 0, 0, 0.12);
}
html[data-theme="light"] #btnPlayAgain:hover {
  background: #4e9636;
}

/* Smooth theme transition */
body, .screen, .mode-card, .leaderboard-panel,
.player-bar, .lb-tab, .lb-sort, .settings-container {
  transition: background-color 0.3s var(--ease),
              color 0.3s var(--ease),
              border-color 0.3s var(--ease);
}

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar       { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--c-border-green); border-radius: 2px; }

/* ── Screen System ───────────────────────────────────────── */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transform: scale(0.96) translateY(6px);
  transition:
    opacity  0.3s var(--ease),
    transform 0.3s var(--ease);
  /* Each screen manages its own scroll */
}

.screen.active {
  opacity: 1;
  pointer-events: auto;
  transform: scale(1) translateY(0);
}

/* ── Common Buttons ──────────────────────────────────────── */
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 28px;
  background: var(--c-green);
  color: #030308;
  font-family: var(--f-head);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  border: none;
  border-radius: var(--r-sm);
  transition: all 0.2s var(--ease);
  box-shadow:
    0 0 16px var(--c-green-glow),
    0 4px 12px rgba(0, 0, 0, 0.35);
  user-select: none;
  white-space: nowrap;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow:
    0 0 28px var(--c-green-glow),
    0 8px 20px rgba(0, 0, 0, 0.4);
}

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

.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 22px;
  background: transparent;
  color: var(--c-text2);
  font-family: var(--f-body);
  font-size: 0.88rem;
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  transition: all 0.2s var(--ease);
  user-select: none;
  white-space: nowrap;
}

.btn-ghost:hover {
  border-color: var(--c-border-green);
  color: var(--c-green);
  background: var(--c-green-glow2);
}

.btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 22px;
  background: rgba(220, 38, 38, 0.15);
  color: #ff6b6b;
  font-family: var(--f-body);
  font-size: 0.85rem;
  font-weight: 600;
  border: 1px solid rgba(220, 38, 38, 0.45);
  border-radius: var(--r-sm);
  transition: all 0.2s var(--ease);
  user-select: none;
  white-space: nowrap;
  margin-top: 8px;
}
.btn-danger:hover {
  background: rgba(220, 38, 38, 0.30);
  border-color: #ff6b6b;
}

.ladder-auto-hint {
  text-align: center;
  color: rgba(255,255,255,0.35);
  font-size: 0.80rem;
  padding: 8px 0 4px;
}

.ladder-sel-host {
  display: flex;
  justify-content: center;
  padding: 10px 0 4px;
}

.hud-apple {
  font-size: 0.75rem;
  color: #f87171;
  font-weight: 600;
  margin-left: auto;
  padding-right: 4px;
}



.btn-ghost.btn-sm {
  padding: 6px 12px;
  font-size: 0.78rem;
}

.btn-icon-round {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: 50%;
  color: var(--c-text2);
  transition: all 0.2s var(--ease);
}

.btn-icon-round:hover {
  border-color: var(--c-border-green);
  color: var(--c-green);
  background: var(--c-green-glow2);
}

/* ============================================================
   HOME SCREEN
   ============================================================ */
#screen-home {
  background: var(--c-bg);
  overflow-y: auto;
  overflow-x: clip;   /* clip visually without creating a touch-event clipping context */
}

/* Atmospheric background */
#screen-home::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at 15% 40%,  rgba(57, 255, 20, 0.06)  0%, transparent 52%),
    radial-gradient(ellipse at 85% 15%,  rgba(0, 200, 255, 0.04)  0%, transparent 48%),
    radial-gradient(ellipse at 55% 88%,  rgba(168, 85, 247, 0.04) 0%, transparent 48%);
  pointer-events: none;
  z-index: 0;
}

#screen-home > * { position: relative; z-index: 1; }

/* Header */
.home-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: clamp(32px, 6vh, 56px) 24px 24px;
  text-align: center;
}

.logo-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 10px;
}

.logo-emoji {
  font-size: clamp(2.2rem, 6vw, 3.5rem);
  filter: drop-shadow(0 0 14px var(--c-green));
  animation: float 3s ease-in-out infinite;
  display: block;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-9px) rotate(3deg); }
}

.game-title {
  font-family: var(--f-head);
  font-size: clamp(1.8rem, 6vw, 3.5rem);
  font-weight: 900;
  line-height: 1.08;
  letter-spacing: 0.05em;
  color: var(--c-text);
}

.game-title span {
  color: var(--c-green);
  text-shadow:
    0 0 8px  var(--c-green),
    0 0 24px var(--c-green-glow),
    0 0 50px var(--c-green-glow2);
}

.tagline {
  color: var(--c-text2);
  font-size: 0.88rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  margin-top: 6px;
}

/* Player bar */
.player-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 auto 20px;
  max-width: 480px;
  width: calc(100% - 40px);
  padding: 12px 16px;
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  backdrop-filter: blur(12px);
}

.player-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.stat-label {
  font-size: 0.66rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--c-muted);
}

.stat-value {
  font-family: var(--f-head);
  font-size: 0.95rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-value.green { color: var(--c-green); }
.stat-value.gold  { color: var(--c-gold); }

/* Mode cards */
.modes-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 480px;
  width: calc(100% - 40px);
  margin: 0 auto;
}

.mode-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 18px;
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  position: relative;
  overflow: hidden;
  transition: all 0.25s var(--ease);
  user-select: none;
}

/* Animated shine overlay */
.mode-shine {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    125deg,
    transparent 0%,
    rgba(57, 255, 20, 0.08) 50%,
    transparent 100%
  );
  transform: translateX(-100%);
  transition: transform 0.6s var(--ease);
}

.mode-active {
  border-color: var(--c-border-green);
  cursor: pointer;
}

.mode-active:hover,
.mode-active:focus-visible {
  transform: translateY(-3px);
  border-color: var(--c-green);
  box-shadow:
    0 0 0 1px var(--c-border-green),
    0 8px 28px var(--c-green-glow),
    0 2px 8px rgba(0,0,0,0.4);
  outline: none;
}

.mode-active:hover .mode-shine {
  transform: translateX(100%);
}

.mode-active:active { transform: translateY(0) scale(0.98); }

.mode-soon {
  opacity: 0.38;
  cursor: default;
}

.mode-icon-wrap {
  font-size: 1.7rem;
  width: 50px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.05);
  border-radius: var(--r-sm);
  flex-shrink: 0;
  position: relative;
  z-index: 1;
}

.mode-text {
  flex: 1;
  min-width: 0;
  position: relative;
  z-index: 1;
}

.mode-text h2 {
  font-family: var(--f-head);
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--c-text);
  margin-bottom: 3px;
  letter-spacing: 0.03em;
}

.mode-text p {
  font-size: 0.78rem;
  color: var(--c-text2);
  line-height: 1.4;
}

.mode-badge {
  padding: 5px 13px;
  border-radius: 20px;
  font-family: var(--f-head);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  background: var(--c-green);
  color: #030308;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
  box-shadow: 0 0 10px var(--c-green-glow);
}

.badge-soon {
  background: transparent;
  border: 1px solid var(--c-muted);
  color: var(--c-muted);
  box-shadow: none;
}

/* ── Grid Size Selector ──────────────────────────────────── */
.grid-selector {
  max-width: 480px;
  width: calc(100% - 40px);
  margin: 0 auto 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.grid-sel-label {
  font-size: 0.74rem;
  color: var(--c-text2);
  letter-spacing: 0.06em;
}

.grid-sel-btns {
  display: flex;
  gap: 8px;
  width: 100%;
}

.grid-sel-btn {
  flex: 1;
  padding: 9px 6px;
  border-radius: var(--r-sm);
  border: 1px solid var(--c-border);
  background: var(--c-card);
  color: var(--c-text2);
  font-size: 0.78rem;
  font-family: var(--f-head);
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: all 0.15s;
}

.grid-sel-btn:hover {
  border-color: var(--c-border-green);
  color: var(--c-text);
}

.grid-sel-btn.grid-active,
.grid-sel-btn[aria-pressed="true"] {
  background: var(--c-green-glow2);
  border-color: var(--c-border-green);
  color: var(--c-green);
  box-shadow: 0 0 8px var(--c-green-glow);
}

/* ── Leaderboard tabs ────────────────────────────────────── */
.lb-tabs, .lb-sort-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
  touch-action: manipulation;   /* tell iOS this row is for tapping, not scrolling */
}

.lb-tab {
  flex: 1;
  padding: 7px 6px;
  border-radius: var(--r-sm);
  border: 1px solid var(--c-border);
  background: var(--c-card);
  color: var(--c-text2);
  font-size: 0.78rem;
  font-family: var(--f-head);
  cursor: pointer;
  transition: all 0.15s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.lb-tab.active {
  border-color: var(--c-border-green);
  background: var(--c-green-glow2);
  color: var(--c-green);
}

.lb-sort {
  flex: 1;
  min-height: 36px;
  padding: 5px 4px;
  border-radius: var(--r-sm);
  border: 1px solid var(--c-border);
  background: transparent;
  color: var(--c-muted);
  font-size: 0.72rem;
  font-family: var(--f-head);
  cursor: pointer;
  transition: all 0.12s;
  touch-action: manipulation;   /* prevent 300ms delay and scroll-eat on mobile */
  -webkit-tap-highlight-color: transparent;
}

.lb-sort.active {
  border-color: var(--c-blue);
  color: var(--c-blue);
  background: rgba(0, 200, 255, 0.08);
}

/* ── Leaderboard loading ─────────────────────────────────── */
.leaderboard-panel {
  max-width: 480px;
  width: calc(100% - 40px);
  margin: 18px auto 0;
  padding: 18px;
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.panel-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--c-text2);
  letter-spacing: 0.05em;
}

.panel-mode-tag {
  font-size: 0.7rem;
  padding: 3px 10px;
  background: var(--c-green-glow2);
  border: 1px solid var(--c-border-green);
  border-radius: 12px;
  color: var(--c-green);
}

.leaderboard-offline {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 20px 16px;
  border: 1px dashed var(--c-border);
  border-radius: var(--r-sm);
  text-align: center;
}

.offline-icon { font-size: 1.5rem; }

.leaderboard-offline p {
  font-size: 0.82rem;
  color: var(--c-text2);
}

.offline-hint {
  font-size: 0.72rem;
  color: var(--c-muted);
  padding: 3px 10px;
  background: var(--c-card);
  border-radius: 10px;
}

/* Footer */
.home-footer {
  text-align: center;
  padding: 20px 24px 32px;
  color: var(--c-muted);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
}

/* ============================================================
   NICKNAME SCREEN
   ============================================================ */
#screen-nickname {
  background: var(--c-bg);
  align-items: center;
  justify-content: center;
  padding: 24px;
}

#screen-nickname::before {
  content: '';
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at 50% 40%, rgba(57, 255, 20, 0.05) 0%, transparent 65%);
  pointer-events: none;
}

.center-wrapper {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nickname-card {
  width: 100%;
  max-width: 400px;
  padding: clamp(28px, 5vw, 44px) clamp(24px, 4vw, 36px);
  background: var(--c-bg2);
  border: 1px solid var(--c-border-green);
  border-radius: var(--r-lg);
  text-align: center;
  box-shadow:
    0 0 40px rgba(57, 255, 20, 0.08),
    0 24px 60px rgba(0, 0, 0, 0.5);
  position: relative;
  z-index: 1;
  animation: cardIn 0.35s var(--ease-spring);
}

@keyframes cardIn {
  from { transform: scale(0.92) translateY(20px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}

.nickname-emoji {
  display: block;
  font-size: 3rem;
  margin-bottom: 14px;
  filter: drop-shadow(0 0 12px var(--c-green));
}

.nickname-card h2 {
  font-family: var(--f-head);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--c-text);
  margin-bottom: 8px;
}

.nickname-card p {
  font-size: 0.84rem;
  color: var(--c-text2);
  line-height: 1.55;
  margin-bottom: 24px;
}

.input-wrap {
  position: relative;
  margin-bottom: 18px;
}

.input-wrap input {
  width: 100%;
  padding: 13px 48px 13px 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  color: var(--c-text);
  font-family: var(--f-body);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  caret-color: var(--c-green);
}

.input-wrap input:focus {
  border-color: var(--c-border-green);
  box-shadow: 0 0 0 3px var(--c-green-glow2);
}

.input-wrap input::placeholder { color: var(--c-muted); }

.char-count {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.72rem;
  color: var(--c-muted);
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

.nick-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.nick-actions .btn-primary,
.nick-actions .btn-ghost { width: 100%; }

/* Shake animation for invalid input */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  15%       { transform: translateX(-10px); }
  30%       { transform: translateX(8px); }
  45%       { transform: translateX(-6px); }
  60%       { transform: translateX(5px); }
  75%       { transform: translateX(-3px); }
  90%       { transform: translateX(2px); }
}

.shake { animation: shake 0.45s var(--ease); }

/* ============================================================
   GAME SCREEN
   ============================================================ */
.screen-game {
  background: #02020c;
  overflow: hidden;
}

/* Light theme — game screen and HUD use cream background */
html[data-theme="light"] .screen-game {
  background: var(--c-bg);
}
html[data-theme="light"] .game-hud {
  background: rgba(240, 232, 218, 0.95);
}

/* HUD bar */
.game-hud {
  display: flex;
  align-items: center;
  padding: 0 14px;
  height: 54px;
  flex-shrink: 0;
  background: rgba(2, 2, 12, 0.92);
  border-bottom: 1px solid var(--c-border);
  backdrop-filter: blur(14px);
  gap: 8px;
}

.hud-left {
  display: flex;
  align-items: center;
  gap: 18px;
  flex: 1;
}

.hud-stat {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.hud-label {
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--c-muted);
}

.hud-val {
  font-family: var(--f-head);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--c-green);
  font-variant-numeric: tabular-nums;
}

@keyframes scorePop {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.45); color: #ffffff; }
  65%  { transform: scale(1.1); }
  100% { transform: scale(1); }
}

.score-pop { animation: scorePop 0.35s var(--ease-spring); }

.hud-center { display: flex; justify-content: center; }

.hud-mode {
  font-size: 0.78rem;
  color: var(--c-text2);
  letter-spacing: 0.04em;
}

.hud-right { display: flex; justify-content: flex-end; }

/* Canvas area */
.canvas-area {
  flex: 1;
  min-height: 0; /* critical for flexbox */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  position: relative;
}

#gameCanvas {
  display: block;
  border-radius: 14px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  touch-action: none;
  max-width: 100%;
  max-height: 100%;
}

html[data-theme="light"] #gameCanvas {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}

/* Canvas overlays (pause, countdown) */
.canvas-overlay {
  position: absolute;
  inset: 6px;
  border-radius: 14px;
  background: rgba(2, 2, 12, 0.82);
  backdrop-filter: blur(14px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  animation: fadeIn 0.25s var(--ease);
}

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

.overlay-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
}

.overlay-icon {
  font-size: 3rem;
  filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.3));
}

.overlay-card h2 {
  font-family: var(--f-head);
  font-size: 1.6rem;
  color: var(--c-text);
}

.overlay-card .btn-primary,
.overlay-card .btn-ghost { min-width: 160px; }

.countdown-number {
  font-family: var(--f-head);
  font-size: clamp(5rem, 20vw, 10rem);
  font-weight: 900;
  color: var(--c-green);
  text-shadow:
    0 0 20px var(--c-green),
    0 0 60px var(--c-green-glow);
  animation: countPulse 0.8s var(--ease-spring);
}

@keyframes countPulse {
  from { transform: scale(1.5); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

/* ── Virtual Joystick ────────────────────────────────────── */

/* Full-screen transparent overlay — only the joystick itself is interactive */
.mobile-ctrl {
  position: absolute;
  inset: 0;
  pointer-events: none;
  height: auto;
}

/* Corner container */
.joystick-container {
  position: absolute;
  bottom: max(18px, env(safe-area-inset-bottom, 18px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: auto;
  user-select: none;
  -webkit-user-select: none;
}

.joystick-container.joy-right { right: 20px; }
.joystick-container.joy-left  { left:  20px; }

/* Settings panel — floats above the cog button */
.joy-settings-panel {
  position: absolute;
  bottom: calc(100% + 10px);
  background: rgba(5, 5, 16, 0.94);
  border: 1px solid rgba(57, 255, 20, 0.22);
  border-radius: 12px;
  padding: 12px 14px;
  text-align: center;
  width: 150px;
  z-index: 60;
  box-shadow: 0 4px 20px rgba(0,0,0,0.50);
  animation: panelFadeIn 0.15s ease;
}

.joystick-container.joy-right .joy-settings-panel { right: 0; }
.joystick-container.joy-left  .joy-settings-panel { left:  0; }

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

.joy-set-label {
  font-size: 0.73rem;
  color: rgba(255,255,255,0.45);
  margin-bottom: 9px;
  letter-spacing: 0.06em;
}

.joy-side-btns {
  display: flex;
  gap: 7px;
  justify-content: center;
}

.joy-side-btn {
  font-size: 0.73rem;
  padding: 5px 9px;
  border-radius: 7px;
  border: 1px solid rgba(57,255,20,0.22);
  background: rgba(57,255,20,0.05);
  color: rgba(255,255,255,0.45);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.joy-side-btn.joy-active {
  background: rgba(57,255,20,0.20);
  border-color: rgba(57,255,20,0.65);
  color: #39ff14;
}

/* Settings cog */
.joy-cfg-btn {
  font-size: 14px;
  color: rgba(255,255,255,0.25);
  background: none;
  border: none;
  padding: 2px 6px;
  cursor: pointer;
  transition: color 0.2s;
  line-height: 1;
}
.joy-cfg-btn:hover { color: rgba(255,255,255,0.60); }

/* Joystick base ring */
.joystick-base {
  width: 128px;
  height: 128px;
  border-radius: 50%;
  background: rgba(255,255,255,0.04);
  border: 2px solid rgba(57, 255, 20, 0.20);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  touch-action: none;
  box-shadow: 0 0 20px rgba(0,0,0,0.30);
}

/* Inner target ring (visual guide) */
.joystick-base::after {
  content: '';
  position: absolute;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 1px solid rgba(57,255,20,0.12);
  pointer-events: none;
}

/* Draggable knob */
.joystick-knob {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 36%,
    rgba(57,255,20,0.80) 0%,
    rgba(18,140,6,0.90)  100%
  );
  border: 2px solid rgba(57,255,20,0.75);
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  box-shadow:
    0 0 14px rgba(57,255,20,0.25),
    inset 0 1px 0 rgba(255,255,255,0.18);
  transition: transform 0.10s cubic-bezier(0.34,1.56,0.64,1); /* spring snap-back */
}

.joystick-knob.dragging {
  transition: none;  /* no transition while actively dragging */
}



/* ============================================================
   GAME OVER SCREEN
   ============================================================ */
#screen-gameover {
  background: var(--c-bg);
  align-items: center;
  justify-content: center;
  padding: 24px;
}

#screen-gameover::before {
  content: '';
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at 50% 45%, rgba(255, 34, 68, 0.06) 0%, transparent 60%);
  pointer-events: none;
}

#screen-gameover .center-wrapper { width: 100%; }

.gameover-card {
  width: 100%;
  max-width: 400px;
  padding: clamp(28px, 5vw, 44px) clamp(24px, 4vw, 36px);
  background: var(--c-bg2);
  border: 1px solid rgba(255, 34, 68, 0.28);
  border-radius: var(--r-lg);
  text-align: center;
  box-shadow:
    0 0 40px rgba(255, 34, 68, 0.08),
    0 24px 60px rgba(0, 0, 0, 0.5);
  position: relative;
  z-index: 1;
  animation: cardIn 0.4s var(--ease-spring);
}

.go-title {
  font-family: var(--f-head);
  font-size: clamp(1.8rem, 6vw, 2.6rem);
  font-weight: 900;
  letter-spacing: 0.1em;
  color: var(--c-red);
  text-shadow:
    0 0 8px  var(--c-red),
    0 0 24px var(--c-red-glow);
  margin-bottom: 6px;
  animation: glitchText 4s infinite;
}

@keyframes glitchText {
  0%, 88%, 100% {
    text-shadow: 0 0 8px var(--c-red), 0 0 24px var(--c-red-glow);
    transform: none;
  }
  90% {
    text-shadow: -3px 0 #0ff, 3px 0 var(--c-red);
    transform: skewX(-1deg);
  }
  92% {
    text-shadow: 3px 0 #f0f, -3px 0 var(--c-red);
    transform: skewX(1deg);
  }
  94% {
    text-shadow: 0 0 8px var(--c-red), 0 0 24px var(--c-red-glow);
    transform: none;
  }
}

.go-player {
  font-size: 0.95rem;
  color: var(--c-text2);
  margin-bottom: 24px;
}

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

.result-cell {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 14px 6px;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
}

.result-label {
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--c-muted);
}

.result-val {
  font-family: var(--f-head);
  font-size: 1.15rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.result-val.white { color: var(--c-text); }
.result-val.gold  { color: var(--c-gold); }
.result-val.big   { font-size: 1.5rem; text-shadow: 0 0 10px var(--c-gold-glow); }

.new-record {
  padding: 10px 18px;
  background: linear-gradient(135deg, rgba(255, 215, 0, 0.12), rgba(255, 215, 0, 0.04));
  border: 1px solid rgba(255, 215, 0, 0.3);
  border-radius: var(--r-sm);
  color: var(--c-gold);
  font-family: var(--f-head);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  margin-bottom: 18px;
  animation: pulseGold 1.6s ease-in-out infinite;
}

@keyframes pulseGold {
  0%, 100% { box-shadow: 0 0 8px  rgba(255, 215, 0, 0.2); }
  50%       { box-shadow: 0 0 20px rgba(255, 215, 0, 0.4); }
}

.go-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.go-actions .btn-primary,
.go-actions .btn-ghost { width: 100%; }

/* ============================================================
   RESPONSIVE ADJUSTMENTS
   ============================================================ */

/* Wide screens: horizontal mode cards */
@media (min-width: 640px) {
  .mode-card { padding: 20px 22px; }
  .mode-text h2 { font-size: 1rem; }
  .mode-text p  { font-size: 0.82rem; }
}

/* Small height (landscape mobile) */
@media (max-height: 640px) and (pointer: coarse) {
  .game-hud { height: 44px; }
  .joystick-base { width: 108px; height: 108px; }
  .joystick-knob { width: 48px;  height: 48px;  }
}


/* Very small screens */
@media (max-width: 360px) {
  .result-row { gap: 6px; }
  .result-cell { padding: 10px 4px; }
  .result-val { font-size: 1rem; }
  .result-val.big { font-size: 1.25rem; }
}

/* ============================================================
   LEVEL MODE — HUD extensions
   ============================================================ */
.hud-level-info {
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.level-badge {
  font-family: var(--f-head);
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--c-green);
  letter-spacing: 0.08em;
  text-shadow: 0 0 6px var(--c-green-glow);
}

.apple-prog {
  font-size: 0.72rem;
  color: var(--c-text2);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}

/* ============================================================
   LEVEL COMPLETE OVERLAY
   ============================================================ */
.lc-card {
  gap: 12px;
  padding: 8px;
}

.lc-badge {
  font-family: var(--f-head);
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--c-green);
  background: var(--c-green-glow2);
  border: 1px solid var(--c-border-green);
  padding: 5px 20px;
  border-radius: 20px;
  animation: badgeSlideIn 0.4s var(--ease-spring);
}

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

.lc-title {
  font-family: var(--f-head);
  font-size: clamp(2rem, 10vw, 3.8rem);
  font-weight: 900;
  letter-spacing: 0.08em;
  color: var(--c-green);
  text-shadow:
    0 0 10px var(--c-green),
    0 0 30px var(--c-green-glow),
    0 0 60px var(--c-green-glow2);
  animation: lcTitlePop 0.45s var(--ease-spring) 0.1s both;
}

@keyframes lcTitlePop {
  from { transform: scale(0.4) rotate(-4deg); opacity: 0; }
  to   { transform: scale(1)   rotate(0deg);  opacity: 1; }
}

.lc-stats {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  animation: fadeUp 0.4s var(--ease) 0.3s both;
}

@keyframes fadeUp {
  from { transform: translateY(14px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.lc-bonus {
  font-family: var(--f-head);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--c-gold);
  text-shadow: 0 0 8px var(--c-gold-glow);
}

.lc-score {
  font-size: 0.82rem;
  color: var(--c-text2);
}

.lc-score span {
  font-family: var(--f-head);
  font-weight: 700;
  color: var(--c-text);
  margin-left: 4px;
}

.lc-next {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--c-muted);
  letter-spacing: 0.06em;
  animation: fadeUp 0.4s var(--ease) 0.55s both;
}

.lc-dots {
  display: flex;
  gap: 4px;
}

.lc-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--c-muted);
  animation: dotPulse 1.1s ease-in-out infinite;
}

.lc-dots span:nth-child(2) { animation-delay: 0.18s; }
.lc-dots span:nth-child(3) { animation-delay: 0.36s; }

@keyframes dotPulse {
  0%, 100% { opacity: 0.25; transform: scale(0.8); }
  50%       { opacity: 1;    transform: scale(1.2); }
}

/* ============================================================
   LEADERBOARD LIST (home screen — when backend online)
   ============================================================ */
.lb-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 18px 0;
  color: var(--c-text2);
  font-size: 0.82rem;
}

.lb-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--c-border-green);
  border-top-color: var(--c-green);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.lb-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0;
  margin: 0;
}

.lb-entry {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r-xs);
  background: rgba(255, 255, 255, 0.025);
  transition: background 0.15s;
}

.lb-entry.lb-me {
  background: var(--c-green-glow2);
  border: 1px solid var(--c-border-green);
}

.lb-rank {
  font-family: var(--f-head);
  font-size: 0.88rem;
  min-width: 28px;
  text-align: center;
}

.rank-1 { color: var(--c-gold); text-shadow: 0 0 6px var(--c-gold-glow); }
.rank-2 { color: #c0c0c0; }
.rank-3 { color: #cd7f32; }
.rank-other { color: var(--c-muted); font-size: 0.75rem; }

.lb-nick {
  flex: 1;
  font-size: 0.84rem;
  color: var(--c-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lb-entry.lb-me .lb-nick {
  color: var(--c-green);
  font-weight: 600;
}

.lb-score {
  font-family: var(--f-head);
  font-size: 0.82rem;
  color: var(--c-text2);
  font-variant-numeric: tabular-nums;
}

/* ============================================================
   SUBMIT SCORE BUTTON (game over screen)
   ============================================================ */
.submit-row {
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
}

.btn-submit-score {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 24px;
  background: linear-gradient(135deg, rgba(0, 200, 255, 0.12), rgba(0, 200, 255, 0.04));
  border: 1px solid rgba(0, 200, 255, 0.35);
  border-radius: var(--r-sm);
  color: var(--c-blue);
  font-family: var(--f-head);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: all 0.2s var(--ease);
  user-select: none;
}

.btn-submit-score:hover:not(:disabled) {
  background: linear-gradient(135deg, rgba(0, 200, 255, 0.2), rgba(0, 200, 255, 0.08));
  box-shadow: 0 0 16px rgba(0, 200, 255, 0.22);
  transform: translateY(-2px);
}

.btn-submit-score:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.submit-hint {
  font-size: 0.78rem;
  color: var(--c-gold);
  text-align: center;
  min-height: 18px;
}

/* ==========================================================
   PHASE 4 — LADDER RACE STYLES
   ========================================================== */
.hidden { display: none !important; }

/* ── Ladder Lobby ────────────────────────────────────────── */
.ladder-lobby-wrap {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 100%; padding: 1rem;
}
.ladder-lobby-card {
  background: rgba(15,20,35,0.95);
  border: 1px solid rgba(0,255,136,0.2);
  border-radius: 20px;
  padding: 2rem 1.75rem;
  width: 100%; max-width: 400px;
  display: flex; flex-direction: column; gap: 1.25rem;
  box-shadow: 0 0 40px rgba(0,255,136,0.08);
}
.ladder-logo {
  font-family: 'Orbitron', sans-serif;
  font-size: 1.5rem; font-weight: 700;
  color: var(--c-green); text-align: center;
  letter-spacing: .08em;
  text-shadow: 0 0 20px rgba(0,255,136,.4);
}
.ladder-nickname-row { display: flex; flex-direction: column; gap: .4rem; }
.ladder-nickname-row label { font-size: .8rem; color: rgba(255,255,255,.6); font-weight: 500; }
.ladder-nickname-row input, .lb-join-row input {
  width: 100%; padding: .65rem 1rem;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 10px; color: #fff; font-size: .95rem;
  outline: none; transition: border-color .2s;
}
.ladder-nickname-row input:focus, .lb-join-row input:focus {
  border-color: var(--c-green);
  box-shadow: 0 0 0 2px rgba(0,255,136,.15);
}
.lb-actions { display: flex; gap: .75rem; }
.lb-actions .btn-primary { flex: 1; }
.lb-join-row { display: flex; gap: .5rem; align-items: center; }
.lb-join-row input { flex: 1; font-size: 1rem; text-align: center; font-family: 'Orbitron', monospace; font-weight: 700; }
.ladder-err { color: #ff6b6b; font-size: .82rem; text-align: center; }
.room-code-display { text-align: center; font-size: .95rem; color: rgba(255,255,255,.7); }
.room-code-val {
  font-family: 'Orbitron', monospace; font-size: 1.8rem; font-weight: 700;
  color: var(--c-green); letter-spacing: .2em;
  text-shadow: 0 0 15px rgba(0,255,136,.5); margin-left: .5rem;
}
.lobby-player-list { display: flex; flex-direction: column; gap: .5rem; min-height: 60px; }
.lobby-player {
  display: flex; align-items: center; gap: .75rem;
  padding: .6rem 1rem; background: rgba(255,255,255,.05);
  border-radius: 10px; font-size: .9rem;
}
.lp-name { flex: 1; font-weight: 500; }
.lp-host { font-size: .7rem; padding: .2rem .5rem; background: rgba(247,220,111,.2); color: var(--c-gold); border-radius: 6px; font-weight: 600; }
.lobby-hint { text-align: center; font-size: .8rem; color: rgba(255,255,255,.45); }
.btn-back { margin-top: .25rem; width: 100%; }

/* ── Ladder Game ─────────────────────────────────────────── */
.ladder-game-wrap {
  display: flex; flex-direction: column; align-items: center;
  height: 100%; width: 100%; overflow: hidden; padding-top: .5rem;
}
.ladder-hud {
  display: flex; align-items: center; gap: 1rem;
  width: 100%; max-width: 420px;
  padding: .4rem .75rem;
  background: rgba(0,0,0,.5); border-radius: 10px;
  margin-bottom: .4rem; flex-shrink: 0;
}
.hud-timer {
  font-family: 'Orbitron', monospace;
  font-size: 1.2rem; font-weight: 700; color: var(--c-gold); min-width: 54px; text-align: center;
}
.hud-scores { display: flex; gap: .5rem; flex-wrap: wrap; flex: 1; }
.hud-player {
  display: flex; align-items: center; gap: .3rem;
  padding: .2rem .5rem; background: rgba(255,255,255,.06);
  border-radius: 6px; font-size: .78rem;
}
.hud-name { font-weight: 500; max-width: 60px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hud-apple { font-size: .72rem; color: rgba(255,255,255,.7); }
.canvas-wrap { display: flex; justify-content: center; align-items: flex-start; flex: 1; overflow: hidden; }
#ladderCanvas { display: block; border-radius: 8px; box-shadow: 0 0 30px rgba(0,255,136,.1); }

/* ── Mobile D-Pad ────────────────────────────────────────── */
.mobile-dpad {
  display: flex; flex-direction: column; align-items: center;
  gap: 2px; padding: .5rem 0 .75rem; flex-shrink: 0;
}
@media (min-width: 600px) { .mobile-dpad { display: none; } }
.dpad-row { display: flex; justify-content: center; gap: 2px; }
.dpad-center { width: 52px; height: 52px; }
.dpad-btn {
  width: 52px; height: 52px;
  background: rgba(0,255,136,.12);
  border: 1px solid rgba(0,255,136,.3);
  border-radius: 10px; color: rgba(255,255,255,.8);
  font-size: 1.1rem; cursor: pointer; touch-action: manipulation;
  transition: background .1s, transform .08s;
  display: flex; align-items: center; justify-content: center;
}
.dpad-btn:active { background: rgba(0,255,136,.35); transform: scale(.92); }

/* ── Results ─────────────────────────────────────────────── */
.results-card {
  background: rgba(15,20,35,.97);
  border: 1px solid rgba(247,220,111,.25);
  border-radius: 20px; padding: 2rem 1.75rem;
  width: 100%; max-width: 400px;
  display: flex; flex-direction: column; gap: 1.25rem;
  box-shadow: 0 0 40px rgba(247,220,111,.08);
}
.results-title {
  font-family: 'Orbitron', sans-serif;
  font-size: 1.4rem; font-weight: 700;
  color: var(--c-gold); text-align: center;
  text-shadow: 0 0 20px rgba(247,220,111,.4);
}
.results-list { display: flex; flex-direction: column; gap: .6rem; }
.result-row {
  display: flex; align-items: center; gap: .75rem;
  padding: .65rem 1rem; background: rgba(255,255,255,.05);
  border-radius: 10px; font-size: .9rem;
}
.result-me { background: rgba(0,255,136,.08); }
.res-medal { font-size: 1.3rem; min-width: 28px; text-align: center; }
.res-name  { flex: 1; font-weight: 500; }
.res-score { color: rgba(255,255,255,.7); font-size: .85rem; }
.res-fin   { font-size: .75rem; padding: .15rem .4rem; background: rgba(0,255,136,.15); color: var(--c-green); border-radius: 5px; }
.results-actions { display: flex; gap: .75rem; }
.results-actions button { flex: 1; }

/* ── Error Toast ─────────────────────────────────────────── */
.err-toast {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%);
  background: rgba(255,80,80,.9); color: #fff;
  padding: .6rem 1.4rem; border-radius: 10px;
  font-size: .88rem; font-weight: 500;
  z-index: 9999; pointer-events: none;
  box-shadow: 0 4px 20px rgba(255,80,80,.4);
}

/* ==========================================================
   SETTINGS SCREEN
   ========================================================== */
#screen-settings {
  background: var(--c-bg);
  align-items: flex-start;
  overflow-y: auto;
}

.settings-container {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 1.2rem 1.4rem 3rem;
}

/* Header */
.settings-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 2rem;
  padding-top: env(safe-area-inset-top, 0.5rem);
}

.settings-back {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border-radius: var(--r-sm);
  border: 1px solid var(--c-border);
  background: var(--c-card);
  color: var(--c-text2);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
}
.settings-back:hover {
  background: var(--c-card-h);
  color: var(--c-text);
}

.settings-title {
  font-family: var(--f-head);
  font-size: 1.1rem;
  color: var(--c-text);
}

/* Sections */
.settings-section {
  margin-bottom: 2rem;
  padding: 1.2rem 1.4rem;
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
}

.settings-section-title {
  font-family: var(--f-head);
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  color: var(--c-text2);
  text-transform: uppercase;
  margin-bottom: 0.5rem;
}

.settings-hint {
  font-size: 0.78rem;
  color: var(--c-muted);
  margin-bottom: 0.9rem;
}

.settings-grid-btns {
  display: flex;
  gap: 8px;
}

/* ── Theme Options ───────────────────────────────── */
.theme-options {
  display: flex;
  gap: 12px;
  margin-top: 0.8rem;
}

.theme-option {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  padding: 0.9rem 0.6rem 0.7rem;
  border-radius: var(--r-md);
  border: 2px solid var(--c-border);
  background: var(--c-card);
  color: var(--c-text2);
  cursor: pointer;
  transition: all 0.2s var(--ease);
  position: relative;
}
.theme-option:hover {
  border-color: var(--c-border-green);
  background: var(--c-card-h);
}
.theme-option[aria-checked="true"] {
  border-color: var(--c-green);
  background: var(--c-green-glow2);
  color: var(--c-text);
}

.theme-check {
  position: absolute;
  top: 7px;
  right: 10px;
  font-size: 0.85rem;
  color: var(--c-green);
  opacity: 0;
  transition: opacity 0.2s;
}
.theme-option[aria-checked="true"] .theme-check {
  opacity: 1;
}

.theme-label {
  font-size: 0.82rem;
  font-weight: 500;
}

/* ── Swatch Mini-Preview ─────────────────────────── */
.theme-swatch {
  width: 80px;
  height: 52px;
  border-radius: var(--r-sm);
  border: 1px solid rgba(128,128,128,0.2);
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.theme-swatch--dark {
  background: #050510;
}
.theme-swatch--light {
  background: #f5ede0;
}

.theme-swatch .swatch-snake {
  position: absolute;
  left: 14px; top: 18px;
  width: 36px; height: 10px;
  border-radius: 5px;
}
.theme-swatch--dark .swatch-snake { background: #39ff14; }
.theme-swatch--light .swatch-snake { background: #2e7d1a; }

.theme-swatch .swatch-apple {
  position: absolute;
  right: 14px; bottom: 10px;
  width: 10px; height: 10px;
  border-radius: 50%;
}
.theme-swatch--dark .swatch-apple { background: #ff2244; }
.theme-swatch--light .swatch-apple { background: #c0392b; }

/* ============================================================
   RULES SCREEN
   ============================================================ */
#screen-rules {
  background: var(--c-bg);
  overflow-y: auto;
  overflow-x: clip;
}

.rules-container {
  max-width: 540px;
  width: 100%;
  margin: 0 auto;
  padding: 0 20px 40px;
}

.rules-body {
  display: flex;
  flex-direction: column;
  gap: 24px;
  margin-top: 8px;
}

.rules-section {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: 18px 20px;
}

.rules-section-title {
  font-family: var(--f-head);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--c-green);
  letter-spacing: 0.04em;
  margin-bottom: 12px;
}

/* Mode tab switcher inside rules section */
.rules-mode-section { padding-bottom: 4px; }

.rules-mode-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.rules-mode-tab {
  padding: 7px 18px;
  border-radius: 20px;
  border: 1px solid var(--c-border);
  background: transparent;
  color: var(--c-text2);
  font-family: var(--f-head);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s, color 0.18s, border-color 0.18s;
  letter-spacing: 0.03em;
}

.rules-mode-tab:hover {
  background: rgba(57, 255, 20, 0.07);
  border-color: rgba(57, 255, 20, 0.35);
  color: var(--c-text);
}

.rules-mode-tab.active {
  background: rgba(57, 255, 20, 0.14);
  border-color: rgba(57, 255, 20, 0.55);
  color: var(--c-green);
}

.rules-mode-panel {
  animation: fadePanel 0.2s ease;
}

@keyframes fadePanel {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

html[data-theme="light"] .rules-mode-tab:hover {
  background: rgba(46, 125, 26, 0.08);
  border-color: rgba(46, 125, 26, 0.35);
}

html[data-theme="light"] .rules-mode-tab.active {
  background: rgba(46, 125, 26, 0.14);
  border-color: rgba(46, 125, 26, 0.5);
  color: var(--c-green);
}

.rules-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rules-list li {
  font-size: 0.85rem;
  color: var(--c-text2);
  line-height: 1.55;
  padding-left: 14px;
  position: relative;
}

.rules-list li::before {
  content: '▸';
  position: absolute;
  left: 0;
  color: var(--c-green);
  opacity: 0.6;
}

.rules-list strong { color: var(--c-text); }

.rules-desc {
  font-size: 0.83rem;
  color: var(--c-text2);
  line-height: 1.55;
  margin-bottom: 14px;
}

/* Combo chain diagram */
.combo-chain {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.combo-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 7px 10px;
  border-radius: var(--r-sm);
  border: 1px solid var(--c-border);
  min-width: 46px;
}

.cs-pts {
  font-family: var(--f-head);
  font-size: 0.95rem;
  font-weight: 800;
  line-height: 1;
}

.cs-label {
  font-size: 0.60rem;
  letter-spacing: 0.06em;
  color: var(--c-muted);
}

.cs-base  { background: rgba(255,255,255,0.03); }
.cs-c1    { background: rgba(57,255,20,0.06);  border-color: rgba(57,255,20,0.25); }
.cs-c2    { background: rgba(57,255,20,0.10);  border-color: rgba(57,255,20,0.35); }
.cs-c3    { background: rgba(57,255,20,0.16);  border-color: rgba(57,255,20,0.45); }
.cs-c4    { background: rgba(57,255,20,0.22);  border-color: rgba(57,255,20,0.55); }
.cs-c5    { background: rgba(57,255,20,0.30);  border-color: rgba(57,255,20,0.70); }

.cs-base .cs-pts { color: #ffffff; }
.cs-c1 .cs-pts   { color: #ffffff; }
.cs-c2 .cs-pts   { color: #ffffff; }
/* x8 and above: background is bright enough — use white text for legibility */
.cs-c3 .cs-pts   { color: #ffffff; }
.cs-c4 .cs-pts   { color: #ffffff; }
.cs-c5 .cs-pts   { color: #ffffff; }

/* Labels: semi-transparent white on all cards */
.cs-base .cs-label,
.cs-c1 .cs-label,
.cs-c2 .cs-label { color: rgba(255, 255, 255, 0.72); }
.cs-c3 .cs-label,
.cs-c4 .cs-label,
.cs-c5 .cs-label { color: rgba(255, 255, 255, 0.72); }

.combo-arrow {
  color: var(--c-muted);
  font-size: 0.75rem;
  flex-shrink: 0;
}

.combo-wrap {
  font-size: 0.72rem;
  color: var(--c-muted);
  background: var(--c-bg2);
  border: 1px dashed var(--c-border);
  border-radius: var(--r-sm);
  padding: 4px 10px;
  margin-left: 4px;
}

/* Rules table */
.rules-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 14px;
  font-size: 0.80rem;
}

.rules-table th {
  text-align: center;
  padding: 7px 8px;
  font-family: var(--f-head);
  font-size: 0.70rem;
  letter-spacing: 0.05em;
  color: var(--c-text2);
  border-bottom: 1px solid var(--c-border);
  background: rgba(255,255,255,0.03);
}

.rules-table td {
  text-align: center;
  padding: 7px 8px;
  color: var(--c-text2);
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.rules-table tbody tr:hover td {
  background: rgba(57,255,20,0.03);
  color: var(--c-text);
}

.rules-table td:first-child {
  font-family: var(--f-head);
  font-weight: 700;
  color: var(--c-green);
}

/* Rules screen code tags */
#screen-rules code {
  font-family: monospace;
  background: rgba(255,255,255,0.07);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.83em;
}

/* Light theme rules overrides */
html[data-theme="light"] .cs-c1 { background: rgba(46,125,26,0.08); border-color: rgba(46,125,26,0.3); }
html[data-theme="light"] .cs-c2 { background: rgba(46,125,26,0.13); border-color: rgba(46,125,26,0.4); }
html[data-theme="light"] .cs-c3 { background: rgba(46,125,26,0.19); border-color: rgba(46,125,26,0.5); }
html[data-theme="light"] .cs-c4 { background: rgba(46,125,26,0.26); border-color: rgba(46,125,26,0.6); }
html[data-theme="light"] .cs-c5 { background: rgba(46,125,26,0.34); border-color: rgba(46,125,26,0.75); }
html[data-theme="light"] .cs-c1 .cs-pts,
html[data-theme="light"] .cs-c2 .cs-pts,
html[data-theme="light"] .cs-c3 .cs-pts,
html[data-theme="light"] .cs-c4 .cs-pts { color: #2e7d1a; }
html[data-theme="light"] #screen-rules code {
  background: rgba(0,0,0,0.07);
}

/* Inline obstacle icon (mini rounded square with ✕) */
.obs-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 17px;
  height: 17px;
  border-radius: 4px;
  background: linear-gradient(135deg, #2d3748, #1a202c);
  color: rgba(148, 163, 184, 0.75);
  font-size: 0.55rem;
  font-weight: 900;
  vertical-align: middle;
  margin: 0 2px;
  flex-shrink: 0;
}

html[data-theme="light"] .obs-icon {
  background: linear-gradient(135deg, #8b7355, #6b5a3e);
  color: rgba(100, 70, 30, 0.65);
}

/* 分顆比率 example box */
.ratio-example {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 14px;
  padding: 10px 14px;
  background: rgba(57, 255, 20, 0.04);
  border: 1px solid rgba(57, 255, 20, 0.18);
  border-radius: var(--r-sm);
  font-size: 0.80rem;
  color: var(--c-text2);
}

.ratio-result {
  font-family: var(--f-head);
  font-size: 0.82rem;
  color: var(--c-green);
}

.ratio-result strong { color: #ffd700; }

html[data-theme="light"] .ratio-example {
  background: rgba(46, 125, 26, 0.05);
  border-color: rgba(46, 125, 26, 0.20);
}

html[data-theme="light"] .ratio-result { color: #2e7d1a; }
html[data-theme="light"] .ratio-result strong { color: #b45309; }

/* ============================================================
   GAME OVER — LANDSCAPE RESPONSIVE
   ============================================================ */
/* Scrollable wrapper so card doesn't get clipped in landscape */
.gameover-scroll {
  overflow-y: auto;
  overflow-x: clip;
  align-items: flex-start;
  padding: 16px 0;
}

/* Compact card in very short viewports (landscape phone) */
@media (max-height: 520px) {
  .gameover-card {
    padding: 18px 24px 20px;
  }
  .go-title {
    font-size: 1.6rem;
    margin-bottom: 4px;
  }
  .go-player {
    font-size: 0.85rem;
    margin-bottom: 10px;
  }
  .result-row {
    gap: 12px;
    margin-bottom: 14px;
  }
  .result-val.big {
    font-size: 2rem;
  }
  .go-actions {
    gap: 8px;
  }
  .go-actions .btn-primary,
  .go-actions .btn-ghost {
    padding: 9px 20px;
    font-size: 0.82rem;
  }
  .new-record {
    padding: 6px 14px;
    font-size: 0.78rem;
  }
}
