/* =========================================================================
   SPHERE TACTICS — style.css
   Identidad visual: esferas luminosas sobre fondo espacial profundo.
   ========================================================================= */

/* ------------------------- Variables ------------------------- */
:root {
  --bg-deep: #05070f;
  --bg-1: #0b1226;
  --bg-2: #0d0a1c;

  --blue: #2f7dfb;
  --blue-light: #8dc0ff;
  --red: #ff4257;
  --red-light: #ff9aa4;
  --yellow: #ffb021;
  --yellow-light: #ffd98c;
  --gray: #8894ab;
  --gray-light: #c9d2e2;

  --cyan: #4de3ff;
  --green: #38d996;

  --ink: #eaf1ff;
  --ink-dim: #93a1bd;
  --line: rgba(255, 255, 255, 0.09);
  --glass: rgba(13, 19, 36, 0.72);
  --glass-2: rgba(9, 14, 28, 0.88);

  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ------------------------- Base ------------------------- */
* { box-sizing: border-box; }

/* =========================================================================
   MÓVIL: áreas seguras y objetivos táctiles (mínimo 48px)
   ========================================================================= */
:root {
  --tap: 48px;                     /* tamaño mínimo de objetivo táctil */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg-deep);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;      /* sin rebotes al arrastrar */
}

body {
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;                 /* alto real en móviles con barra dinámica */
  overflow: hidden;
}

#board {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;             /* el canvas se maneja con nuestros eventos */
  cursor: default;
}

.hidden { display: none !important; }

/* ------------------------- Logo ------------------------- */
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-orb {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, var(--blue-light), var(--blue) 55%, #0d2f78);
  box-shadow: 0 0 14px rgba(47, 125, 251, 0.85), 0 0 30px rgba(77, 227, 255, 0.25);
  animation: orbFloat 3.4s ease-in-out infinite;
  flex: 0 0 auto;
}

@keyframes orbFloat {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-3px) scale(1.06); }
}

.logo-text {
  font-weight: 800;
  letter-spacing: 3px;
  font-size: 17px;
  color: #ffffff;
  line-height: 1;
}

.logo-text em {
  font-style: normal;
  color: var(--cyan);
  text-shadow: 0 0 14px rgba(77, 227, 255, 0.6);
}

/* ------------------------- HUD ------------------------- */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: calc(12px + var(--safe-top)) calc(14px + var(--safe-right)) 12px calc(14px + var(--safe-left));
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
  z-index: 20;
  animation: fadeDown 0.5s ease both;
}

#hud > * { pointer-events: auto; }

.hud-left {
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px;
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
}

.hud-center {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 7px 10px;
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
}

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

.hud-divider {
  width: 1px;
  height: 26px;
  background: var(--line);
  margin: 0 4px;
}

/* Marcadores de facción: forma + esferas + tropas */
.fchip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: var(--tap);
  padding: 6px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 800;
  color: inherit;
  cursor: default;
  font-family: var(--font);
}

.fchip .fshape {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  filter: drop-shadow(0 0 6px currentColor);
}

.fchip .fcount,
.fchip .ftroops {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-variant-numeric: tabular-nums;
}

.fchip .fdot { font-size: 11px; opacity: 0.9; }
.fchip .fplus { font-size: 11px; opacity: 0.75; }

.fchip-player { color: var(--blue-light); }
.fchip-red { color: var(--red-light); }
.fchip-yellow { color: var(--yellow-light); }
.fchip-purple { color: #d8b4fe; }

/* Formas por facción (mismo código que en el canvas) */
.shape-player { clip-path: circle(50%); background: currentColor; }
.shape-red { clip-path: polygon(50% 0%, 100% 100%, 0% 100%); background: currentColor; }
.shape-yellow { border-radius: 3px; background: currentColor; }
.shape-purple { clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%); background: currentColor; }

/* Estadísticas */
.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 56px;
  padding: 0 6px;
}

.stat-label {
  font-size: 9px;
  letter-spacing: 2px;
  color: var(--ink-dim);
  font-weight: 700;
}

.stat-value {
  font-size: 17px;
  font-weight: 800;
  color: #fff;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

/* Medidor de decisión de la IA */
.ai-meter {
  display: flex;
  align-items: center;
  gap: 7px;
  padding-left: 6px;
}

.ai-label {
  font-size: 9px;
  letter-spacing: 2px;
  color: var(--ink-dim);
  font-weight: 800;
}

.ai-track {
  width: 62px;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
  display: block;
}

.ai-fill {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--cyan), var(--red));
  box-shadow: 0 0 10px rgba(77, 227, 255, 0.6);
  transition: width 0.12s linear;
}

/* ------------------------- Botones ------------------------- */
.btn {
  position: relative;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  font-family: var(--font);
  font-weight: 800;
  letter-spacing: 1.4px;
  font-size: 13px;
  border-radius: 999px;
  padding: 10px 18px;
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.12s ease, background 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
  white-space: nowrap;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.11);
  border-color: rgba(255, 255, 255, 0.22);
}

.btn:active:not(:disabled) { transform: translateY(1px) scale(0.99); }

.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(135deg, #3b8bff, #2f5cff 55%, #7a3bff);
  border-color: rgba(255, 255, 255, 0.28);
  color: #fff;
  box-shadow: 0 10px 30px rgba(47, 92, 255, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.btn-primary:hover:not(:disabled) {
  box-shadow: 0 14px 38px rgba(47, 92, 255, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

.btn-ghost { background: rgba(255, 255, 255, 0.05); }

.btn-big {
  font-size: 17px;
  padding: 15px 46px;
  letter-spacing: 3px;
  margin-top: 6px;
}

.btn-sm { font-size: 11px; padding: 8px 14px; letter-spacing: 1px; }

.btn-ad {
  background: linear-gradient(135deg, rgba(255, 176, 33, 0.22), rgba(255, 66, 87, 0.2));
  border-color: rgba(255, 176, 33, 0.45);
  color: #ffe6b8;
  box-shadow: 0 6px 20px rgba(255, 176, 33, 0.18);
  display: inline-flex;
  align-items: center;
  gap: 9px;
}

.btn-ad:hover:not(:disabled) {
  background: linear-gradient(135deg, rgba(255, 176, 33, 0.34), rgba(255, 66, 87, 0.3));
  border-color: rgba(255, 200, 90, 0.7);
}

.btn-ad.is-cooling {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--line);
  color: var(--ink-dim);
  box-shadow: none;
}

.ad-icon {
  font-size: 10px;
  color: var(--yellow);
  text-shadow: 0 0 8px rgba(255, 176, 33, 0.8);
}

.icon-btn {
  width: var(--tap);
  height: var(--tap);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--glass);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.2s ease, transform 0.12s ease, border-color 0.2s ease;
  padding: 0;
  font-family: var(--font);
  position: relative;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.24);
  transform: translateY(-1px);
}

.icon-btn.muted { opacity: 0.55; }
.icon-btn.is-cooling { opacity: 0.5; }

.icon-btn-ad {
  background: linear-gradient(135deg, rgba(255, 176, 33, 0.24), rgba(255, 66, 87, 0.18));
  border-color: rgba(255, 176, 33, 0.45);
  color: #ffe6b8;
}

.icon-btn-gem {
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.26), rgba(77, 227, 255, 0.16));
  border-color: rgba(200, 160, 255, 0.5);
  color: #edd9ff;
}

/* Insignia con los vídeos de gemas que quedan hoy */
.icon-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 9px;
  background: #ff4257;
  color: #fff;
  font-size: 10px;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(255, 66, 87, 0.6);
}

.icon-badge:empty { display: none; }

/* Brillo que recorre los botones principales */
.btn-shine {
  position: absolute;
  top: 0;
  left: -60%;
  width: 45%;
  height: 100%;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, 0.45), transparent);
  transform: skewX(-18deg);
  animation: shine 3.4s ease-in-out infinite;
  pointer-events: none;
}

@keyframes shine {
  0%, 65% { left: -60%; }
  100% { left: 130%; }
}

/* ------------------------- Pista ------------------------- */
#hint {
  position: absolute;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  background: var(--glass-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 20px;
  font-size: 13px;
  color: var(--ink-dim);
  letter-spacing: 0.3px;
  backdrop-filter: blur(10px);
  z-index: 15;
  animation: fadeUp 0.6s ease both;
  text-align: center;
  box-shadow: var(--shadow);
}

.hint-key {
  color: var(--cyan);
  font-weight: 800;
  letter-spacing: 1.5px;
  margin-right: 4px;
}

/* ------------------------- Cuenta atrás ------------------------- */
.countdown {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
  pointer-events: none;
  background: rgba(5, 7, 15, 0.35);
  backdrop-filter: blur(2px);
}

.countdown-num {
  font-size: 130px;
  font-weight: 900;
  letter-spacing: 4px;
  color: #fff;
  text-shadow: 0 0 40px rgba(77, 227, 255, 0.85), 0 0 90px rgba(47, 125, 251, 0.6);
}

.countdown.pop .countdown-num { animation: countPop 0.8s ease-out both; }

@keyframes countPop {
  0% { transform: scale(0.35); opacity: 0; }
  25% { transform: scale(1.12); opacity: 1; }
  70% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0; }
}

/* ------------------------- Modales ------------------------- */
.modal {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 60;
  background: radial-gradient(circle at 50% 40%, rgba(12, 20, 42, 0.78), rgba(3, 5, 11, 0.94));
  backdrop-filter: blur(8px);
  overflow: auto;
}

.modal.show {
  display: flex;
  animation: fadeIn 0.28s ease both;
}

.panel {
  position: relative;
  width: min(620px, 100%);
  background: linear-gradient(160deg, rgba(20, 30, 58, 0.95), rgba(9, 13, 27, 0.96));
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 26px;
  padding: 34px 38px 30px;
  text-align: center;
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  animation: panelIn 0.4s cubic-bezier(0.2, 0.9, 0.25, 1.2) both;
  overflow: hidden;
}

.panel::before {
  content: "";
  position: absolute;
  top: -60%;
  left: -20%;
  width: 60%;
  height: 200%;
  background: radial-gradient(circle, rgba(47, 125, 251, 0.22), transparent 70%);
  pointer-events: none;
}

.panel::after {
  content: "";
  position: absolute;
  bottom: -70%;
  right: -20%;
  width: 65%;
  height: 200%;
  background: radial-gradient(circle, rgba(255, 66, 87, 0.16), transparent 70%);
  pointer-events: none;
}

.panel-small { width: min(420px, 100%); }

.panel-title {
  position: relative;
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--ink);
}

.panel-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 3px;
  color: var(--cyan);
  border: 1px solid rgba(77, 227, 255, 0.35);
  background: rgba(77, 227, 255, 0.08);
  border-radius: 999px;
  padding: 5px 13px;
  margin-bottom: 14px;
}

/* Título del juego */
.game-title {
  margin: 0 0 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.title-sphere {
  width: 74px;
  height: 74px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, var(--blue-light), var(--blue) 52%, #081c4d);
  box-shadow: 0 0 34px rgba(47, 125, 251, 0.75), 0 0 80px rgba(77, 227, 255, 0.3),
    inset -8px -10px 22px rgba(0, 0, 0, 0.45);
  animation: titleSphere 4s ease-in-out infinite;
}

@keyframes titleSphere {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-8px) rotate(6deg); }
}

.title-text {
  font-size: clamp(30px, 6.5vw, 46px);
  font-weight: 900;
  letter-spacing: 6px;
  line-height: 1;
  color: #fff;
  text-shadow: 0 4px 26px rgba(0, 0, 0, 0.6);
}

.title-text em {
  font-style: normal;
  background: linear-gradient(120deg, var(--cyan), var(--blue-light) 45%, #b28cff);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 16px rgba(77, 227, 255, 0.55));
}

.panel-text {
  position: relative;
  color: var(--ink-dim);
  font-size: 14.5px;
  line-height: 1.65;
  margin: 14px auto 18px;
  max-width: 480px;
}

.panel-text strong { color: var(--ink); }
.c-red { color: var(--red-light) !important; }
.c-yellow { color: var(--yellow-light) !important; }
.c-purple { color: #d8b4fe !important; }

/* Insignia de nivel */
.level-badge {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 1.6px;
  color: var(--ink-dim);
  white-space: nowrap;
}

.level-badge #valLevel { color: var(--cyan); }
.level-sep { color: rgba(255, 255, 255, 0.25); }

/* Acciones de panel (botones en fila) */
.panel-actions {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 6px;
}

/* Reglas */
.rules {
  position: relative;
  list-style: none;
  margin: 0 auto 22px;
  padding: 0;
  max-width: 470px;
  text-align: left;
  display: grid;
  gap: 9px;
}

.rules li {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 13px;
  font-size: 13px;
  color: var(--ink-dim);
  line-height: 1.45;
}

.rules li b { color: var(--ink); font-weight: 700; }

.rule-ico {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 800;
  background: rgba(47, 125, 251, 0.16);
  border: 1px solid rgba(47, 125, 251, 0.35);
  color: var(--blue-light);
}

.ico-drag { background: rgba(47, 125, 251, 0.16); border-color: rgba(47, 125, 251, 0.35); color: var(--blue-light); }
.ico-grow { background: rgba(56, 217, 150, 0.14); border-color: rgba(56, 217, 150, 0.35); color: #7ff0c0; }
.ico-ai { background: rgba(255, 66, 87, 0.14); border-color: rgba(255, 66, 87, 0.35); color: var(--red-light); }
.ico-ad { background: rgba(255, 176, 33, 0.14); border-color: rgba(255, 176, 33, 0.35); color: var(--yellow-light); }

.best-info {
  position: relative;
  margin: 16px 0 0;
  font-size: 12px;
  letter-spacing: 1px;
  color: var(--cyan);
  font-weight: 700;
}

.credits {
  position: relative;
  margin: 6px 0 0;
  font-size: 11.5px;
  color: rgba(147, 161, 189, 0.7);
}

/* ------------------------- Anuncio simulado ------------------------- */
.modal-ad { background: rgba(2, 4, 9, 0.93); }

.ad-frame {
  width: min(480px, 100%);
  background: linear-gradient(165deg, #161a2c, #0a0c16);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 22px;
  overflow: hidden;
  box-shadow: var(--shadow);
  animation: panelIn 0.35s cubic-bezier(0.2, 0.9, 0.25, 1.2) both;
}

.ad-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px;
  background: #ffcc33;
  color: #241a00;
}

.ad-tag {
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 2px;
  background: rgba(0, 0, 0, 0.82);
  color: #ffcc33;
  padding: 4px 9px;
  border-radius: 6px;
}

.ad-timer { font-size: 12px; font-weight: 800; letter-spacing: 0.6px; }

.ad-creative {
  position: relative;
  height: 320px;
  background: radial-gradient(circle at 50% 120%, #2b1a5e, #120c28 60%, #08060f);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ad-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(1px);
  opacity: 0.75;
  animation: orbSpin linear infinite;
}

.ad-orb-1 {
  width: 130px; height: 130px;
  left: -40px; top: -30px;
  background: radial-gradient(circle at 30% 30%, #ffd98c, #ff7a3d);
  animation-duration: 14s;
}

.ad-orb-2 {
  width: 90px; height: 90px;
  right: -25px; bottom: 40px;
  background: radial-gradient(circle at 30% 30%, #8dc0ff, #2f5cff);
  animation-duration: 19s;
  animation-direction: reverse;
}

.ad-orb-3 {
  width: 60px; height: 60px;
  right: 30%; top: 18px;
  background: radial-gradient(circle at 30% 30%, #ff9aa4, #ff2d55);
  animation-duration: 11s;
}

@keyframes orbSpin {
  from { transform: translate(0, 0) scale(1); }
  50% { transform: translate(18px, 22px) scale(1.12); }
  to { transform: translate(0, 0) scale(1); }
}

.ad-body {
  position: relative;
  text-align: center;
  padding: 20px 26px;
  z-index: 2;
}

.ad-app {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 2.5px;
  color: #ffd98c;
  margin-bottom: 14px;
}

.ad-app-ico { font-size: 18px; color: #fff; }

.ad-headline {
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 900;
  color: #fff;
  line-height: 1.25;
  text-shadow: 0 4px 18px rgba(0, 0, 0, 0.7);
}

.ad-sub {
  margin: 0 0 16px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7);
  letter-spacing: 0.4px;
}

.ad-cta {
  display: inline-block;
  background: linear-gradient(135deg, #38d996, #14a86e);
  color: #04150d;
  font-weight: 900;
  font-size: 13px;
  letter-spacing: 2px;
  padding: 11px 30px;
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(56, 217, 150, 0.4);
  animation: ctaPulse 1.6s ease-in-out infinite;
}

@keyframes ctaPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

.ad-stars {
  margin-top: 12px;
  font-size: 12px;
  font-weight: 800;
  color: #ffcc33;
  letter-spacing: 1px;
}

.ad-reward {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 44px;
  font-weight: 900;
  letter-spacing: 3px;
  color: #fff;
  background: rgba(6, 20, 14, 0.82);
  text-shadow: 0 0 30px rgba(56, 217, 150, 0.9);
  z-index: 3;
  animation: rewardIn 0.35s ease both;
}

.ad-reward.show { display: flex; }

@keyframes rewardIn {
  from { transform: scale(0.6); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.ad-bottom {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: #0b0d16;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.ad-track {
  flex: 1;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}

.ad-progress {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--yellow), var(--red));
  transition: width 0.1s linear;
}

/* ------------------------- Fin de partida ------------------------- */
.panel-end { width: min(520px, 100%); }

.end-title {
  font-size: clamp(38px, 9vw, 62px);
  font-weight: 900;
  letter-spacing: 6px;
  line-height: 1;
  margin-bottom: 10px;
}

#endScreen.win .end-title {
  background: linear-gradient(120deg, #8dc0ff, #4de3ff 40%, #38d996);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 26px rgba(77, 227, 255, 0.55));
}

#endScreen.lose .end-title {
  background: linear-gradient(120deg, #ff9aa4, #ff4257 45%, #b31d3a);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 26px rgba(255, 66, 87, 0.5));
}

.end-subtitle {
  position: relative;
  color: var(--ink-dim);
  font-size: 14px;
  margin: 0 0 20px;
}

.end-stats {
  position: relative;
  display: grid;
  gap: 7px;
  margin-bottom: 18px;
  text-align: left;
}

.end-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 9px 14px;
  font-size: 13px;
}

.end-key { color: var(--ink-dim); letter-spacing: 0.4px; }

.end-val {
  color: #fff;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.end-record {
  position: relative;
  margin: 0 0 14px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1.5px;
  color: var(--yellow-light);
  min-height: 16px;
}

/* ------------------------- Monedas ------------------------- */
.coin-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(255, 176, 33, 0.18), rgba(255, 176, 33, 0.06));
  border: 1px solid rgba(255, 200, 90, 0.35);
  font-size: 13px;
  font-weight: 800;
  color: #ffd98c;
  white-space: nowrap;
}

.coin-pill.big { font-size: 15px; padding: 8px 16px; }
.coin-ico { font-size: 1.05em; filter: drop-shadow(0 0 6px rgba(255, 200, 90, 0.5)); }
.coin-num { font-variant-numeric: tabular-nums; }

/* ------------------------- Menú principal ------------------------- */
.menu-actions {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.menu-meta {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.menu-upgrades {
  font-size: 11.5px;
  letter-spacing: 0.6px;
  color: var(--ink-dim);
}

/* ------------------------- Tienda ------------------------- */
.panel-shop { width: min(560px, 100%); }

.coins-big {
  position: relative;
  margin: 4px 0 10px;
  font-size: 20px;
  font-weight: 900;
  color: #ffd98c;
}

.shop-hint {
  position: relative;
  margin: 0 0 16px;
  font-size: 12px;
  color: var(--ink-dim);
}

.shop-list {
  position: relative;
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
  text-align: left;
}

.shop-item {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid var(--line);
  transition: border-color 0.2s ease, background 0.2s ease;
}

.shop-item:hover { border-color: rgba(255, 255, 255, 0.2); }

.shop-item.maxed { opacity: 0.75; }

.shop-ico {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 19px;
  background: linear-gradient(135deg, rgba(47, 125, 251, 0.2), rgba(168, 85, 247, 0.18));
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.shop-info { flex: 1; min-width: 0; }

.shop-name {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 14px;
  font-weight: 800;
  color: var(--ink);
}

.shop-lvl {
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--cyan);
  background: rgba(77, 227, 255, 0.1);
  border: 1px solid rgba(77, 227, 255, 0.3);
  border-radius: 999px;
  padding: 2px 8px;
}

.shop-desc {
  margin-top: 3px;
  font-size: 12px;
  color: var(--ink-dim);
  line-height: 1.45;
}

.btn-shop {
  flex: 0 0 auto;
  background: linear-gradient(135deg, rgba(255, 176, 33, 0.28), rgba(255, 120, 40, 0.22));
  border-color: rgba(255, 200, 90, 0.45);
  color: #ffe6b8;
}

.btn-shop:hover:not(:disabled) {
  background: linear-gradient(135deg, rgba(255, 176, 33, 0.42), rgba(255, 120, 40, 0.34));
  border-color: rgba(255, 220, 130, 0.7);
}

/* ------------------------- Gemas y monedas ------------------------- */
.coin-pill,
.gem-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
  min-height: 36px;
}

.coin-pill {
  background: linear-gradient(135deg, rgba(255, 176, 33, 0.18), rgba(255, 176, 33, 0.06));
  border: 1px solid rgba(255, 200, 90, 0.35);
  color: #ffd98c;
}

.gem-pill {
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.22), rgba(77, 227, 255, 0.08));
  border: 1px solid rgba(200, 160, 255, 0.4);
  color: #e3c8ff;
  box-shadow: 0 0 14px rgba(168, 85, 247, 0.18);
}

.coin-pill.big, .gem-pill.big { font-size: 15px; padding: 8px 16px; }
.coin-ico { font-size: 1.05em; filter: drop-shadow(0 0 6px rgba(255, 220, 140, 0.5)); }
.gem-pill .coin-ico { filter: drop-shadow(0 0 6px rgba(200, 150, 255, 0.6)); }
.coin-num { font-variant-numeric: tabular-nums; }

/* Botón de peligro (borrar progreso) */
.btn-danger {
  background: linear-gradient(135deg, rgba(255, 66, 87, 0.3), rgba(180, 20, 50, 0.24));
  border-color: rgba(255, 120, 135, 0.5);
  color: #ffd9de;
}

.btn-danger:hover:not(:disabled) {
  background: linear-gradient(135deg, rgba(255, 66, 87, 0.44), rgba(180, 20, 50, 0.34));
}

/* Botón de compra (Flow) */
.btn-buy {
  flex: 0 0 auto;
  min-height: var(--tap);
  background: linear-gradient(135deg, #38d996, #14a86e);
  border-color: rgba(255, 255, 255, 0.25);
  color: #04150d;
}

.btn-buy:hover:not(:disabled) { filter: brightness(1.08); }

/* Botón de vídeo por gemas */
.btn-gem {
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.28), rgba(77, 227, 255, 0.18));
  border-color: rgba(200, 160, 255, 0.5);
  color: #edd9ff;
}

.btn-gem:hover:not(:disabled) {
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.42), rgba(77, 227, 255, 0.28));
  border-color: rgba(220, 190, 255, 0.8);
}

/* ------------------------- Selección de planetas ------------------------- */
.panel-planets { width: min(880px, 100%); }

.planet-grid {
  position: relative;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin: 8px 0 20px;
}

.planet-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 16px 15px 13px;
  border-radius: 18px;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  color: var(--ink);
  background:
    radial-gradient(120% 90% at 20% 0%, var(--p-a, rgba(47,125,251,0.2)), transparent 60%),
    rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  font-family: var(--font);
  transition: transform 0.14s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.planet-card::after {
  content: "";
  position: absolute;
  right: -30%;
  bottom: -60%;
  width: 80%;
  height: 160%;
  background: radial-gradient(circle, var(--p-b, rgba(255,66,87,0.16)), transparent 70%);
  pointer-events: none;
}

.planet-card:hover {
  transform: translateY(-3px);
  border-color: rgba(255, 255, 255, 0.28);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.45);
}

.planet-card.locked {
  cursor: not-allowed;
  opacity: 0.5;
  filter: grayscale(0.7);
}

.planet-card.cleared { border-color: rgba(56, 217, 150, 0.45); }

.planet-icon { font-size: 34px; line-height: 1; filter: drop-shadow(0 4px 12px rgba(0,0,0,0.5)); }
.planet-name { font-size: 15px; font-weight: 900; letter-spacing: 0.6px; }
.planet-meta { font-size: 11.5px; color: var(--ink-dim); letter-spacing: 0.3px; }

.planet-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  margin-top: 6px;
  font-size: 11.5px;
  font-weight: 800;
}

.planet-ok { color: var(--green); letter-spacing: 0.6px; }
.planet-reward { color: #ffd98c; }

/* ------------------------- Tienda: pestañas ------------------------- */
.panel-shop { width: min(600px, 100%); }

.shop-head {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.shop-tabs {
  position: relative;
  display: flex;
  gap: 6px;
  padding: 5px;
  margin-bottom: 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
}

.shop-tab {
  flex: 1;
  border: 0;
  border-radius: 999px;
  padding: 9px 10px;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.6px;
  color: var(--ink-dim);
  background: transparent;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
  white-space: nowrap;
}

.shop-tab:hover { color: var(--ink); }

.shop-tab.active {
  background: linear-gradient(135deg, rgba(47, 125, 251, 0.35), rgba(168, 85, 247, 0.3));
  color: #fff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.shop-pane { position: relative; }

/* Paquetes de gemas (compras reales) */
.pack-item {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 13px 14px;
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.14), rgba(255, 255, 255, 0.03));
  border: 1px solid rgba(200, 160, 255, 0.22);
}

.pack-item.owned { opacity: 0.7; }

.pack-ico { font-size: 30px; flex: 0 0 auto; filter: drop-shadow(0 4px 10px rgba(168, 85, 247, 0.4)); }
.pack-info { flex: 1; min-width: 0; }
.pack-name { font-size: 14px; font-weight: 900; color: var(--ink); }
.pack-gems { font-size: 12.5px; font-weight: 800; color: #e3c8ff; margin-top: 2px; }
.pack-bonus {
  margin-left: 6px;
  font-size: 10px;
  letter-spacing: 0.6px;
  color: var(--green);
  background: rgba(56, 217, 150, 0.14);
  border: 1px solid rgba(56, 217, 150, 0.35);
  border-radius: 999px;
  padding: 2px 7px;
}
.pack-price { font-size: 11px; color: var(--ink-dim); margin-top: 3px; }

.btn-buy {
  flex: 0 0 auto;
  background: linear-gradient(135deg, #38d996, #14a86e);
  border-color: rgba(255, 255, 255, 0.25);
  color: #04150d;
}

.btn-buy:hover:not(:disabled) { filter: brightness(1.08); }

.btn-gem {
  flex: 0 0 auto;
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.3), rgba(77, 227, 255, 0.2));
  border-color: rgba(200, 160, 255, 0.5);
  color: #edd9ff;
}

.shop-item .btn-gem { flex: 0 0 auto; }

.epic-ico {
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.28), rgba(77, 227, 255, 0.18)) !important;
  border-color: rgba(200, 160, 255, 0.35) !important;
}

.shop-lvl.gem {
  color: #e3c8ff;
  background: rgba(168, 85, 247, 0.14);
  border-color: rgba(200, 160, 255, 0.35);
}

.gem-text { color: #e3c8ff !important; }

.shop-hint code {
  font-size: 11px;
  padding: 1px 5px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.08);
  color: #b9e6ff;
}

.ad-creative.tall { height: 300px; }

/* ------------------------- Menú de pausa / ajustes ------------------------- */
.modal-pause { background: radial-gradient(circle at 50% 40%, rgba(12, 20, 42, 0.72), rgba(3, 5, 11, 0.9)); }

.panel-pause { width: min(430px, 100%); }

.pause-block {
  position: relative;
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
  text-align: left;
}

.pause-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
}

.pause-ai-track { width: 100%; height: 8px; }

.pause-label { color: var(--ink-dim); font-weight: 700; letter-spacing: 0.4px; }
.pause-value { color: var(--ink); font-weight: 800; font-variant-numeric: tabular-nums; }
.pause-arrow { color: var(--ink-dim); font-size: 20px; }

.pause-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: var(--tap);
  padding: 10px 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid var(--line);
  color: var(--ink);
  font-family: var(--font);
  font-size: 13.5px;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
  text-align: left;
}

.pause-btn:hover { background: rgba(255, 255, 255, 0.1); border-color: rgba(255, 255, 255, 0.22); }
.pause-btn .pause-label { flex: 1; }
.pause-ico { font-size: 19px; width: 24px; text-align: center; }

/* ------------------------- Flow (pasarela de pagos) ------------------------- */
.panel-flow { width: min(430px, 100%); text-align: center; }

.flow-title {
  position: relative;
  margin: 2px 0 18px;
  font-size: 15px;
  font-weight: 800;
  color: var(--ink);
}

.flow-steps {
  position: relative;
  list-style: none;
  margin: 0 0 18px;
  padding: 0;
  display: grid;
  gap: 10px;
  text-align: left;
}

.flow-step {
  display: flex;
  align-items: center;
  gap: 11px;
  font-size: 13px;
  color: var(--ink-dim);
  transition: color 0.25s ease;
}

.flow-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.25);
  flex: 0 0 auto;
  transition: border-color 0.25s ease, background 0.25s ease, box-shadow 0.25s ease;
}

.flow-step.active { color: var(--ink); }
.flow-step.active .flow-dot {
  border-color: var(--cyan);
  background: rgba(77, 227, 255, 0.4);
  animation: flowPulse 1s ease-in-out infinite;
}

.flow-step.done { color: var(--green); }
.flow-step.done .flow-dot {
  border-color: var(--green);
  background: var(--green);
  box-shadow: 0 0 10px rgba(56, 217, 150, 0.7);
}

@keyframes flowPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(77, 227, 255, 0.55); }
  50% { box-shadow: 0 0 0 7px rgba(77, 227, 255, 0); }
}

.flow-result { position: relative; animation: panelIn 0.35s cubic-bezier(0.2, 0.9, 0.25, 1.2) both; }

.flow-big { font-size: 22px; font-weight: 900; letter-spacing: 1px; margin-bottom: 8px; }
.flow-big.ok { color: var(--green); }
.flow-big.err { color: var(--red-light); }
.flow-detail { font-size: 14px; color: var(--ink); font-weight: 700; }
.flow-detail.small { font-size: 12px; color: var(--ink-dim); margin-top: 4px; font-weight: 600; }

#flowModal.ok .panel { border-color: rgba(56, 217, 150, 0.45); }
#flowModal.err .panel { border-color: rgba(255, 66, 87, 0.45); }

/* ------------------------- Meta Ads / Audience Network ------------------------- */
.meta-banner {
  position: fixed;
  left: 50%;
  bottom: calc(8px + var(--safe-bottom));
  transform: translateX(-50%);
  width: min(320px, calc(100vw - 24px));
  height: 50px;
  z-index: 30;
  border-radius: 10px;
  overflow: hidden;
  background: linear-gradient(135deg, rgba(24, 119, 242, 0.16), rgba(255, 255, 255, 0.05));
  border: 1px solid rgba(24, 119, 242, 0.35);
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.45);
  pointer-events: auto;
}

.meta-banner-inner {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1.4px;
  color: #bcd6ff;
}

.meta-tag {
  position: absolute;
  top: 2px;
  left: 6px;
  font-size: 8px;
  letter-spacing: 1px;
  color: rgba(255, 255, 255, 0.45);
}

.meta-close {
  position: absolute;
  top: 2px;
  right: 4px;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  font-size: 11px;
  cursor: pointer;
}

/* ------------------------- Notificaciones ------------------------- */
.toasts {
  position: absolute;
  left: 50%;
  top: 88px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  z-index: 55;
  pointer-events: none;
}

.toast {
  background: var(--glass-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 20px;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.6px;
  color: var(--ink);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  opacity: 0;
  transform: translateY(-12px);
  transition: opacity 0.35s ease, transform 0.35s ease;
  white-space: nowrap;
}

.toast.show { opacity: 1; transform: translateY(0); }

/* ------------------------- Animaciones ------------------------- */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

@keyframes panelIn {
  from { opacity: 0; transform: translateY(24px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes fadeDown { from { opacity: 0; transform: translateY(-14px); } to { opacity: 1; transform: none; } }
@keyframes fadeUp { from { opacity: 0; transform: translate(-50%, 14px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ------------------------- Responsivo ------------------------- */
/* =========================================================================
   RESPONSIVO INTELIGENTE
   · > 768px  → PC: layout completo y amplio, distribuido en horizontal.
   · <= 768px → Móvil: cabecera compacta, barra de recursos reducida y los
     botones secundarios (vídeo, potenciador, pausa) pasan a una barra
     flotante abajo para liberar el canvas.
   ========================================================================= */
@media (max-width: 768px) {
  /* ---- Cabecera compacta ---- */
  #hud {
    padding: calc(6px + var(--safe-top)) calc(8px + var(--safe-right)) 6px calc(8px + var(--safe-left));
    gap: 6px;
    flex-wrap: nowrap;
    align-items: center;
  }

  .hud-left {
    padding: 6px 10px;
    border-radius: 12px;
    min-width: 0;
    flex: 0 1 auto;
  }

  .logo-orb { width: 18px; height: 18px; }
  .logo-text { font-size: 11px; letter-spacing: 1px; }
  .level-badge { margin-top: 3px; font-size: 8.5px; letter-spacing: 0.8px; }
  .level-badge #valLevelName { max-width: 92px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* ---- Marcadores compactos ---- */
  .hud-center {
    padding: 4px 6px;
    gap: 4px;
    border-radius: 12px;
    flex: 1 1 auto;
    min-width: 0;
    justify-content: flex-start;
    overflow: hidden;
  }

  .fchip {
    min-height: 38px;
    padding: 4px 7px;
    font-size: 11px;
    gap: 4px;
    border-radius: 9px;
  }

  .fchip .fshape { width: 12px; height: 12px; }
  .fchip .fdot, .fchip .fplus { font-size: 9px; }
  .stat { min-width: 40px; padding: 0 3px; }
  .stat-label { font-size: 8px; letter-spacing: 1px; }
  .stat-value { font-size: 13px; }
  .hud-divider { height: 20px; margin: 0 2px; }

  /* ---- Recursos compactos ---- */
  .hud-right {
    flex: 0 0 auto;
    gap: 5px;
  }

  .coin-pill, .gem-pill {
    font-size: 11px;
    padding: 4px 8px;
    min-height: 34px;
    border-radius: 999px;
  }

  /* Los botones secundarios salen del HUD → barra flotante inferior */
  .hud-right #btnGemVideo,
  .hud-right #btnAd,
  .hud-right #btnPause {
    position: fixed;
    z-index: 25;
    width: var(--tap);
    height: var(--tap);
    font-size: 19px;
    border-radius: 16px;
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(10px);
  }

  .hud-right #btnAd {
    right: calc(14px + var(--safe-right));
    bottom: calc(16px + var(--safe-bottom));
  }

  .hud-right #btnGemVideo {
    right: calc(70px + var(--safe-right));
    bottom: calc(16px + var(--safe-bottom));
  }

  .hud-right #btnPause {
    right: calc(126px + var(--safe-right));
    bottom: calc(16px + var(--safe-bottom));
  }

  /* la pista de ayuda se queda en el centro, sin tapar la barra */
  #hint { bottom: calc(78px + var(--safe-bottom)); font-size: 11.5px; }
  .toasts { top: calc(74px + var(--safe-top)); }
}

/* Móviles muy estrechos (≤ 380px) */
@media (max-width: 380px) {
  .fchip { padding: 3px 5px; font-size: 10px; gap: 3px; }
  .coin-pill, .gem-pill { font-size: 10px; padding: 3px 6px; min-height: 30px; }
  .stat-value { font-size: 12px; }
  .hud-right #btnAd { right: calc(10px + var(--safe-right)); bottom: calc(12px + var(--safe-bottom)); }
  .hud-right #btnGemVideo { right: calc(62px + var(--safe-right)); bottom: calc(12px + var(--safe-bottom)); }
  .hud-right #btnPause { right: calc(114px + var(--safe-right)); bottom: calc(12px + var(--safe-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
