:root {
  --font: "Arial Rounded MT Bold", "Nunito", "Trebuchet MS", system-ui, sans-serif;
  --ink: #2b2140;
  --cream: #fff8e8;
  --accent: #ff7a1a;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #7cc6e8; font-family: var(--font); color: var(--ink); user-select: none; }
canvas#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
canvas#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 50; }
.hidden { display: none !important; }
button { font-family: var(--font); cursor: pointer; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud button { pointer-events: auto; }
#clock {
  position: absolute; z-index: 2; top: 10px; left: 50%; transform: translateX(-50%);
  background: var(--cream); border: 4px solid var(--ink); border-radius: 999px;
  padding: 4px 26px; font-size: 34px; letter-spacing: 1px; box-shadow: 0 4px 0 var(--ink);
}
#clock.stopped { background: #e6e9ef; color: #6b7280; }
#clock.stopped::before { content: '⏸ '; }
#clock.hurry { background: #ffdddd; color: #d11; animation: pulse 0.5s infinite alternate; }
@keyframes pulse { to { transform: translateX(-50%) scale(1.08); } }
#hud-left { position: absolute; top: 18px; left: 16px; }
#hud-diff { background: var(--cream); border: 3px solid var(--ink); border-radius: 12px; padding: 4px 12px; font-size: 18px; }
#hud-right { position: absolute; top: 12px; right: 14px; display: flex; gap: 8px; }
.icon-btn { font-size: 22px; width: 46px; height: 46px; border-radius: 12px; border: 3px solid var(--ink); background: var(--cream); box-shadow: 0 3px 0 var(--ink); }
#stamina { position: absolute; left: 16px; bottom: 16px; display: flex; align-items: center; gap: 8px; font-size: 24px; }
#stamina .bar { width: 160px; height: 18px; border: 3px solid var(--ink); border-radius: 10px; background: #fff; overflow: hidden; }
#stamina-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #22c55e, #a3e635); transition: background 0.2s; }
#stamina.tired #stamina-fill { background: #f87171; }

#toasts { position: absolute; z-index: 2; top: 70px; left: 50%; transform: translateX(-50%); width: 600px; display: flex; flex-direction: column; gap: 6px; align-items: center; }
.toast {
  background: var(--cream); border: 3px solid var(--ink); border-radius: 14px; padding: 8px 14px;
  font-size: 18px; box-shadow: 0 3px 0 var(--ink); animation: toast-in 0.25s ease-out;
}
.toast.good { background: #dcfce7; }
.toast.bad { background: #ffe4e6; }
.toast.fact { background: #e0f2fe; font-size: 17px; }
.toast.out { opacity: 0; transform: translateY(-16px); transition: all 0.4s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-20px) scale(0.9); } }

/* Sort Card: near-full-screen so it's clear nothing else can happen until you choose. */
#sortcard {
  position: absolute; inset: 0; z-index: 1; pointer-events: auto;
  background: rgba(30, 20, 60, 0.55); display: flex; align-items: center; justify-content: center;
  animation: fade-in 0.15s;
}
@keyframes fade-in { from { opacity: 0; } }
.sc-panel {
  width: min(1000px, 92vw); height: min(680px, 86vh); background: var(--cream); border: 6px solid var(--ink);
  border-radius: 36px; box-shadow: 0 10px 0 var(--ink); text-align: center;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  animation: card-in 0.3s cubic-bezier(.3,1.6,.6,1);
}
@keyframes card-in { from { transform: translateY(80px) scale(0.6); opacity: 0; } }
/* bitten food icons are images; size them like a 1em emoji */
.food-ic { height: 1em; width: auto; vertical-align: -0.12em; }
#sc-icon { font-size: min(130px, 16vh); line-height: 1; animation: bob 0.8s ease-in-out infinite alternate; }
#sc-name { font-size: min(46px, 6vh); }
.sc-q { font-size: min(26px, 3.6vh); margin-bottom: 14px; }
.sc-choices { display: flex; gap: 28px; }
.sc-choices button {
  position: relative; width: min(250px, 26vw); padding: 18px 8px 16px; border: 5px solid var(--ink); border-radius: 26px;
  background: var(--c); color: #fff; font-size: min(32px, 4.4vh); box-shadow: 0 7px 0 var(--ink); text-shadow: 0 2px 0 rgba(0,0,0,0.3);
}
.sc-choices button:hover { filter: brightness(1.1); }
.sc-choices button .ic { display: block; font-size: min(84px, 11vh); line-height: 1.15; }
.sc-choices button .key {
  position: absolute; top: -20px; left: -20px; width: 50px; height: 50px; border-radius: 50%;
  background: #fff; color: var(--ink); border: 4px solid var(--ink); font-size: 28px; line-height: 42px; text-shadow: none;
}
.sc-choices button.focus { transform: translateY(-6px); outline: 5px solid #fff; outline-offset: -12px; }
.sc-note { margin-top: 14px; font-size: min(20px, 3vh); opacity: 0.75; }
.sc-choices button.hint { animation: hint 0.6s infinite alternate; }
@keyframes hint { to { box-shadow: 0 4px 0 var(--ink), 0 0 0 8px #fde047; } }

#debug { position: fixed; left: 8px; bottom: 60px; z-index: 60; background: rgba(0,0,0,0.7); color: #0f0; font: 12px/1.35 monospace; padding: 8px; border-radius: 6px; pointer-events: none; }

/* ---------- Screens ---------- */
.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 20; background: rgba(40, 30, 70, 0.35); }
.card { background: var(--cream); border: 5px solid var(--ink); border-radius: 28px; padding: 26px 36px; box-shadow: 0 8px 0 var(--ink); text-align: center; max-width: 92vw; }
.menu-card h1 { font-size: 64px; margin: 0; color: var(--accent); -webkit-text-stroke: 2px var(--ink); text-shadow: 0 5px 0 var(--ink); }
.title-art { font-size: 54px; animation: bob 1.4s ease-in-out infinite alternate; }
@keyframes bob { to { transform: translateY(-8px) rotate(-3deg); } }
#version { margin-top: 8px; font-size: 13px; opacity: 0.5; }
.tagline { font-size: 20px; margin: 10px 0 20px; }
.diff-pick { display: flex; gap: 10px; justify-content: center; margin-bottom: 20px; }
.diff-pick button { font-size: 20px; padding: 10px 18px; border-radius: 14px; border: 3px solid var(--ink); background: #fff; box-shadow: 0 3px 0 var(--ink); }
.diff-pick button.selected { background: #fde047; transform: translateY(-3px); box-shadow: 0 6px 0 var(--ink); }
.big-btn { display: block; margin: 0 auto; font-size: 30px; padding: 12px 48px; border-radius: 18px; border: 4px solid var(--ink); background: #22c55e; color: #fff; box-shadow: 0 6px 0 var(--ink); text-shadow: 0 2px 0 rgba(0,0,0,0.3); }
.big-btn:hover { filter: brightness(1.08); }
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--ink); }
.link-btn { margin-top: 14px; background: none; border: none; font-size: 18px; text-decoration: underline; color: var(--ink); }
.howto-card { text-align: left; max-width: 640px; }
.howto-card h2 { text-align: center; margin-top: 0; font-size: 36px; }
.howto-card li { font-size: 19px; margin-bottom: 12px; }
.k { display: inline-block; background: #fff; border: 2px solid var(--ink); border-radius: 8px; padding: 0 7px; box-shadow: 0 2px 0 var(--ink); font-size: 16px; }
.howto-bins { display: flex; gap: 10px; margin-top: 8px; }
.howto-bins div { flex: 1; background: #fff; border: 2px solid var(--ink); border-radius: 12px; padding: 6px 8px; font-size: 17px; }
.howto-bins small { display: block; opacity: 0.7; font-size: 14px; }
.howto-card .big-btn { margin-top: 16px; }

/* ---------- Results Show ---------- */
#results { background: rgba(30, 20, 60, 0.55); overflow: hidden; }
.rs { width: min(1100px, 96vw); height: min(780px, 96vh); background: var(--cream); border: 5px solid var(--ink); border-radius: 28px; box-shadow: 0 8px 0 var(--ink); padding: 14px 24px; position: relative; display: flex; flex-direction: column; align-items: center; }
.rs.shake, .rs-panel.shake { animation: shake 0.4s; }
@keyframes shake { 20% { transform: translate(-10px, 6px) rotate(-1deg); } 40% { transform: translate(9px, -6px) rotate(1deg); } 60% { transform: translate(-6px, 3px); } 80% { transform: translate(4px, -2px); } }
.rs-title { font-size: 44px; margin: 0 0 6px; color: var(--accent); -webkit-text-stroke: 1.5px var(--ink); text-shadow: 0 4px 0 var(--ink); animation: drop 0.5s cubic-bezier(.3,1.6,.6,1); }
@keyframes drop { from { transform: translateY(-80px); opacity: 0; } }
.rs-bins { display: flex; gap: 28px; justify-content: center; width: 100%; flex: 1; min-height: 0; }
.rs-bin { width: 190px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; opacity: 0.35; transition: opacity 0.3s; }
.rs-bin.on, .rs-panel.on { opacity: 1; }
.rs-stack { display: flex; flex-wrap: wrap-reverse; justify-content: center; align-content: flex-start; gap: 2px; width: 170px; min-height: 40px; }
.rs-stack span, .rs-items span, .rs-pile span { font-size: 30px; display: inline-block; }
.rs-stack.many span { font-size: 20px; }
.pop { animation: pop 0.45s cubic-bezier(.3,1.8,.5,1); }
@keyframes pop { 0% { transform: translateY(40px) scale(0.2); opacity: 0; } 60% { transform: translateY(-14px) scale(1.25); opacity: 1; } }
.rs-can { width: 120px; height: 92px; margin-top: 6px; border: 4px solid var(--ink); border-radius: 12px 12px 22px 22px; background: var(--c); display: flex; align-items: center; justify-content: center; font-size: 48px; box-shadow: 0 4px 0 var(--ink); }
.rs-bin.wiggle .rs-can { animation: wiggle 0.5s; }
@keyframes wiggle { 25% { transform: rotate(-8deg) scale(1.08); } 50% { transform: rotate(7deg); } 75% { transform: rotate(-4deg); } }
.rs-label { font-size: 20px; margin-top: 6px; }
.rs-count { font-size: 40px; line-height: 1; }
.rs-count.bump { animation: bump 0.2s; }
@keyframes bump { 50% { transform: scale(1.4); color: var(--accent); } }
.rs-row { display: flex; gap: 28px; justify-content: center; width: 100%; margin-top: 8px; }
.rs-panel { width: 300px; height: 150px; border: 4px solid var(--ink); border-radius: 18px; background: #fff; opacity: 0.35; position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 6px; transition: opacity 0.3s; }
.rs-ptitle { font-size: 20px; }
.rs-items { min-height: 40px; display: flex; flex-wrap: wrap; justify-content: center; gap: 3px; }
.rs-items span.wobble { animation: wobble 0.5s 2; }
@keyframes wobble { 25% { transform: rotate(-20deg); } 75% { transform: rotate(20deg); } }
.sticker { position: absolute; top: 40%; left: 50%; font-size: 24px; background: #fde047; border: 3px solid var(--ink); border-radius: 12px; padding: 4px 12px; transform: translate(-50%, -50%) rotate(-8deg); animation: slap 0.35s cubic-bezier(.3,1.8,.5,1); white-space: nowrap; }
@keyframes slap { from { transform: translate(-50%, -50%) rotate(-30deg) scale(2.5); opacity: 0; } }
.rs-stolen { flex-direction: row; gap: 10px; }
.rs-window { width: 120px; height: 110px; border: 4px solid #7c4a1d; background: linear-gradient(#bfe8ff, #e9f8ff); border-radius: 8px; position: relative; overflow: hidden; flex-shrink: 0; }
.rs-bandit-wrap { position: absolute; left: 50%; bottom: -80px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; transition: bottom 0.4s cubic-bezier(.3,1.6,.6,1); }
.rs-bandit-wrap.up { bottom: 0; }
.rs-bandit { font-size: 54px; line-height: 1; transition: transform 0.4s; }
.rs-pile { display: flex; flex-direction: column-reverse; align-items: center; margin-bottom: -6px; }
.rs-pile span { font-size: 22px; margin-top: -8px; }
.rs-stolen-info { display: flex; flex-direction: column; align-items: center; }
.bubble { position: absolute; background: #fff; border: 3px solid var(--ink); border-radius: 14px; padding: 6px 10px; font-size: 16px; white-space: nowrap; animation: pop 0.4s; z-index: 3; }
.rs-barwrap { width: 70%; margin-top: 12px; display: flex; align-items: center; gap: 10px; font-size: 22px; }
.rs-bar { flex: 1; height: 30px; border: 4px solid var(--ink); border-radius: 16px; background: #fff; overflow: hidden; }
.rs-fill { height: 100%; width: 0; background: linear-gradient(90deg, #f59e0b, #22c55e); border-radius: 12px 0 0 12px; }
.rs-stamp { position: absolute; top: 38%; left: 50%; transform: translate(-50%, -50%) rotate(-12deg); font-size: 96px; padding: 6px 34px; border: 8px solid currentColor; border-radius: 22px; background: rgba(255,255,255,0.92); white-space: nowrap; z-index: 5; animation: stamp 0.35s cubic-bezier(.5,0,.75,0) both; }
@keyframes stamp { from { transform: translate(-50%, -50%) rotate(-12deg) scale(4); opacity: 0; } }
.rs-stamp.perfect { color: #a855f7; } .rs-stamp.awesome { color: #ec4899; } .rs-stamp.good { color: #2563eb; } .rs-stamp.needswork { color: #ea580c; font-size: 78px; }
.rs-bottom { display: flex; align-items: center; gap: 18px; margin-top: 10px; opacity: 0; transition: opacity 0.5s; width: 100%; justify-content: center; }
.rs-bottom.on { opacity: 1; }
.rs-earth { font-size: 70px; position: relative; }
.rs-earth .face { position: absolute; left: 50%; top: 52%; transform: translate(-50%, -50%); font-size: 28px; }
.rs-takeaway { max-width: 440px; font-size: 18px; text-align: left; }
.rs-takeaway .fact { font-size: 15px; opacity: 0.8; margin-top: 4px; }
.rs-buttons { display: flex; flex-direction: column; gap: 6px; }
.rs-buttons .big-btn { font-size: 24px; padding: 10px 26px; }
.rs-buttons .link-btn { margin-top: 0; }
.rs-skip { position: absolute; bottom: 8px; right: 16px; font-size: 14px; opacity: 0.55; }
.balloon { position: fixed; bottom: -80px; font-size: 56px; z-index: 55; animation: rise 4s ease-in forwards; pointer-events: none; }
@keyframes rise { to { transform: translateY(-120vh) rotate(10deg); } }
