:root {
  --tomato: #e9472f;
  --tomato-dark: #b72d21;
  --egg: #f6c548;
  --cream: #fff8dc;
  --paper: #fffdf2;
  --soy: #251d17;
  --green: #34724a;
  --muted: #74685c;
  --line: rgba(37, 29, 23, 0.18);
  --shadow: 0 24px 70px rgba(84, 45, 16, 0.2);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--soy);
  background:
    radial-gradient(circle at 10% 15%, rgba(255,255,255,.58) 0 2px, transparent 3px),
    linear-gradient(125deg, #f7cf58 0%, #f3bd37 58%, #efac28 100%);
  background-size: 28px 28px, auto;
  font-family: "Noto Sans SC", system-ui, sans-serif;
  overflow-x: hidden;
}

button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible { outline: 4px solid #fff; outline-offset: 4px; }

.noise {
  position: fixed;
  inset: 0;
  z-index: -1;
  opacity: .16;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.3'/%3E%3C/svg%3E");
}

.topbar {
  width: min(1180px, calc(100% - 40px));
  height: 88px;
  margin: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--soy);
  font-weight: 900;
  text-decoration: none;
  letter-spacing: -.04em;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 12px 8px 13px 7px;
  color: #fff;
  background: var(--tomato);
  box-shadow: 3px 4px 0 var(--soy);
  transform: rotate(-4deg);
}

.history-button {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px 10px 18px;
  border: 1.5px solid var(--soy);
  border-radius: 999px;
  background: rgba(255, 248, 220, .64);
  cursor: pointer;
  font-weight: 700;
  transition: transform .2s ease, background .2s ease;
}

.history-button:hover { transform: translateY(-2px); background: var(--cream); }
.history-count { min-width: 25px; height: 25px; display: grid; place-items: center; border-radius: 50%; color: #fff; background: var(--soy); font-size: 12px; }

.hero {
  width: min(1180px, calc(100% - 40px));
  min-height: calc(100vh - 88px);
  margin: auto;
  padding: 28px 0 72px;
  display: grid;
  grid-template-columns: minmax(250px, .72fr) minmax(440px, 1.25fr) minmax(260px, .72fr);
  gap: 28px;
  align-items: center;
}

.eyebrow { display: flex; align-items: center; gap: 9px; margin: 0 0 18px; font-size: 13px; font-weight: 900; letter-spacing: .16em; }
.eyebrow span { width: 34px; height: 4px; border-radius: 4px; background: var(--tomato); }

h1 {
  margin: 0;
  font-size: clamp(56px, 7.3vw, 106px);
  line-height: .92;
  letter-spacing: -.1em;
  font-weight: 900;
}

h1 em {
  position: relative;
  display: inline-block;
  margin-top: 16px;
  color: var(--tomato);
  font-family: "Ma Shan Zheng", cursive;
  font-weight: 400;
  letter-spacing: -.04em;
  transform: rotate(-3deg);
}

h1 em::after { content: ""; position: absolute; left: 3%; right: -4%; bottom: -4px; height: 9px; border-radius: 50%; background: var(--soy); transform: rotate(1deg); }
.lede { max-width: 340px; margin: 34px 0 0; color: #5f4b38; line-height: 1.9; font-size: 16px; }
.lede strong { color: var(--soy); font-size: 21px; }

.machine { position: relative; min-height: 620px; display: grid; place-items: center; isolation: isolate; }
.machine-shadow { position: absolute; width: 62%; height: 18%; bottom: 9%; border-radius: 50%; background: rgba(91, 49, 13, .25); filter: blur(24px); transform: rotate(-4deg); }
.food-orbit { width: min(100%, 670px); position: relative; z-index: 1; filter: drop-shadow(0 18px 20px rgba(79, 38, 5, .22)); animation: float 5s ease-in-out infinite; will-change: transform; }

.ticker {
  position: absolute;
  z-index: 3;
  width: 34%;
  min-width: 200px;
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  border: 8px solid var(--soy);
  border-radius: 50%;
  background: var(--paper);
  box-shadow: inset 0 0 0 5px var(--egg), 8px 12px 0 rgba(37, 29, 23, .22);
}

.ticker-label { margin-bottom: 9px; color: var(--tomato); font-size: 12px; font-weight: 900; letter-spacing: .22em; }
.ticker-window { width: 100%; height: 64px; display: grid; place-items: center; overflow: hidden; border-block: 2px dashed var(--line); }
.ticker-window span { display: block; font-weight: 900; font-size: clamp(17px, 2vw, 26px); line-height: 1.2; letter-spacing: -.05em; }
.ticker-window span.tick { animation: tickerFlip .12s ease both; }
.ticker-hint { margin-top: 10px; color: var(--muted); font-size: 11px; }

.draw-button { position: absolute; z-index: 5; bottom: 5%; border: 0; padding: 0; border-radius: 999px; background: var(--soy); box-shadow: 0 9px 0 var(--soy), 0 15px 28px rgba(64, 31, 6, .32); cursor: pointer; transition: transform .16s ease, box-shadow .16s ease; }
.draw-button-face { min-width: 190px; padding: 17px 27px; display: flex; justify-content: center; gap: 10px; border: 2px solid var(--soy); border-radius: 999px; color: #fff; background: var(--tomato); font-size: 18px; font-weight: 900; transform: translateY(-6px); transition: transform .16s ease, background .2s ease; }
.draw-button:hover { transform: translateY(-2px); }
.draw-button:hover .draw-button-face { background: #f05038; }
.draw-button:active { box-shadow: 0 3px 0 var(--soy); transform: translateY(6px); }
.draw-button:active .draw-button-face { transform: translateY(-2px); }
.draw-button:disabled { cursor: wait; }
.dice { font-size: 20px; }

.machine.is-drawing .food-orbit { animation: spinDraw .55s linear infinite; }
.machine.is-drawing .ticker { animation: machineShake .18s linear infinite; }

.controls { padding: 26px; border: 2px solid var(--soy); border-radius: 27px 18px 29px 16px; background: rgba(255, 248, 220, .72); box-shadow: 7px 8px 0 rgba(37,29,23,.16); backdrop-filter: blur(12px); transform: rotate(1deg); }
.control-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.control-heading span { font-weight: 900; font-size: 18px; }
.control-heading button { border: 0; padding: 4px; color: var(--muted); background: none; cursor: pointer; font-size: 12px; }
.control-heading button:hover { color: var(--tomato); }
.category-list { display: flex; flex-wrap: wrap; gap: 9px; }
.category-chip { border: 1.5px solid var(--soy); border-radius: 999px; padding: 8px 12px; background: transparent; cursor: pointer; font-size: 12px; font-weight: 700; transition: transform .16s ease, color .16s ease, background .16s ease; }
.category-chip:hover { transform: translateY(-2px) rotate(-1deg); }
.category-chip.active { color: #fff; background: var(--soy); }
.exclude-toggle { margin-top: 20px; display: flex; align-items: center; gap: 10px; cursor: pointer; color: var(--muted); font-size: 12px; }
.exclude-toggle input { position: absolute; opacity: 0; }
.toggle-ui { width: 38px; height: 22px; padding: 3px; border: 1.5px solid var(--soy); border-radius: 999px; background: var(--paper); transition: background .2s ease; }
.toggle-ui::after { content: ""; display: block; width: 13px; height: 13px; border-radius: 50%; background: var(--soy); transition: transform .2s ease; }
.exclude-toggle input:checked + .toggle-ui { background: var(--green); }
.exclude-toggle input:checked + .toggle-ui::after { background: #fff; transform: translateX(16px); }

.receipt-stage { display: none; min-height: 100vh; padding: 96px 20px; place-items: center; background: var(--soy); }
.receipt-stage.visible { display: grid; }
.receipt { position: relative; width: min(430px, 92vw); padding: 50px 42px 42px; text-align: center; background: var(--paper); box-shadow: var(--shadow); transform-origin: top center; animation: printReceipt .85s cubic-bezier(.2,.85,.2,1) both; }
.receipt-tear { position: absolute; left: 0; right: 0; height: 15px; background: radial-gradient(circle at 10px -2px, transparent 10px, var(--paper) 10.5px) 0 0 / 20px 20px repeat-x; }
.receipt-tear.top { top: -10px; transform: rotate(180deg); }
.receipt-tear.bottom { bottom: -10px; }
.receipt-kicker { margin: 0; font-size: 12px; font-weight: 900; letter-spacing: .28em; }
.receipt-number { margin: 8px 0 0; color: var(--muted); font: 12px ui-monospace, monospace; }
.result-image { width: 230px; height: 210px; margin: 6px auto -4px; object-fit: contain; filter: drop-shadow(0 12px 10px rgba(64,32,11,.16)); animation: resultPop .7s .45s cubic-bezier(.2,1.3,.4,1) both; }
.receipt-rule { height: 2px; margin: 4px 0 22px; background: var(--soy); }
.receipt-rule.dashed { height: 0; margin: 25px 0 16px; border-top: 1.5px dashed var(--line); background: none; }
.result-category { display: inline-block; margin: 0 0 10px; padding: 5px 10px; border-radius: 999px; color: #fff; background: var(--green); font-size: 11px; font-weight: 700; }
.receipt h2 { margin: 0; font-size: clamp(29px, 7vw, 42px); line-height: 1.15; letter-spacing: -.07em; }
.result-reason { margin: 14px auto 0; max-width: 290px; color: var(--muted); font-size: 14px; line-height: 1.7; }
.receipt-meta { margin: 0; display: flex; justify-content: space-between; text-align: left; font: 12px ui-monospace, monospace; }
.receipt-meta div:last-child { text-align: right; }
.receipt-meta dt { color: var(--muted); }
.receipt-meta dd { margin: 4px 0 0; font-weight: 700; }
.stamp { position: absolute; right: 25px; bottom: 105px; width: 73px; height: 73px; display: grid; place-items: center; border: 5px double var(--tomato); border-radius: 50%; color: var(--tomato); font-family: "Ma Shan Zheng", cursive; font-size: 29px; transform: rotate(-13deg) scale(0); opacity: .78; animation: stampIn .35s .8s ease-out forwards; }
.receipt-actions { margin-top: 38px; display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; }
.receipt-actions button { min-height: 48px; border: 2px solid var(--soy); border-radius: 10px; cursor: pointer; font-weight: 900; }
.receipt-actions .secondary { background: transparent; }
.receipt-actions .primary { color: #fff; background: var(--tomato); box-shadow: 3px 4px 0 var(--soy); }

.confetti { position: absolute; inset: 0; z-index: 6; pointer-events: none; overflow: visible; }
.confetti i { position: absolute; left: 50%; top: 50%; width: 10px; height: 18px; border-radius: 3px; background: var(--c); animation: confettiFly .9s ease-out forwards; }

.history-drawer { position: fixed; inset: 0; z-index: 20; visibility: hidden; pointer-events: none; }
.history-drawer.open { visibility: visible; pointer-events: auto; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(37,29,23,.48); opacity: 0; transition: opacity .3s ease; }
.drawer-panel { position: absolute; top: 0; right: 0; width: min(420px, 92vw); height: 100%; padding: 34px; display: flex; flex-direction: column; background: var(--paper); transform: translateX(100%); transition: transform .36s cubic-bezier(.2,.8,.2,1); }
.history-drawer.open .drawer-backdrop { opacity: 1; }
.history-drawer.open .drawer-panel { transform: none; }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2px solid var(--soy); padding-bottom: 18px; }
.drawer-head p { margin: 0; color: var(--tomato); font-size: 11px; font-weight: 900; letter-spacing: .2em; }
.drawer-head h2 { margin: 5px 0 0; font-size: 29px; }
.drawer-head button { width: 38px; height: 38px; border: 1.5px solid var(--soy); border-radius: 50%; background: none; cursor: pointer; font-size: 24px; }
.history-list { flex: 1; margin: 0; padding: 12px 0; overflow: auto; list-style: none; counter-reset: meals; }
.history-list li { counter-increment: meals; padding: 16px 4px; display: grid; grid-template-columns: 34px 1fr; border-bottom: 1px dashed var(--line); }
.history-list li::before { content: counter(meals, decimal-leading-zero); color: var(--tomato); font: 12px ui-monospace, monospace; }
.history-list strong { display: block; font-size: 15px; }
.history-list small { display: block; margin-top: 4px; color: var(--muted); }
.history-empty { color: var(--muted); text-align: center; padding-top: 70px !important; display: block !important; }
.history-empty::before { display: none; }
.clear-history { min-height: 46px; border: 1.5px solid var(--soy); border-radius: 10px; background: transparent; cursor: pointer; }
.toast { position: fixed; z-index: 30; left: 50%; bottom: 28px; padding: 12px 18px; border-radius: 999px; color: #fff; background: var(--soy); transform: translate(-50%, 120px); transition: transform .3s ease; font-size: 13px; font-weight: 700; }
.toast.show { transform: translate(-50%, 0); }

@keyframes float { 0%,100% { transform: translateY(0) rotate(-1deg); } 50% { transform: translateY(-12px) rotate(1deg); } }
@keyframes spinDraw { to { transform: rotate(360deg) scale(.96); } }
@keyframes machineShake { 0%,100% { transform: translate(0); } 25% { transform: translate(-3px, 2px); } 75% { transform: translate(3px, -2px); } }
@keyframes tickerFlip { 0% { transform: translateY(-35px); opacity: 0; } 100% { transform: none; opacity: 1; } }
@keyframes printReceipt { 0% { transform: translateY(-60px) scaleY(.1); opacity: 0; } 60% { transform: translateY(8px) scaleY(1.02); opacity: 1; } 100% { transform: none; } }
@keyframes resultPop { from { transform: translateY(20px) scale(.72) rotate(-5deg); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes stampIn { 0% { transform: rotate(-13deg) scale(1.8); opacity: 0; } 100% { transform: rotate(-13deg) scale(1); opacity: .78; } }
@keyframes confettiFly { to { transform: translate(var(--x), var(--y)) rotate(var(--r)); opacity: 0; } }

@media (max-width: 980px) {
  .hero { grid-template-columns: 1fr 1.4fr; align-items: start; }
  .intro { padding-top: 80px; }
  .controls { grid-column: 1 / -1; width: min(650px, 100%); justify-self: center; transform: none; }
}

@media (max-width: 680px) {
  .topbar { width: min(100% - 28px, 1180px); height: 72px; }
  .history-button > span:first-child { display: none; }
  .hero { width: min(100% - 28px, 1180px); padding-top: 22px; display: flex; flex-direction: column; gap: 8px; }
  .intro { width: 100%; padding-top: 0; text-align: center; }
  .eyebrow { justify-content: center; margin-bottom: 12px; }
  h1 { font-size: clamp(54px, 16vw, 66px); }
  h1 em { margin-top: 8px; }
  .lede { margin: 17px auto 0; line-height: 1.65; }
  .machine { width: 100%; min-height: 390px; margin: -24px 0 40px; }
  .food-orbit { width: min(94%, 445px); max-width: none; }
  .ticker { width: 40%; min-width: 164px; padding: 18px; border-width: 6px; }
  .ticker-window { height: 54px; }
  .ticker-window span { font-size: 17px; }
  .draw-button { bottom: -40px; }
  .controls { width: 100%; padding: 21px; margin-top: 8px; }
  .receipt-stage { padding: 70px 12px; }
  .receipt { padding-inline: 28px; }
}

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