* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: #fff;
  background:
    radial-gradient(circle at 15% 20%, rgba(255, 255, 255, .06) 0 2px, transparent 3px) 0 0 / 120px 120px,
    radial-gradient(circle at 70% 60%, rgba(255, 255, 255, .05) 0 2px, transparent 3px) 0 0 / 170px 170px,
    radial-gradient(ellipse at 50% -10%, #5a34c4 0%, #2a1668 50%, #140b3a 100%) fixed;
  background-color: #140b3a;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button {
  font: inherit;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}

#app {
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- Top bar ---------- */
#bar {
  display: flex;
  align-items: center;
  padding: 12px 14px 6px;
  padding: max(env(safe-area-inset-top), 12px) max(env(safe-area-inset-right), 14px) 6px max(env(safe-area-inset-left), 14px);
}

#levelLabel {
  flex: 1;
  text-align: center;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: .5px;
  text-shadow: 0 2px 8px rgba(0, 0, 0, .35);
  white-space: nowrap;
  margin: 0 10px;
}

.tools { display: flex; }
.tools .btn + .btn { margin-left: 10px; }

.btn {
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 18px;
  background: rgba(255, 255, 255, .14);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .18);
  color: #fff;
  display: grid;
  place-items: center;
  padding: 0;
  transition: transform .1s, background .2s, opacity .2s;
}
.btn:active { transform: scale(.9); background: rgba(255, 255, 255, .25); }
.btn:disabled { opacity: .3; }
.btn svg {
  width: 30px;
  height: 30px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.3;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.btn.nudge { animation: nudge .5s ease-in-out 3; background: rgba(255, 214, 10, .45); }

@media (max-width: 560px) {
  .btn { width: 44px; height: 44px; border-radius: 14px; }
  .btn svg { width: 24px; height: 24px; }
  .tools .btn + .btn { margin-left: 6px; }
  #levelLabel { font-size: 20px; }
}

/* ---------- Board & tubes ---------- */
#board {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 0 8px 14px;
  padding: 0 8px max(env(safe-area-inset-bottom), 14px);
}

.row { display: flex; justify-content: center; }

.slot {
  position: relative;
  width: calc(var(--tw) * 1.5);
  height: calc(var(--th) + var(--tw) * .95);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  cursor: pointer;
}

.bottle {
  position: relative;
  width: var(--tw);
  height: var(--th);
  transition: transform .22s cubic-bezier(.3, .7, .4, 1);
}
.bottle.selected { transform: translateY(calc(var(--tw) * -.45)); }
.bottle.pouring { z-index: 50; transition: transform .3s ease-in-out; }

.wob { position: absolute; top: 0; right: 0; bottom: 0; left: 0; }

/* rim of the tube */
.wob::before {
  content: "";
  position: absolute;
  top: calc(var(--bw) * -1.1);
  left: calc(var(--bw) * -1.7);
  right: calc(var(--bw) * -1.7);
  height: calc(var(--bw) * 2.3);
  border-radius: 999px;
  background: rgba(255, 255, 255, .85);
  z-index: 3;
}

.glass {
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  border: var(--bw) solid rgba(255, 255, 255, .7);
  border-top: 0;
  border-radius: 0 0 calc(var(--tw) / 2) calc(var(--tw) / 2);
  background: linear-gradient(90deg, rgba(255, 255, 255, .05), rgba(255, 255, 255, .14) 40%, rgba(255, 255, 255, .05));
  overflow: hidden;
  transition: box-shadow .3s, border-color .3s;
}
/* glass shine */
.glass::after {
  content: "";
  position: absolute;
  top: 7%;
  bottom: 14%;
  left: 15%;
  width: 13%;
  border-radius: 999px;
  background: linear-gradient(rgba(255, 255, 255, .6), rgba(255, 255, 255, .12));
  z-index: 2;
  pointer-events: none;
}
.bottle.selected .glass { border-color: #fff; box-shadow: 0 0 16px rgba(255, 255, 255, .55); }

.liquid {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column-reverse;
}

.seg {
  flex: none;
  height: var(--sh);
  background: linear-gradient(90deg, var(--cd) 0%, var(--c) 22%, var(--cl) 42%, var(--c) 64%, var(--cd) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition-property: height;
  transition-timing-function: linear;
  transition-duration: 0s;
}
.liquid .seg:last-child { box-shadow: inset 0 3px 0 rgba(255, 255, 255, .35); }

.sym {
  display: none;
  font-size: calc(var(--sh) * .5);
  line-height: 1;
  color: rgba(0, 0, 0, .38);
}
body.shapes .sym { display: block; }

/* finished tube */
.slot.done .glass { border-color: #fff6c2; box-shadow: 0 0 20px var(--glow, #fff); }
.star {
  position: absolute;
  left: 50%;
  bottom: calc(var(--th) + var(--tw) * .14);
  font-size: calc(var(--tw) * .5);
  line-height: 1;
  transform: translateX(-50%) scale(0);
  pointer-events: none;
}
.slot.done .star { animation: starPop .55s cubic-bezier(.2, 1.6, .4, 1) forwards; }

/* hint */
.arrow {
  display: none;
  position: absolute;
  left: 50%;
  bottom: calc(var(--th) + var(--tw) * .2);
  width: calc(var(--tw) * .7);
  height: calc(var(--tw) * .7);
  margin-left: calc(var(--tw) * -.35);
  pointer-events: none;
  z-index: 5;
}
.arrow svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: #ffd60a;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, .4));
}
.slot.hint-to .arrow { display: block; animation: bounce .6s ease-in-out infinite alternate; }
.slot.hint-from .wob { animation: bob .55s ease-in-out infinite alternate; }
.slot.hint-from .glass, .slot.hint-to .glass { border-color: #ffd60a; box-shadow: 0 0 18px rgba(255, 214, 10, .7); }

.wob.shake { animation: shake .35s ease-in-out; }
.slot.appear .bottle { animation: appear .45s cubic-bezier(.2, 1.4, .4, 1); }

.stream {
  position: absolute;
  z-index: 40;
  border-radius: 999px;
  transform-origin: 50% 0;
  transform: scaleY(0);
  transition: transform .12s ease-out;
  pointer-events: none;
}
.stream.on { transform: scaleY(1); }
.stream.off { transform-origin: 50% 100%; transform: scaleY(0); transition-duration: .15s; }

/* ---------- Toast ---------- */
#toast {
  position: absolute;
  left: 50%;
  bottom: 22px;
  bottom: max(env(safe-area-inset-bottom), 22px);
  transform: translate(-50%, 30px);
  opacity: 0;
  padding: 14px 24px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .95);
  color: #2a1860;
  font-size: 20px;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .3);
  transition: opacity .25s, transform .25s;
  pointer-events: none;
  z-index: 60;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Overlays ---------- */
#fx { position: fixed; top: 0; right: 0; bottom: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 120; }

.overlay {
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(10, 5, 35, .55);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}
.overlay.hidden { display: none; }

.card {
  position: relative;
  width: 100%;
  max-width: 440px;
  max-height: 100%;
  padding: 28px 26px 26px;
  border-radius: 30px;
  background: linear-gradient(#ffffff, #efe9ff);
  color: #2a1860;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .45);
  animation: cardIn .4s cubic-bezier(.2, 1.4, .4, 1);
}
.card h2 { margin: 6px 0 4px; font-size: 34px; }
.card h3 { margin: 22px 0 10px; font-size: 20px; }
.card p { margin: 0 0 18px; font-size: 20px; opacity: .8; }
.bigEmoji { font-size: 72px; line-height: 1; animation: wiggle 1.2s ease-in-out infinite; }

.cta {
  border: 0;
  border-radius: 999px;
  padding: 16px 36px;
  font-size: 24px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(#9b6bff, #6a3df0);
  box-shadow: 0 6px 0 #4a24b8, 0 10px 20px rgba(106, 61, 240, .4);
  transition: transform .1s, box-shadow .1s;
}
.cta:active { transform: translateY(4px); box-shadow: 0 2px 0 #4a24b8; }

.menu { display: flex; flex-direction: column; }
.menu .howto { font-size: 17px; line-height: 1.4; margin-bottom: 14px; }
.close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 46px;
  height: 46px;
  background: #ece6ff;
  color: #2a1860;
  box-shadow: none;
}
.toggles { display: flex; justify-content: center; flex-wrap: wrap; }
.toggles .toggle { margin: 5px; }
.toggle {
  border: 0;
  border-radius: 16px;
  padding: 12px 18px;
  font-size: 18px;
  font-weight: 700;
  background: #ece6ff;
  color: #2a1860;
}
.toggle.on { background: #6a3df0; color: #fff; }

#levelGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
  grid-gap: 10px;
  gap: 10px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  max-height: 42vh;
  padding: 4px;
}
.lvl {
  height: 60px;
  border: 0;
  border-radius: 16px;
  font-size: 22px;
  font-weight: 800;
  background: #ece6ff;
  color: #2a1860;
}
.lvl.current { background: #6a3df0; color: #fff; }
.lvl.new { background: #ffd60a; }

/* ---------- Animations ---------- */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px) rotate(-3deg); }
  40% { transform: translateX(6px) rotate(3deg); }
  60% { transform: translateX(-4px) rotate(-2deg); }
  80% { transform: translateX(3px); }
}
@keyframes bob { from { transform: translateY(0); } to { transform: translateY(calc(var(--tw) * -.25)); } }
@keyframes bounce { from { transform: translateY(0); } to { transform: translateY(calc(var(--tw) * -.25)); } }
@keyframes starPop {
  0% { transform: translateX(-50%) scale(0) rotate(-90deg); }
  100% { transform: translateX(-50%) scale(1) rotate(0); }
}
@keyframes appear { from { transform: scale(0); } to { transform: scale(1); } }
@keyframes cardIn { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes wiggle { 0%, 100% { transform: rotate(-8deg); } 50% { transform: rotate(8deg) scale(1.08); } }
@keyframes nudge { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.18); } }
