:root {
  --bg1: #0b1033;
  --bg2: #141c52;
  --glass: rgba(170, 200, 255, 0.55);
  --glass-dim: rgba(170, 200, 255, 0.22);
  --text: #eef2ff;
  --muted: #9aa6d6;
  --accent: #4f8cff;
  --accent2: #2f5fe0;
  --bw: 48px;   /* ancho de botella (lo ajusta game.js) */
  --seg: 32px;  /* alto de un segmento */
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg1);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(ellipse 90% 60% at 50% 45%, #1b2670 0%, transparent 70%),
    radial-gradient(circle at 15% 20%, rgba(255,255,255,0.035) 0 2px, transparent 3px) 0 0 / 46px 46px,
    radial-gradient(circle at 70% 60%, rgba(255,255,255,0.03) 0 1.5px, transparent 2.5px) 0 0 / 31px 31px,
    linear-gradient(180deg, var(--bg2), var(--bg1));
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: max(10px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  max-width: 560px;
  margin: 0 auto;
}

/* ---------- HUD ---------- */

.hud { flex: none; }
.hud-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
}
.moves { display: flex; flex-direction: column; line-height: 1.1; }
.moves-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.moves-num { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; }

.level-badge {
  padding: 8px 22px;
  border-radius: 14px;
  background: linear-gradient(180deg, #1d2a7a, #121a55);
  border: 2px solid var(--accent);
  box-shadow: 0 0 0 3px rgba(79,140,255,.18), inset 0 2px 0 rgba(255,255,255,.08);
  font-size: 22px;
  font-weight: 800;
  white-space: nowrap;
}
.level-badge span { font-weight: 700; opacity: .85; }

.icon-btn {
  justify-self: end;
  width: 44px; height: 44px;
  border-radius: 50%;
  border: none;
  color: #fff;
  background: radial-gradient(circle at 35% 30%, #6aa0ff, var(--accent2));
  box-shadow: 0 3px 0 #1d3a9a, 0 6px 14px rgba(0,0,0,.35);
  display: grid; place-items: center;
}

.difficulty {
  margin: 10px auto 0;
  width: min(100%, 300px);
}
.diff-top {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 13px; color: var(--muted);
}
#diff-label { font-weight: 700; color: var(--text); }
.challenge {
  font-size: 11px; font-weight: 800; color: #1a1300;
  background: #ffd23f; border-radius: 99px; padding: 2px 8px;
}
.stars { letter-spacing: 1px; color: #ffd23f; font-size: 13px; }
.stars .off { color: rgba(255,255,255,.18); }
.diff-bar {
  margin-top: 5px; height: 7px; border-radius: 99px;
  background: rgba(255,255,255,.1); overflow: hidden;
}
#diff-fill {
  height: 100%; width: 0;
  border-radius: 99px;
  background: linear-gradient(90deg, #4ade80, #ffd23f 45%, #ff8a1f 70%, #ff3d5a);
  background-size: 300px 100%;
  transition: width .5s ease;
}

/* ---------- tablero ---------- */

#board {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: calc(var(--seg) * 1.1);
  padding-top: calc(var(--seg) * 0.8);
}
.shelf {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: calc(var(--bw) * 0.42);
}

.bottle {
  position: relative;
  width: var(--bw);
  height: calc(var(--bw) * 0.36 + var(--seg) * (var(--cap, 4) + 0.45));
  transition: transform .26s cubic-bezier(.3,.7,.4,1);
  transform-origin: 50% 50%;
  cursor: pointer;
}
.bottle.selected { transform: translateY(calc(var(--seg) * -0.6)); }
.bottle.pouring { z-index: 40; transition: none; will-change: transform; }

/* boca y cuello */
.bottle .lip {
  position: absolute; top: 0; left: 50%;
  width: calc(var(--bw) * 0.5);
  height: calc(var(--bw) * 0.12);
  transform: translateX(-50%);
  border-radius: 5px;
  border: 2px solid var(--glass);
  background: rgba(150, 180, 255, .16);
}
.bottle .neck {
  position: absolute; left: 50%;
  top: calc(var(--bw) * 0.1);
  width: calc(var(--bw) * 0.36);
  height: calc(var(--bw) * 0.28);
  transform: translateX(-50%);
  border-left: 2px solid var(--glass);
  border-right: 2px solid var(--glass);
  background: rgba(150, 180, 255, .06);
}
.bottle .body {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: calc(var(--seg) * (var(--cap, 4) + 0.45));
  border: 2px solid var(--glass);
  border-radius: calc(var(--bw) * 0.34) calc(var(--bw) * 0.34) calc(var(--bw) * 0.3) calc(var(--bw) * 0.3);
  background: linear-gradient(90deg, rgba(150,180,255,.08), rgba(150,180,255,.02) 40%, rgba(150,180,255,.1));
  box-shadow: inset 0 -6px 12px rgba(0,0,0,.25), 0 6px 14px rgba(0,0,0,.25);
}
.bottle .liquid {
  position: absolute; left: 3px; right: 3px; bottom: 3px; top: 3px;
  border-radius: calc(var(--bw) * 0.3) calc(var(--bw) * 0.3) calc(var(--bw) * 0.26) calc(var(--bw) * 0.26);
  overflow: hidden;
}
.bottle .shine {
  position: absolute; top: 12%; bottom: 10%; left: 16%;
  width: 11%;
  border-radius: 99px;
  background: linear-gradient(180deg, rgba(255,255,255,.4), rgba(255,255,255,.08));
  pointer-events: none;
}
.bottle .shine2 {
  position: absolute; top: 18%; height: 18%; right: 14%;
  width: 6%;
  border-radius: 99px;
  background: rgba(255,255,255,.22);
  pointer-events: none;
}

.seg {
  position: absolute; left: 0; right: 0;
  height: var(--seg);
  background-color: var(--c);
  transition: height .42s ease-in-out;
}
.seg::before { /* volumen del líquido */
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, rgba(0,0,0,.18), rgba(255,255,255,.12) 35%, rgba(0,0,0,.22));
}
.seg.top::after { /* superficie */
  content: ""; position: absolute; left: 0; right: 0; top: 0;
  height: calc(var(--seg) * 0.16);
  background: rgba(255,255,255,.28);
  border-radius: 0 0 50% 50% / 0 0 100% 100%;
}

/* texturas opcionales (para distinguir sin depender sólo del color) */
body.textures .seg { background-image: var(--tex); background-size: var(--texs, 9px 9px); }

/* botella completa: tapón */
.cap {
  position: absolute; left: 50%; top: calc(var(--bw) * -0.12);
  width: calc(var(--bw) * 0.44);
  height: calc(var(--bw) * 0.3);
  transform: translateX(-50%) scale(0);
  border-radius: 6px 6px 4px 4px;
  background: linear-gradient(180deg, #c98a4b, #8a5426);
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.25), 0 2px 4px rgba(0,0,0,.4);
  transition: transform .3s cubic-bezier(.3,1.6,.5,1);
}
.bottle.done .cap { transform: translateX(-50%) scale(1); }
.bottle.done .body { border-color: rgba(255, 230, 150, .75); }

/* botellita "+¼" (petaca) */
.bottle.mini { height: calc(var(--bw) * 0.32 + var(--seg) * 1.5); width: calc(var(--bw) * 1.05); }
.bottle.mini .body {
  height: calc(var(--seg) * 1.5);
  border-radius: calc(var(--bw) * 0.22) calc(var(--bw) * 0.22) calc(var(--bw) * 0.16) calc(var(--bw) * 0.16);
  border-style: solid;
  border-color: rgba(255, 210, 63, .6);
}
.bottle.mini .liquid { border-radius: calc(var(--bw) * 0.18) calc(var(--bw) * 0.18) calc(var(--bw) * 0.12) calc(var(--bw) * 0.12); }
.bottle.mini .neck { top: calc(var(--bw) * 0.08); height: calc(var(--bw) * 0.26); width: calc(var(--bw) * 0.3); }
.bottle.mini .lip { width: calc(var(--bw) * 0.42); border-color: rgba(255, 210, 63, .6); }
.bottle.mini .tag {
  position: absolute; left: 50%; bottom: calc(var(--seg) * -0.62);
  transform: translateX(-50%);
  font-size: 11px; font-weight: 800; color: #ffd23f; opacity: .85;
}
.bottle.mini.appear { animation: appear .45s cubic-bezier(.3,1.5,.5,1); }
@keyframes appear { from { transform: scale(.2); opacity: 0; } }

/* pista */
.bottle.hint-src { animation: hintSrc 0.9s ease-in-out infinite; }
.bottle.hint-src .body, .bottle.hint-dst .body {
  border-color: #7cf3ff;
  box-shadow: 0 0 0 3px rgba(124,243,255,.25), 0 0 18px rgba(124,243,255,.55);
}
.bottle.hint-dst .body { border-style: dashed; }
@keyframes hintSrc { 50% { transform: translateY(calc(var(--seg) * -0.35)); } }

.bottle.shake { animation: shake .3s; }
@keyframes shake {
  25% { transform: translateX(-5px); } 75% { transform: translateX(5px); }
}

/* chorro */
#fx { position: fixed; inset: 0; pointer-events: none; z-index: 30; }
.stream {
  position: absolute;
  border-radius: 99px;
  transform-origin: 50% 0;
  transform: scaleY(0);
  will-change: transform;
}

/* ---------- avisos ---------- */

.banner {
  position: fixed; left: 50%; top: calc(max(10px, env(safe-area-inset-top)) + 112px);
  transform: translateX(-50%);
  width: min(92vw, 420px);
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(40, 14, 40, .94);
  border: 2px solid #ff5d7a;
  box-shadow: 0 10px 30px rgba(0,0,0,.45);
  text-align: center;
  z-index: 20;
  animation: slideUp .25s ease-out;
}
#banner-text { font-weight: 700; margin-bottom: 10px; }
#banner-text small { display: block; font-weight: 400; color: #f3c3cf; margin-top: 3px; }
.banner-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
@keyframes slideUp { from { transform: translate(-50%, -14px); opacity: 0; } }

.tip {
  position: fixed; left: 50%; top: calc(max(10px, env(safe-area-inset-top)) + 118px);
  transform: translateX(-50%);
  width: max-content; max-width: 88vw;
  padding: 8px 14px;
  border-radius: 12px;
  background: rgba(20, 30, 90, .9);
  border: 1px solid rgba(124, 160, 255, .5);
  color: #dfe6ff; font-size: 14px; text-align: center;
  z-index: 15; pointer-events: none;
  animation: slideUp .25s ease-out;
}

/* ---------- controles ---------- */

.controls {
  flex: none;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding-top: 8px;
}
.ctl {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 4px 8px;
  border: none; border-radius: 18px;
  color: #fff;
  background: linear-gradient(180deg, #4f8cff, #2c58d6);
  box-shadow: 0 4px 0 #1b3a9a, 0 8px 16px rgba(0,0,0,.35), inset 0 2px 0 rgba(255,255,255,.25);
  font: inherit; font-size: 12px; font-weight: 700;
}
.ctl:active { transform: translateY(3px); box-shadow: 0 1px 0 #1b3a9a, inset 0 2px 0 rgba(255,255,255,.25); }
.ctl svg { width: 28px; height: 28px; }
.ctl .quarter { font-size: 22px; line-height: 28px; height: 28px; }
.ctl:disabled { filter: grayscale(.8) brightness(.6); box-shadow: none; transform: none; }

.pill {
  border: none; border-radius: 99px;
  padding: 10px 16px;
  font: inherit; font-weight: 700; font-size: 14px;
  color: #fff;
  background: linear-gradient(180deg, #4f8cff, #2c58d6);
  box-shadow: 0 3px 0 #1b3a9a;
}
.pill.ghost { background: rgba(255,255,255,.1); box-shadow: none; }
.pill.danger { background: rgba(255, 70, 100, .2); color: #ffb3c1; box-shadow: none; }
.pill.big { font-size: 18px; padding: 14px 28px; }
.pill:disabled { opacity: .35; }

/* ---------- overlays ---------- */

.overlay {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center;
  background: rgba(5, 8, 30, .7);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
.overlay[hidden], .banner[hidden], .tip[hidden], .loading[hidden] { display: none; }
.card {
  width: min(88vw, 360px);
  padding: 22px 20px;
  border-radius: 22px;
  background: linear-gradient(180deg, #1d2a7a, #111850);
  border: 2px solid var(--accent);
  box-shadow: 0 20px 50px rgba(0,0,0,.5);
  display: flex; flex-direction: column; gap: 12px; align-items: stretch;
  text-align: center;
  animation: pop .3s cubic-bezier(.3,1.5,.5,1);
}
@keyframes pop { from { transform: scale(.8); opacity: 0; } }
.win-title { font-size: 28px; font-weight: 900; color: #ffd23f; }
.win-sub { color: var(--muted); }
.card-title { font-size: 20px; font-weight: 800; }
.row { display: flex; gap: 10px; align-items: center; justify-content: center; }
.row input { width: 20px; height: 20px; }
.level-nav .pill { flex: 1; font-size: 13px; }

.loading {
  position: fixed; inset: 0; z-index: 70;
  display: flex; flex-direction: column; gap: 14px; align-items: center; justify-content: center;
  background: rgba(5, 8, 30, .55);
  color: var(--muted);
}
.spinner {
  width: 40px; height: 40px; border-radius: 50%;
  border: 4px solid rgba(255,255,255,.15);
  border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.confetti {
  position: absolute; width: 8px; height: 12px; border-radius: 2px;
  animation: fall 1.4s cubic-bezier(.2,.6,.4,1) forwards;
}
@keyframes fall {
  to { transform: translate(var(--dx), 110vh) rotate(var(--rot)); opacity: .8; }
}

/* ---------- complicaciones ---------- */

.moves-num.warn { color: #ff6b81; }

/* segmentos "?" */
.seg.hidden {
  background: #3a4266;
  background-image: none !important;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.08);
}
.seg.hidden::before { background: linear-gradient(90deg, rgba(0,0,0,.25), rgba(255,255,255,.06) 35%, rgba(0,0,0,.3)); }
.seg.hidden::after {
  content: "?";
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-weight: 900;
  font-size: calc(var(--seg) * 0.55);
  color: rgba(220, 228, 255, .75);
}

/* capacidades distintas: número chiquito abajo */
.bottle.cap3 .tag, .bottle.cap5 .tag {
  position: absolute; left: 50%; bottom: calc(var(--seg) * -0.62);
  transform: translateX(-50%);
  font-size: 11px; font-weight: 800; color: var(--muted);
}

/* botella fija: base de metal atornillada */
.bottle.fixed .body { border-color: rgba(200, 210, 230, .85); }
.bottle.fixed .plate {
  position: absolute; left: -10%; right: -10%;
  bottom: calc(var(--seg) * -0.32);
  height: calc(var(--seg) * 0.32);
  border-radius: 4px;
  background: linear-gradient(180deg, #d9dfec, #7d8699 60%, #5b6376);
  box-shadow: 0 3px 6px rgba(0,0,0,.4);
  display: flex; justify-content: space-between; align-items: center;
  padding: 0 12%;
}
.bottle.fixed .plate i {
  width: 5px; height: 5px; border-radius: 50%;
  background: #3d4455; box-shadow: inset 0 1px 0 rgba(255,255,255,.4);
}
.bottle.fixed.shake { animation: shakeFixed .3s; }
@keyframes shakeFixed { 25% { transform: rotate(-2deg); } 75% { transform: rotate(2deg); } }

/* candado */
.lockbox {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: calc(var(--seg) * (var(--cap, 4) + 0.45));
  border-radius: calc(var(--bw) * 0.34) calc(var(--bw) * 0.34) calc(var(--bw) * 0.3) calc(var(--bw) * 0.3);
  background:
    repeating-linear-gradient(135deg, rgba(10,14,40,.0) 0 9px, rgba(10,14,40,.35) 9px 12px),
    rgba(10, 14, 40, .38);
  display: grid; place-items: center;
  pointer-events: none;
  transition: opacity .5s ease;
}
.lockbox svg {
  width: calc(var(--bw) * 0.62); height: calc(var(--bw) * 0.62);
  filter: drop-shadow(0 3px 4px rgba(0,0,0,.5));
  transition: transform .5s cubic-bezier(.3,1.4,.5,1), opacity .5s;
}
.bottle.locked .body { border-color: rgba(170, 200, 255, .3); }
.bottle.unlocked .lockbox { opacity: 0; }
.bottle.unlocking .lockbox { animation: unlockFade .7s ease forwards; }
.bottle.unlocking .lockbox svg { animation: unlockFly .7s ease forwards; }
@keyframes unlockFade { from { opacity: 1; } to { opacity: 0; } }
@keyframes unlockFly { 40% { transform: translateY(-6px) scale(1.15); opacity: 1; } to { transform: translateY(-40px) scale(.6); opacity: 0; } }

/* toque anotado durante un volcado */
.bottle.queued .body {
  border-color: #ffd23f;
  box-shadow: 0 0 0 3px rgba(255, 210, 63, .25), 0 0 14px rgba(255, 210, 63, .45);
}

/* ir a cualquier nivel */
.level-go input {
  width: 84px; padding: 9px 10px;
  border-radius: 12px; border: 2px solid var(--accent);
  background: #0e1546; color: var(--text);
  font: inherit; font-size: 16px; font-weight: 700; text-align: center;
}
.level-go label { font-weight: 700; }
