/* =========================================================================
   ORBI — Estilos. Estética neón oscura, responsive, mobile-first.
   ========================================================================= */

:root {
  --bg: #0a0d24;
  --bg2: #11163a;
  --panel: #1a2050;
  --panel-light: #242b66;
  --accent: #4fa8ff;
  --accent2: #ff66ff;
  --gold: #ffd23f;
  --text: #eef1ff;
  --text-dim: #9aa3d8;
  --danger: #ff4d6d;
  --radius: 14px;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#app { height: 100%; height: 100dvh; }

/* ---------- pantallas ---------- */

.screen {
  display: none;
  flex-direction: column;
  height: 100%;
  background: radial-gradient(ellipse at 50% -20%, var(--bg2), var(--bg) 70%);
}
.screen.active { display: flex; }

.screen-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
}
.screen-header h2 { flex: 1; font-size: 1.3rem; letter-spacing: 1px; }
.header-coins { color: var(--gold); font-weight: 700; }

/* ---------- título ---------- */

#screen-title { justify-content: center; align-items: center; }
.title-wrap { text-align: center; padding: 24px; max-width: 420px; width: 100%; }

.logo-hero { display: block; margin: 0 auto 6px; animation: float 3s ease-in-out infinite; }
@keyframes float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }

.logo h1 {
  font-size: clamp(3.2rem, 16vw, 5rem);
  letter-spacing: 0.18em;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 18px rgba(79, 168, 255, 0.45));
}
.subtitle { color: var(--text-dim); letter-spacing: 0.3em; text-transform: uppercase; font-size: 0.8rem; margin-top: 4px; }

.title-stats {
  display: flex; justify-content: center; gap: 22px;
  margin: 22px 0; font-weight: 700; font-size: 1.05rem;
}

.title-buttons { display: flex; flex-direction: column; gap: 12px; align-items: center; }
.title-settings { display: flex; gap: 10px; }
.title-settings .btn { min-width: 0; }
.card-relic { font-size: 0.8em; }
.credits { margin-top: 26px; color: var(--text-dim); font-size: 0.75rem; }

/* ---------- botones ---------- */

.btn {
  appearance: none; border: none; cursor: pointer;
  background: var(--panel);
  color: var(--text);
  font: inherit; font-weight: 700;
  padding: 12px 26px;
  border-radius: var(--radius);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  transition: transform 0.12s, box-shadow 0.12s, background 0.12s;
  min-width: 200px;
}
.btn:hover:not(:disabled) { background: var(--panel-light); transform: translateY(-2px); }
.btn:active:not(:disabled) { transform: translateY(1px) scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: default; }

.btn-primary {
  background: linear-gradient(135deg, #2f7fe0, #7b3ff2);
  box-shadow: 0 4px 22px rgba(79, 168, 255, 0.4);
}
.btn-primary:hover:not(:disabled) { background: linear-gradient(135deg, #3a8df0, #8b52f7); }

.btn-big { font-size: 1.2rem; padding: 16px 34px; }

.btn-story {
  border-color: rgba(209, 139, 255, 0.45);
  box-shadow: 0 4px 18px rgba(209, 139, 255, 0.25);
}
.btn-story:hover:not(:disabled) { box-shadow: 0 4px 24px rgba(209, 139, 255, 0.4); }
.btn-small { min-width: 0; padding: 8px 18px; font-size: 0.85rem; }
.btn-icon {
  min-width: 0; width: 42px; height: 42px; padding: 0;
  font-size: 1.15rem; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
}

/* ---------- selección de niveles ---------- */

.levels-grid {
  padding: 10px 16px 24px;
  overflow-y: auto;
}

.world-header { margin: 14px 4px 10px; }
.world-header h3 { font-size: 1.05rem; letter-spacing: 0.5px; }
.world-header h3 small { color: var(--gold); font-weight: 700; margin-left: 8px; }
.world-header p { color: var(--text-dim); font-size: 0.82rem; margin-top: 4px; max-width: 640px; }

.world-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 14px;
}

.level-card {
  appearance: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  padding: 18px 10px;
  color: var(--text); font: inherit;
  transition: transform 0.12s, background 0.12s;
}
.level-card:hover:not(.locked) { background: var(--panel-light); transform: translateY(-3px); }
.level-card.locked { opacity: 0.45; cursor: default; }
.level-num {
  font-size: 1.6rem; font-weight: 800;
  color: var(--accent);
}
.level-name { font-size: 0.78rem; color: var(--text-dim); text-align: center; }
.level-stars { color: var(--gold); letter-spacing: 2px; }

/* ---------- tienda ---------- */

.shop-tip { padding: 0 20px 10px; color: var(--text-dim); font-size: 0.85rem; }

.shop-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
  padding: 10px 16px 24px;
  overflow-y: auto;
}

.skin-card {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  padding: 16px 12px;
}
.skin-card.active { border-color: var(--accent); box-shadow: 0 0 18px rgba(79, 168, 255, 0.3); }
.skin-info { text-align: center; }
.skin-info small { display: block; color: var(--text-dim); margin-top: 2px; }

/* ---------- juego ---------- */

#screen-game { padding-bottom: env(safe-area-inset-bottom); }

.hud {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  background: rgba(10, 13, 36, 0.7);
}
.hud-stats {
  flex: 1;
  display: flex; flex-wrap: wrap; gap: 6px 14px;
  font-weight: 700; font-size: 0.92rem;
  justify-content: center;
}
.hud-item.over-par { color: var(--danger); }
.hud-actions { display: flex; gap: 8px; }

.level-hint {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.8rem;
  padding: 2px 18px 6px;
  min-height: 1.2em;
}

.canvas-wrap {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  min-height: 0;
  padding: 4px;
}
#canvas {
  border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.06);
  touch-action: none;
}

/* ---------- controles táctiles ---------- */

.touch-controls {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 6px 22px 14px;
}
@media (pointer: coarse) {
  .touch-controls { display: flex; }
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(2, 52px);
  gap: 4px;
}
.dpad-btn {
  appearance: none; border: none;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text);
  border-radius: 12px;
  font-size: 1.1rem;
  display: flex; align-items: center; justify-content: center;
  touch-action: manipulation;
}
.dpad-btn:active { background: var(--panel-light); transform: scale(0.94); }
.dpad-up    { grid-column: 2; grid-row: 1; }
.dpad-left  { grid-column: 1; grid-row: 2; }
.dpad-down  { grid-column: 2; grid-row: 2; }
.dpad-right { grid-column: 3; grid-row: 2; }

.action-btn {
  appearance: none; border: none;
  width: 76px; height: 76px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2f7fe0, #7b3ff2);
  color: #fff; font-size: 1.5rem; font-weight: 700;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  box-shadow: 0 6px 22px rgba(79, 168, 255, 0.4);
  touch-action: manipulation;
}
.action-btn small { font-size: 0.6rem; font-weight: 600; opacity: 0.85; }
.action-btn:active { transform: scale(0.93); }

/* ---------- modales ---------- */

.modal-overlay {
  position: fixed; inset: 0;
  display: none;
  align-items: center; justify-content: center;
  background: rgba(5, 7, 20, 0.72);
  backdrop-filter: blur(4px);
  z-index: 50;
}
.modal-overlay.visible { display: flex; }

.modal {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 28px 30px;
  text-align: center;
  max-width: 360px; width: calc(100% - 40px);
  box-shadow: 0 20px 70px rgba(0, 0, 0, 0.6);
  animation: pop 0.25s ease;
}
@keyframes pop { from { transform: scale(0.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.modal h3 { font-size: 1.4rem; margin-bottom: 12px; }
.modal p { color: var(--text-dim); font-size: 0.92rem; margin-bottom: 6px; }

.modal-buttons {
  display: flex; gap: 10px; justify-content: center;
  margin-top: 18px; flex-wrap: wrap;
}
.modal-buttons .btn { min-width: 130px; }

.win-stars { font-size: 2.6rem; letter-spacing: 8px; margin: 6px 0 10px; }
.win-stars .star { color: #3a4185; display: inline-block; }
.win-stars .star.earned {
  color: var(--gold);
  filter: drop-shadow(0 0 10px rgba(255, 210, 63, 0.7));
  animation: starpop 0.5s cubic-bezier(0.2, 2.2, 0.4, 1) backwards;
}
@keyframes starpop { from { transform: scale(0) rotate(-30deg); } to { transform: scale(1) rotate(0); } }

.win-details { color: var(--text-dim); font-size: 0.92rem; display: grid; gap: 4px; }

.lives-left { color: var(--gold); font-weight: 700; }

.btn-undo-count { position: relative; }
.btn-undo-count small {
  position: absolute; top: 2px; right: 5px;
  font-size: 0.55rem; color: var(--gold); font-weight: 800;
}

/* ---------- intro cinemática ---------- */

.intro-overlay {
  position: fixed; inset: 0;
  display: none;
  flex-direction: column;
  align-items: center; justify-content: center;
  gap: 22px;
  background: radial-gradient(ellipse at 50% 30%, #0d1130, #050410 75%);
  z-index: 80;
  padding: 20px;
}
.intro-overlay.visible { display: flex; }

#intro-canvas {
  width: min(360px, 92vw);
  border-radius: 18px;
  box-shadow: 0 16px 60px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(255, 255, 255, 0.07);
  cursor: pointer;
}

#intro-text {
  max-width: 380px;
  text-align: center;
  font-size: 1.05rem;
  line-height: 1.5;
  color: var(--text);
  min-height: 3.2em;
  animation: introtext 0.5s ease;
}
@keyframes introtext { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; } }

.intro-skip {
  position: absolute;
  top: calc(14px + env(safe-area-inset-top));
  right: 16px;
  opacity: 0.7;
}

.modal-help { max-width: 460px; text-align: left; }
.modal-help h3 { text-align: center; }
.help-grid {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 8px 10px;
  font-size: 0.84rem;
  color: var(--text-dim);
  max-height: 55vh;
  overflow-y: auto;
}
.help-grid span:nth-child(odd) { text-align: center; font-size: 1rem; }

/* ---------- escritorio ---------- */

@media (min-width: 700px) and (pointer: fine) {
  .hud-stats { font-size: 1rem; gap: 8px 22px; }
  .level-hint { font-size: 0.88rem; }
}
