:root {
  --bg: #fff4e2;
  --bg-glow: #ffe2b8;
  --ink: #3b2416;
  --muted: #8a6a52;
  --accent: #d9762b;
  --shadow: rgba(80, 40, 10, .22);
  --code-bg: rgba(217, 118, 43, .1);
  --card: rgba(255, 255, 255, .6);
  --card-line: rgba(80, 40, 10, .12);
  --good: #4f9a3a;
  --warn: #e0962e;
  --bad: #d4483b;
  --plate: #3b3330;
  --plate-side: #231d1b;
  --rim: #7a6c64;
  --well: #141010;
  --tray: #e8c993;
  --tray-edge: #c9a065;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1410;
    --bg-glow: #3a2214;
    --ink: #fbe9d4;
    --muted: #b8977c;
    --accent: #f0a35e;
    --shadow: rgba(0, 0, 0, .5);
    --code-bg: rgba(240, 163, 94, .12);
    --card: rgba(255, 240, 220, .06);
    --card-line: rgba(255, 240, 220, .12);
  }
}
:root[data-theme="dark"] {
  --bg: #1c1410;
  --bg-glow: #3a2214;
  --ink: #fbe9d4;
  --muted: #b8977c;
  --accent: #f0a35e;
  --shadow: rgba(0, 0, 0, .5);
  --code-bg: rgba(240, 163, 94, .12);
  --card: rgba(255, 240, 220, .06);
  --card-line: rgba(255, 240, 220, .12);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: radial-gradient(circle at 50% 30%, var(--bg-glow), var(--bg) 60%) var(--bg) fixed;
  color: var(--ink);
  font-family: "Fredoka", ui-rounded, system-ui, sans-serif;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
.mono, .tagline, .hint, .pill, .shop, .customer, footer { font-family: "JetBrains Mono", ui-monospace, monospace; }
.defs { position: absolute; width: 0; height: 0; overflow: hidden; }

/* ---------- layout ---------- */
.app {
  flex: 1;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px 16px 8px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "header" "tagline" "stage" "shop";
  gap: 10px 24px;
  align-content: start;
}
@media (min-width: 900px) {
  .app {
    grid-template-columns: minmax(0, 1fr) 290px;
    grid-template-areas: "header header" "tagline tagline" "stage shop";
    padding-top: 24px;
  }
}
header { grid-area: header; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
h1 { font-weight: 600; font-size: clamp(1.7rem, 6vw, 2.4rem); letter-spacing: -.01em; margin: 0; line-height: 1; }
h1 .c {
  color: var(--accent);
  text-decoration: underline wavy var(--accent);
  text-decoration-thickness: 2px;
  text-underline-offset: 6px;
}
.hud { display: flex; gap: 6px; flex-wrap: wrap; }
.pill {
  font-size: .85rem;
  font-weight: 500;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--card-line);
  font-variant-numeric: tabular-nums;
}
.pill.money { color: var(--accent); font-weight: 700; }
.pill.sound { cursor: pointer; color: inherit; font-family: inherit; line-height: inherit; }
.pill.sound:hover { border-color: var(--accent); }
.pill.sound:focus-visible { outline: 2px dashed var(--accent); outline-offset: 2px; }
.pill.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

.tagline {
  grid-area: tagline;
  font-size: clamp(.8rem, 3.2vw, .95rem);
  color: var(--muted);
  margin: 0;
  min-height: 1.4em;
}
.tagline::before { content: "// "; opacity: .6; }

.stage { grid-area: stage; display: flex; flex-direction: column; align-items: center; gap: 12px; min-width: 0; }
.grill-wrap { width: 100%; display: flex; justify-content: center; }
.hint { font-size: .78rem; color: var(--muted); margin: 6px 0 0; text-align: center; }
.hint code { background: var(--code-bg); padding: 2px 6px; border-radius: 6px; }

/* ---------- fever ---------- */
.fever {
  width: 100%;
  max-width: 560px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: .7rem;
  color: var(--muted);
}
.fever .label { min-width: 9.5em; white-space: nowrap; }
.fever .bar { flex: 1; height: 8px; border-radius: 4px; background: var(--card-line); overflow: hidden; }
.fever .bar i {
  display: block;
  height: 100%;
  transform-origin: left;
  transform: scaleX(var(--f, 0));
  background: linear-gradient(90deg, #d59a70, #f6d8bb);
  border-radius: inherit;
  transition: transform .3s;
}
body.in-fever .fever .label { color: #ff7a18; font-weight: 700; }
body.in-fever .fever .bar i {
  background: linear-gradient(90deg, #ff3d3d, #ff9a1f, #ffd23f, #ff9a1f, #ff3d3d);
  background-size: 200% 100%;
  animation: flame 0.8s linear infinite;
  transition: none;
}
body.in-fever .grill { animation: glow .7s ease-in-out infinite alternate; }
@keyframes flame { to { background-position: -200% 0; } }
@keyframes glow {
  from { box-shadow: 0 calc(var(--cell) * .1) 0 var(--plate-side), 0 0 0 3px #ff8a2a, 0 0 24px 4px rgba(255, 120, 30, .45); }
  to   { box-shadow: 0 calc(var(--cell) * .1) 0 var(--plate-side), 0 0 0 3px #ffc24a, 0 0 48px 12px rgba(255, 90, 20, .6); }
}
.bonito-bit { position: fixed; z-index: 11; pointer-events: none; }
.bonito-bit svg { width: 100%; height: 100%; display: block; overflow: visible; }

/* ---------- customers ---------- */
.queue {
  position: relative;
  list-style: none;
  margin: 0;
  padding: 0;
  width: 100%;
  display: grid;
  --q: 3; /* grows with the context window upgrade */
  grid-template-columns: repeat(var(--q), minmax(0, 1fr));
  gap: 12px 8px;
  min-height: 118px;
  max-width: calc(var(--q) * 187px);
}
@media (max-width: 560px) { .queue { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.customer {
  position: relative;
  background: var(--card);
  border: 1px solid var(--card-line);
  border-radius: 14px;
  padding: 8px 8px 9px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  animation: arrive .35s cubic-bezier(.3, 1.4, .5, 1) both;
  font-size: .72rem;
}
.customer.front { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent); }
.customer.front::after {
  content: "now serving";
  position: absolute;
  top: -9px;
  left: 10px;
  font-size: .6rem;
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
}
.customer.paid { animation: happy .7s ease-in forwards; }
.customer.left { animation: storm-off .6s ease-in forwards; }
@keyframes arrive { from { opacity: 0; transform: translateX(30px); } }
@keyframes happy { 30% { transform: translateY(-6px); } to { opacity: 0; transform: translateY(-24px); } }
@keyframes storm-off { 20% { transform: rotate(-3deg); } to { opacity: 0; transform: translateX(-30px) rotate(-6deg); } }
.who { display: flex; align-items: center; gap: 5px; min-width: 0; }
.avatar { font-size: 1.3rem; line-height: 1; }
.role { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; color: var(--muted); }
.size { font-weight: 700; color: var(--ink); }
.tray {
  --cols: 3;
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  gap: 2px;
  padding: 4px 5px;
  background: var(--tray);
  border: 2px solid var(--tray-edge);
  border-radius: 10px 10px 16px 16px;
}
.slot { aspect-ratio: 1; border-radius: 50%; background: rgba(120, 80, 30, .18); position: relative; }
.slot svg { position: absolute; inset: -8%; width: 116%; height: 116%; animation: plop .25s ease-out; }
.slot.q-overcooked svg { filter: brightness(.7) saturate(.8); }
.slot.q-perfect::after { content: "✦"; position: absolute; top: -6px; right: -3px; font-size: .6rem; color: #f4b400; }
@keyframes plop { from { transform: scale(1.4); } }
.patience { height: 5px; border-radius: 3px; background: var(--card-line); overflow: hidden; }
.patience i { display: block; height: 100%; width: 100%; background: var(--good); border-radius: inherit; transform-origin: left; }
.patience.warn i { background: var(--warn); }
.patience.bad i { background: var(--bad); }
.payout {
  position: absolute;
  left: 50%;
  top: 30%;
  transform: translateX(-50%);
  font-weight: 700;
  font-size: .95rem;
  color: var(--good);
  pointer-events: none;
  white-space: nowrap;
}

/* ---------- the pan ---------- */
.grill {
  --n: 3;
  --cell: 100px;
  display: grid;
  grid-template-columns: repeat(var(--n), var(--cell));
  padding: calc(var(--cell) * .1) calc(var(--cell) * .1) calc(var(--cell) * .04);
  background: var(--plate);
  border-radius: calc(var(--cell) * .22);
  box-shadow: 0 calc(var(--cell) * .1) 0 var(--plate-side), 0 calc(var(--cell) * .22) 30px var(--shadow);
  margin-bottom: calc(var(--cell) * .1);
}
.cup {
  all: unset;
  display: block;
  position: relative;
  width: var(--cell);
  aspect-ratio: 216 / 200;
  cursor: pointer;
  touch-action: manipulation;
  border-radius: 30%;
}
.cup:focus-visible { outline: 3px dashed var(--accent); outline-offset: -2px; }
.cup.flip, .cup.tako-out { z-index: 2; }
.cup svg { width: 100%; height: 100%; overflow: visible; display: block; }
.cup.nope svg { animation: nope .3s; }
@keyframes nope { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }

/* what's in the cup */
.batter, .ball, .lid, .badge, .steam, .lid-price { display: none; }
.cup[data-state="batter"] .batter, .cup[data-state="set"] .batter { display: inline; }
.cup[data-state="set"] .badge { display: inline; }
.cup:is([data-state="cooking"], [data-state="golden"], [data-state="overcooked"], [data-state="burnt"]) .ball,
.cup.flip .ball { display: inline; }
.cup[data-state="locked"] .lid { display: inline; }
.cup[data-state="locked"][data-next] .lid-price { display: inline; }
.cup[data-state="locked"]:not([data-next]) { cursor: default; opacity: .75; }
.cup.steamy:is([data-state="cooking"], [data-state="golden"]) .steam,
.cup:is([data-state="overcooked"], [data-state="burnt"]) .steam { display: inline; }

.lid-price { font: 700 30px "JetBrains Mono", ui-monospace, monospace; fill: #ffe2b8; }
.cup[data-state="locked"][data-next]:hover .lid { transform: translateY(-6px); }
.lid { transition: transform .15s; }

.batter { transform-box: view-box; transform-origin: 120px 190px; animation: pour-in .35s ease-out; }
@keyframes pour-in { from { transform: scale(.3, .2); opacity: .4; } }
.crust { opacity: 0; transition: opacity .6s; }
/* the batter puffs up as it sets */
.dome { transform-box: view-box; transform-origin: 120px 196px; transform: scaleY(.4); transition: transform 2.5s ease-out; }
.cup[data-state="set"] .dome { transform: scaleY(1.05); }
.cup[data-state="set"] .crust { opacity: .85; }
.bubbles circle { transform-box: fill-box; transform-origin: center; animation: bubble 1.4s ease-in-out infinite; }
.bubbles circle:nth-child(2) { animation-delay: -.5s; }
.bubbles circle:nth-child(3) { animation-delay: -1s; }
@keyframes bubble { 0%, 100% { transform: scale(.4); opacity: 0; } 50% { transform: scale(1); opacity: 1; } }
.badge { transform-box: view-box; transform-origin: 120px 128px; animation: bob .8s ease-in-out infinite alternate; }
@keyframes bob { from { transform: translateY(0) scale(1); } to { transform: translateY(-8px) scale(1.06); } }

.raw { opacity: var(--raw, 0); transition: opacity .3s linear; }
.char { opacity: var(--burn, 0); transition: opacity .3s linear; }
.sparkle { display: none; }
.cup[data-perfect] .sparkle { display: inline; }
.sparkle path { transform-box: fill-box; transform-origin: center; animation: twinkle 1s ease-in-out infinite alternate; }
.sparkle path:nth-child(2) { animation-delay: -.5s; }
@keyframes twinkle { from { transform: scale(.5) rotate(0); opacity: .5; } to { transform: scale(1.1) rotate(20deg); opacity: 1; } }

.ball, .orbit { transform-box: view-box; transform-origin: 120px 140px; }
.cup:is([data-state="golden"], [data-state="overcooked"]):hover .ball { animation: jiggle .5s ease-in-out; }
@keyframes jiggle {
  0%, 100% { transform: scale(1, 1); }
  30% { transform: scale(1.04, .96); }
  60% { transform: scale(.98, 1.02); }
}

/* flip like at the stall: the pick pokes in, rolls the ball in its cup, pulls out, the ball spins on */
.pick { opacity: 0; }
.cup.flip .ball  { animation: roll 1.4s linear; }
.cup.flip .orbit { animation: orbit 1.4s linear; }
.cup.flip .pick  { animation: poke 1.4s linear; }
@keyframes poke {
  0%   { transform: translateX(150px); opacity: 0; animation-timing-function: ease-out; }
  8%   { opacity: 1; }
  24%  { transform: translateX(-6px); opacity: 1; }
  62%  { transform: translateX(-6px); opacity: 1; animation-timing-function: ease-in; }
  78%  { transform: translateX(150px); opacity: 1; }
  86%, 100% { transform: translateX(150px); opacity: 0; }
}
@keyframes orbit {
  0%, 28% { transform: rotate(0); animation-timing-function: cubic-bezier(.45, 0, .8, .6); }
  62%, 100% { transform: rotate(-150deg); }
}
@keyframes roll {
  0%, 22% { transform: rotate(0) scale(1, 1); }
  26%  { transform: rotate(0) scale(.97, 1.03); }
  28%  { transform: rotate(0) scale(1, 1); animation-timing-function: cubic-bezier(.45, 0, .8, .6); }
  62%  { transform: rotate(-150deg); animation-timing-function: cubic-bezier(.2, .6, .35, 1); }
  90%  { transform: rotate(-366deg); animation-timing-function: ease-in-out; }
  100% { transform: rotate(-360deg); }
}

.steam path { animation: steam 3s ease-in-out infinite; animation-delay: var(--seed, 0s); opacity: 0; }
.steam path:nth-child(2) { animation-delay: calc(var(--seed, 0s) + 1s); }
.steam path:nth-child(3) { animation-delay: calc(var(--seed, 0s) + 2s); }
@keyframes steam {
  0%   { opacity: 0; transform: translateY(10px); }
  30%  { opacity: .55; }
  100% { opacity: 0; transform: translateY(-22px); }
}
.cup[data-state="burnt"] .steam path { stroke: #6f6a68; stroke-width: 8; animation: smoke 1.6s ease-in-out infinite; }
.cup[data-state="burnt"] .steam path:nth-child(2) { animation-delay: .5s; }
.cup[data-state="burnt"] .steam path:nth-child(3) { animation-delay: 1s; }
@keyframes smoke {
  0%   { opacity: 0; transform: translateY(10px); }
  30%  { opacity: .85; }
  100% { opacity: 0; transform: translateY(-26px); }
}

/* faces */
.pupils { transition: transform .12s ease-out; }
.eyes { transform-box: fill-box; transform-origin: center; }
.eyes.blink { animation: blink .18s ease-in-out; }
@keyframes blink { 50% { transform: scaleY(.1); } }
.face-dizzy, .face-burnt, .sweat { display: none; }
.cup.flip .face-dizzy { display: inline; }
.cup.flip .face-happy { display: none; }
.cup[data-state="burnt"]:not(.flip) .face-burnt { display: inline; }
.cup[data-state="burnt"] .face-happy { display: none; }
.cup[data-state="overcooked"]:not(.flip) .sweat { display: inline; animation: sweat 1.2s ease-in infinite; }
@keyframes sweat {
  0%   { transform: translateY(0); opacity: 0; }
  20%  { opacity: 1; }
  100% { transform: translateY(14px); opacity: 0; }
}

/* the rare one: a tentacle peeks out after the flip */
.tentacle { display: none; }
.cup.tako-out .tentacle { display: inline; }
.tentacle-wiggle { transform-box: view-box; transform-origin: 0 0; }
.cup.tako-out .tentacle-wiggle {
  animation: peek .5s cubic-bezier(.3, 1.6, .5, 1) both, wave 1.1s ease-in-out .5s infinite alternate;
}
@keyframes peek { from { transform: scale(0); } to { transform: scale(1); } }
@keyframes wave { from { transform: rotate(-6deg); } to { transform: rotate(14deg); } }

/* team: one emoji per intern / cron job / load balancer */
.team { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; min-height: 0; }
.crew {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--card-line);
  font-size: .72rem;
  color: var(--muted);
}
.crew .who { font-size: 1.05rem; display: inline-block; }
.crew .who.busy { animation: hop .4s ease-out; }
.crew .label { margin-left: 4px; }
@keyframes hop { 40% { transform: translateY(-6px) rotate(-8deg); } }

/* a burnt one gets a halo and floats away */
.angel { position: fixed; z-index: 10; pointer-events: none; }
.angel svg { width: 100%; height: 100%; display: block; overflow: visible; }
.angel .halo { transform-box: fill-box; transform-origin: center; animation: halo-in .35s cubic-bezier(.3, 1.6, .5, 1) both; }
.angel .wings { transform-box: fill-box; transform-origin: center; animation: flap .25s ease-in-out .3s infinite alternate; }
@keyframes halo-in { from { transform: translateY(14px) scale(0); opacity: 0; } }
@keyframes flap { to { transform: scaleY(.8); } }

/* a served piece flying to the tray */
.ghost { position: fixed; z-index: 10; pointer-events: none; }
.ghost svg { width: 100%; height: 100%; display: block; }

/* ---------- shop ---------- */
.shop { grid-area: shop; font-size: .8rem; }
.shop h2 { font-size: .85rem; font-weight: 500; color: var(--muted); margin: 8px 0 8px; }
.shop h2 span, .shop h3 span { color: var(--accent); }
.shop h3 { grid-column: 1 / -1; font-size: .85rem; font-weight: 500; color: var(--muted); margin: 14px 0 0; }
.items { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
@media (min-width: 900px) { .items { grid-template-columns: 1fr; } }
.item {
  all: unset;
  cursor: pointer;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 10px;
  padding: 9px 12px;
  border-radius: 12px;
  background: var(--card);
  border: 1px solid var(--card-line);
  color: var(--ink);
  transition: transform .1s, border-color .15s;
}
.item:hover:not(.owned) { border-color: var(--accent); }
.item:active:not(.owned) { transform: scale(.98); }
.item:focus-visible { outline: 2px dashed var(--accent); outline-offset: 2px; }
.item .name { font-weight: 700; }
.item .price { font-weight: 700; color: var(--accent); text-align: right; }
.item .desc { grid-column: 1 / -1; color: var(--muted); font-size: .72rem; }
.item .lv { font-weight: 500; font-size: .68rem; color: var(--muted); margin-left: 6px; }
.item .pips { grid-column: 1 / -1; display: flex; gap: 3px; margin-top: 3px; }
.item .pips i { width: 14px; height: 4px; border-radius: 2px; background: var(--card-line); }
.item .pips i.on { background: var(--accent); }
.item.owned .pips i.on { background: var(--good); }
.item.poor .price { color: var(--muted); }
.item.poor { opacity: .7; }
.item.owned { cursor: default; opacity: .6; }
.item.owned .price { color: var(--good); }

footer { font-size: .72rem; color: var(--muted); opacity: .7; text-align: center; padding: 16px; }

@media (prefers-reduced-motion: reduce) {
  .steam path, .bubbles circle, .badge, .sparkle path, .batter, .customer, .slot svg,
  .cup:hover .ball, .cup.flip .ball, .cup.flip .orbit, .cup.flip .pick,
  .cup[data-state="overcooked"] .sweat, .cup.tako-out .tentacle-wiggle,
  .crew .who.busy, .angel .halo, .angel .wings,
  body.in-fever .grill, body.in-fever .fever .bar i { animation: none; }
  .steam path { opacity: .35; }
}
