/* Sandwich-Bot. Colours are the book's theme colours. */
:root {
  color-scheme: light;
  --teal: #0B6E7F; --teal-dark: #08525F; --yellow: #FFC83D; --red: #D7263D; --grape: #5B4BB7;
  --ink: #1D2B45; --muted: #5A6B85; --pale: #E4F3F5; --green: #1E8449; --blue: #1F6FB5; --orange: #F28C28;
  --white: #FFFFFF; --line: #CFE3E7;
  --font: "Century Gothic", "Avenir Next", "Avenir", "Nunito", "Segoe UI", system-ui, sans-serif;
  --radius: 16px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { font-family: var(--font); color: var(--ink); background: var(--pale); line-height: 1.4; }
button, select { font: inherit; color: inherit; }
img { display: block; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ico { width: 1.2em; height: 1.2em; flex: none; }
:focus-visible { outline: 3px solid var(--grape); outline-offset: 2px; }

/* ---- Top bar ---- */
.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; padding: 10px 16px; background: var(--teal); color: var(--white); }
.back { color: var(--white); text-decoration: none; font-weight: 700; padding: 6px 10px; border-radius: 999px; background: rgba(255, 255, 255, .14); }
.back:hover { background: rgba(255, 255, 255, .26); }
.game-title { margin: 0; font-size: 1.5rem; letter-spacing: .02em; }
.levels { display: flex; flex-wrap: wrap; gap: 6px; margin-right: auto; }
.level { display: inline-flex; align-items: center; gap: 6px; border: 0; border-radius: 999px; padding: 8px 14px; min-height: 40px; cursor: pointer; background: rgba(255, 255, 255, .16); color: var(--white); font-weight: 700; }
.level:hover { background: rgba(255, 255, 255, .28); }
.level[aria-pressed="true"] { background: var(--yellow); color: var(--ink); }
.level .num { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: rgba(0, 0, 0, .18); font-size: .85rem; }
.level[aria-pressed="true"] .num { background: var(--ink); color: var(--white); }
.level .tick { color: #9BE7A8; font-weight: 800; }
.level[aria-pressed="true"] .tick { color: var(--green); }
.tools { display: flex; flex-wrap: wrap; gap: 8px; }
.tool { display: inline-flex; align-items: center; gap: 6px; border: 2px solid rgba(255, 255, 255, .5); background: transparent; color: var(--white); border-radius: 999px; padding: 6px 12px; min-height: 40px; cursor: pointer; font-weight: 700; }
.tool:hover { background: rgba(255, 255, 255, .14); }
.tool select { border: 0; border-radius: 8px; padding: 2px 4px; background: var(--white); color: var(--ink); }
#soundBtn .mute { display: none; }
#soundBtn[aria-pressed="false"] .mute { display: inline; }
#soundBtn[aria-pressed="false"] .waves { display: none; }
#voiceBtn .mute { display: none; }
#voiceBtn[aria-pressed="false"] .mute { display: inline; }
#voiceBtn[aria-pressed="false"] .lines { display: none; }

/* ---- Layout ---- */
.game { display: grid; grid-template-columns: minmax(0, 1fr) 340px; grid-template-areas: "stage program" "cards cards"; gap: 16px; padding: 16px; max-width: 1400px; margin: 0 auto; }
.stage-wrap { grid-area: stage; }
.program-panel { grid-area: program; }
.palette { grid-area: cards; }
.panel { background: var(--white); border-radius: var(--radius); padding: 16px; box-shadow: 0 2px 0 var(--line); }
.panel h2 { margin: 0 0 10px; font-size: 1.15rem; }
.muted { display: block; font-size: .85rem; font-weight: 400; color: var(--muted); }

/* ---- Stage ---- */
.stage { position: relative; aspect-ratio: 16 / 9; border-radius: var(--radius); overflow: hidden; background: #FDF4E7; box-shadow: 0 2px 0 var(--line); }
#kitchen { position: absolute; inset: 0; width: 100%; height: 100%; }
.who { position: absolute; bottom: 5%; width: auto; transition: transform .25s; }
.who-gabi { left: 1.5%; height: 57%; }
.who-bot { right: 2%; height: 64%; }
.who.bob { animation: bob .5s ease-out; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-4%); } }
.say { position: absolute; top: 3%; max-width: 38%; margin: 0; padding: .55em .8em; border-radius: 14px; background: var(--white); border: 3px solid var(--ink); font-weight: 800; font-size: clamp(.75rem, 1.6vw, 1.05rem); line-height: 1.25; box-shadow: 0 3px 0 rgba(29, 43, 69, .15); }
.say:empty { display: none; }
.say::after { content: ""; position: absolute; bottom: -12px; width: 18px; height: 18px; background: inherit; border: inherit; border-top: 0; border-left: 0; transform: rotate(45deg); }
.say-bot { right: 2.5%; color: var(--teal); text-transform: uppercase; }
.say-bot::after { right: 24%; }
.say-gabi { left: 2%; font-weight: 700; }
.say-gabi::after { left: 22%; }
.say-bot.is-error { color: var(--red); border-color: var(--red); background: #FFF1F2; }
.say-bot.is-note { color: var(--grape); border-color: var(--grape); }

/* kitchen animations (SVG groups) */
#kitchen .pop { transform-box: fill-box; transform-origin: 50% 100%; animation: pop .45s ease-out; }
#kitchen .shake { transform-box: fill-box; animation: shake .5s ease-in-out; }
#kitchen .drop { animation: drop .45s ease-in; }
#kitchen .dip { animation: dip .7s ease-in-out; }
#kitchen .swish { animation: swish .8s ease-in-out; }
#kitchen .lid-off { transform-box: fill-box; transform-origin: 50% 50%; animation: lidoff .8s ease-in-out; }
#kitchen .served { transform: translate(-130px, 4px); }
#kitchen .served.slide { animation: slide .9s ease-out; }
@keyframes pop { 0% { transform: scale(.4); opacity: 0; } 70% { transform: scale(1.08); opacity: 1; } 100% { transform: scale(1); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-9px); } 40% { transform: translateX(9px); } 60% { transform: translateX(-6px); } 80% { transform: translateX(6px); } }
@keyframes drop { from { transform: translateY(-46px); } to { transform: translateY(0); } }
@keyframes dip { 0%, 100% { transform: translate(0, 0); } 45%, 60% { transform: translate(-62px, 42px); } }
@keyframes swish { 0%, 100% { transform: translate(0, 0); } 30% { transform: translate(-230px, 70px); } 55% { transform: translate(-180px, 76px); } 80% { transform: translate(-230px, 70px); } }
/* The lid starts exactly where it sat on the jar (LID_ON in game.js), twists, pops up, then lands on the table (LID_OFF). */
@keyframes lidoff {
  0%   { transform: translate(-68px, -76px) rotate(0); }
  12%  { transform: translate(-68px, -76px) rotate(-9deg); }
  24%  { transform: translate(-68px, -76px) rotate(9deg); }
  36%  { transform: translate(-68px, -76px) rotate(0); }
  55%  { transform: translate(-46px, -112px) rotate(-6deg); }
  100% { transform: translate(0, 0) rotate(0); }
}
@keyframes slide { from { transform: translate(0, 0); } to { transform: translate(-130px, 4px); } }

/* result card */
.result { margin-top: 12px; background: var(--white); border-radius: var(--radius); border: 4px solid var(--teal); padding: 14px 18px; box-shadow: 0 6px 18px rgba(29, 43, 69, .14); text-align: center; animation: pop-card .35s ease-out; }
.result h2 { margin: 0 0 4px; font-size: clamp(1.05rem, 2.4vw, 1.6rem); color: var(--teal); }
.result h2:focus { outline: none; }
.result p { margin: 4px 0; }
.result .hint { font-weight: 700; color: var(--grape); }
.result .note { font-size: .9rem; color: var(--muted); }
.result .hint:empty, .result .note:empty { display: none; }
.result.is-win { border-color: var(--green); }
.result.is-win h2 { color: var(--green); }
.result.is-bug { border-color: var(--red); }
.result.is-bug h2 { color: var(--red); }
.result-btns { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
@keyframes pop-card { from { transform: translateY(14px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.confetti i { position: absolute; top: -20px; width: 12px; height: 16px; border-radius: 3px; animation: fall 2.2s ease-in forwards; }
@keyframes fall { to { transform: translateY(620px) rotate(540deg); opacity: .9; } }

/* ---- Program ---- */
.mission { background: var(--pale); border-radius: 12px; padding: 10px 12px; margin-bottom: 14px; }
.mission p { margin: 0; }
.mission-level { font-weight: 800; color: var(--teal); }
.mission-text { margin: 4px 0 2px !important; }
.link-btn { border: 0; background: none; padding: 6px 0; color: var(--teal-dark); font-weight: 700; text-decoration: underline; cursor: pointer; }
.program { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; counter-reset: step; max-height: 470px; overflow: auto; }
.pcard { display: grid; grid-template-columns: 26px 1fr auto auto; align-items: center; gap: 6px; padding: 4px; border-radius: 12px; border: 3px solid transparent; }
.pnum { font-weight: 800; color: var(--muted); text-align: center; }
.pchip { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 4px 10px 4px 4px; border-radius: 10px; background: var(--c); color: var(--ink-c); font-weight: 800; font-size: .95rem; }
.pchip img { width: 36px; height: 36px; border-radius: 50%; background: var(--white); flex: none; }
.pmark { width: 26px; height: 26px; border-radius: 50%; display: inline-grid; place-items: center; font-weight: 800; font-size: .9rem; color: var(--white); visibility: hidden; }
.pbtns { display: flex; gap: 2px; }
.pbtns button { width: 34px; height: 40px; border: 2px solid var(--line); border-radius: 8px; background: var(--white); cursor: pointer; font-weight: 800; line-height: 1; }
.pbtns button:hover:not(:disabled) { border-color: var(--teal); }
.pbtns button:disabled { opacity: .35; cursor: default; }
.pcard.is-current { border-color: var(--grape); background: #F1EFFC; }
.pcard.is-ok .pmark { visibility: visible; background: var(--green); }
.pcard.is-note .pmark { visibility: visible; background: var(--grape); }
.pcard.is-error { border-color: var(--red); background: #FFF1F2; }
.pcard.is-error .pmark { visibility: visible; background: var(--red); }
.pcard.is-skipped .pchip { opacity: .35; }
.program-empty { margin: 6px 0 0; padding: 18px; border: 3px dashed var(--line); border-radius: 12px; text-align: center; color: var(--muted); }
.run-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 4px; }

/* ---- Buttons ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 46px; padding: 8px 18px; border-radius: 999px; border: 3px solid transparent; font-weight: 800; cursor: pointer; text-decoration: none; }
.btn:disabled { opacity: .45; cursor: default; }
.btn-green { background: var(--green); color: var(--white); }
.btn-green:hover:not(:disabled) { background: #176B3A; }
.run { font-size: 1.15rem; padding: 8px 24px; }
.btn-teal { background: var(--teal); color: var(--white); }
.btn-teal:hover:not(:disabled) { background: var(--teal-dark); }
.btn-yellow { background: var(--yellow); color: var(--ink); }
.btn-white { background: var(--white); color: var(--ink); border-color: var(--line); }
.btn-white:hover:not(:disabled) { border-color: var(--teal); }

/* ---- Card palette ---- */
.cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.ccard { display: grid; grid-template-columns: 56px 1fr; align-items: center; gap: 10px; text-align: left; min-height: 84px; padding: 10px; border: 0; border-radius: 14px; background: var(--c); color: var(--ink-c); cursor: pointer; box-shadow: 0 4px 0 rgba(29, 43, 69, .18); transition: transform .1s; }
.ccard:hover:not(:disabled) { transform: translateY(-2px); }
.ccard:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 rgba(29, 43, 69, .18); }
.ccard:disabled { opacity: .5; cursor: default; }
.ccard img { width: 56px; height: 56px; border-radius: 50%; background: var(--white); }
.ccard .label { display: block; font-weight: 800; font-size: 1.02rem; }
.ccard .does { display: block; font-size: .82rem; margin-top: 2px; }

/* ---- Help ---- */
dialog { border: 0; border-radius: var(--radius); padding: 0; width: min(640px, calc(100% - 32px)); max-height: calc(100% - 32px); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
dialog::backdrop { background: rgba(29, 43, 69, .5); }
.help-body { padding: 20px 24px; }
.help-body h2 { margin-top: 0; color: var(--teal); }
.help-body h3 { margin: 16px 0 4px; }
.help-body a { color: var(--teal-dark); }

/* ---- Smaller screens ---- */
@media (max-width: 980px) {
  .game { grid-template-columns: 1fr; grid-template-areas: "stage" "program" "cards"; }
  .program { max-height: none; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .game { padding: 10px; gap: 10px; }
  .game-title { font-size: 1.2rem; }
  .bar { padding: 8px 10px; }
  .tool { padding: 4px 10px; }
  .ccard { grid-template-columns: 44px 1fr; min-height: 72px; }
  .ccard img { width: 44px; height: 44px; }
  .ccard .does { display: none; }
  .say { max-width: 44%; font-size: .72rem; }
  .result { padding: 10px 12px; }
  .result p { font-size: .9rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
