/*
 * Calm, focused layout: one object in the middle (the glass machine with the box inside),
 * one question, three answers. Colour carries meaning only:
 *   orange = machine, kraft = the box, green = added / bigger, red = taken away / smaller, blue = the same.
 */

/* ================= Tokens ================= */
:root {
  --ink: #0f2a4a;
  --ink-70: rgba(15, 42, 74, .72);
  --ink-50: rgba(15, 42, 74, .5);
  --bg: #eef2f7;
  --card: #fff;
  --line: #dbe3ee;
  --machine: #f97316;
  --machine-dark: #c2410c;
  --kraft-dark: #92572a;
  /* meaning, never judgement: red is not used anywhere (it reads as "wrong" to children) */
  --down: #2563eb;  --down-bg: #dbeafe;   /* smaller  = blue */
  --same: #64748b;  --same-bg: #f1f5f9;   /* the same = slate grey */
  --up: #16a34a;    --up-bg: #dcfce7;     /* bigger   = green */
  --wrong: #d97706; --wrong-bg: #fef3c7;  /* a wrong guess = soft amber */
  --navy: #0f2a4a;
  --radius: 20px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

/* ================= Base ================= */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: 'Nunito', system-ui, sans-serif; font-weight: 700; color: var(--ink); background: var(--bg);
  overflow: hidden; overscroll-behavior: none; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none;
  user-select: none; touch-action: manipulation; -webkit-text-size-adjust: 100%;
}
h1, h2, p, ol { margin: 0; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; }
a { color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid #0ea5e9; outline-offset: 3px; }

.fr { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; font-size: .72em; line-height: 1.02; margin: 0 .06em; }
.fr-n { padding: 0 .14em .04em; border-bottom: .09em solid currentColor; }
.fr-d { padding: .04em .14em 0; }
.mx { margin-right: .06em; }
.dc { white-space: nowrap; font-variant-numeric: tabular-nums; }

.screen { position: fixed; inset: 0; transition: opacity .35s ease, visibility .35s ease; }
.screen.off { opacity: 0; visibility: hidden; pointer-events: none; }

.icon-btn {
  width: 44px; height: 44px; flex-shrink: 0; border-radius: 14px; display: grid; place-items: center;
  background: var(--card); color: var(--ink); box-shadow: 0 1px 0 var(--line), 0 2px 8px rgba(15, 42, 74, .08);
  transition: transform .15s, background-color .2s;
}
.icon-btn:active { transform: scale(.94); }
.icon-btn.ghost { background: rgba(255, 255, 255, .1); color: #e0f2fe; box-shadow: none; }
.icon-btn.is-off { opacity: .55; }

.btn {
  min-height: 52px; padding: 12px 20px; border-radius: 16px; width: 100%;
  font-family: 'Fredoka', system-ui, sans-serif; font-weight: 600; font-size: 18px;
  background: #f1f5f9; color: var(--ink); transition: transform .15s;
}
.btn:active { transform: translateY(2px); }
.btn.primary { background: var(--machine); color: #fff; box-shadow: 0 4px 0 var(--machine-dark); }
.btn.ghost { background: none; color: var(--ink-70); }

/* ================= Start ================= */
.start { background: var(--navy); color: #fff; }
.start-bar {
  position: absolute; z-index: 5; left: 0; right: 0; top: 0; display: flex; justify-content: space-between; align-items: center;
  padding: calc(var(--safe-t) + 10px) calc(var(--safe-r) + 12px) 10px calc(var(--safe-l) + 12px);
  background: var(--navy);
}
.sound-group { display: flex; gap: 6px; }
.lang-switch { display: flex; gap: 2px; padding: 3px; border-radius: 999px; background: rgba(255, 255, 255, .08); }
.lang-btn { min-width: 42px; height: 38px; padding: 0 8px; border-radius: 999px; font-family: 'Fredoka', system-ui, sans-serif; font-weight: 600; font-size: 14px; color: #cbd5e1; }
.lang-btn[aria-pressed="true"] { background: #fff; color: var(--navy); }
.start-scroll { height: 100%; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.start-col {
  width: min(560px, 100%); min-height: 100%; margin: 0 auto; display: flex; flex-direction: column; justify-content: center; gap: 18px;
  padding: calc(var(--safe-t) + 74px) calc(var(--safe-r) + 18px) calc(var(--safe-b) + 24px) calc(var(--safe-l) + 18px);
}
.start-head { text-align: center; }
.brand { display: inline-flex; align-items: center; gap: 8px; font-family: 'Fredoka', system-ui, sans-serif; font-weight: 600; font-size: 15px; letter-spacing: .1em; text-transform: uppercase; color: #fdba74; }
.title { margin-top: 8px; font-family: 'Fredoka', system-ui, sans-serif; font-weight: 700; font-size: clamp(34px, 8vw, 52px); line-height: 1.05; text-wrap: balance; }
.tagline { margin-top: 8px; font-size: 16px; line-height: 1.4; color: #cbd5e1; text-wrap: balance; }

.mode-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: 18px; background: rgba(255, 255, 255, .08); }
.mode-btn { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border-radius: 14px; text-align: left; color: #cbd5e1; transition: background-color .2s, color .2s; }
.mode-btn b { font-family: 'Fredoka', system-ui, sans-serif; font-weight: 600; font-size: 17px; }
.mode-btn small { font-size: 12.5px; line-height: 1.3; opacity: .85; }
.mode-btn[aria-checked="true"] { background: #fff; color: var(--navy); }

.list-title { margin-top: 4px; font-size: 13px; letter-spacing: .1em; text-transform: uppercase; color: #94a3b8; }
.shifts { list-style: none; padding: 0; display: grid; gap: 8px; }
.shift {
  width: 100%; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: 16px; background: #fff; color: var(--navy); text-align: left;
  transition: transform .15s, box-shadow .2s;
}
@media (hover: hover) { .shift:hover { box-shadow: 0 0 0 3px var(--c); } }
.shift:active { transform: scale(.98); }
.shift-n { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; background: var(--c); color: #fff; font-family: 'Fredoka', system-ui, sans-serif; font-weight: 700; font-size: 19px; }
.shift-txt { display: flex; flex-direction: column; min-width: 0; }
.shift-name { font-family: 'Fredoka', system-ui, sans-serif; font-weight: 600; font-size: 18px; line-height: 1.2; }
.shift-desc { font-size: 13.5px; color: var(--ink-70); }
.shift-end { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.stars { display: flex; gap: 1px; }
.stars svg { width: 17px; height: 17px; }
.stars path { fill: #e2e8f0; stroke: #cbd5e1; }
.stars .on path { fill: #facc15; stroke: #eab308; }
.shift-best { font-size: 11.5px; color: var(--ink-50); }
.start-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 16px; }
.link-btn { min-height: 44px; padding: 8px 4px; color: #93c5fd; font-size: 15px; text-decoration: underline; text-underline-offset: 3px; }

/* ================= Game layout ================= */
.play { display: grid; grid-template-rows: auto minmax(0, 1fr); background: var(--bg); }
.hud {
  display: flex; align-items: center; gap: 10px;
  padding: calc(var(--safe-t) + 10px) calc(var(--safe-r) + 12px) 6px calc(var(--safe-l) + 12px);
}
.hud-mid { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.line-name { max-width: 100%; font-family: 'Fredoka', system-ui, sans-serif; font-weight: 600; font-size: 14px; color: var(--ink-70); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trip { display: flex; gap: 4px; }
.trip i { width: 18px; height: 6px; border-radius: 3px; background: #cbd5e1; }
.trip i.now { background: var(--ink); }
.trip i.ok { background: var(--up); }
.trip i.no { background: var(--wrong); }
@media (max-width: 380px) { .trip i { width: 13px; } }
.score { display: flex; align-items: center; gap: 5px; padding: 0 4px; font-family: 'Fredoka', system-ui, sans-serif; font-weight: 700; font-size: 20px; font-variant-numeric: tabular-nums; }
.score.bump { animation: bump .35s ease; }
.menu-wrap { position: relative; }
.menu {
  position: absolute; z-index: 50; right: 0; top: calc(100% + 8px); min-width: 230px; padding: 6px; border-radius: 16px;
  background: #fff; box-shadow: 0 12px 34px rgba(15, 42, 74, .2); display: none;
}
.menu.show { display: grid; }
.menu-item { min-height: 46px; padding: 0 12px; border-radius: 10px; text-align: left; font-size: 15.5px; display: flex; align-items: center; gap: 10px; }
.menu-item svg { flex-shrink: 0; }
@media (hover: hover) { .menu-item:hover { background: #f1f5f9; } }
.menu-item.is-off { color: var(--ink-50); }

.stage {
  min-height: 0; display: grid; grid-template-rows: minmax(0, 1fr) auto; gap: 12px;
  width: min(760px, 100%); margin: 0 auto;
  padding: 4px calc(var(--safe-r) + 14px) calc(var(--safe-b) + 14px) calc(var(--safe-l) + 14px);
}

/* ================= The machine ================= */
.factory { position: relative; min-height: 0; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 10px; }
.machine {
  width: 100%; display: flex; flex-direction: column; gap: 10px; padding: 10px;
  border-radius: 28px; background: var(--machine); box-shadow: 0 6px 0 var(--machine-dark), 0 16px 30px rgba(194, 65, 12, .18);
}
.m-head { display: flex; align-items: center; gap: 10px; }
.m-led { width: 12px; height: 12px; border-radius: 50%; background: #fde68a; box-shadow: 0 0 0 3px rgba(255, 255, 255, .35); flex-shrink: 0; }
.machine.running .m-led { animation: blink .3s steps(2) infinite; }
.m-screen { flex: 1; min-height: clamp(56px, 11vh, 86px); display: grid; place-items: center; border-radius: 16px; background: var(--navy); }
.op { font-family: 'Fredoka', system-ui, sans-serif; font-weight: 700; color: #fde047; font-size: clamp(34px, 7vh, 56px); line-height: 1; white-space: nowrap; }
.op .sign { color: #fff; margin-right: .14em; }
.m-screen.flip .op { animation: flip .4s ease; }

.chamber {
  position: relative; height: clamp(150px, 30vh, 270px); border-radius: 18px; overflow: hidden;
  background: linear-gradient(180deg, #f0f9ff, #dbeafe);
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, .7), inset 0 6px 18px rgba(15, 42, 74, .08);
}
.chamber::before { /* glass reflection */
  content: ''; position: absolute; z-index: 4; top: -30%; left: 12%; width: 10%; height: 160%; transform: rotate(18deg);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .55), transparent); pointer-events: none;
}
.chamber::after { /* belt inside the machine */
  content: ''; position: absolute; left: 0; right: 0; bottom: 9%; height: 7%;
  background: repeating-linear-gradient(90deg, #475569 0 14px, #334155 14px 28px); opacity: .85;
}
.machine.running .chamber::after { animation: belt .5s linear infinite; }

/* the reference length: where the box was before the machine worked */
.outline { position: absolute; left: 6%; bottom: 16%; height: 40%; border: 2.5px dashed rgba(15, 42, 74, .35); border-radius: 8px; }
.outline span { position: absolute; right: -2px; top: -20px; transform: translateX(50%); font-size: 12px; color: var(--ink-50); display: none; }
.details .outline span { display: block; }

.box-row { position: absolute; left: 6%; right: 6%; bottom: 16%; height: 40%; transition: transform .8s cubic-bezier(.3, .8, .3, 1); }
.box-row.outside { transform: translateX(-120%); transition: none; }
.box-row.leaving-right { transform: translateX(130%); transition: transform .7s cubic-bezier(.6, 0, .8, .4); }
.slice { position: absolute; top: 0; bottom: 0; display: grid; place-items: center; transition: left .38s cubic-bezier(.3, 1.2, .5, 1), transform .4s cubic-bezier(.3, 1.2, .5, 1), opacity .4s; }
.slice::before {
  content: ''; position: absolute; inset: 0 2px; border-radius: 6px;
  background: linear-gradient(180deg, #f3cf9f, #dfa767); border: 2.5px solid var(--kraft-dark);
  transition: inset .3s, border-radius .3s;
}
.slice b { position: relative; font-size: 12px; color: rgba(92, 51, 18, .7); }
/* uncut box: slices look like one piece */
.box-row.whole .slice::before { inset: 0; border-radius: 0; border-left-width: 0; border-right-width: 0; }
.box-row.whole .slice:first-child::before { border-left-width: 2.5px; border-radius: 8px 0 0 8px; }
.box-row.whole .slice:last-child::before { border-right-width: 2.5px; border-radius: 0 8px 8px 0; }
.box-row.whole .slice b { opacity: 0; }
.slice.pulse::before { animation: pulse .35s ease; }
.slice.added::before { background: linear-gradient(180deg, #bbf7d0, #4ade80); border-color: #15803d; }
.slice.lifted { transform: translateY(-115%); }
.slice.removing { transform: translateY(-22%); }
.slice.removing::before { background: linear-gradient(180deg, #bfdbfe, #60a5fa); border-color: var(--down); }
.slice.gone { transform: translate(240%, -260%) rotate(14deg); opacity: 0; transition: transform .7s cubic-bezier(.5, 0, .8, .5), opacity .6s .1s; }
/* finished box: one solid box, thin seams still show the pieces */
.box-row.joined .slice:not(.gone)::before { inset: 0; border-radius: 0; border-left-width: 0; }
.box-row.joined .slice:first-child::before { border-left-width: 2.5px; border-radius: 8px 0 0 8px; }

.box-label {
  position: absolute; z-index: 3; bottom: calc(56% + 12px); transform: translateX(-50%);
  min-width: 56px; padding: 4px 12px; border-radius: 12px; background: #fff; border: 2.5px solid var(--kraft-dark);
  font-family: 'Fredoka', system-ui, sans-serif; font-weight: 700; font-size: clamp(22px, 4.6vh, 34px); line-height: 1.05; text-align: center; white-space: nowrap;
  transition: left .38s cubic-bezier(.3, 1.2, .5, 1), transform .8s cubic-bezier(.3, .8, .3, 1), opacity .3s;
}
.box-label::after { content: ''; position: absolute; left: 50%; bottom: -9px; margin-left: -7px; border: 7px solid transparent; border-top-color: var(--kraft-dark); border-bottom: 0; }
.box-label.outside { transform: translateX(-50%) translateX(-120vw); transition: none; }
.box-label.leaving-right { transform: translateX(-50%) translateX(120vw); opacity: 0; transition: transform .7s cubic-bezier(.6, 0, .8, .4), opacity .4s .3s; }
.box-label.pop { animation: labelPop .45s cubic-bezier(.34, 1.56, .64, 1); }
.chamber.done.up .box-label { border-color: var(--up); background: var(--up-bg); color: #14532d; }
.chamber.done.up .box-label::after { border-top-color: var(--up); }
.chamber.done.down .box-label { border-color: var(--down); background: var(--down-bg); color: #1e3a8a; }
.chamber.done.down .box-label::after { border-top-color: var(--down); }
.chamber.done.same .box-label { border-color: var(--same); background: var(--same-bg); color: #334155; }
.chamber.done.same .box-label::after { border-top-color: var(--same); }

.step-cap {
  position: absolute; z-index: 5; left: 50%; top: 7%; transform: translate(-50%, -6px); opacity: 0; pointer-events: none;
  padding: 4px 12px; border-radius: 999px; background: var(--navy); color: #fff; font-size: clamp(13px, 2.2vh, 16px); white-space: nowrap;
  transition: opacity .25s, transform .3s;
}
.step-cap.show { opacity: 1; transform: translate(-50%, 0); }
.saw { position: absolute; z-index: 3; top: 10%; bottom: 12%; width: 3px; margin-left: -1.5px; border-radius: 2px; background: #f97316; box-shadow: 0 0 10px 3px rgba(249, 115, 22, .55); opacity: 0; }
.saw.zap { animation: zap .22s ease-out; }

/* closed machine: a metal cover until the answer is given */
.shutter {
  position: absolute; z-index: 6; inset: 0; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: repeating-linear-gradient(180deg, #cbd5e1 0 16px, #94a3b8 16px 18px); color: #334155; text-align: center; padding: 0 12px;
  transition: transform .6s cubic-bezier(.6, 0, .3, 1);
}
.closed .shutter { display: flex; }
.shutter.open { transform: translateY(-101%); }
.shutter-num { min-width: 64px; padding: 4px 14px; border-radius: 12px; background: #fff; border: 2.5px solid var(--kraft-dark); font-family: 'Fredoka', system-ui, sans-serif; font-weight: 700; font-size: clamp(22px, 4.6vh, 34px); line-height: 1.05; color: var(--ink); margin-bottom: 6px; }
.shutter small { font-size: 13px; padding: 2px 8px; border-radius: 8px; background: rgba(255, 255, 255, .7); }

.recipe { min-height: 22px; display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 4px 8px; font-size: 14.5px; color: var(--ink-70); text-align: center; }
.recipe i { font-style: normal; color: var(--ink-50); }
.recipe .fr { font-size: .8em; }

/* hint: the operand on a 0–1–2 line, shown under the machine */
.hint {
  position: absolute; z-index: 20; left: 50%; bottom: 0; width: min(100%, 440px); padding: 8px 14px 2px; border-radius: 16px;
  background: #fff; box-shadow: 0 10px 30px rgba(15, 42, 74, .18); border: 2.5px solid #facc15;
  opacity: 0; transform: translate(-50%, 10px); pointer-events: none; transition: opacity .2s, transform .3s;
}
.hint.show { opacity: 1; transform: translate(-50%, 0); }
.hint-title { text-align: center; font-size: 14px; color: var(--ink-70); }
.gauge { position: relative; height: 76px; margin: 4px 14px 0; }
.g-zone { position: absolute; top: 40px; height: 8px; border-radius: 4px; }
.g-zone.lt { background: rgba(37, 99, 235, .18); }
.g-zone.gt { background: rgba(22, 163, 74, .2); }
.g-line { position: absolute; left: 0; right: 0; top: 43px; height: 3px; background: #94a3b8; border-radius: 2px; }
.g-tick { position: absolute; top: 37px; width: 3px; height: 15px; margin-left: -1.5px; background: #64748b; border-radius: 2px; }
.g-tick.one { top: 31px; height: 27px; width: 5px; margin-left: -2.5px; background: var(--ink); }
.g-num { position: absolute; top: 59px; transform: translateX(-50%); font-family: 'Fredoka', system-ui, sans-serif; font-size: 13px; color: var(--ink-70); }
.g-num.one { font-size: 15px; color: var(--ink); }
.g-mark { position: absolute; top: 0; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; }
.g-mark .g-val { padding: 2px 8px; border-radius: 9px; background: var(--navy); color: #fde047; font-family: 'Fredoka', system-ui, sans-serif; font-weight: 600; font-size: 17px; line-height: 1.05; white-space: nowrap; }
.g-mark .g-val .fr { font-size: .7em; }
.g-mark::after { content: ''; width: 0; height: 0; border: 6px solid transparent; border-top: 7px solid var(--navy); }

/* ================= Answers / feedback ================= */
.controls, .fb { width: 100%; }
.ask-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.prompt { font-family: 'Fredoka', system-ui, sans-serif; font-weight: 600; font-size: 17px; color: var(--ink-70); }
.hint-btn { flex-shrink: 0; display: inline-flex; align-items: center; gap: 5px; min-height: 40px; padding: 6px 12px; border-radius: 999px; background: #fff; color: #92400e; font-size: 14.5px; box-shadow: 0 1px 0 var(--line); }
.hint-btn small { font-size: 12px; opacity: .75; }
.hint-btn:disabled { opacity: .45; cursor: default; }
.answers { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.ans {
  --c: var(--same);
  min-height: 72px; padding: 8px 6px; border-radius: 18px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: var(--c); color: #fff; font-family: 'Fredoka', system-ui, sans-serif; font-weight: 600; font-size: clamp(15px, 2.4vw, 19px); line-height: 1.1;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .2); transition: transform .12s, box-shadow .12s, opacity .2s;
}
.ans svg { width: 26px; height: 26px; }
.ans.down { --c: var(--down); }
.ans.up { --c: var(--up); }
.ans:not(:disabled):active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, .2); }
.ans:disabled { cursor: default; opacity: .45; }
.ans.picked { opacity: 1; box-shadow: 0 0 0 4px var(--ink); }

.fb { display: none; padding: 14px 16px; border-radius: var(--radius); background: #fff; border-left: 6px solid var(--c, var(--up)); box-shadow: 0 2px 10px rgba(15, 42, 74, .08); }
.fb.show { display: block; animation: rise .3s ease; }
.fb.good { --c: var(--up); }
.fb.bad { --c: var(--wrong); }
.play.answered .controls { display: none; }
.fb-head { display: flex; align-items: center; gap: 10px; }
.fb-icon { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--c); color: #fff; flex-shrink: 0; }
.fb-icon svg { width: 20px; height: 20px; }
.fb-title { font-family: 'Fredoka', system-ui, sans-serif; font-weight: 700; font-size: 21px; color: var(--c); }
.fb-pts { margin-left: auto; font-family: 'Fredoka', system-ui, sans-serif; font-weight: 600; font-size: 17px; color: #a16207; }
.fb-eq { margin-top: 6px; font-family: 'Fredoka', system-ui, sans-serif; font-weight: 700; font-size: 24px; }
.fb-eq .res { color: var(--dir, var(--c)); }
.fb-eq .sign, .fb-eq .eqs { margin: 0 .2em; color: var(--ink-50); }
.fb-why { margin-top: 4px; font-size: 15.5px; line-height: 1.4; }
.fb-why b { color: var(--dir, var(--ink)); }
.fb.dir-up { --dir: var(--up); } .fb.dir-down { --dir: var(--down); } .fb.dir-same { --dir: var(--same); }
.fb-diag { margin-top: 8px; padding: 8px 10px; border-radius: 12px; background: var(--wrong-bg); color: #78350f; font-size: 15px; line-height: 1.4; }
.fb-diag:empty { display: none; }
.fb-diag .fr, .fb-why .fr { font-size: .8em; }
.fb-next {
  position: relative; overflow: hidden; width: 100%; margin-top: 12px; min-height: 50px; border-radius: 14px;
  background: var(--ink); color: #fff; font-family: 'Fredoka', system-ui, sans-serif; font-weight: 600; font-size: 18px;
}
.fb-next:active { transform: translateY(2px); }
.fb-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgba(255, 255, 255, .2); }
.fb-bar span { display: block; height: 100%; width: 0; background: rgba(255, 255, 255, .8); }

/* ================= Landscape phones: machine left, answers right ================= */
@media (orientation: landscape) and (max-height: 540px) {
  .hud { padding-top: calc(var(--safe-t) + 6px); padding-bottom: 2px; }
  .stage { width: 100%; grid-template-rows: minmax(0, 1fr); grid-template-columns: minmax(0, 1fr) minmax(220px, 34%); gap: 14px; align-items: center; }
  .machine { gap: 6px; padding: 8px; border-radius: 22px; }
  .m-screen { min-height: 48px; }
  .op { font-size: 34px; }
  .chamber { height: clamp(120px, 44vh, 200px); }
  .box-label { font-size: 22px; }
  .recipe { min-height: 0; font-size: 13px; }
  .controls, .fb { grid-column: 2; grid-row: 1; }
  .ask-row { flex-wrap: wrap; justify-content: center; text-align: center; }
  .prompt { font-size: 15px; }
  .answers { grid-template-columns: 1fr; gap: 8px; }
  .answers .up { order: -1; }
  .answers .down { order: 1; }
  .ans { min-height: 50px; flex-direction: row; gap: 10px; }
  .fb { padding: 10px 12px; max-height: calc(100dvh - 70px); overflow-y: auto; }
  .fb-eq { font-size: 20px; }
  .fb-why, .fb-diag { font-size: 14px; }
}

/* ================= Overlays ================= */
.overlay {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; overflow-y: auto;
  padding: calc(var(--safe-t) + 16px) 16px calc(var(--safe-b) + 16px); background: rgba(15, 42, 74, .55);
  opacity: 0; visibility: hidden; transition: opacity .25s, visibility .25s;
}
.overlay.show { opacity: 1; visibility: visible; }
.modal { width: min(460px, 100%); padding: 22px 20px 18px; border-radius: 24px; background: #fff; text-align: center; box-shadow: 0 20px 50px rgba(15, 42, 74, .3); }
.modal-title { font-family: 'Fredoka', system-ui, sans-serif; font-weight: 700; font-size: 26px; }
.help-steps { margin: 14px 0 10px; padding-left: 22px; display: grid; gap: 8px; text-align: left; font-size: 15.5px; line-height: 1.45; }
.help-steps b { color: var(--machine-dark); }
.help-tip { padding: 10px 12px; border-radius: 12px; background: var(--navy); color: #fde047; font-size: 15px; }
.help-keys { margin: 10px 0 14px; font-size: 13px; color: var(--ink-50); }
@media (pointer: coarse) { .help-keys { display: none; } .help-tip { margin-bottom: 14px; } }
.res-stars { display: flex; justify-content: center; gap: 6px; }
.res-stars svg { width: 52px; height: 52px; }
.res-stars path { fill: #e2e8f0; stroke: #cbd5e1; stroke-width: 1.4; }
.res-stars .on path { fill: #facc15; stroke: #eab308; }
.res-stars .on { animation: starIn .5s cubic-bezier(.34, 1.56, .64, 1) both; }
.res-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0 10px; }
.res-stats div { display: flex; flex-direction: column; padding: 8px 4px; border-radius: 14px; background: #f1f5f9; }
.res-stats b { font-family: 'Fredoka', system-ui, sans-serif; font-size: 24px; }
.res-stats span { font-size: 12px; color: var(--ink-50); }
.res-new { display: none; margin-bottom: 10px; font-family: 'Fredoka', system-ui, sans-serif; color: #b45309; }
.res-new.show { display: block; }
.res-tip { margin-bottom: 14px; padding: 10px 12px; border-radius: 12px; background: #fff7ed; font-size: 15px; line-height: 1.4; text-align: left; }
.res-tip b { color: var(--machine-dark); }
.res-actions { display: grid; gap: 8px; }

/* ================= Effects ================= */
.fx { position: fixed; inset: 0; pointer-events: none; z-index: 40; overflow: hidden; }
.particle { position: absolute; left: 0; top: 0; border-radius: 2px; }

@keyframes belt { to { background-position: 28px 0; } }
@keyframes blink { 50% { filter: brightness(1.6); } }
@keyframes flip { from { transform: rotateX(90deg); opacity: 0; } }
@keyframes pulse { 50% { filter: brightness(1.15); transform: translateY(-4px); } }
@keyframes zap { 0% { opacity: 0; transform: scaleY(.2); } 40% { opacity: 1; transform: scaleY(1); } 100% { opacity: 0; } }
@keyframes labelPop { 40% { transform: translateX(-50%) scale(1.18); } }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
@keyframes bump { 40% { transform: scale(1.2); } }
@keyframes starIn { from { transform: scale(0) rotate(-60deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .1s !important; }
}

/* ================= Polish: a little colour and depth, nothing that competes with the machine ================= */
.start {
  background:
    radial-gradient(ellipse 60% 40% at 15% 0%, rgba(249, 115, 22, .22), transparent 70%),
    radial-gradient(ellipse 60% 45% at 100% 100%, rgba(56, 189, 248, .2), transparent 70%),
    linear-gradient(rgba(147, 197, 253, .06) 1px, transparent 1px) 0 0 / 32px 32px,
    linear-gradient(90deg, rgba(147, 197, 253, .06) 1px, transparent 1px) 0 0 / 32px 32px,
    linear-gradient(170deg, #12345c, #0b2140);
}
.start-bar { background: transparent; }
.title { background: linear-gradient(180deg, #fff 40%, #fde7c7); -webkit-background-clip: text; background-clip: text; color: transparent; }
.title::after { content: ''; display: block; width: 72px; height: 5px; margin: 12px auto 0; border-radius: 3px; background: linear-gradient(90deg, #f97316, #facc15); }
.mode-switch { background: rgba(255, 255, 255, .07); border: 1px solid rgba(255, 255, 255, .1); }
.mode-btn[aria-checked="true"] { box-shadow: 0 6px 18px rgba(0, 0, 0, .25), inset 0 -3px 0 #f97316; }
.shift { box-shadow: 0 4px 0 rgba(0, 0, 0, .18); border-left: 5px solid var(--c); }
.shift-n { background: linear-gradient(160deg, color-mix(in srgb, var(--c) 75%, #fff), var(--c)); box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .15); }

.play {
  background:
    radial-gradient(ellipse 70% 50% at 50% 0%, #fff7ed, transparent 70%),
    radial-gradient(circle at 1px 1px, rgba(15, 42, 74, .07) 1px, transparent 1.5px) 0 0 / 22px 22px,
    linear-gradient(180deg, #f1f5fb, #e6edf6);
}
.icon-btn { border: 1px solid rgba(15, 42, 74, .06); }
.trip i { background: #d5deea; }
.trip i.now { background: #f97316; box-shadow: 0 0 0 2px rgba(249, 115, 22, .25); }
.score { padding: 6px 12px 6px 8px; border-radius: 999px; background: #fff; box-shadow: 0 1px 0 var(--line), 0 2px 8px rgba(15, 42, 74, .08); font-size: 18px; }

/* the machine: painted metal, bolts, a glowing screen */
.machine {
  position: relative;
  background: linear-gradient(180deg, #fb923c 0%, #f97316 45%, #ea580c 100%);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .35), inset 0 -4px 0 rgba(0, 0, 0, .12), 0 6px 0 var(--machine-dark), 0 18px 34px rgba(194, 65, 12, .22);
}
.machine::before, .machine::after { /* bolts */
  content: ''; position: absolute; bottom: 8px; width: 8px; height: 8px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff7ed, #c2410c 70%); opacity: .8;
}
.machine::before { left: 9px; } .machine::after { right: 9px; }
.m-led { background: #86efac; box-shadow: 0 0 0 3px rgba(255, 255, 255, .3), 0 0 10px #4ade80; }
.m-head .m-led:last-child { background: #fde68a; box-shadow: 0 0 0 3px rgba(255, 255, 255, .3), 0 0 10px #facc15; }
.m-screen { background: radial-gradient(ellipse at 50% 30%, #1d4170, #0b1d33 75%); box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .08), inset 0 6px 14px rgba(0, 0, 0, .35); }
.op { text-shadow: 0 0 14px rgba(253, 224, 71, .45); }
.chamber {
  background:
    linear-gradient(rgba(59, 130, 246, .07) 1px, transparent 1px) 0 0 / 100% 24px,
    linear-gradient(90deg, rgba(59, 130, 246, .07) 1px, transparent 1px) 0 0 / 24px 100%,
    linear-gradient(180deg, #f5fbff, #d8eafe);
}
.chamber::after { /* belt with rollers */
  height: 8%;
  background:
    radial-gradient(circle at 50% 50%, #94a3b8 0 3px, transparent 3.5px) 0 50% / 28px 100% repeat-x,
    repeating-linear-gradient(90deg, #475569 0 14px, #3b4a5f 14px 28px);
  border-top: 2px solid #64748b;
}

/* the box: kraft cardboard with a strip of tape */
.slice::before {
  background:
    linear-gradient(180deg, transparent 0 40%, rgba(255, 255, 255, .28) 40% 52%, transparent 52%),
    linear-gradient(180deg, #f6d3a4, #dca263);
  box-shadow: inset 0 -4px 0 rgba(146, 87, 42, .18);
}
.slice.added::before { background: linear-gradient(180deg, transparent 0 40%, rgba(255, 255, 255, .35) 40% 52%, transparent 52%), linear-gradient(180deg, #bbf7d0, #4ade80); }
.slice.removing::before { background: linear-gradient(180deg, transparent 0 40%, rgba(255, 255, 255, .35) 40% 52%, transparent 52%), linear-gradient(180deg, #bfdbfe, #60a5fa); }
.box-label { box-shadow: 0 3px 0 rgba(146, 87, 42, .25); }

/* answers: soft gradient, round icon badge */
.ans { background: linear-gradient(180deg, color-mix(in srgb, var(--c) 82%, #fff), var(--c)); box-shadow: 0 4px 0 color-mix(in srgb, var(--c) 70%, #000), 0 8px 16px color-mix(in srgb, var(--c) 25%, transparent); }
.ans svg { width: 30px; height: 30px; padding: 4px; border-radius: 50%; background: rgba(255, 255, 255, .22); }
.ans:not(:disabled):active { box-shadow: 0 1px 0 color-mix(in srgb, var(--c) 70%, #000); }
@media (hover: hover) { .ans:not(:disabled):hover { filter: brightness(1.06); } }
.hint-btn { background: #fef9c3; box-shadow: 0 2px 0 #fde047; }

.fb { background: linear-gradient(180deg, color-mix(in srgb, var(--c) 7%, #fff), #fff 60%); }
.fb-next { background: linear-gradient(180deg, #1e3a5f, var(--ink)); box-shadow: 0 3px 0 #020617; }
.modal { border-top: 6px solid var(--machine); }
