/* POTION PANIC — dark claymorphism. Base styles suit phones; the 900px+ block is the main laptop layout. */
:root {
  --bg: #0d0a14;
  --surface: #1e1530;
  --surface-2: #2a1d42;
  --line: #3a2a55;
  --primary: #7CFF4F;
  --on-primary: #0d0a14;
  --secondary: #FF8A1F;
  --on-secondary: #0d0a14;
  --accent: #B98CFF;
  --ghost: #BFE6FF;
  --text: #F3EEFF;
  --muted: #B7A9CF;
  --radius: 20px;
  --font-head: "Fredoka", ui-rounded, "Segoe UI", system-ui, sans-serif;
  --font-body: "Nunito", ui-rounded, "Segoe UI", system-ui, sans-serif;
  --clay: inset 0 2px 0 rgba(255,255,255,.08), inset 0 -5px 0 rgba(0,0,0,.35), 0 10px 24px rgba(0,0,0,.45);
  --ease-pop: cubic-bezier(.34, 1.56, .64, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(ellipse at 50% -10%, rgba(185,140,255,.22), transparent 60%),
    radial-gradient(ellipse at 50% 110%, rgba(124,255,79,.12), transparent 55%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  overflow-x: hidden;
}
body.wobble { animation: wobble .5s ease-in-out; }

#app {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 16px 24px;
  position: relative;
  z-index: 1;
}
/* Auto margins centre each screen vertically but, unlike justify-content, never clip tall content */
.screen { margin-block: auto; width: 100%; display: flex; flex-direction: column; align-items: center; text-align: center; animation: screen-in .35s ease-out; }
.screen[hidden] { display: none; }

h1, h2, h3 { font-family: var(--font-head); margin: 0; line-height: 1.1; }
:focus { outline: none; }
:focus-visible { outline: 3px solid var(--ghost); outline-offset: 3px; border-radius: 8px; }
[tabindex="-1"]:focus-visible { outline: none; }

/* Decorations */
.web { position: fixed; top: 0; width: 110px; height: 110px; color: rgba(243,238,255,.14); pointer-events: none; z-index: 0; }
.web--left { left: 0; }
.web--right { right: 0; transform: scaleX(-1); }
.shelf { width: min(320px, 90%); height: auto; margin-bottom: 12px; }

/* Landing */
.title {
  font-size: clamp(3rem, 15vw, 5.5rem);
  font-weight: 700;
  letter-spacing: .02em;
  color: var(--primary);
  text-shadow: 0 4px 0 #2a7a14, 0 0 28px rgba(124,255,79,.45);
}
.title span { color: var(--secondary); text-shadow: 0 4px 0 #8a4204, 0 0 28px rgba(255,138,31,.4); }
.subtitle { font-family: var(--font-head); font-size: clamp(1.2rem, 4.8vw, 1.6rem); font-weight: 600; color: var(--ghost); margin: 10px 0 0; }
.lede { max-width: 32rem; margin: 4px 0 20px; color: var(--text); }
.fine { font-size: .9rem; color: var(--muted); margin: 14px 0 0; }

/* Cauldron */
.cauldron-wrap { position: relative; width: min(220px, 60vw); aspect-ratio: 200 / 175; margin: 18px 0 10px; }
.cauldron-wrap--big { width: min(300px, 78vw); margin-top: 28px; }
.cauldron { width: 100%; height: 100%; overflow: visible; display: block; }
.cauldron .liquid { fill: var(--liquid); transition: fill .8s ease; filter: drop-shadow(0 0 10px var(--liquid)); }
.cauldron .bubbles circle { fill: var(--liquid); opacity: 0; transform-box: fill-box; transform-origin: center; animation: bubble 2.2s ease-in infinite; transition: fill .8s ease; }
.cauldron .bubbles circle:nth-child(2) { animation-delay: .5s; }
.cauldron .bubbles circle:nth-child(3) { animation-delay: 1s; }
.cauldron .bubbles circle:nth-child(4) { animation-delay: 1.5s; }
.cauldron .bubbles circle:nth-child(5) { animation-delay: 1.8s; }

.smoke, .sparkles { position: absolute; inset: 0; pointer-events: none; }
.smoke span {
  position: absolute; left: 50%; top: 20%; width: 60px; height: 60px; margin-left: -30px;
  border-radius: 50%; background: var(--liquid); opacity: 0; filter: blur(14px);
  animation: smoke 1.8s ease-out infinite;
}
.smoke span:nth-child(2) { animation-delay: .6s; margin-left: -60px; }
.smoke span:nth-child(3) { animation-delay: 1.2s; margin-left: 0; }
.sparkles span {
  position: absolute; width: 10px; height: 10px; background: var(--ghost);
  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
  animation: sparkle 1.2s ease-in-out infinite; opacity: 0;
}
.sparkles span:nth-child(1) { left: 8%;  top: 10%; }
.sparkles span:nth-child(2) { left: 86%; top: 6%;  animation-delay: .3s; }
.sparkles span:nth-child(3) { left: 18%; top: 50%; animation-delay: .6s; }
.sparkles span:nth-child(4) { left: 78%; top: 44%; animation-delay: .9s; }
.sparkles span:nth-child(5) { left: 50%; top: -6%; animation-delay: .45s; }

/* Buttons */
.btn {
  appearance: none; border: 3px solid var(--bg); cursor: pointer;
  min-height: 56px; padding: 14px 28px; border-radius: 999px;
  font-family: var(--font-head); font-weight: 700; font-size: 1.15rem; letter-spacing: .04em;
  box-shadow: inset 0 3px 0 rgba(255,255,255,.45), inset 0 -5px 0 rgba(0,0,0,.25), 0 6px 0 rgba(0,0,0,.5), 0 12px 24px rgba(0,0,0,.4);
  transition: transform .2s ease-out, box-shadow .2s ease-out, opacity .2s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.btn:active:not(:disabled) { transform: translateY(4px) scale(.97); box-shadow: inset 0 3px 0 rgba(255,255,255,.4), inset 0 -3px 0 rgba(0,0,0,.25), 0 2px 0 rgba(0,0,0,.5); }
.btn--primary { background: var(--primary); color: var(--on-primary); }
.btn--secondary { background: var(--secondary); color: var(--on-secondary); }
.btn:disabled { cursor: not-allowed; background: var(--surface-2); color: var(--muted); box-shadow: inset 0 -4px 0 rgba(0,0,0,.3); border-color: var(--line); }
#start-btn { animation: pulse-glow 2.4s ease-in-out infinite; }
.btn--ghost {
  min-height: 48px; padding: 10px 22px; font-size: 1rem;
  background: var(--surface-2); color: var(--ghost); border-color: var(--line);
  box-shadow: inset 0 2px 0 rgba(255,255,255,.08), inset 0 -4px 0 rgba(0,0,0,.3), 0 4px 0 rgba(0,0,0,.45);
}
.book-count { margin-left: 6px; padding: 1px 9px; border-radius: 999px; background: var(--bg); color: var(--primary); font-size: .9rem; }
.landing-actions { display: flex; flex-direction: column; align-items: center; gap: 12px; }

/* Selection */
.screen-title { font-size: clamp(1.8rem, 7vw, 2.4rem); font-weight: 700; color: var(--primary); }
.hint { color: var(--muted); margin: 6px 0 16px; }
.tag { display: inline-block; margin-top: 4px; padding: 2px 10px; border-radius: 999px; background: var(--surface-2); color: var(--ghost); font-size: .85rem; font-weight: 700; }
.grid { width: 100%; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; padding-bottom: 130px; }

.card {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px;
  min-height: 190px; padding: 14px 10px 14px; text-align: center;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 3px solid var(--line); border-radius: var(--radius);
  color: var(--text); font: inherit; cursor: pointer;
  box-shadow: var(--clay);
  transition: transform .2s ease-out, border-color .2s, box-shadow .2s, opacity .2s;
  animation: pop-in .45s var(--ease-pop) both;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.card:active { transform: scale(.96); }
.card svg { width: 64px; height: 64px; color: var(--ing); flex-shrink: 0; filter: drop-shadow(0 0 8px color-mix(in srgb, var(--ing) 45%, transparent)); }
.card-name { font-family: var(--font-head); font-weight: 600; font-size: 1.05rem; line-height: 1.15; }
.card-joke { font-size: .9rem; color: var(--muted); line-height: 1.35; }
.card[aria-pressed="true"] {
  border-color: var(--primary);
  box-shadow: inset 0 2px 0 rgba(255,255,255,.1), inset 0 -5px 0 rgba(0,0,0,.35), 0 0 0 3px rgba(124,255,79,.25), 0 0 26px rgba(124,255,79,.35);
  transform: translateY(-3px);
}
.card[aria-pressed="true"]::after {
  content: ""; position: absolute; top: -10px; right: -8px; width: 32px; height: 32px; border-radius: 50%;
  background: var(--primary) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%230d0a14' stroke-width='4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12l5 5L20 7'/%3E%3C/svg%3E") center / 18px no-repeat;
  border: 3px solid var(--bg);
}
.card.is-dim { opacity: .55; }
.card.nope { animation: nope .35s ease-in-out; }

.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 12px 16px max(14px, env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(13,10,20,0), rgba(13,10,20,.92) 28%);
}
.dock .btn { width: min(420px, 100%); }
.counter { margin: 0; padding: 4px 14px; border-radius: 999px; background: var(--surface-2); border: 2px solid var(--line); font-weight: 700; }
.counter strong { color: var(--primary); }
.counter.full { border-color: var(--secondary); }

/* Brew: on phones the panel's children flow in one column with the cauldron between them */
.brew-panel { display: contents; }
#stage, .pumpkin-test { order: 1; }
.stir-ui { order: 2; }
.token kbd { display: none; }

/* Chemistry: formula chip on cards, science note, floating formula tag, chem fact strip */
.formula-chip {
  margin-top: auto; padding: 2px 8px; border-radius: 999px;
  background: var(--bg); border: 1px solid var(--line); color: var(--ghost);
  font-size: .78rem; font-weight: 700; line-height: 1.4; white-space: nowrap;
}
.science {
  order: 3; display: flex; align-items: flex-start; gap: 10px; width: min(460px, 100%); margin-top: 14px; padding: 10px 14px;
  background: rgba(124,255,79,.07); border: 2px solid rgba(124,255,79,.35); border-radius: 16px; text-align: left;
}
.science.say { animation: say .35s var(--ease-pop); }
.science p { margin: 0; font-size: .95rem; line-height: 1.4; }
.science b { color: var(--primary); }
.sci-label {
  flex-shrink: 0; display: inline-flex; align-items: center; gap: 4px; margin-top: 1px; padding: 2px 8px; border-radius: 999px;
  background: var(--primary); color: var(--on-primary); font: 700 .72rem var(--font-head); letter-spacing: .08em;
}
.sci-label svg, .chem-topic svg { width: 14px; height: 14px; }
.formula-tag {
  position: absolute; left: 50%; top: 18%; z-index: 3; padding: 3px 12px; border-radius: 999px;
  background: var(--bg); border: 2px solid var(--ghost); color: var(--ghost);
  font: 700 1rem var(--font-head); white-space: nowrap; opacity: 0; transform: translateX(-50%); pointer-events: none;
}
.formula-tag.go { animation: formula-rise 1.8s ease-out forwards; }
.chem-fact {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin-top: 14px; padding: 10px 14px;
  background: rgba(124,255,79,.07); border: 2px solid rgba(124,255,79,.35); border-radius: 16px; text-align: left;
}
.chem-topic {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 10px; border-radius: 999px;
  background: var(--primary); color: var(--on-primary); font: 700 .8rem var(--font-head); letter-spacing: .04em; white-space: nowrap;
}
.chem-text { flex: 1 1 260px; margin: 0; font-size: .95rem; line-height: 1.4; }
.chem-eq { margin: 0; padding: 2px 10px; border-radius: 8px; background: var(--bg); color: var(--ghost); font: 600 .95rem var(--font-head); white-space: nowrap; }
.chem-eq[hidden] { display: none; }
.page-topic { padding: 0 8px; border-radius: 999px; background: rgba(124,255,79,.12); color: var(--primary); font-size: .68rem; font-weight: 700; }

/* Brew: tokens */
.tokens { display: flex; justify-content: center; gap: 10px; width: 100%; min-height: 104px; }
.tokens:empty { min-height: 0; }
.token {
  flex: 1 1 0; max-width: 130px; min-height: 100px; padding: 8px 6px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 3px solid var(--ing); border-radius: var(--radius); box-shadow: var(--clay);
  color: var(--text); font: inherit; font-size: .85rem; font-weight: 700; line-height: 1.2; cursor: pointer;
  animation: pop-in .4s var(--ease-pop) both, nudge 1.6s ease-in-out .6s infinite;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.token svg { width: 48px; height: 48px; color: var(--ing); }
.token:active { transform: scale(.94); }
.token.used { visibility: hidden; animation: none; }
.flyer { position: fixed; z-index: 15; width: 56px; height: 56px; pointer-events: none; animation: throw .55s ease-in forwards; }
.flyer svg { width: 100%; height: 100%; color: var(--ing); }

/* Brew: stage, speech bubble, cauldron face */
.stage[hidden] { display: none; }
.stage { position: relative; display: flex; flex-direction: column; align-items: center; width: 100%; }
.speech {
  position: relative; max-width: 300px; min-height: 2.8em; margin: 14px 0 0; padding: 8px 16px;
  display: flex; align-items: center; justify-content: center;
  background: var(--text); color: var(--bg); border-radius: 18px;
  font-family: var(--font-head); font-weight: 600; font-size: 1.05rem; line-height: 1.25;
  box-shadow: 0 6px 0 rgba(0,0,0,.35);
}
.speech::after { content: ""; position: absolute; bottom: -10px; left: 50%; margin-left: -10px; border: 10px solid transparent; border-bottom: 0; border-top-color: var(--text); }
.speech.say { animation: say .35s var(--ease-pop); }
.cauldron-wrap--big .cauldron { overflow: visible; }
#brew-cauldron { margin-top: 18px; }
.face .eyes-x, .face .mouth { display: none; }
[data-mood="idle"] .m-idle, [data-mood="happy"] .m-happy, [data-mood="worried"] .m-worried,
[data-mood="dizzy"] .m-dizzy, [data-mood="shocked"] .m-shocked { display: inline; }
[data-mood="dizzy"] .eyes { display: none; }
[data-mood="dizzy"] .eyes-x { display: inline; }
.eyes { transform-box: fill-box; transform-origin: center; animation: blink 4s infinite; }
[data-mood="shocked"] .eyes { animation: none; transform: scale(1.3); }
[data-mood="worried"] .pupil { transform: translateY(-2px); }
.spoon { display: none; transform-box: view-box; transform-origin: 100px 74px; transform: rotate(var(--spoon, 0deg)); transition: transform .12s ease-out; }
.is-stirring .spoon { display: inline; }
.is-stirring { touch-action: none; cursor: grab; }
.swirl { opacity: var(--swirl-o, 0); transition: opacity .3s; }
.is-stirring .bubbles circle { animation-duration: 1s; }

/* Brew: stir */
.stir-ui { display: flex; flex-direction: column; align-items: center; gap: 12px; width: min(420px, 100%); margin-top: 14px; }
.stir-ui[hidden] { display: none; }
.stir-ui .btn { width: 100%; }
.meter { width: 100%; height: 22px; border-radius: 999px; background: var(--surface-2); border: 3px solid var(--line); overflow: hidden; }
#stir-fill { height: 100%; width: 100%; background: linear-gradient(90deg, var(--primary), var(--secondary)); transform-origin: left; transform: scaleX(var(--stir, 0)); transition: transform .1s linear; }

/* Brew: reveal effects */
.rumble .cauldron { animation: rumble .12s linear infinite; }
.puff .smoke span { animation: smoke 1s ease-out 2; }
.boom .smoke span { width: 120px; height: 120px; margin-left: -60px; animation: smoke-big 1.1s ease-out 1; }
.boom .smoke span:nth-child(2) { margin-left: -120px; }
.boom .smoke span:nth-child(3) { margin-left: 0; }
.cauldron-wrap .smoke span, .cauldron-wrap .sparkles span { animation-play-state: paused; opacity: 0; }
.puff .smoke span, .boom .smoke span, .is-secret-reveal .sparkles span { animation-play-state: running; }
.is-secret-reveal .sparkles span { width: 18px; height: 18px; background: #FFD84D; }
.splash i {
  position: absolute; left: 50%; top: 34%; width: 12px; height: 12px; margin: -6px; border-radius: 50%;
  background: var(--c); animation: droplet .7s ease-out forwards;
}
.creature { position: absolute; left: 50%; top: 20%; width: 90px; height: 90px; margin-left: -45px; opacity: 0; pointer-events: none; }
.creature svg { position: absolute; inset: 0; width: 100%; height: 100%; display: none; }
.creature[data-kind="ghost"] .ghost, .creature[data-kind="bat"] .bat { display: block; }
.creature.go { animation: fly-off 1.8s ease-in forwards; }
.flash { position: fixed; inset: 0; z-index: 25; pointer-events: none; background: #fff; opacity: 0; }
.flash.gold { background: #FFD84D; }
.flash.go { animation: flash .6s ease-out; }
.confetti { position: fixed; inset: 0; z-index: 24; pointer-events: none; overflow: hidden; }
.confetti i {
  position: absolute; top: -20px; left: var(--x); width: 10px; height: 16px; border-radius: 3px; background: var(--c);
  animation: confetti var(--t, 2s) cubic-bezier(.25,.6,.5,1) var(--d, 0s) forwards;
}

/* Brew: pumpkin test */
.pumpkin-test {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  width: min(420px, 100%); margin-top: 18px; padding: 20px 16px;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 3px solid var(--line); border-radius: 28px; box-shadow: var(--clay);
  color: var(--text); font: inherit; cursor: pointer; animation: pop-in .4s var(--ease-pop) both;
}
.pumpkin-test[hidden] { display: none; }
.pumpkin { width: 150px; height: 150px; overflow: visible; }
.pk-body { transform-box: fill-box; transform-origin: 50% 100%; animation: hop .5s ease-out 2; }
.pk-shades { opacity: 0; transition: opacity .3s; }
.fx-color .pk-body { --pk: var(--potion); }
.fx-float .pk-body { animation: hover-up 1.6s ease-in-out infinite; }
.fx-spin .pk-body { transform-origin: center; animation: spin 1s linear infinite; }
.fx-ghost .pk-body { opacity: .2; transition: opacity .8s; }
.fx-shades .pk-shades { opacity: 1; }
.fx-grow .pk-body { transform: scale(1.35); transition: transform .5s var(--ease-pop); animation: none; }
.test-caption { font-family: var(--font-head); font-weight: 600; font-size: 1.15rem; color: var(--ghost); min-height: 2.6em; }
.skip { font-size: .85rem; color: var(--muted); text-decoration: underline; }

/* Combo badge (pops above the cauldron when two ingredients react) */
.combo-badge {
  position: absolute; left: 50%; top: 4%; z-index: 3; padding: 4px 14px; border-radius: 999px;
  background: var(--secondary); color: var(--on-secondary); border: 3px solid var(--bg);
  font: 700 1.15rem var(--font-head); letter-spacing: .06em; white-space: nowrap;
  opacity: 0; transform: translateX(-50%); pointer-events: none;
}
.combo-badge.go { animation: combo 1.5s var(--ease-pop) forwards; }
.combo-sparks .sparkles span { animation-play-state: running; width: 18px; height: 18px; background: #FFD84D; }

/* Potion Book */
.book {
  width: min(1060px, calc(100vw - 32px)); max-height: calc(100dvh - 40px); padding: 0;
  border: 3px solid var(--line); border-radius: 28px; color: var(--text);
  background: linear-gradient(180deg, var(--surface-2), var(--surface)); box-shadow: 0 30px 80px rgba(0,0,0,.6);
}
.book[open] { display: flex; flex-direction: column; animation: reveal .35s var(--ease-pop); }
.book::backdrop { background: rgba(8,6,14,.78); }
.book-head { display: flex; align-items: center; gap: 16px; padding: 16px 18px 12px 26px; border-bottom: 2px solid var(--line); }
.book-head h2 { font-size: 2rem; color: var(--primary); }
.book-progress { flex: 1; margin: 0; color: var(--muted); font-weight: 700; }
.book-close { flex-shrink: 0; }
.book-grid { overflow-y: auto; padding: 18px 22px 24px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.book-section { grid-column: 1 / -1; margin: 4px 0 0; font: 700 .9rem var(--font-head); letter-spacing: .14em; text-transform: uppercase; color: var(--secondary); }
.page {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px;
  min-height: 132px; padding: 14px 8px 12px; text-align: center;
  background: var(--bg); border: 2px solid var(--line); border-radius: 18px;
}
.page svg { width: 44px; height: 58px; flex-shrink: 0; }
.page.found svg { filter: drop-shadow(0 0 8px var(--c)); }
.page-name { font-family: var(--font-head); font-weight: 600; font-size: .95rem; line-height: 1.2; }
.page.locked .page-name { color: var(--muted); }
.page-hint { font-size: .8rem; line-height: 1.3; color: var(--ghost); }
.page.secret { border-color: #6b5320; }
.page.secret.found { border-color: #FFD84D; box-shadow: 0 0 16px rgba(255,216,77,.25); }
.page-badge {
  position: absolute; top: -10px; left: 50%; transform: translateX(-50%); padding: 0 8px; border-radius: 999px;
  background: #FFD84D; color: var(--bg); font: 700 .7rem var(--font-head); letter-spacing: .08em;
}

/* Mute */
.corner { position: fixed; top: max(10px, env(safe-area-inset-top)); right: 10px; z-index: 30; display: flex; gap: 8px; }
.mute {
  width: 46px; height: 46px; padding: 10px; border-radius: 50%;
  background: var(--surface-2); color: var(--ghost); border: 2px solid var(--line); cursor: pointer;
  box-shadow: 0 4px 0 rgba(0,0,0,.4);
}
.mute svg { width: 100%; height: 100%; display: block; }
.mute .snd-off, .mute[aria-pressed="true"] .snd-on { display: none; }
.mute[aria-pressed="true"] .snd-off { display: inline; }
.fs[hidden] { display: none; }
.fs { display: flex; align-items: center; gap: 8px; }
.fs svg { width: 24px; height: 24px; flex-shrink: 0; }
.fs-label { display: none; font: 700 .95rem var(--font-head); white-space: nowrap; }
.fs .fs-exit, .is-fullscreen .fs .fs-enter { display: none; }
.is-fullscreen .fs .fs-exit { display: inline; }

/* Result */
.banner {
  margin: 0 0 12px; padding: 8px 18px; border-radius: 999px;
  background: var(--secondary); color: var(--on-secondary);
  font-family: var(--font-head); font-weight: 700; letter-spacing: .04em;
  border: 3px solid var(--bg); box-shadow: 0 0 24px rgba(255,138,31,.55);
  animation: pop-in .5s var(--ease-pop) both, pulse-glow-orange 2s ease-in-out .5s infinite;
}
.result-card {
  width: min(560px, 100%); padding: 20px 18px 22px;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 3px solid var(--line); border-radius: 28px; box-shadow: var(--clay);
  animation: reveal .55s var(--ease-pop) both;
}
.result-card.is-secret { border-color: var(--secondary); }
.bottle-wrap { width: 130px; margin: 0 auto 4px; }
.bottle { width: 100%; height: auto; display: block; overflow: visible; animation: float 3s ease-in-out infinite; filter: drop-shadow(0 0 18px var(--potion)); }
.bottle-liquid { fill: var(--potion); }
.bottle-bubbles circle { transform-box: fill-box; animation: rise 2s ease-in infinite; }
.bottle-bubbles circle:nth-child(2) { animation-delay: .6s; }
.bottle-bubbles circle:nth-child(3) { animation-delay: 1.1s; }
.bottle-bubbles circle:nth-child(4) { animation-delay: 1.5s; }
.rarity { margin: 6px 0 2px; font-weight: 800; font-size: .85rem; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.rarity.legendary { color: var(--secondary); }
.potion-name { font-size: clamp(1.8rem, 8vw, 2.6rem); color: var(--primary); text-wrap: balance; }
.potion-desc { font-size: 1.1rem; margin: 10px 0 16px; text-wrap: pretty; }

.stats { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 10px; text-align: left; }
.stat { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; }
.stat-label { font-weight: 700; }
.stat-value { font-family: var(--font-head); font-weight: 600; color: var(--ghost); text-align: right; }
.stat-bar { grid-column: 1 / -1; height: 12px; border-radius: 999px; background: var(--bg); border: 2px solid var(--line); overflow: hidden; }
.stat-bar i { display: block; height: 100%; border-radius: 999px; background: var(--bar, var(--primary)); transform-origin: left; animation: fill .9s var(--ease-pop) both; animation-delay: var(--d, .2s); }

.side { background: var(--bg); border: 2px dashed var(--line); border-radius: 16px; padding: 10px 14px; text-align: left; }
.side h3 { font-size: .85rem; letter-spacing: .14em; text-transform: uppercase; color: var(--secondary); margin-bottom: 2px; }
.side p { margin: 0; }
.reaction { font-family: var(--font-head); font-weight: 600; font-size: 1.15rem; color: var(--accent); margin: 16px 0 6px; }
.made-with { margin: 0; color: var(--muted); font-size: .95rem; }
.secret-count { font-weight: 800; color: var(--primary); }
.whisper { max-width: 640px; margin: 14px 0 0; font-family: var(--font-head); font-weight: 600; font-size: 1.05rem; color: var(--ghost); }
.whisper b { color: var(--secondary); }
.actions { display: flex; flex-direction: column; gap: 12px; width: min(420px, 100%); margin-top: 14px; }

.safety {
  position: relative; z-index: 0; /* below #app so it never covers the fixed Mix button */
  max-width: 640px; margin: 0 auto; padding: 16px 16px 24px;
  font-size: .82rem; line-height: 1.45; color: var(--muted); text-align: center;
}
body.on-select .safety { padding-bottom: 150px; }

/* Keep the fixed mute button clear of headings on phones */
@media (max-width: 599px) {
  #app { padding-top: max(62px, env(safe-area-inset-top)); }
}

/* Wider screens */
@media (min-width: 600px) {
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
  .book-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .actions { flex-direction: row; width: auto; }
  .web { width: 160px; height: 160px; }
}
/* Laptop layout: everything fits a ~1280x650 viewport without scrolling */
@media (min-width: 900px) {
  #app { max-width: 1200px; padding: 24px 40px 16px; }
  .web { width: 180px; height: 180px; }
  .screen-title { font-size: 2.6rem; }
  .hint { font-size: 1.05rem; }

  /* Landing: words left, cauldron right */
  #landing { display: grid; grid-template-columns: 1.1fr 1fr; column-gap: 48px; align-items: center; align-content: center; justify-items: start; text-align: left; }
  #landing > * { grid-column: 1; }
  #landing .cauldron-wrap { grid-column: 2; grid-row: 1 / span 6; justify-self: center; width: min(420px, 100%, 62vh); margin: 0; }
  #landing .shelf { width: 300px; margin: 0 0 6px; }
  .title { font-size: clamp(4.5rem, 7vw, 6.5rem); }
  .lede { font-size: 1.1rem; margin: 12px 0 24px; }
  #start-btn { font-size: 1.3rem; padding: 18px 44px; }
  .landing-actions { flex-direction: row; gap: 16px; }
  /* 24-unit grid: potions take 3 units (8 per row), wider secrets take 4 (6 per row) */
  .book-grid { grid-template-columns: repeat(24, minmax(0, 1fr)); gap: 12px; padding: 14px 22px 20px; }
  .page { grid-column: span 3; }
  .page.secret { grid-column: span 4; }
  .page { min-height: 0; padding: 12px 6px 10px; gap: 4px; }
  .page svg { width: 30px; height: 40px; }
  .page-name { font-size: .85rem; }
  .page-hint { font-size: .75rem; }

  /* Select: 6 x 2 grid with the counter + button underneath */
  #select .hint { margin-bottom: 18px; }
  .grid { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 14px; padding-bottom: 0; }
  .card { min-height: 0; padding: 14px 8px; }
  .card svg { width: 60px; height: 60px; }
  .card-joke { font-size: .85rem; }
  .dock { position: sticky; bottom: 0; flex-direction: row; justify-content: center; gap: 20px; width: 100%; margin-top: 6px; padding: 18px 0 14px; }
  .dock .btn { width: auto; min-width: 300px; }
  .counter { font-size: 1.05rem; padding: 8px 18px; }
  body.on-select .safety { padding-bottom: 24px; }

  /* Brew: cauldron left, controls right */
  #brew { display: grid; grid-template-columns: 1fr 1fr; column-gap: 48px; align-items: center; align-content: center; }
  .brew-panel { display: flex; flex-direction: column; align-items: center; grid-column: 2; grid-row: 1; }
  #stage, .pumpkin-test { grid-column: 1; grid-row: 1; justify-self: center; }
  #brew-cauldron { width: min(400px, 100%, 56vh); }
  .science { width: 100%; max-width: 460px; }
  .science p, .chem-text { font-size: 1rem; }
  .speech { max-width: 360px; font-size: 1.15rem; }
  .tokens { gap: 16px; }
  .token { max-width: 160px; min-height: 130px; font-size: 1rem; position: relative; }
  .token svg { width: 64px; height: 64px; }
  .stir-ui { width: 100%; max-width: 440px; margin-top: 6px; }
  .pumpkin-test { width: min(460px, 100%); margin: 0; }
  .pumpkin { width: 200px; height: 200px; }

  #landing[hidden], #brew[hidden] { display: none; }

  /* Height-aware spacing so every screen fits short laptop screens (e.g. 1366x657) */
  #app { padding: clamp(8px, 2vh, 24px) 40px clamp(6px, 1.5vh, 16px); }
  .safety { max-width: 960px; padding: 6px 16px 10px; font-size: .78rem; }
  .screen-title { font-size: clamp(2rem, 5.5vh, 2.6rem); }
  .hint { margin: 4px 0 clamp(8px, 1.6vh, 18px); }
  #select .hint { margin-bottom: clamp(8px, 1.6vh, 18px); }
  .card { padding: clamp(8px, 1.4vh, 14px) 8px; gap: 4px; }
  .card svg { width: clamp(40px, 7vh, 60px); height: clamp(40px, 7vh, 60px); }
  .dock { padding: clamp(8px, 1.6vh, 18px) 0 clamp(6px, 1.2vh, 14px); }
  .potion-name { font-size: clamp(1.7rem, 5vh, 2.6rem); }
  .potion-desc { margin-top: 6px; }
  .stats { gap: 6px; margin-bottom: 10px; }
  .reaction { margin: 10px 0 4px; }
  .actions { margin-top: clamp(6px, 1.4vh, 14px); }
  .whisper { max-width: 960px; margin-top: clamp(6px, 1.4vh, 14px); }

  /* Fullscreen button gets a text label on laptops */
  .fs { width: auto; padding: 10px 16px 10px 12px; border-radius: 999px; }
  .on-landing .fs-label { display: inline; }
  body:not(.on-landing) .fs { padding: 10px; }

  /* Result: potion left, stats right */
  .result-card { width: min(980px, 100%); display: grid; grid-template-columns: 1fr 1.1fr; gap: 14px 36px; align-items: center; padding: 18px 32px; }
  .rc-right { text-align: left; }
  .bottle-wrap { width: clamp(64px, 12vh, 130px); }
  .chem-fact { grid-column: 1 / -1; margin-top: 0; }
  .potion-desc { margin-bottom: 0; }
  .reaction { margin-top: 14px; }
  .secret-count { margin-top: 12px; }
}
/* Short laptop screens (e.g. 1366x768 minus taskbar and browser bars ≈ 610px) */
@media (min-width: 900px) and (max-height: 720px) {
  .stats { grid-template-columns: 1fr 1fr; gap: 6px 20px; }
  .stat { align-content: start; }
  .side { padding: 6px 12px; }
  .reaction { margin: 8px 0 2px; font-size: 1.05rem; }
  .result-card { padding: 14px 28px; }
  .chem-fact { padding: 8px 12px; }
  .page { padding: 9px 6px 8px; }
  .page svg { width: 24px; height: 32px; }
  .book-head { padding: 10px 14px 8px 22px; }
  .book-grid { padding: 8px 20px 12px; gap: 8px; }
  .book-section { margin: 0; }
  .book { max-height: calc(100dvh - 12px); }
  .book-head h2 { font-size: 1.6rem; }
  .bottle-wrap { width: clamp(56px, 10vh, 90px); }
  .banner { margin-bottom: 6px; padding: 4px 16px; }
  .whisper { font-size: .95rem; }
  .result-card { row-gap: 8px; }
  .rarity { margin: 2px 0 0; }
  .potion-desc { font-size: 1rem; }
  .page-hint { font-size: .7rem; line-height: 1.25; }
}
@media (min-width: 900px) and (hover: hover) and (pointer: fine) {
  .token kbd {
    display: block; position: absolute; top: 6px; left: 8px; min-width: 24px; padding: 1px 6px; border-radius: 6px;
    background: var(--bg); border: 2px solid var(--line); color: var(--ghost); font: 700 .8rem var(--font-head);
  }
}
@media (hover: hover) {
  .card:hover { border-color: var(--accent); }
  .btn:hover:not(:disabled) { transform: translateY(-2px); }
}

/* Keyframes (transform/opacity only) */
@keyframes screen-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(16px) scale(.92); } to { opacity: 1; transform: none; } }
@keyframes reveal { from { opacity: 0; transform: scale(.85); } to { opacity: 1; transform: none; } }
@keyframes bubble { 0% { opacity: 0; transform: translateY(0) scale(.4); } 20% { opacity: .9; } 100% { opacity: 0; transform: translateY(-46px) scale(1.1); } }
@keyframes rise { 0% { opacity: 0; transform: translateY(0); } 30% { opacity: 1; } 100% { opacity: 0; transform: translateY(-50px); } }
@keyframes smoke { 0% { opacity: 0; transform: translateY(0) scale(.5); } 30% { opacity: .5; } 100% { opacity: 0; transform: translateY(-110px) scale(1.8); } }
@keyframes sparkle { 0%, 100% { opacity: 0; transform: scale(.3) rotate(0); } 50% { opacity: 1; transform: scale(1.2) rotate(90deg); } }
@keyframes float { 0%, 100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-8px) rotate(2deg); } }
@keyframes fill { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes wobble { 0%, 100% { transform: none; } 20% { transform: rotate(-1deg) translateX(-6px); } 40% { transform: rotate(1deg) translateX(6px); } 60% { transform: rotate(-.6deg) translateX(-3px); } 80% { transform: rotate(.4deg) translateX(2px); } }
@keyframes nope { 0%, 100% { transform: none; } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
@keyframes pulse-glow { 0%, 100% { box-shadow: inset 0 3px 0 rgba(255,255,255,.45), inset 0 -5px 0 rgba(0,0,0,.25), 0 6px 0 rgba(0,0,0,.5), 0 0 0 rgba(124,255,79,0); } 50% { box-shadow: inset 0 3px 0 rgba(255,255,255,.45), inset 0 -5px 0 rgba(0,0,0,.25), 0 6px 0 rgba(0,0,0,.5), 0 0 30px rgba(124,255,79,.55); } }
@keyframes pulse-glow-orange { 0%, 100% { box-shadow: 0 0 10px rgba(255,138,31,.35); } 50% { box-shadow: 0 0 30px rgba(255,138,31,.7); } }

@keyframes nudge { 0%, 100% { transform: none; } 50% { transform: translateY(-5px); } }
@keyframes throw { 0% { transform: translate(0, 0) rotate(0) scale(1); } 50% { transform: translate(calc(var(--dx) * .5), calc(var(--dy) * .5 - 90px)) rotate(200deg) scale(1.1); } 100% { transform: translate(var(--dx), var(--dy)) rotate(400deg) scale(.3); opacity: .2; } }
@keyframes say { from { transform: scale(.7); } to { transform: none; } }
@keyframes blink { 0%, 92%, 100% { transform: none; } 95% { transform: scaleY(.1); } }
@keyframes rumble { 0%, 100% { transform: none; } 25% { transform: translate(-4px, 1px) rotate(-2deg); } 75% { transform: translate(4px, -1px) rotate(2deg); } }
@keyframes smoke-big { 0% { opacity: 0; transform: translateY(0) scale(.4); } 20% { opacity: .9; } 100% { opacity: 0; transform: translateY(-140px) scale(2.6); } }
@keyframes droplet { from { transform: translate(0, 0) scale(1); opacity: 1; } to { transform: translate(var(--x), var(--y)) scale(.4); opacity: 0; } }
@keyframes fly-off { 0% { opacity: 0; transform: translateY(20px) scale(.3); } 20% { opacity: 1; transform: translateY(-40px) scale(1.1); } 40% { transform: translate(-30px, -80px) rotate(-10deg); } 100% { opacity: 0; transform: translate(220px, -320px) rotate(20deg) scale(.6); } }
@keyframes flash { 0% { opacity: .9; } 100% { opacity: 0; } }
@keyframes confetti { to { transform: translate(var(--dx), 110vh) rotate(var(--rot)); } }
@keyframes hop { 0%, 100% { transform: none; } 50% { transform: translateY(-18px) scaleY(1.05); } }
@keyframes hover-up { 0%, 100% { transform: translateY(-14px); } 50% { transform: translateY(-30px); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes formula-rise { 0% { opacity: 0; transform: translate(-50%, 20px) scale(.8); } 15% { opacity: 1; transform: translate(-50%, 0) scale(1.05); } 75% { opacity: 1; transform: translate(-50%, -30px); } 100% { opacity: 0; transform: translate(-50%, -50px); } }
@keyframes combo { 0% { opacity: 0; transform: translate(-50%, 10px) scale(.5) rotate(-8deg); } 20% { opacity: 1; transform: translate(-50%, -10px) scale(1.15) rotate(4deg); } 80% { opacity: 1; transform: translate(-50%, -16px) scale(1); } 100% { opacity: 0; transform: translate(-50%, -30px) scale(.9); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .cauldron .bubbles circle, .smoke span, .sparkles span, .bottle-bubbles circle, .confetti, .creature { display: none; }
}
