:root {
  --bg: #0b0e16;
  --bg2: #121728;
  --panel: #182036;
  --panel2: #202a45;
  --line: #2b3654;
  --text: #eef1fb;
  --muted: #8d97b5;
  --accent: #ffc94d;
  --accent2: #5ee08a;
  --pink: #ff5d73;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background:
    radial-gradient(1100px 600px at 15% -10%, #1a2340 0%, transparent 60%),
    radial-gradient(900px 500px at 110% 0%, #2a1633 0%, transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior: none;
}

.app {
  width: min(760px, 100%);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
}

/* ---------- HUD ---------- */
.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 2px;
}

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

.level-badge {
  font-weight: 800;
  font-size: 15px;
  letter-spacing: .4px;
  text-transform: uppercase;
  padding: 8px 14px;
  border-radius: 12px;
  background: linear-gradient(180deg, #2a3554, #1b2440);
  border: 1px solid #3a486e;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .35);
  white-space: nowrap;
}

.moves { display: flex; flex-direction: column; align-items: flex-start; line-height: 1; }
.moves-num { font-size: 26px; font-weight: 800; color: var(--accent2); font-variant-numeric: tabular-nums; transition: color .2s ease; }
.moves-num.low { color: var(--pink); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.moves-label { font-size: 10px; letter-spacing: 1.4px; text-transform: uppercase; color: var(--muted); margin-top: 3px; }

.hud-right { text-align: right; }
.score-line { display: flex; align-items: baseline; justify-content: flex-end; gap: 6px; font-variant-numeric: tabular-nums; line-height: 1; }
.goal-label { font-size: 10px; letter-spacing: 1.6px; text-transform: uppercase; color: var(--muted); }
.score-num { font-size: 30px; font-weight: 800; color: #fff; }
.score-target { font-size: 14px; color: var(--muted); }

.stars { margin-top: 5px; font-size: 20px; letter-spacing: 3px; color: #37405d; }
.stars .star.on { color: var(--accent); text-shadow: 0 0 12px rgba(255, 201, 77, .65); }
.stars-hint { margin-top: 2px; font-size: 10px; letter-spacing: .4px; color: var(--muted); }
@media (max-width: 520px) { .stars-hint { display: none; } }

/* ---------- progress ---------- */
.progress {
  position: relative;
  height: 12px;
  border-radius: 999px;
  background: #131a2e;
  border: 1px solid var(--line);
  overflow: hidden;
}
.progress-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #ff9f43, #ffc94d);
  box-shadow: 0 0 14px rgba(255, 201, 77, .45);
  transition: width .25s ease, background .3s ease, box-shadow .3s ease;
}
.progress-fill.win {
  background: linear-gradient(90deg, #35c47a, #8be9a0);
  box-shadow: 0 0 16px rgba(94, 224, 138, .6);
}
.progress-marks { position: absolute; inset: 0; pointer-events: none; }
.progress-marks i {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, .22);
  border-radius: 2px;
}
.progress-marks i.goal { background: rgba(255, 255, 255, .55); width: 3px; }

/* ---------- board ---------- */
.board-wrap {
  position: relative;
  border-radius: 20px;
  padding: 8px;
  background: linear-gradient(180deg, #1a2238, #121a2d);
  border: 1px solid #2e3a5c;
  box-shadow: 0 18px 40px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255, 255, 255, .05);
}

#board {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  border-radius: 14px;
  touch-action: none;
  cursor: pointer;
  outline: none;
}

/* ---------- nivel: objetivo ---------- */
.level-intro {
  position: absolute;
  left: 50%;
  top: 50%;
  width: max-content;
  max-width: 88%;
  padding: 16px 26px;
  text-align: center;
  border-radius: 18px;
  background: rgba(10, 15, 27, .9);
  border: 1px solid #3a486e;
  box-shadow: 0 22px 55px rgba(0, 0, 0, .6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -50%) scale(.9);
  transition: opacity .25s ease, transform .25s ease;
  z-index: 6;
}
.level-intro.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.li-level { font-size: 12px; letter-spacing: 2.4px; text-transform: uppercase; color: var(--muted); }
.li-goal { margin: 5px 0 3px; font-size: 26px; font-weight: 800; color: var(--accent); white-space: nowrap; }
.li-moves { font-size: 13px; color: #c3cbe4; }
@media (max-width: 520px) { .li-goal { font-size: 21px; } }

/* ---------- controls ---------- */
.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 2px;
}

.icon-btn {
  width: 44px; height: 44px;
  border-radius: 13px;
  border: 1px solid #33415f;
  background: linear-gradient(180deg, #232d49, #18203a);
  color: var(--text);
  font-size: 20px; font-weight: 700;
  cursor: pointer;
  box-shadow: 0 5px 14px rgba(0, 0, 0, .35);
  transition: transform .08s ease, filter .15s ease;
}
.icon-btn:active { transform: translateY(1px) scale(.97); }
.icon-btn.muted { filter: grayscale(1) brightness(.7); }

.status {
  font-size: 13px;
  letter-spacing: .6px;
  color: var(--muted);
  text-transform: uppercase;
  text-align: center;
  flex: 1;
  min-height: 18px;
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 92px;
  transform: translate(-50%, 24px);
  background: rgba(24, 32, 54, .96);
  border: 1px solid #3a486e;
  color: var(--text);
  padding: 10px 18px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s ease, transform .22s ease;
  z-index: 30;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- overlay ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 9, 17, .78);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 40;
}
.overlay[hidden] { display: none; }

.panel {
  width: min(430px, 100%);
  max-height: 92vh;
  max-height: 92dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: linear-gradient(180deg, #1e2740, #141b2f);
  border: 1px solid #3a486e;
  border-radius: 22px;
  padding: 24px 22px 20px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .6);
  text-align: center;
  animation: pop .22s ease;
}
@keyframes pop { from { transform: scale(.94); opacity: .4; } to { transform: scale(1); opacity: 1; } }

.panel h2 { margin: 0 0 6px; font-size: 26px; letter-spacing: .3px; }
.panel h3 { margin: 16px 0 2px; font-size: 12px; letter-spacing: 1.8px; text-transform: uppercase; color: var(--accent); }
.panel p { margin: 6px 0; color: #c3cbe4; font-size: 15px; line-height: 1.45; }
.panel .mono { color: #fff; font-variant-numeric: tabular-nums; white-space: nowrap; }
.panel .big { font-size: 40px; font-weight: 800; color: var(--accent); margin: 4px 0 2px; }
.panel .stars-big { font-size: 34px; letter-spacing: 8px; color: #37405d; margin: 6px 0 2px; }
.panel .stars-big .star.on { color: var(--accent); text-shadow: 0 0 18px rgba(255, 201, 77, .7); }

.panel .btn {
  display: inline-block;
  margin-top: 14px;
  padding: 13px 26px;
  border-radius: 14px;
  border: 0;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: .4px;
  cursor: pointer;
  color: #10182b;
  background: linear-gradient(180deg, #ffe07a, #ffc94d);
  box-shadow: 0 8px 20px rgba(255, 201, 77, .28);
  transition: transform .08s ease, filter .15s ease;
}
.panel .btn:active { transform: translateY(1px) scale(.98); }
.panel .btn.ghost {
  background: linear-gradient(180deg, #2a3554, #1c2541);
  color: var(--text);
  box-shadow: none;
  border: 1px solid #3a486e;
  margin-left: 8px;
}
.panel .hint { font-size: 13px; color: var(--muted); margin-top: 10px; }
.panel ul { text-align: left; margin: 10px 0 0; padding-left: 20px; color: #c3cbe4; font-size: 14px; line-height: 1.6; }
.panel ul b { color: #fff; }

/* ---------- accesibilidad: movimiento reducido ---------- */
@media (prefers-reduced-motion: reduce) {
  .moves-num.low { animation: none; }
  .progress-fill { transition: none; }
  .level-intro { transition: none; }
  .toast { transition: none; }
}

/* ---------------- gelatina ---------------- */
.jelly-chip {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px 5px 9px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(255, 110, 180, .22), rgba(255, 84, 166, .1));
  border: 1px solid rgba(255, 140, 200, .35);
  color: #ffd7ea;
  font-size: 11px;
  letter-spacing: .06em;
  text-transform: uppercase;
  transition: background .2s ease, border-color .2s ease, color .2s ease;
}
.jelly-chip[hidden] { display: none; }
.jelly-chip b { color: #fff; font-size: 14px; letter-spacing: 0; }
.jelly-chip .jc-icon { font-size: 15px; line-height: 1; }
.jelly-chip.done {
  background: linear-gradient(180deg, rgba(94, 224, 138, .26), rgba(94, 224, 138, .1));
  border-color: rgba(94, 224, 138, .5);
  color: #d6ffe5;
}

/* ---------------- mapa de niveles ---------------- */
.map {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 14px 0 18px;
}
.map .lvl {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 4px 8px;
  border-radius: 14px;
  cursor: pointer;
  background: rgba(255, 255, 255, .05);
  border: 1px solid rgba(255, 255, 255, .1);
  color: var(--text);
  font: inherit;
  transition: transform .12s ease, background .12s ease, border-color .12s ease;
}
.map .lvl:hover {
  background: rgba(255, 255, 255, .1);
  border-color: rgba(255, 201, 77, .45);
  transform: translateY(-2px);
}
.map .lvl-num { font-weight: 700; font-size: 16px; }
.map .lvl-star { font-size: 10px; letter-spacing: 1px; color: var(--accent); }
.map .lvl-goal { font-size: 11px; opacity: .75; }
.map .lvl.locked { opacity: .45; cursor: not-allowed; }
.map .lvl.locked:hover { transform: none; background: rgba(255, 255, 255, .05); border-color: rgba(255, 255, 255, .1); }

.map .lvl-star { font-size: 11px; }
.map .lvl.locked .lvl-goal { display: none; }
.map .lvl.locked .lvl-star { font-size: 15px; opacity: .8; }

/* reto diario + tarjeta */
.daily {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin: 2px 0 14px; padding: 11px 14px; border-radius: 14px;
  background: linear-gradient(135deg, rgba(255,201,77,0.14), rgba(255,201,77,0.04));
  border: 1px solid rgba(255,201,77,0.28);
}
.daily-txt { display: flex; flex-direction: column; text-align: left; line-height: 1.25; }
.daily-txt b { font-size: 15px; color: var(--accent); }
.daily-txt span { font-size: 12px; opacity: .75; }
.daily-done { font-size: 14px; font-weight: 700; color: var(--accent2); }
.btn.small { padding: 7px 16px; font-size: 14px; }
.share-img {
  display: block; width: 100%; max-width: 320px; margin: 6px auto 14px;
  border-radius: 14px; box-shadow: 0 16px 40px rgba(0,0,0,.5);
}

/* Tanda 5: escarcha, recogida y mapa por mundos */
.map .world {
  margin: 12px 0 4px;
  font-size: 11px;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: var(--accent);
  opacity: .85;
  text-align: left;
}
.jc-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin: 0 3px;
  vertical-align: -1px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .35);
}
.jelly-chip .jc-text { white-space: nowrap; }
.lvl.goal-ice .lvl-goal { color: #8fd8ff; }
.lvl.goal-collect .lvl-goal { color: #ffb3d0; }

.panel.wide { width: min(560px, 100%); }
.panel.wide .map { grid-template-columns: repeat(5, 1fr); }
.panel .world {
  margin: 12px 0 4px;
  font-size: 11px;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: var(--accent);
  opacity: .85;
  text-align: left;
}
@media (max-width: 560px) {
  .panel.wide { width: 100%; }
  .panel.wide .map { grid-template-columns: repeat(4, 1fr); }
  .map .lvl { padding: 8px 4px; }
}
