/* Potion Pour — styles */

:root {
  --bg-deep: #0f0a07;
  --bg: #1a120d;
  --wood: #4a2f1c;
  --wood-light: #6e4628;
  --ink: #f6e9d2;
  --ink-soft: #d4bd9b;
  --ink-mute: #9c8569;
  --gold: #f2b84b;
  --gold-hi: #ffd98a;
  --ember: #e86a2c;
  --panel: #241912;
  --panel-edge: rgba(242, 184, 75, 0.28);
  --glass: rgba(255, 244, 225, 0.55);
  --glass-soft: rgba(255, 244, 225, 0.18);
  --danger: #e5484d;
  --parchment: #ecdcb8;
  --parchment-dark: #d6bf90;
  --parchment-ink: #4a3220;

  --font-display: "Palatino Linotype", Palatino, "Book Antiqua", "Iowan Old Style", "URW Palladio L", Georgia, serif;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;

  --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);

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg-deep);
}

body {
  color: var(--ink);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  position: fixed;
  inset: 0;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}
button:focus { outline: none; }
button:focus-visible { outline: 2px solid var(--gold-hi); outline-offset: 2px; }

svg { display: block; }

/* ---------- Workshop backdrop ---------- */

.workshop {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background:
    radial-gradient(ellipse 120% 60% at 50% 120%, rgba(110, 56, 24, 0.55), transparent 70%),
    repeating-linear-gradient(0deg, transparent 0 46px, rgba(0, 0, 0, 0.18) 46px 48px),
    repeating-linear-gradient(90deg, transparent 0 94px, rgba(0, 0, 0, 0.12) 94px 96px),
    linear-gradient(180deg, #22170f 0%, #170f0a 55%, #0e0906 100%);
}
.workshop::after { /* vignette */
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 85% 75% at 50% 45%, transparent 55%, rgba(0, 0, 0, 0.6) 100%);
}
.lantern {
  position: absolute;
  width: 90vmax;
  height: 90vmax;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255, 168, 72, 0.22), rgba(255, 140, 50, 0.08) 45%, transparent 70%);
  animation: flicker 5s ease-in-out infinite;
}
.lantern-a { left: -45vmax; top: -50vmax; }
.lantern-b { right: -50vmax; top: -35vmax; animation-delay: -2.3s; animation-duration: 6.5s; opacity: 0.75; }
@keyframes flicker {
  0%, 100% { opacity: 1; }
  40% { opacity: 0.86; }
  55% { opacity: 0.95; }
  70% { opacity: 0.82; }
}
.motes i {
  position: absolute;
  bottom: -10px;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: #ffcf80;
  box-shadow: 0 0 6px 1px rgba(255, 190, 90, 0.7);
  opacity: 0;
  animation: mote 14s linear infinite;
}
.motes i:nth-child(1) { left: 8%; animation-delay: 0s; }
.motes i:nth-child(2) { left: 22%; animation-delay: -4s; animation-duration: 17s; }
.motes i:nth-child(3) { left: 41%; animation-delay: -9s; }
.motes i:nth-child(4) { left: 58%; animation-delay: -2s; animation-duration: 19s; }
.motes i:nth-child(5) { left: 73%; animation-delay: -11s; }
.motes i:nth-child(6) { left: 88%; animation-delay: -6s; animation-duration: 16s; }
.motes i:nth-child(7) { left: 95%; animation-delay: -13s; }
@keyframes mote {
  0% { transform: translate3d(0, 0, 0); opacity: 0; }
  10% { opacity: 0.7; }
  80% { opacity: 0.4; }
  100% { transform: translate3d(30px, -105vh, 0); opacity: 0; }
}

/* ---------- App shell ---------- */

#app {
  position: fixed;
  inset: 0;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
}
.screen {
  position: absolute;
  inset: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
  display: flex;
  flex-direction: column;
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: opacity 0.28s var(--ease-out), transform 0.28s var(--ease-out), visibility 0s linear 0.28s;
}
/* Don't spend frames animating screens nobody can see. */
.screen:not(.is-active),
.screen:not(.is-active) * { animation-play-state: paused !important; }
.screen.is-active {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition: opacity 0.28s var(--ease-out), transform 0.28s var(--ease-out), visibility 0s;
}

.bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 12px 4px;
  min-height: 60px;
  flex: none;
  position: relative;
  z-index: 5;
}
.bar-spacer { flex: 1; }
.bar-title {
  flex: 1;
  margin: 0;
  text-align: center;
  font: 600 1.3rem/1 var(--font-display);
  letter-spacing: 0.04em;
  color: var(--gold-hi);
}

.icon-btn {
  position: relative;
  width: 48px;
  height: 48px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 14px;
  color: var(--ink);
  background: linear-gradient(180deg, rgba(255, 236, 205, 0.09), rgba(255, 236, 205, 0.03));
  box-shadow: inset 0 0 0 1px rgba(255, 228, 185, 0.14), 0 2px 6px rgba(0, 0, 0, 0.3);
  transition: transform 0.12s, background-color 0.2s, opacity 0.2s;
}
.icon-btn svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-btn:active { transform: scale(0.92); }
.icon-btn[aria-disabled="true"] { opacity: 0.38; }
.icon-btn.ink { color: var(--parchment-ink); background: rgba(74, 50, 32, 0.08); box-shadow: inset 0 0 0 1px rgba(74, 50, 32, 0.18); }
.icon-btn.ink[aria-disabled="true"] { opacity: 0.25; }
.badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 9px;
  font: 700 11px/17px var(--font-ui);
  text-align: center;
  color: #2b1a0c;
  background: var(--gold);
  box-shadow: 0 0 6px rgba(242, 184, 75, 0.6);
}
.icon-btn[aria-disabled="true"] .badge { background: var(--ink-mute); box-shadow: none; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 52px;
  padding: 0 26px;
  border-radius: 999px;
  font-weight: 650;
  font-size: 1.05rem;
  letter-spacing: 0.01em;
  transition: transform 0.12s, filter 0.2s;
}
.btn svg { width: 20px; height: 20px; fill: currentColor; stroke: none; }
.btn:active { transform: scale(0.96); }
.btn-primary {
  color: #2b1608;
  background: linear-gradient(180deg, #ffe0a0 0%, #f2b84b 48%, #d98a2b 100%);
  box-shadow: 0 0 0 1px rgba(255, 230, 170, 0.6) inset, 0 6px 22px rgba(242, 160, 60, 0.38), 0 2px 0 #9a5a1c;
}
.btn-ghost {
  color: var(--ink);
  background: rgba(255, 236, 205, 0.06);
  box-shadow: inset 0 0 0 1.5px rgba(242, 184, 75, 0.4);
}
.btn-ghost svg { fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.btn-danger {
  color: #ffd9d4;
  background: rgba(229, 72, 77, 0.12);
  box-shadow: inset 0 0 0 1.5px rgba(229, 72, 77, 0.45);
  font-size: 0.95rem;
  min-height: 48px;
}
.btn-danger.armed { background: var(--danger); color: #fff; }

/* ---------- Home ---------- */

.home-hero {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  min-height: 0;
}
.logo-flask {
  width: min(42vw, 26vh, 190px);
  height: auto;
  overflow: visible;
  filter: drop-shadow(0 0 18px rgba(255, 170, 70, 0.35));
  animation: bob 4s ease-in-out infinite;
}
@keyframes bob { 50% { transform: translateY(-6px) rotate(-2deg); } }
.logo-wave { animation: wave 3s ease-in-out infinite; }
@keyframes wave { 50% { transform: translateX(-14px); } }
.logo-bubble { animation: bubble 2.6s ease-in infinite; }
.logo-bubble.b2 { animation-delay: -0.9s; animation-duration: 3.1s; }
.logo-bubble.b3 { animation-delay: -1.7s; }
@keyframes bubble {
  0% { transform: translateY(0); opacity: 0; }
  20% { opacity: 0.85; }
  100% { transform: translateY(-46px); opacity: 0; }
}
.title {
  margin: 14px 0 0;
  font: 700 clamp(2.6rem, 13vw, 4.2rem)/0.95 var(--font-display);
  letter-spacing: 0.02em;
  text-align: center;
  background: linear-gradient(180deg, #fff1c9 0%, #ffcf6b 45%, #e98a2e 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 14px rgba(255, 170, 60, 0.45)) drop-shadow(0 3px 0 rgba(60, 25, 5, 0.9));
}
.title span { display: inline-block; }
.tagline {
  margin: 10px 0 0;
  font: italic 1.05rem var(--font-display);
  color: var(--ink-soft);
  letter-spacing: 0.03em;
}
.home-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 8px 24px 28px;
}
.home-actions .btn { width: min(100%, 300px); }
#btn-play { min-height: 64px; font-size: 1.3rem; position: relative; overflow: hidden; }
#btn-play::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 40%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.55), transparent);
  transform: translateX(-150%) skewX(-20deg);
  animation: playSheen 4.5s ease-in-out 1.2s infinite;
}
@keyframes playSheen { 0%, 70% { transform: translateX(-150%) skewX(-20deg); } 100% { transform: translateX(320%) skewX(-20deg); } }
.logo-flask { cursor: pointer; }
#btn-play small { font-weight: 600; font-size: 0.85rem; opacity: 0.75; margin-left: 2px; }
.home-stars {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 4px 0 0;
  color: var(--ink-soft);
  font-weight: 600;
}
.home-stars svg { width: 18px; height: 18px; fill: var(--gold); }

/* ---------- Recipe book ---------- */

.book {
  flex: 1;
  min-height: 0;
  padding: 6px 14px 18px;
  display: flex;
}
.book-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-width: 560px;
  margin: 0 auto;
  border-radius: 6px 14px 14px 6px;
  color: var(--parchment-ink);
  background:
    radial-gradient(ellipse at 20% 10%, rgba(255, 250, 235, 0.55), transparent 60%),
    radial-gradient(ellipse at 90% 95%, rgba(150, 100, 50, 0.22), transparent 55%),
    linear-gradient(90deg, rgba(90, 55, 25, 0.25), transparent 6%),
    var(--parchment);
  box-shadow:
    0 0 0 4px #5a3820,
    0 0 0 7px #3a2312,
    -6px 0 0 7px #2a190d,
    0 18px 40px rgba(0, 0, 0, 0.55);
  padding: 14px 14px 16px 18px;
}
.chapter-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 10px;
  margin-bottom: 12px;
  border-bottom: 1.5px dashed rgba(74, 50, 32, 0.3);
}
.chapter-head { flex: 1; text-align: center; }
.chapter-head h3 { margin: 0; font: 700 1.35rem/1.1 var(--font-display); letter-spacing: 0.03em; }
.chapter-head p { margin: 2px 0 0; font: italic 0.9rem var(--font-display); color: rgba(74, 50, 32, 0.72); }
.level-grid {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(58px, 1fr));
  gap: 10px;
  align-content: start;
  padding: 6px 6px 4px;
}
.level-cell {
  position: relative;
  aspect-ratio: 1 / 1.1;
  min-height: 56px;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--parchment-ink);
  background: linear-gradient(180deg, rgba(255, 250, 238, 0.7), rgba(230, 210, 170, 0.6));
  box-shadow: inset 0 0 0 1.5px rgba(74, 50, 32, 0.28), 0 2px 0 rgba(74, 50, 32, 0.2);
  transition: transform 0.12s;
}
.level-cell:active { transform: scale(0.94); }
.level-cell { animation: cellIn 0.42s var(--ease-spring) both; animation-delay: calc(var(--i, 0) * 16ms); }
@keyframes cellIn { from { opacity: 0; transform: translateY(10px) scale(0.85); } }
.level-cell.current { animation: cellIn 0.42s var(--ease-spring) both, currentGlow 2.2s ease-in-out 0.6s infinite; animation-delay: calc(var(--i, 0) * 16ms), 0.6s; }
@keyframes currentGlow { 50% { box-shadow: inset 0 0 0 2px #b8741d, 0 0 22px rgba(242, 160, 50, 0.85); } }
.level-cell .num { font: 700 1.25rem/1 var(--font-display); }
.level-cell .stars { display: flex; gap: 1px; }
.level-cell .stars svg { width: 11px; height: 11px; fill: rgba(74, 50, 32, 0.22); }
.level-cell .stars svg.on { fill: #c9871f; filter: drop-shadow(0 0 2px rgba(201, 135, 31, 0.5)); }
.level-cell.current {
  background: linear-gradient(180deg, #fff3cf, #f6cd76);
  box-shadow: inset 0 0 0 2px #b8741d, 0 0 14px rgba(242, 160, 50, 0.6);
}
.level-cell.locked {
  color: rgba(74, 50, 32, 0.35);
  background: rgba(120, 85, 50, 0.08);
  box-shadow: inset 0 0 0 1.5px rgba(74, 50, 32, 0.12);
  cursor: default;
}
.level-cell.locked svg.lock { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; }
.level-cell .tag {
  position: absolute;
  top: -5px;
  right: -5px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  font: 700 11px/18px var(--font-display);
  text-align: center;
  color: #fff;
}
.level-cell .tag-mystery { background: #6c5f7c; }
.level-cell .tag-seal { background: radial-gradient(circle at 38% 34%, #e0574a, #a8231f 60%, #6e1010); box-shadow: 0 1px 2px rgba(60, 20, 10, 0.4); }

/* ---------- Game ---------- */

.game-bar { gap: 4px; padding-left: 8px; padding-right: 8px; }
.level-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding-left: 4px;
  line-height: 1.15;
}
.level-info strong { font: 700 1.15rem var(--font-display); color: var(--gold-hi); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.level-info span { font-size: 0.8rem; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.actions { display: flex; gap: 4px; }
#btn-hint[hidden] { display: none; }

.board {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 0 8px 12px;
  gap: var(--row-gap, 24px);
}
.row {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: flex-end;
}
.row::after { /* wooden shelf */
  content: "";
  position: absolute;
  left: -10px;
  right: -10px;
  bottom: calc(var(--fw) * -0.18);
  height: calc(var(--fw) * 0.24);
  min-height: 9px;
  border-radius: 4px;
  background: linear-gradient(180deg, #8a5a33 0%, #5c3a20 45%, #3b2414 100%);
  box-shadow: 0 8px 14px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 210, 160, 0.25);
  z-index: 0;
}

/* Flask */
.flask {
  position: relative;
  z-index: 1;
  width: var(--slot);
  height: var(--slot-h);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.flask.pouring { z-index: 40; }
.fi {
  position: relative;
  width: var(--fw);
  transform-origin: 50% 0;
  transition: transform 0.16s var(--ease-out);
  will-change: transform;
}
.flask.selected .fi {
  transform: translateY(var(--lift));
  animation: float 1.8s ease-in-out 0.25s infinite;
}
.flask.selected .aura { opacity: 0.95; }
@keyframes float { 50% { translate: 0 -3px; } }
.flask:not(.selected):not(.pouring):active .fi { transform: scale(0.96); transition-duration: 0.08s; }
.flask.nope .rim,
.flask.nope .tube { animation: nope 0.45s ease-out; }
@keyframes nope {
  25% { box-shadow: inset 0 0 0 1.5px rgba(255, 120, 110, 0.9), 0 0 14px 2px rgba(229, 72, 77, 0.55); }
}
.flask.pouring .fi { transition: none; }

.rim {
  position: relative;
  z-index: 2;
  height: calc(var(--fw) * 0.16);
  margin: 0 calc(var(--fw) * -0.07);
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(255, 248, 235, 0.55), rgba(255, 248, 235, 0.18));
  box-shadow: inset 0 0 0 1.5px var(--glass), 0 1px 2px rgba(0, 0, 0, 0.3);
}
.tube {
  position: relative;
  z-index: 1;
  height: var(--tube-h);
  margin-top: -2px;
  border-radius: 0 0 calc(var(--fw) * 0.5) calc(var(--fw) * 0.5);
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.02) 40%, rgba(255, 255, 255, 0.08));
  box-shadow: inset 0 0 0 1.5px var(--glass), inset 0 -6px 12px rgba(255, 255, 255, 0.05), 0 6px 14px rgba(0, 0, 0, 0.35);
}
.liquid {
  position: absolute;
  left: 3px;
  right: 3px;
  bottom: 3px;
  height: calc(var(--lh) * var(--cap));
  border-radius: 0 0 calc(var(--fw) * 0.5 - 3px) calc(var(--fw) * 0.5 - 3px);
  overflow: hidden;
}
.layer {
  position: absolute;
  left: 0;
  right: 0;
  height: calc(var(--lh) + 1px);
  transform-origin: 50% 100%;
  background: linear-gradient(90deg, var(--d) 0%, var(--c) 26%, var(--l) 46%, var(--c) 68%, var(--d) 100%);
  box-shadow: inset 0 0 calc(var(--lh) * 0.35) rgba(255, 255, 255, 0.12);
}
.layer.top { height: var(--lh); }
.meniscus { /* liquid surface; sloshes via JS */
  position: absolute;
  z-index: 1;
  left: 6%;
  right: 6%;
  top: 0;
  height: 3px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.55);
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.6);
  transform-origin: 50% 50%;
}
.sheen {
  position: absolute;
  z-index: 2;
  top: -10%;
  bottom: -10%;
  left: 0;
  width: 45%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.55), transparent);
  pointer-events: none;
}
.layer.seam { box-shadow: inset 0 0 calc(var(--lh) * 0.35) rgba(255, 255, 255, 0.12), inset 0 -1px 0 rgba(0, 0, 0, 0.18); }
.layer .sym {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--sym);
  height: var(--sym);
  margin: calc(var(--sym) / -2) 0 0 calc(var(--sym) / -2);
  fill: var(--ink-c);
  color: var(--ink-c);
}
.layer.mystery {
  overflow: hidden;
  background: radial-gradient(circle at 50% 50%, #8e7f9d 0%, #625770 55%, #4a4157 100%);
}
.layer.mystery .swirl {
  position: absolute;
  left: 50%;
  top: 50%;
  width: calc(var(--fw) * 1.6);
  height: calc(var(--fw) * 1.6);
  margin: calc(var(--fw) * -0.8) 0 0 calc(var(--fw) * -0.8);
  border-radius: 50%;
  background: repeating-conic-gradient(rgba(255, 255, 255, 0.13) 0 18deg, transparent 18deg 45deg);
  animation: swirl 7s linear infinite;
}
.layer.mystery::after {
  content: "?";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font: 700 calc(var(--lh) * 0.6) / 1 var(--font-display);
  color: rgba(255, 255, 255, 0.82);
  text-shadow: 0 0 6px rgba(200, 180, 255, 0.7);
}
@keyframes swirl { to { transform: rotate(360deg); } }
.layer.revealing { animation: reveal 0.45s var(--ease-out); }
@keyframes reveal {
  0% { transform: scaleX(0.2); filter: brightness(2.2); }
  60% { transform: scaleX(1.06); }
  100% { transform: none; filter: none; }
}

.shine {
  position: absolute;
  z-index: 3;
  left: 16%;
  top: 6%;
  width: 14%;
  height: 72%;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0.08));
  pointer-events: none;
}
.aura {
  position: absolute;
  z-index: 0;
  left: -70%;
  right: -70%;
  top: 0;
  bottom: -25%;
  border-radius: 50%;
  background: radial-gradient(closest-side, var(--glow, transparent), transparent);
  opacity: 0.55;
  pointer-events: none;
  transition: opacity 0.4s;
}
.flask.complete .aura { opacity: 1; animation: glow 2.4s ease-in-out infinite; }
@keyframes glow { 50% { opacity: 0.6; } }

.cork {
  position: absolute;
  z-index: 4;
  left: 50%;
  top: calc(var(--fw) * -0.3);
  width: calc(var(--fw) * 0.66);
  height: calc(var(--fw) * 0.44);
  margin-left: calc(var(--fw) * -0.33);
  border-radius: 30% 30% 12% 12% / 40% 40% 12% 12%;
  background:
    radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.25) 0 8%, transparent 9%),
    radial-gradient(circle at 65% 55%, rgba(60, 30, 10, 0.35) 0 7%, transparent 8%),
    linear-gradient(180deg, #d39c69 0%, #a8703f 55%, #7a4c27 100%);
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.45);
  display: none;
}
.flask.complete .cork { display: block; }

.seal {
  position: absolute;
  z-index: 5;
  left: 50%;
  top: calc(var(--fw) * -0.28);
  width: calc(var(--fw) * 0.92);
  height: calc(var(--fw) * 0.92);
  margin-left: calc(var(--fw) * -0.46);
  border-radius: 46% 54% 50% 50% / 52% 48% 52% 48%;
  display: none;
  place-items: center;
  font: 700 calc(var(--fw) * 0.4) / 1 var(--font-display);
  color: #ffd9c4;
  background: radial-gradient(circle at 38% 34%, #e0574a 0%, #a8231f 55%, #6e1010 100%);
  box-shadow: inset 0 0 0 calc(var(--fw) * 0.07) rgba(70, 5, 5, 0.45), 0 3px 6px rgba(0, 0, 0, 0.5);
  text-shadow: 0 1px 0 rgba(60, 0, 0, 0.7);
}
.flask.sealed .seal { display: grid; }
.flask.sealed .liquid { filter: saturate(0.55) brightness(0.72); }
.flask.sealed .tube::after { /* binding cord */
  content: "";
  position: absolute;
  left: -3px;
  right: -3px;
  top: 34%;
  height: 4px;
  background: repeating-linear-gradient(90deg, #8d6239 0 4px, #5a3a1f 4px 7px);
  border-radius: 2px;
  box-shadow: 0 calc(var(--lh) * 1.2) 0 #6e4a2a;
}
.seal.breaking { display: grid; animation: sealbreak 0.55s var(--ease-out) forwards; }
@keyframes sealbreak {
  0% { transform: scale(1); opacity: 1; }
  30% { transform: scale(1.25) rotate(-8deg); filter: brightness(1.6); }
  100% { transform: scale(0.4) translateY(-40px) rotate(30deg); opacity: 0; }
}

/* Hint highlight */
.flask.hint-from .tube,
.flask.hint-to .tube { animation: hintPulse 0.9s ease-in-out infinite; }
.flask.hint-from .tube { box-shadow: inset 0 0 0 1.5px var(--glass), 0 0 0 2.5px #c9b3ff, 0 0 22px 6px rgba(170, 140, 255, 0.55); }
.flask.hint-to .tube { box-shadow: inset 0 0 0 1.5px var(--glass), 0 0 0 2.5px #ffe08a, 0 0 22px 6px rgba(255, 210, 110, 0.5); }
.flask.hint-to::before {
  content: "";
  position: absolute;
  z-index: 6;
  left: 50%;
  top: 0;
  width: 0;
  height: 0;
  margin-left: -9px;
  border: 9px solid transparent;
  border-top: 12px solid #ffe08a;
  filter: drop-shadow(0 0 6px rgba(255, 210, 110, 0.9));
  animation: hintArrow 0.9s ease-in-out infinite;
}
@keyframes hintPulse { 50% { filter: brightness(1.35); } }
@keyframes hintArrow { 50% { transform: translateY(6px); } }

/* Effects layer */
.fx {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 60;
  overflow: hidden;
}
.stream {
  position: absolute;
  border-radius: 4px;
  transform-origin: 50% 0;
  background: linear-gradient(90deg, var(--d), var(--l) 45%, var(--c));
  box-shadow: 0 0 10px 2px var(--glow);
}
.ripple {
  position: absolute;
  border-radius: 50%;
  border: 2px solid var(--l);
  box-shadow: 0 0 8px var(--glow);
}
.spark {
  position: absolute;
  width: 10px;
  height: 10px;
  margin: -5px 0 0 -5px;
  background: radial-gradient(circle, #fff 0 20%, transparent 22%), conic-gradient(from 45deg, transparent 0 10%, #fff3c0 12% 13%, transparent 15% 35%, #fff3c0 37% 38%, transparent 40% 60%, #fff3c0 62% 63%, transparent 65% 85%, #fff3c0 87% 88%, transparent 90%);
  border-radius: 50%;
  filter: drop-shadow(0 0 3px #ffd36b);
}
.fx canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.bubble {
  position: absolute;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0.35) 60%, transparent 70%);
  box-shadow: 0 0 4px rgba(255, 255, 255, 0.5);
}
.droplet {
  position: absolute;
  width: 5px;
  height: 5px;
  margin: -2.5px 0 0 -2.5px;
  border-radius: 50%;
  background: var(--l);
  box-shadow: 0 0 6px var(--glow);
}
.wax {
  position: absolute;
  border-radius: 45% 55% 40% 60% / 55% 40% 60% 45%;
  background: radial-gradient(circle at 35% 30%, #e0574a, #a8231f 60%, #6e1010);
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.4);
}
#moves-label.bump { animation: bump 0.35s var(--ease-spring); }
@keyframes bump {
  40% { transform: scale(1.18); color: var(--gold-hi); }
}
#moves-label { display: inline-block; transform-origin: 0 50%; }

.toast {
  position: absolute;
  left: 50%;
  bottom: 18px;
  max-width: calc(100% - 32px);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.92rem;
  font-weight: 600;
  text-align: center;
  color: var(--ink);
  background: rgba(30, 20, 14, 0.92);
  box-shadow: inset 0 0 0 1px var(--panel-edge), 0 8px 20px rgba(0, 0, 0, 0.5);
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s var(--ease-out);
  z-index: 20;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Overlays ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
  background: rgba(8, 5, 3, 0.72);
  animation: fadeIn 0.25s ease-out;
}
.overlay[hidden] { display: none; }
@keyframes fadeIn { from { opacity: 0; } }
.panel {
  position: relative;
  width: min(100%, 380px);
  max-height: 100%;
  overflow-y: auto;
  padding: 26px 22px 22px;
  border-radius: 22px;
  text-align: center;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(255, 190, 90, 0.16), transparent 60%),
    linear-gradient(180deg, #2c1f16, #1d140e);
  box-shadow: inset 0 0 0 1.5px var(--panel-edge), 0 24px 60px rgba(0, 0, 0, 0.6);
  animation: popIn 0.35s var(--ease-spring);
}
@keyframes popIn { from { transform: scale(0.88); opacity: 0; } }
.panel-title {
  margin: 0;
  font: 700 1.75rem/1.1 var(--font-display);
  color: var(--gold-hi);
  text-shadow: 0 0 16px rgba(255, 180, 70, 0.45);
}
.panel-sub { margin: 10px 0 0; color: var(--ink-soft); line-height: 1.5; }
.panel-close { position: absolute; top: 10px; right: 10px; }

.win-stars { display: flex; justify-content: center; align-items: flex-end; gap: 6px; margin: -4px 0 12px; }
.win-stars .star { width: 52px; height: 52px; fill: rgba(255, 236, 205, 0.12); stroke: rgba(255, 236, 205, 0.2); stroke-width: 1; }
.win-stars .s2 { width: 66px; height: 66px; }
.win-stars .star.on { fill: var(--gold); stroke: #fff0c2; filter: drop-shadow(0 0 10px rgba(255, 190, 70, 0.8)); animation: starIn 0.45s var(--ease-spring) both; }
.win-stars .s2.on { animation-delay: 0.15s; }
.win-stars .s3.on { animation-delay: 0.3s; }
@keyframes starIn { from { transform: scale(0) rotate(-40deg); opacity: 0; } }
.win-actions { display: flex; gap: 10px; justify-content: center; margin-top: 20px; }
.win-actions .btn { flex: 1; padding: 0 16px; }
.countdown {
  height: 4px;
  margin: 16px 10px 0;
  border-radius: 2px;
  background: rgba(255, 236, 205, 0.1);
  overflow: hidden;
}
.countdown i { display: block; height: 100%; width: 100%; background: var(--gold); transform-origin: 0 50%; transform: scaleX(0); }
.countdown.run i { animation: countdown var(--dur, 3s) linear forwards; }
.countdown[hidden] { display: none; }
@keyframes countdown { from { transform: scaleX(0); } to { transform: scaleX(1); } }

.settings-panel { text-align: left; }
.settings-panel .panel-title { margin-bottom: 14px; }
.toggle {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 60px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 236, 205, 0.08);
  cursor: pointer;
}
.toggle span { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.toggle small { color: var(--ink-mute); font-size: 0.82rem; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle i {
  position: relative;
  flex: none;
  width: 52px;
  height: 30px;
  border-radius: 15px;
  background: rgba(255, 236, 205, 0.14);
  transition: background-color 0.2s;
}
.toggle i::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #f6e9d2;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
  transition: transform 0.2s var(--ease-out);
}
.toggle input:checked + i { background: var(--gold); }
.toggle input:checked + i::after { transform: translateX(22px); }
.toggle input:focus-visible + i { outline: 2px solid var(--gold-hi); outline-offset: 2px; }
.toggle.disabled { opacity: 0.5; cursor: default; }
.symbol-legend {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  padding: 12px 6px 4px;
}
.symbol-legend[hidden] { display: none; }
.symbol-legend div {
  aspect-ratio: 1;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--c);
  box-shadow: inset 0 -3px 6px rgba(0, 0, 0, 0.25), 0 0 8px var(--glow);
}
.symbol-legend svg { width: 58%; height: 58%; fill: var(--ink-c); color: var(--ink-c); }
#btn-reset { width: 100%; margin-top: 18px; }

.tut-art {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 14px;
  min-height: 150px;
  margin-bottom: 14px;
  padding-top: 18px;
}
.tut-art .ball { width: 96px; height: 110px; overflow: visible; }
.tutorial-panel .btn { margin-top: 20px; width: 100%; }

/* Static mini flasks used in tutorials */
.mini { display: flex; gap: 12px; align-items: flex-end; }
.mini .flask { height: auto; width: auto; }

@media (min-width: 700px) {
  .bar { padding: 14px 24px 6px; }
  .actions { gap: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .lantern, .motes i, .logo-flask, .logo-wave, .logo-bubble, .layer.mystery .swirl, .flask.complete .aura,
  .flask.selected .fi, #btn-play::after, .level-cell, .level-cell.current, #moves-label.bump { animation: none !important; }
}
