/* ============================================================================
   Parking Rush — Estilos
   Tema base: Noche. Otros temas se aplican con body[data-theme="..."].
   ==========================================================================*/
:root {
  --bg: radial-gradient(1200px 700px at 18% -10%, rgba(79, 142, 247, 0.16), transparent 60%),
        radial-gradient(1000px 700px at 90% 110%, rgba(52, 199, 89, 0.12), transparent 60%),
        radial-gradient(800px 500px at 80% -20%, rgba(168, 85, 247, 0.10), transparent 55%),
        linear-gradient(160deg, #0d1322 0%, #0b101c 55%, #0a0e18 100%);
  --text: #e9edf6;
  --muted: #97a3bd;
  --panel: rgba(22, 28, 45, 0.72);
  --panel-solid: #161c2d;
  --border: rgba(255, 255, 255, 0.09);
  --glass: rgba(255, 255, 255, 0.06);
  --glass-hover: rgba(255, 255, 255, 0.13);
  --input-bg: rgba(255, 255, 255, 0.05);
  --accent: #4f8ef7;
  --accent-2: #34c759;
  --orb3: #a855f7;
  --danger: #ef4444;
  --gold: #fbbf24;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --text-inverse: #0b101c;
}

body[data-theme="neon"] {
  --bg: radial-gradient(1100px 700px at 20% -10%, rgba(34, 211, 238, 0.18), transparent 60%),
        radial-gradient(1000px 700px at 85% 110%, rgba(232, 121, 249, 0.16), transparent 60%),
        linear-gradient(160deg, #0b0f1e 0%, #0a0d18 60%, #0d0a18 100%);
  --text: #eaf6ff;
  --muted: #9fb3c8;
  --panel: rgba(16, 22, 40, 0.72);
  --panel-solid: #101628;
  --border: rgba(34, 211, 238, 0.16);
  --glass: rgba(34, 211, 238, 0.07);
  --glass-hover: rgba(34, 211, 238, 0.16);
  --input-bg: rgba(34, 211, 238, 0.07);
  --accent: #22d3ee;
  --accent-2: #e879f9;
  --orb3: #34d399;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
}

body[data-theme="sunset"] {
  --bg: radial-gradient(1100px 700px at 20% -10%, rgba(251, 146, 60, 0.18), transparent 60%),
        radial-gradient(1000px 700px at 85% 110%, rgba(244, 114, 182, 0.16), transparent 60%),
        linear-gradient(160deg, #1a0e1a 0%, #140c18 60%, #120a14 100%);
  --text: #fdeef2;
  --muted: #c2a3ae;
  --panel: rgba(34, 18, 32, 0.74);
  --panel-solid: #221226;
  --border: rgba(251, 146, 60, 0.16);
  --glass: rgba(251, 146, 60, 0.08);
  --glass-hover: rgba(251, 146, 60, 0.16);
  --input-bg: rgba(251, 146, 60, 0.08);
  --accent: #fb923c;
  --accent-2: #f472b6;
  --orb3: #fbbf24;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
}

body[data-theme="day"] {
  --bg: radial-gradient(1200px 700px at 18% -10%, rgba(79, 142, 247, 0.14), transparent 60%),
        radial-gradient(1000px 700px at 90% 110%, rgba(52, 199, 89, 0.12), transparent 60%),
        linear-gradient(160deg, #eef2f9 0%, #e6ebf4 60%, #dfe6f2 100%);
  --text: #1a2233;
  --muted: #5a6478;
  --panel: rgba(255, 255, 255, 0.82);
  --panel-solid: #f6f8fc;
  --border: rgba(20, 30, 60, 0.12);
  --glass: rgba(20, 30, 60, 0.06);
  --glass-hover: rgba(20, 30, 60, 0.12);
  --input-bg: rgba(20, 30, 60, 0.05);
  --accent: #2563eb;
  --accent-2: #059669;
  --orb3: #7c3aed;
  --shadow: 0 18px 50px rgba(30, 45, 90, 0.18);
  --text-inverse: #ffffff;
}

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

html, body { height: 100%; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  background-attachment: fixed;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

/* -------------------- Orbes de fondo -------------------- */
.orbs { position: fixed; inset: 0; overflow: hidden; z-index: 0; pointer-events: none; }
.orb { position: absolute; border-radius: 50%; filter: blur(80px); opacity: 0.45; }
.orb-1 { width: 460px; height: 460px; background: var(--accent); top: -140px; left: -100px; animation: float1 20s ease-in-out infinite; }
.orb-2 { width: 420px; height: 420px; background: var(--accent-2); bottom: -140px; right: -100px; animation: float2 24s ease-in-out infinite; }
.orb-3 { width: 300px; height: 300px; background: var(--orb3); top: 40%; left: 55%; opacity: 0.3; animation: float3 26s ease-in-out infinite; }
body[data-theme="day"] .orb { opacity: 0.22; }
@keyframes float1 { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(70px, 50px); } }
@keyframes float2 { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(-60px, -50px); } }
@keyframes float3 { 0%, 100% { transform: translate(0, 0) scale(1); } 50% { transform: translate(-50px, 40px) scale(1.1); } }

#app { position: fixed; inset: 0; z-index: 1; }

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.screen.active { display: flex; }

/* ============================ BOTONES ============================ */
.btn {
  appearance: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.3px;
  color: var(--text);
  padding: 13px 26px;
  border-radius: 14px;
  transition: transform 0.12s ease, box-shadow 0.2s ease, background 0.2s ease, opacity 0.2s;
  background: var(--glass);
  border: 1px solid var(--border);
}
.btn:hover { background: var(--glass-hover); transform: translateY(-1px); }
.btn:active { transform: translateY(1px) scale(0.98); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn:disabled:hover { background: var(--glass); transform: none; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}
.btn-primary:hover { filter: brightness(1.07); }

.btn-ghost { background: var(--glass); }

.btn-resume {
  border-color: var(--accent-2);
  color: var(--accent-2);
  animation: resumePulse 2s ease-in-out infinite;
}
@keyframes resumePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(52, 199, 89, 0); }
  50% { box-shadow: 0 0 0 5px rgba(52, 199, 89, 0.14); }
}

.btn-small { padding: 9px 16px; font-size: 14px; border-radius: 11px; }
.btn-square {
  width: 58px; height: 58px;
  padding: 0; font-size: 24px;
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
}

.icon-btn {
  position: fixed; top: 18px; right: 18px;
  width: 46px; height: 46px;
  border-radius: 50%;
  font-size: 20px;
  background: var(--glass);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  z-index: 50;
  transition: background 0.2s, transform 0.12s;
}
.icon-btn:hover { background: var(--glass-hover); }
.icon-btn:active { transform: scale(0.94); }

/* ============================ MENÚ ============================ */
.menu-card {
  display: flex; flex-direction: column; align-items: center;
  gap: 14px;
  text-align: center;
  padding: 46px 44px;
  border-radius: 28px;
  background: var(--panel);
  border: 1px solid var(--border);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
  max-width: 460px;
  width: 100%;
  animation: rise 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes rise {
  from { opacity: 0; transform: translateY(22px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.logo-badge { font-size: 52px; animation: bob 3s ease-in-out infinite; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-7px); } }

.logo {
  font-size: 46px;
  font-weight: 900;
  letter-spacing: 2px;
  line-height: 1;
  color: var(--text);
  text-shadow: 0 4px 22px rgba(0, 0, 0, 0.25);
}
.logo span { color: var(--accent); }

.tagline { color: var(--muted); font-size: 15px; line-height: 1.5; max-width: 320px; }

.menu-buttons { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; margin-top: 6px; }

.menu-stats {
  margin-top: 12px;
  font-size: 14px;
  color: var(--muted);
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 18px;
}
.menu-stats b { color: var(--gold); }

/* ============================ SELECTOR DE NIVELES ============================ */
#screen-levels { justify-content: flex-start; gap: 16px; padding-top: 26px; }

.levels-header {
  width: 100%;
  max-width: 820px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.levels-header h2 { font-size: 22px; font-weight: 800; }
.levels-progress { margin-left: auto; color: var(--muted); font-size: 14px; }
.levels-progress b { color: var(--gold); }

.tabs { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.tab {
  appearance: none; border: 1px solid var(--border); cursor: pointer;
  font-family: inherit; font-size: 14px; font-weight: 700;
  color: var(--muted); padding: 9px 18px; border-radius: 999px;
  background: var(--glass);
  transition: all 0.18s ease;
}
.tab:hover { color: var(--text); background: var(--glass-hover); }
.tab.active { color: var(--text-inverse); background: var(--text); border-color: var(--text); }
.tab .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 7px; }

.levels-grid {
  width: 100%;
  max-width: 820px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
  gap: 14px;
  overflow-y: auto;
  padding: 6px 4px 30px;
  flex: 1;
  align-content: start;
}

.level-card {
  position: relative;
  aspect-ratio: 1;
  border-radius: 18px;
  background: var(--panel);
  border: 1px solid var(--border);
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px;
  transition: transform 0.14s ease, border-color 0.2s, box-shadow 0.2s;
}
.level-card:hover { transform: translateY(-3px); border-color: var(--accent); }
.level-card .num { font-size: 26px; font-weight: 900; color: var(--text); }
.level-card .stars { display: flex; gap: 2px; font-size: 14px; min-height: 16px; }
.level-card .stars .star { color: rgba(128, 140, 170, 0.3); }
.level-card .stars .star.on { color: var(--gold); text-shadow: 0 0 8px rgba(251, 191, 36, 0.6); }
.level-card .best { font-size: 11px; color: var(--muted); }

.level-card.locked { opacity: 0.45; cursor: not-allowed; }
.level-card.locked:hover { transform: none; border-color: var(--border); }
.level-card.locked .lock { font-size: 22px; }
.level-card.locked .num { display: none; }
.level-card.shake { animation: shake 0.4s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  50% { transform: translateX(6px); }
  75% { transform: translateX(-4px); }
}

/* ============================ JUEGO ============================ */
#screen-game { justify-content: flex-start; gap: 10px; padding-top: 16px; }

.game-header {
  width: 100%;
  max-width: 780px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.game-title { display: flex; align-items: center; gap: 10px; }
.level-badge {
  font-size: 12px; font-weight: 800; letter-spacing: 0.5px;
  padding: 4px 10px; border-radius: 999px; color: #fff;
}
.level-name { font-size: 16px; font-weight: 700; color: var(--muted); }
.tta-progress {
  font-size: 12px; font-weight: 800; letter-spacing: 0.5px;
  padding: 4px 10px; border-radius: 999px;
  background: var(--glass); border: 1px solid var(--border); color: var(--text);
}

.game-stats { margin-left: auto; display: flex; gap: 18px; }
.stat { display: flex; flex-direction: column; align-items: flex-end; }
.stat-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.6px; }
.stat-value { font-size: 20px; font-weight: 800; color: var(--text); }
.stat-value.danger { color: var(--danger); animation: pulse 0.6s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }

.level-nav { display: flex; gap: 6px; margin-left: 8px; }
.level-nav .btn { padding: 9px 13px; }

/* ============================ LOGROS ============================ */
.ach-card { max-width: 560px; }
.ach-stats { font-size: 13.5px; color: var(--muted); }
.ach-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
  max-height: 56vh; overflow-y: auto; text-align: left;
  padding: 2px;
}
.ach-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--input-bg); border: 1px solid var(--border);
  border-radius: 14px; padding: 10px 12px;
}
.ach-item .icon { font-size: 26px; }
.ach-item .name { font-weight: 700; font-size: 13.5px; display: block; }
.ach-item .desc { font-size: 12px; color: var(--muted); }
.ach-item.locked { opacity: 0.45; filter: grayscale(1); }

.board-wrap { flex: 1; width: 100%; display: flex; align-items: center; justify-content: center; min-height: 0; }
#board { touch-action: none; cursor: grab; }
#board.dragging { cursor: grabbing; }

.game-footer { display: flex; gap: 12px; padding-bottom: 4px; }
.game-hint-text { font-size: 12px; color: var(--muted); padding-bottom: 12px; }

/* ============================ OVERLAYS ============================ */
.overlay {
  position: fixed; inset: 0;
  display: none;
  align-items: center; justify-content: center;
  background: rgba(6, 9, 16, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 100;
  padding: 20px;
}
.overlay.active { display: flex; }

.overlay-card {
  position: relative;
  background: var(--panel-solid);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 38px 36px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  display: flex; flex-direction: column; gap: 16px;
  animation: rise 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.overlay-card h2 { font-size: 26px; font-weight: 900; }

.win-card { overflow: hidden; }
.win-emoji { font-size: 52px; }
#confetti, #confetti-tta { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

.stars { display: flex; justify-content: center; gap: 10px; font-size: 42px; }
.stars .star { color: rgba(128, 140, 170, 0.3); transition: color 0.2s, transform 0.3s; }
.stars .star.on { color: var(--gold); text-shadow: 0 0 18px rgba(251, 191, 36, 0.7); }
.stars .star.pop { animation: starPop 0.45s cubic-bezier(0.2, 1.4, 0.4, 1); }
@keyframes starPop {
  0% { transform: scale(0.2) rotate(-30deg); }
  60% { transform: scale(1.35) rotate(8deg); }
  100% { transform: scale(1) rotate(0); }
}

.win-info { color: var(--muted); font-size: 15px; line-height: 1.5; }
.win-info b { color: var(--text); }

.win-record {
  display: none;
  align-self: center;
  background: linear-gradient(135deg, var(--gold), #f59e0b);
  color: #1a1200;
  font-weight: 800;
  font-size: 13px;
  padding: 6px 14px;
  border-radius: 999px;
}
.win-record.show { display: inline-block; animation: recordPop 0.5s cubic-bezier(0.2, 1.4, 0.4, 1); }
@keyframes recordPop { 0% { transform: scale(0.4); } 60% { transform: scale(1.2); } 100% { transform: scale(1); } }

/* ============================ AJUSTES ============================ */
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; font-size: 15px; font-weight: 600; }
.setting-block { flex-direction: column; align-items: stretch; gap: 10px; text-align: left; }

.toggle {
  width: 54px; height: 30px; border-radius: 999px;
  background: var(--glass); border: 1px solid var(--border);
  position: relative; cursor: pointer; transition: background 0.2s;
  flex-shrink: 0;
}
.toggle::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%; background: #fff;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}
.toggle.on { background: var(--accent); }
.toggle.on::after { transform: translateX(24px); }

.theme-picker { display: flex; gap: 8px; flex-wrap: wrap; }
.theme-btn {
  display: flex; align-items: center; gap: 7px;
  padding: 9px 14px; border-radius: 12px;
  background: var(--glass); border: 1px solid var(--border);
  color: var(--text); cursor: pointer; font-size: 13px; font-weight: 700;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.theme-btn .swatch { width: 16px; height: 16px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.15); }
.theme-btn.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }

/* ============================ AYUDA ============================ */
.help-list { list-style: none; text-align: left; display: flex; flex-direction: column; gap: 12px; }
.help-list li { color: var(--text); font-size: 14.5px; line-height: 1.5; padding-left: 20px; position: relative; }
.help-list li::before { content: "▸"; position: absolute; left: 2px; color: var(--accent); }
.help-list b { color: var(--text); }

/* ============================ TOAST ============================ */
.toast {
  position: fixed; left: 50%; bottom: 26px;
  transform: translateX(-50%) translateY(20px);
  background: var(--panel-solid); color: var(--text);
  border: 1px solid var(--border);
  padding: 12px 22px; border-radius: 14px; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 200; max-width: 90vw; text-align: center;
  font-size: 14px; font-weight: 600;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Zonas seguras (móviles con notch) */
.icon-btn { top: calc(18px + env(safe-area-inset-top)); right: calc(18px + env(safe-area-inset-right)); }
#screen-game {
  padding-top: calc(16px + env(safe-area-inset-top));
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
  padding-left: calc(20px + env(safe-area-inset-left));
  padding-right: calc(20px + env(safe-area-inset-right));
}

@media (max-width: 640px) {
  .logo { font-size: 36px; }
  .menu-card { padding: 34px 26px; }
  .game-stats { gap: 12px; }
  .stat-value { font-size: 16px; }
  .btn { font-size: 15px; padding: 12px 20px; }
  .btn-square { width: 52px; height: 52px; }
  .levels-grid { grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 10px; }
  .ach-grid { grid-template-columns: 1fr; }
  .level-nav { margin-left: auto; }
}

/* Móvil apaisado: menos cromo vertical para un tablero mayor */
@media (max-height: 520px) and (orientation: landscape) {
  #screen-game { padding-top: calc(8px + env(safe-area-inset-top)); }
  .game-stats { gap: 14px; }
  .stat-value { font-size: 15px; }
  .stat-label { font-size: 9px; }
  .game-footer { gap: 8px; }
  .btn-square { width: 44px; height: 44px; font-size: 19px; border-radius: 12px; }
  .game-hint-text { display: none; }
}
