:root {
  --bg-sky-top: #2b3f6b;
  --bg-sky-bottom: #6d8fc9;
  --panel-dark: #10182b;
  --panel-dark-2: #182240;
  --gold: #f4b53f;
  --gold-2: #ffd873;
  --blue-accent: #3aa0ff;
  --purple: #8b5cf6;
  --red: #ef4444;
  --green: #34d67a;
  --text-light: #f5f7ff;
  --text-dim: #9aa4c7;
  --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);
}

/* Fondo por fase: cada nivel nuevo rota a la siguiente paleta (ver
   applyLevelBackground en ui.js), y vuelve a empezar en el nivel 6. La fase 0
   (nivel 1) usa el azul de :root de arriba, sin necesidad de override. */
body[data-bg-phase="1"] { --bg-sky-top: #4a2b6b; --bg-sky-bottom: #b26dc9; }
body[data-bg-phase="2"] { --bg-sky-top: #1f6b52; --bg-sky-bottom: #4fd9b0; }
body[data-bg-phase="3"] { --bg-sky-top: #6b2b2b; --bg-sky-bottom: #d97a4f; }
body[data-bg-phase="4"] { --bg-sky-top: #6b5a1f; --bg-sky-bottom: #f4c95f; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(ellipse at 50% -10%, var(--bg-sky-bottom), var(--bg-sky-top) 65%, #101a33 100%);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

svg { display: block; width: 100%; height: 100%; fill: currentColor; }

/* Utilidad generica: cualquier elemento con .hidden se oculta, salvo que un
   selector mas especifico (ej. .modal-overlay.hidden) ya lo cubra. */
.hidden { display: none !important; }

/* ---------- Sacudida de pantalla ---------- */
@keyframes shakeSmall {
  0%, 100% { transform: translate(0, 0); }
  25% { transform: translate(-3px, 2px); }
  50% { transform: translate(3px, -2px); }
  75% { transform: translate(-2px, -3px); }
}

@keyframes shakeMedium {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-6px, 3px); }
  40% { transform: translate(7px, -4px); }
  60% { transform: translate(-5px, -5px); }
  80% { transform: translate(4px, 4px); }
}

@keyframes shakeStrong {
  0%, 100% { transform: translate(0, 0) rotate(0deg); }
  15% { transform: translate(-10px, 6px) rotate(-1.2deg); }
  30% { transform: translate(12px, -8px) rotate(1.4deg); }
  45% { transform: translate(-14px, -4px) rotate(-1.6deg); }
  60% { transform: translate(10px, 8px) rotate(1.2deg); }
  75% { transform: translate(-8px, -6px) rotate(-0.8deg); }
  90% { transform: translate(6px, 4px) rotate(0.6deg); }
}

@media (prefers-reduced-motion: reduce) {
  .screen-shake-small, .screen-shake-medium, .screen-shake-strong { animation: none !important; }
}

.screen-shake-small { animation: shakeSmall 0.12s ease; }
.screen-shake-medium { animation: shakeMedium 0.18s ease; }
.screen-shake-strong { animation: shakeStrong 0.28s ease; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
}

.currency {
  display: flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(180deg, var(--panel-dark-2), var(--panel-dark));
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 20px;
  padding: 6px 8px 6px 6px;
  color: var(--text-light);
  font-weight: 700;
  font-size: 15px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25), inset 0 1px 0 rgba(255,255,255,0.05);
}

.currency-icon {
  width: 26px;
  height: 26px;
  padding: 5px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ranking-icon { background: radial-gradient(circle at 35% 30%, var(--gold-2), var(--gold)); color: #7a4b00; box-shadow: 0 0 8px rgba(244,181,63,0.5); }
.gem-icon { background: radial-gradient(circle at 35% 30%, #a9e6ff, var(--blue-accent)); color: #013a63; box-shadow: 0 0 8px rgba(58,160,255,0.5); }

.add-btn {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: var(--blue-accent);
  color: white;
  font-weight: 900;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

.settings-btn {
  margin-left: auto;
  width: 38px;
  height: 38px;
  padding: 9px;
  border-radius: 10px;
  border: none;
  background: var(--panel-dark);
  color: var(--text-light);
  cursor: pointer;
  transition: transform 0.15s ease;
}
.settings-btn:active { transform: scale(0.9) rotate(20deg); }

.topbar-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  padding: 0;
  border: 2px solid var(--panel-dark-2);
  background: var(--panel-dark);
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.15s ease;
}
.topbar-avatar:active { transform: scale(0.9); }
.topbar-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.topbar-avatar svg { width: 20px; height: 20px; fill: currentColor; }

.topbar-alias {
  margin-left: -4px;
  max-width: 74px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-light);
  font-weight: 700;
  font-size: 13px;
}

/* ---------- Level bar ---------- */
.level-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 14px 0;
  background: var(--panel-dark);
  border-radius: 20px;
  padding: 8px 14px;
}

.level-label {
  color: var(--text-light);
  font-weight: 800;
  font-size: 13px;
  white-space: nowrap;
}

.level-pct {
  color: var(--text-light);
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
}

.bar {
  flex: 1;
  height: 12px;
  background: #0a0f1e;
  border-radius: 10px;
  overflow: hidden;
  position: relative;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.5);
}

.bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 10px;
  transition: width 0.2s linear;
}

.bar-level .bar-fill { background: linear-gradient(to right, #6fe36f, var(--green)); }
.bar-clock .bar-fill { background: linear-gradient(to right, #ff7847, var(--gold)); }

/* Estado critico (>=95% dentro de los primeros 10s) */
@keyframes criticalPulse {
  0%, 100% { transform: scaleY(1); box-shadow: 0 0 6px 2px rgba(239,68,68,0.6); }
  50% { transform: scaleY(1.25); box-shadow: 0 0 14px 6px rgba(239,68,68,0.9); }
}
.bar-clock.critical .bar-fill {
  background: linear-gradient(to right, #ff3b3b, #ff7a7a);
  animation: criticalPulse 0.5s ease-in-out infinite;
}
.clock-bar.critical {
  box-shadow: 0 0 0 2px rgba(239,68,68,0.6), 0 0 18px rgba(239,68,68,0.5);
}
@media (prefers-reduced-motion: reduce) {
  .bar-clock.critical .bar-fill { animation: none; background: #ff3b3b; }
}

/* ---------- Screens ---------- */
.screens {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  padding: 6px 14px 0;
  overflow-y: auto;
}

.screen.active { display: flex; position: relative; }

.screen-close-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--panel-dark);
  color: var(--text-dim);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  z-index: 5;
}
.screen-close-btn:active { transform: scale(0.9); }

.screen-title {
  color: var(--text-light);
  font-size: 18px;
  font-weight: 900;
  text-align: center;
  margin: 6px 0 10px;
  letter-spacing: 0.5px;
}

.placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-light);
}

.placeholder-icon { width: 48px; height: 48px; opacity: 0.8; }
.placeholder-icon svg { fill: none; stroke: currentColor; stroke-width: 1.4; }
.placeholder p { font-weight: 700; font-size: 16px; opacity: 0.85; }

/* ---------- Banner de reto en vivo ---------- */
.duel-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0;
  padding: 8px 10px;
  background: var(--panel-dark);
  border: 1px solid var(--gold);
  border-radius: 14px;
}
.duel-banner.hidden { display: none; }
.duel-vs { font-size: 11px; font-weight: 900; color: var(--gold); flex-shrink: 0; }

/* Cada lado: avatar + nombre solamente — las barras de progreso ya NO viven
   aca, cada una esta junto a su propio reloj (ver #breakBarWrap y
   #duelRivalBarWrap). */
.duel-side {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
.duel-side:last-child { flex-direction: row-reverse; text-align: right; }

.duel-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1) center/cover no-repeat;
  border: 2px solid var(--blue-accent);
  flex-shrink: 0;
}
.duel-side:last-child .duel-avatar { border-color: var(--red); }

.duel-name {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-light);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.headline {
  text-align: center;
  color: white;
  text-shadow: 0 2px 6px rgba(0,0,0,0.4);
  font-size: 20px;
  letter-spacing: 0.5px;
  margin: 8px 0 6px;
}

/* ---------- Barra de destruccion ---------- */
.clock-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel-dark);
  border-radius: 20px;
  padding: 8px 14px;
  margin-bottom: 8px;
  transition: box-shadow 0.2s ease;
}

.clock-bar-icon { width: 18px; height: 18px; color: var(--text-light); }
.clock-bar-icon svg { fill: none; stroke: currentColor; stroke-width: 1.6; }
.clock-bar-text {
  color: var(--text-light);
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
}

/* ---------- Contador de gemas dobles (primeros 15s de cada reloj) ---------- */
.gems-countdown {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  margin-bottom: 4px;
}
.gems-countdown.hidden { display: none; }

.gems-countdown-number {
  font-size: 44px;
  font-weight: 900;
  line-height: 1;
  color: var(--gold-2);
  text-shadow: 0 2px 8px rgba(244,181,63,0.5);
  font-variant-numeric: tabular-nums;
  transition: color 0.15s ease, text-shadow 0.15s ease;
}

.gems-countdown-label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--text-dim);
}

.gems-countdown.critical .gems-countdown-number {
  color: #ff4d4d;
  text-shadow: 0 0 10px rgba(255,210,80,0.9), 0 0 22px rgba(255,80,80,0.7);
  animation: gemsCountdownPulse 0.5s ease-in-out infinite;
}
.gems-countdown.critical .gems-countdown-label { color: #ff8080; }

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

@media (prefers-reduced-motion: reduce) {
  .gems-countdown.critical .gems-countdown-number { animation: none; }
}

/* ---------- Game area ---------- */
.game-area {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.multiplier-box {
  position: absolute;
  left: 0;
  top: 8px;
  background: var(--panel-dark-2);
  border: 2px solid var(--gold);
  border-radius: 14px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  z-index: 5;
  box-shadow: 0 0 16px rgba(244,181,63,0.6);
}

.multiplier-box.hidden { display: none; }

.multiplier-label {
  color: var(--gold);
  font-size: 10px;
  font-weight: 800;
}

.multiplier-value {
  color: white;
  font-size: 20px;
  font-weight: 900;
}

.multiplier-timer {
  color: var(--text-dim);
  font-size: 11px;
}

.tools-col {
  position: absolute;
  right: 0;
  top: 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 5;
}

.tool-btn {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 16px;
  border: 2px solid rgba(255,255,255,0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: white;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  box-shadow: 0 4px 10px rgba(0,0,0,0.35);
}
.tool-btn:active { transform: scale(0.88); }
.tool-icon { width: 26px; height: 26px; }

.tool-hammer { background: linear-gradient(160deg, #3a6f96, #1a2e42); }
.tool-lightning { background: linear-gradient(160deg, #8b4de0, #3a1e63); }
.tool-star { background: linear-gradient(160deg, #2a3f5c, #0e1930); border-color: var(--gold); }

.tool-btn.unaffordable { opacity: 0.5; filter: grayscale(0.5); box-shadow: none; }
.tool-btn.tool-pop { animation: toolPop 0.3s ease; }
.tool-btn.tool-active {
  box-shadow: 0 0 0 3px var(--gold-2), 0 0 16px rgba(244,181,63,0.8);
  animation: toolActivePulse 0.6s ease-in-out infinite;
}
@keyframes toolActivePulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}
@keyframes toolPop {
  0% { transform: scale(1); }
  40% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

/* Golpe de martillo: se dispara en CADA tap al reloj (ver playHammerSwing
   en effects.js), no solo con la herramienta martillo activa — es el
   feedback visual de "le estas pegando". */
.tool-hammer .tool-icon { transform-origin: 78% 78%; }
.tool-hammer .tool-icon.hammer-swing { animation: hammerSwing 0.26s ease-out; }
@keyframes hammerSwing {
  0%   { transform: rotate(0deg); }
  30%  { transform: rotate(-26deg); }
  60%  { transform: rotate(10deg); }
  100% { transform: rotate(0deg); }
}

.tool-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 20px;
  height: 20px;
  padding: 0 4px;
  border-radius: 10px;
  background: var(--blue-accent);
  color: white;
  font-size: 12px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--panel-dark);
}

.clock-tap-target {
  position: relative;
  width: min(78vw, 340px);
  height: min(78vw, 340px);
  touch-action: none;
  cursor: pointer;
}

#clock3dCanvas,
#rivalClock3dCanvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  filter: drop-shadow(0 14px 24px rgba(0,0,0,0.4));
}

/* Pantalla dividida del duelo: mi reloj (arriba) y el del rival (abajo) se
   agrandan a este tamaño — hay sobra de alto disponible en .screens una vez
   ocultos headline/hints/gems-countdown, así que no hace falta achicarlos
   tanto como antes. */
body.duel-active .clock-tap-target:not(.clock-tap-target-rival) {
  width: min(58vw, 220px);
  height: min(58vw, 220px);
}
/* En duelo hay dos relojes + banner en la misma pantalla, dentro del mismo
   alto disponible de siempre (.screens ya viene con overhead fijo de
   topbar+barra de nivel+nav abajo) — se esconde todo lo redundante y se
   achican margenes/relojes para que los DOS entren juntos sin scroll,
   que es todo el sentido de una pantalla dividida. */
body.duel-active #jugarHints,
body.duel-active #jugarHeadline,
body.duel-active #gemsCountdown { display: none !important; }
body.duel-active .clock-bar { margin-bottom: 2px; }
body.duel-active .game-area { flex: 0 0 auto; }
body.duel-active .duel-banner { padding: 4px 8px; margin: 2px 0; }

/* Fila de herramientas: en duelo se saca de la columna a la derecha (ahi
   queda pegada a MI reloj nomas, no tiene sentido cuando hay dos) y se pone
   horizontal, centrada en la franja entre los dos relojes — asi queda claro
   que las herramientas aplican al duelo entero, no solo al de arriba, y de
   paso se libera el costado derecho de mi reloj. #duelRivalArea le deja el
   margen de arriba para que la fila entre sin pisar ningun reloj. */
body.duel-active .tools-col {
  position: absolute;
  left: 50%;
  right: auto;
  top: 100%;
  transform: translate(-50%, 14px);
  flex-direction: row;
  gap: 14px;
}
body.duel-active .duel-rival-area { margin: 86px 0 4px; }

.duel-my-label,
.duel-rival-label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  align-self: flex-start;
  margin: 0 0 2px 4px;
}
.duel-my-label.hidden { display: none; }
.duel-my-label { color: var(--blue-accent); }
.duel-rival-label { color: var(--red); }

.duel-rival-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  margin: 2px 0 4px;
}
.duel-rival-area.hidden { display: none; }
/* 100% del ancho de #duelRivalArea, que a su vez ya ocupa todo el ancho de
   .screens (mismo ancho final que #breakBarWrap) — no puede quedar en
   "auto" porque el padre es flex con align-items:center, que no estira a
   los hijos por su cross-axis. */
#duelRivalBarWrap { width: 100%; }
#duelRivalBarWrap .bar-fill { background: linear-gradient(to right, #ff7a7a, var(--red)); }
.clock-tap-target-rival {
  width: min(58vw, 220px);
  height: min(58vw, 220px);
  pointer-events: none;
}

#clock3dCanvas.shatter-anim {
  animation: shatterPop 0.4s ease forwards;
}

@keyframes shatterPop {
  0% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.18); opacity: 0.35; }
  100% { transform: scale(0.6); opacity: 0; }
}

.clock-face {
  fill: #f2e8d0;
  stroke: #2b1d0e;
  stroke-width: 6;
}

.clock-rim {
  fill: none;
  stroke: #6b4a25;
  stroke-width: 10;
}

.clock-ticks line {
  stroke: #2b1d0e;
  stroke-width: 3;
}

.clock-numeral {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 20px;
  font-weight: 700;
  fill: #2b1d0e;
}

.clock-jewel {
  stroke: #ffffff;
  stroke-width: 1;
  filter: drop-shadow(0 0 3px rgba(255,255,255,0.7));
}

.clock-hand {
  stroke: #1a1108;
  stroke-linecap: round;
}
.clock-hand.hour { stroke-width: 9; }
.clock-hand.minute { stroke-width: 6; }

.clock-pin { fill: #1a1108; }

.crack-layer path {
  fill: none;
  stroke: #14171c;
  stroke-width: 2.5;
  stroke-linecap: round;
  opacity: 0.85;
}

#crackGlowLayer path {
  fill: none;
  stroke: #ffb347;
  stroke-width: 4;
  stroke-linecap: round;
  opacity: 0.55;
}

.detached-piece {
  position: absolute;
  will-change: transform, opacity;
  pointer-events: none;
}

/* ---------- Reloj de arena (modelo 5) ---------- */
@keyframes sandFall {
  0% { transform: translateY(0); opacity: 0.9; }
  100% { transform: translateY(90px); opacity: 0; }
}

.sand-grain {
  animation: sandFall 0.7s linear infinite;
}
.sand-grain-0 { animation-delay: 0s; }
.sand-grain-1 { animation-delay: 0.22s; }
.sand-grain-2 { animation-delay: 0.44s; }

/* ---------- FX layer (particulas / texto flotante / iconos de herramienta) ---------- */
.fx-layer {
  position: absolute;
  inset: -40px;
  pointer-events: none;
  overflow: visible;
}

.shard {
  position: absolute;
  width: 8px;
  height: 8px;
  background: linear-gradient(135deg, #fff, #cfd8ff);
  clip-path: polygon(50% 0%, 100% 100%, 0% 100%);
  opacity: 0.95;
  will-change: transform, opacity;
}

.float-dmg {
  position: absolute;
  font-weight: 900;
  font-size: 20px;
  color: var(--gold-2);
  text-shadow: 0 2px 4px rgba(0,0,0,0.5);
  will-change: transform, opacity;
  pointer-events: none;
}

.tool-fly-icon {
  position: absolute;
  width: 24px;
  height: 24px;
  color: white;
  pointer-events: none;
  will-change: transform, opacity;
}

.gem-fly {
  position: absolute;
  width: 16px;
  height: 16px;
  color: var(--blue-accent);
  pointer-events: none;
  will-change: transform, opacity;
}

/* Cursor de herramienta activa: reemplaza la flechita del mouse por el
   icono de la herramienta mientras esta encendida (ver effects.js). */
.tool-cursor {
  position: fixed;
  left: 0; top: 0;
  width: 34px;
  height: 34px;
  display: none;
  align-items: center;
  justify-content: center;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 300;
  color: var(--gold-2);
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.6));
}
body.tool-cursor-active #clockTapTarget,
body.tool-cursor-active .tools-col,
body.tool-cursor-active .tool-btn {
  cursor: none;
}

/* Mira del rifle: circulo + cruz + punto rojo tipo laser, en vez del
   icono plano que usan martillo/combo de thor. */
.tool-cursor.tool-cursor-scope { width: 60px; height: 60px; color: initial; filter: none; }
.tool-cursor.tool-cursor-scope .scope-ring {
  position: absolute;
  inset: 0;
  border: 2px solid rgba(255,60,60,0.9);
  border-radius: 50%;
  box-shadow: 0 0 10px rgba(255,30,30,0.55), inset 0 0 10px rgba(255,30,30,0.25);
}
.tool-cursor.tool-cursor-scope .scope-line { position: absolute; background: rgba(255,60,60,0.9); }
.tool-cursor.tool-cursor-scope .scope-line-h { top: 50%; left: 6%; right: 6%; height: 1.5px; transform: translateY(-50%); }
.tool-cursor.tool-cursor-scope .scope-line-v { left: 50%; top: 6%; bottom: 6%; width: 1.5px; transform: translateX(-50%); }
.tool-cursor.tool-cursor-scope .scope-dot {
  position: absolute;
  left: 50%; top: 50%;
  width: 6px; height: 6px;
  background: #ff2020;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 8px 3px rgba(255,20,20,0.9);
}

@keyframes floatUp {
  0% { transform: translate(-50%, -50%); opacity: 1; }
  100% { transform: translate(-50%, calc(-50% - 50px)); opacity: 0; }
}

@keyframes shardBurst {
  0% { transform: translate(0, 0) scale(1); opacity: 0.95; }
  100% { transform: translate(var(--dx), var(--dy)) scale(0.4) rotate(var(--rot)); opacity: 0; }
}

@keyframes toolIconFly {
  0% { transform: translate(-50%, -50%) scale(0.6); opacity: 0; }
  30% { opacity: 1; }
  100% { transform: translate(calc(-50% + var(--tx)), calc(-50% + var(--ty))) scale(1.1); opacity: 0; }
}

@keyframes gemFlyToCounter {
  0% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  70% { opacity: 1; }
  100% { transform: translate(calc(-50% + var(--tx)), calc(-50% + var(--ty))) scale(0.4); opacity: 0; }
}

@keyframes pieceFly {
  0% { transform: translate(0,0) rotate(0deg); opacity: 1; }
  100% { transform: translate(var(--px), var(--py)) rotate(var(--prot)); opacity: 0; }
}

/* ---------- Hints ---------- */
.hints {
  display: flex;
  justify-content: center;
  gap: 14px;
  padding: 10px 0 8px;
}

.hint-chip {
  background: var(--panel-dark);
  border-radius: 14px;
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-light);
}

.hint-icon { width: 20px; height: 20px; }
.hint-icon svg { fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.hint-text { font-size: 11px; font-weight: 700; line-height: 1.2; }

/* ---------- Bottom nav ---------- */
.bottom-nav {
  display: flex;
  background: var(--panel-dark);
  border-top: 1px solid rgba(255,255,255,0.08);
  padding-bottom: 2px;
}

.nav-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 0 10px;
  font-size: 10px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.12s ease, color 0.12s ease;
}
.nav-btn:active { transform: scale(0.9); }

.nav-icon { width: 20px; height: 20px; }

.nav-btn.active {
  color: var(--blue-accent);
}

/* ---------- Toast ---------- */
.toast {
  position: absolute;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%) translateY(10px);
  background: rgba(20,20,30,0.92);
  color: white;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 20;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- Modales genericos ---------- */
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(4, 8, 20, 0.72);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
  padding: 20px;
}
.modal-overlay.hidden { display: none; }

.modal-card {
  background: linear-gradient(180deg, var(--panel-dark-2), var(--panel-dark));
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 20px;
  padding: 22px 20px;
  width: 100%;
  max-width: 340px;
  max-height: 90vh;
  overflow-y: auto;
  color: var(--text-light);
  box-shadow: 0 20px 50px rgba(0,0,0,0.5);
  text-align: center;
}

.modal-card h2 {
  margin: 0 0 14px;
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 0.5px;
}

.primary-btn {
  width: 100%;
  border: none;
  border-radius: 14px;
  background: linear-gradient(180deg, var(--gold-2), var(--gold));
  color: #4a2e00;
  font-weight: 900;
  font-size: 14px;
  padding: 13px;
  margin-top: 8px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(244,181,63,0.4);
  transition: transform 0.1s ease;
}
.primary-btn:active { transform: scale(0.96); }

.secondary-btn {
  width: 100%;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 14px;
  background: rgba(255,255,255,0.05);
  color: var(--text-light);
  font-weight: 800;
  font-size: 13px;
  padding: 11px;
  margin-top: 8px;
  cursor: pointer;
  transition: transform 0.1s ease;
}
.secondary-btn:active { transform: scale(0.96); }

.danger-btn.primary-btn {
  background: linear-gradient(180deg, #ff6b6b, var(--red));
  color: #3a0505;
  box-shadow: 0 4px 12px rgba(239,68,68,0.4);
}
.danger-btn.secondary-btn {
  border-color: rgba(239,68,68,0.4);
  color: #ff8080;
}

.reset-confirm-text {
  margin: 0 0 4px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--text-dim);
}

.text-input {
  width: 100%;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 12px;
  background: rgba(0,0,0,0.25);
  color: var(--text-light);
  font-size: 14px;
  padding: 12px;
  margin-top: 10px;
  text-align: center;
}
.text-input::placeholder { color: var(--text-dim); }

.modal-error {
  color: #ff8080;
  font-size: 12px;
  font-weight: 700;
  margin: 8px 0 0;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
}

/* ---------- Resultados ---------- */
.results-rows { margin: 10px 0 4px; }
.results-row {
  display: flex;
  justify-content: space-between;
  padding: 7px 2px;
  font-size: 14px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.results-row span { color: var(--text-dim); }
.results-total {
  border-bottom: none;
  margin-top: 4px;
  padding-top: 10px;
  border-top: 1px solid rgba(255,255,255,0.15);
  font-size: 17px;
}
.results-total strong { color: var(--gold-2); }

/* ---------- Perfil ---------- */
.photo-picker {
  display: block;
  width: 96px;
  height: 96px;
  margin: 4px auto 6px;
  border-radius: 50%;
  background: rgba(255,255,255,0.08);
  border: 2px dashed rgba(255,255,255,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: pointer;
  font-size: 32px;
}
.photo-picker img { width: 100%; height: 100%; object-fit: cover; }
.photo-picker img.hidden { display: none; }
.photo-placeholder-icon { width: 36px; height: 36px; color: var(--text-dim); }

.profile-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 20px;
  color: var(--text-light);
}
.profile-avatar-lg {
  width: 96px; height: 96px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1) center/cover no-repeat;
  border: 3px solid var(--gold);
  margin-bottom: 10px;
}
.profile-alias-lg { font-size: 18px; font-weight: 900; margin-bottom: 14px; }
.profile-stats {
  display: flex;
  gap: 24px;
  margin-bottom: 18px;
}
.profile-stats div { display: flex; flex-direction: column; align-items: center; }
.profile-stats span { font-size: 20px; font-weight: 900; color: var(--gold-2); }
.profile-stats label { font-size: 11px; color: var(--text-dim); }

.google-account-box { margin-top: 16px; display: flex; justify-content: center; }
.google-linked {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: var(--panel-dark);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  padding: 10px 18px;
}
.google-linked-label { font-size: 11px; color: var(--text-dim); }
.google-linked-email { font-size: 13px; font-weight: 700; color: var(--text-light); }
.google-signin-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.15);
  background: #fff;
  color: #1f1f1f;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.google-signin-btn:active { transform: scale(0.97); }
#btnChallengeGoogleGate { width: 100%; margin-top: 10px; }

.google-account-box-modal {
  flex-direction: column;
  gap: 8px;
  padding-top: 14px;
  margin-top: 14px;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.google-prompt-text {
  font-size: 12px;
  color: var(--text-dim);
  text-align: center;
  margin: 0;
}

/* ---------- Ranking ---------- */
.ranking-me {
  background: rgba(58,160,255,0.12);
  border: 1px solid var(--blue-accent);
  border-radius: 14px;
  padding: 8px 12px;
  margin-bottom: 10px;
}
.ranking-me:empty { display: none; }

.ranking-list { display: flex; flex-direction: column; gap: 8px; padding-bottom: 12px; }

.ranking-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel-dark);
  border-radius: 14px;
  padding: 8px 12px;
}
.ranking-row.top1 { border: 1px solid var(--gold); background: linear-gradient(90deg, rgba(244,181,63,0.15), var(--panel-dark)); }
.ranking-row.top2 { border: 1px solid #c7cbd6; }
.ranking-row.top3 { border: 1px solid #b5793a; }
.ranking-row.is-me { outline: 2px solid var(--blue-accent); }

.ranking-rank {
  width: 28px;
  font-size: 18px;
  font-weight: 900;
  color: var(--text-dim);
  text-align: center;
}
.ranking-row.top1 .ranking-rank { color: var(--gold); }

.ranking-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.12) center/cover no-repeat;
  flex-shrink: 0;
}

.ranking-info { flex: 1; min-width: 0; }
.ranking-alias { color: var(--text-light); font-weight: 800; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ranking-sub { color: var(--text-dim); font-size: 11px; }

.ranking-points { color: var(--gold-2); font-weight: 900; font-size: 14px; white-space: nowrap; }

.challenge-btn {
  border: none;
  background: var(--blue-accent);
  color: white;
  font-weight: 800;
  font-size: 11px;
  border-radius: 10px;
  padding: 6px 10px;
  cursor: pointer;
}
.challenge-btn:disabled {
  background: rgba(255,255,255,0.08);
  color: var(--text-dim);
  cursor: not-allowed;
}

.load-more-btn {
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.05);
  color: var(--text-light);
  border-radius: 12px;
  padding: 10px;
  font-weight: 700;
  margin-bottom: 14px;
  cursor: pointer;
}
.load-more-btn.hidden { display: none; }

/* ---------- Reto ---------- */
.challenge-code {
  font-size: 32px;
  font-weight: 900;
  letter-spacing: 6px;
  color: var(--gold-2);
  background: rgba(0,0,0,0.25);
  border-radius: 12px;
  padding: 12px;
  margin: 10px 0;
}
.challenge-status { color: var(--text-dim); font-size: 12px; margin-top: 8px; }

.challenge-clock-picker {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 12px 0;
}
.challenge-clock-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 6px;
  min-width: 58px;
  border-radius: 10px;
  border: 2px solid transparent;
  background: var(--panel-dark);
  color: var(--text-dim);
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
}
.challenge-clock-btn .dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: linear-gradient(180deg, #cfd8e3, #8b95a3);
}
.challenge-clock-btn.selected {
  border-color: var(--gold-2);
  color: var(--text-light);
  background: var(--panel-dark-2);
}

.challenge-level-picker {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 12px 0;
  color: var(--text-light);
  font-weight: 700;
}
.stepper-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: var(--blue-accent);
  color: white;
  font-weight: 900;
  font-size: 16px;
  cursor: pointer;
}
.stepper-btn:active { transform: scale(0.9); }

/* ---------- Onboarding / countdown cinematografico ---------- */
.cinematic-overlay {
  position: absolute;
  inset: 0;
  z-index: 60;
  background: #05060d;
  overflow: hidden;
}
.cinematic-overlay.hidden { display: none; }
.cinematic-overlay canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.build-version-tag {
  position: absolute;
  left: 10px;
  bottom: calc(10px + var(--safe-bottom));
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: rgba(255,255,255,0.35);
  z-index: 61;
}

/* El countdown deja ver el reloj real detras, desenfocado (no un fondo
   opaco como el onboarding) */
#countdownOverlay {
  background: rgba(5, 8, 16, 0.5);
  backdrop-filter: blur(5px);
}

.cinematic-content {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 20px;
  text-align: center;
}
.cinematic-content.hidden { display: none; }

.cinematic-title {
  color: white;
  font-size: 26px;
  font-weight: 900;
  line-height: 1.3;
  text-shadow: 0 0 20px rgba(255,255,255,0.35), 0 6px 18px rgba(0,0,0,0.7);
  letter-spacing: 0.5px;
}

.crack-word {
  position: relative;
  display: inline-block;
  color: #ff5252;
  text-shadow: 0 0 24px rgba(255,60,60,0.7), 0 6px 18px rgba(0,0,0,0.8);
}

.crack-word-svg {
  position: absolute;
  inset: -6px -10px;
  width: calc(100% + 20px);
  height: calc(100% + 12px);
  pointer-events: none;
}

.crack-word-path {
  fill: none;
  stroke: #fff2c2;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 0 6px rgba(255,255,255,0.8));
  stroke-dasharray: 320;
  stroke-dashoffset: 320;
  animation: crackReveal 0.5s 0.15s ease-out forwards;
}

@keyframes crackReveal {
  to { stroke-dashoffset: 0; }
}

.cinematic-btn {
  max-width: 220px;
}

/* ---------- Splash inicial "TIME KILLER" ---------- */
.title-splash {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(120,80,220,0.35), transparent 55%),
    radial-gradient(ellipse at 75% 75%, rgba(40,110,220,0.3), transparent 55%),
    radial-gradient(ellipse at 50% 50%, #10152b, #04050d 75%);
  overflow: hidden;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.title-splash.hidden { display: none; }

.starfield {
  position: absolute;
  inset: -10%;
  background-image:
    radial-gradient(1.6px 1.6px at 20% 30%, #fff, transparent),
    radial-gradient(1.2px 1.2px at 65% 15%, #cdd8ff, transparent),
    radial-gradient(1.8px 1.8px at 80% 60%, #fff, transparent),
    radial-gradient(1.2px 1.2px at 40% 80%, #b9c6ff, transparent),
    radial-gradient(1.4px 1.4px at 90% 85%, #fff, transparent),
    radial-gradient(1.2px 1.2px at 10% 65%, #fff, transparent),
    radial-gradient(1.6px 1.6px at 55% 45%, #cdd8ff, transparent),
    radial-gradient(1.2px 1.2px at 30% 95%, #fff, transparent);
  background-repeat: repeat;
  background-size: 260px 260px;
  animation: starDrift 60s linear infinite;
  opacity: 0.9;
}
@keyframes starDrift {
  from { transform: translate(0, 0); }
  to { transform: translate(-260px, -180px); }
}

.title-splash-text {
  position: relative;
  margin: 0;
  text-align: center;
  font-family: 'Arial Black', Impact, 'Franklin Gothic Bold', sans-serif;
  font-weight: 900;
  font-size: clamp(52px, 16vw, 92px);
  line-height: 0.95;
  letter-spacing: 3px;
  color: #f2f5ff;
  text-shadow:
    0 0 2px #000,
    3px 3px 0 #0a0f24,
    6px 6px 0 rgba(0,0,0,0.5),
    0 0 40px rgba(120,150,255,0.6);
}

.title-splash-hint {
  position: relative;
  margin: 0;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 2px;
  animation: hintPulse 1.6s ease-in-out infinite;
}
@keyframes hintPulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

/* ---------- Transicion breve al romper el reloj ---------- */
.clock-break-transition {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(120,80,220,0.35), transparent 55%),
    radial-gradient(ellipse at 75% 75%, rgba(40,110,220,0.3), transparent 55%),
    radial-gradient(ellipse at 50% 50%, #10152b, #04050d 75%);
  overflow: hidden;
  animation: clockBreakFade 2s ease forwards;
}
.clock-break-transition.hidden { display: none; }

@keyframes clockBreakFade {
  0% { opacity: 0; }
  12% { opacity: 1; }
  85% { opacity: 1; }
  100% { opacity: 0; }
}

.clock-break-transition-text {
  position: relative;
  margin: 0;
  text-align: center;
  font-family: 'Arial Black', Impact, 'Franklin Gothic Bold', sans-serif;
  font-weight: 900;
  font-size: clamp(26px, 7vw, 38px);
  line-height: 1.25;
  letter-spacing: 1px;
  color: #f2f5ff;
  text-shadow:
    0 0 2px #000,
    2px 2px 0 #0a0f24,
    0 0 30px rgba(120,150,255,0.6);
}

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