:root {
  --espresso: #2b1a10;
  --copper: #b5562a;
  --saffron: #f4a623;
  --cream: #fff1d6;
  --cobalt: #2e63b0;
  --tomato: #d9342b;
  --ink-dim: rgba(255, 241, 214, 0.72);
  --panel: rgba(43, 26, 16, 0.72);
  --panel-line: rgba(255, 241, 214, 0.18);
  --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);
  --display: "Lilita One", "Arial Rounded MT Bold", "Trebuchet MS", system-ui, sans-serif;
  --ui: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--espresso);
  font-family: var(--ui);
  color: var(--cream);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#scene {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

#vig {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 2;
  background: radial-gradient(130% 100% at 50% 45%, transparent 60%, rgba(30, 14, 6, 0.5) 100%);
}

button {
  font-family: inherit;
  border: none;
  cursor: pointer;
  color: inherit;
  user-select: none;
  -webkit-user-select: none;
}
button:focus-visible { outline: 3px solid var(--saffron); outline-offset: 3px; }

/* ---------------- HUD ---------------- */
#hud { position: fixed; inset: 0; z-index: 5; pointer-events: none; }
#hud[hidden] { display: none; }
#hud button { pointer-events: auto; }
#hud.dim #topbar { opacity: 0; transform: translateY(-12px); }

#topbar {
  position: absolute;
  top: calc(var(--safe-t) + 10px);
  left: calc(var(--safe-l) + 12px);
  right: calc(var(--safe-r) + 12px);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: start;
  gap: 8px;
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.plates { display: flex; gap: 6px; padding-top: 6px; }
.plate {
  position: relative;
  width: 28px; height: 28px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 42% 38%, #fffdf6 0 30%, #f1e4c8 31% 44%, #fffaf0 45% 58%, var(--cobalt) 59% 66%, #fffaf0 67% 74%, #e6d6b6 75% 100%);
  box-shadow: 0 2px 0 rgba(43, 26, 16, 0.55), 0 0 0 2px var(--espresso), 0 4px 10px rgba(0, 0, 0, 0.3);
  transition: transform 0.35s cubic-bezier(.3, 1.6, .5, 1), opacity 0.4s ease, filter 0.4s ease;
}
.plate.broken { opacity: 0.35; filter: grayscale(0.8); transform: scale(0.82) rotate(-18deg); clip-path: polygon(0 0, 46% 0, 58% 32%, 40% 58%, 56% 100%, 0 100%); }
.plate.breaking { animation: plateBreak 0.55s ease; }
.plate.back { animation: plateBack 0.6s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes plateBreak { 0% { transform: scale(1.3); } 30% { transform: scale(1.35) rotate(12deg); filter: brightness(1.6); } 100% { transform: scale(0.82) rotate(-18deg); } }
@keyframes plateBack { 0% { transform: scale(0.2) rotate(-90deg); } 100% { transform: scale(1) rotate(0); } }

.center { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 0; }
.score-row { display: flex; align-items: center; gap: 8px; }
.score {
  font-family: var(--display);
  font-size: 40px;
  line-height: 1;
  color: var(--saffron);
  font-variant-numeric: tabular-nums;
  -webkit-text-stroke: 2px var(--espresso);
  paint-order: stroke fill;
  text-shadow: 0 3px 0 var(--espresso), 0 6px 18px rgba(0, 0, 0, 0.35);
  transition: transform 0.12s ease;
}
.score.bump { transform: scale(1.18); }
.streak {
  display: inline-flex; align-items: center; gap: 3px;
  font-family: var(--display);
  font-size: 18px;
  padding: 4px 9px 4px 7px;
  border-radius: 999px;
  background: var(--espresso);
  color: var(--ink-dim);
  border: 2px solid rgba(255, 241, 214, 0.25);
  transition: transform 0.2s cubic-bezier(.3, 1.6, .5, 1), color 0.3s, background 0.3s, box-shadow 0.3s;
}
.streak svg { color: rgba(255, 241, 214, 0.4); transition: transform 0.3s, color 0.3s; }
.streak[data-m="2"] { color: var(--cream); border-color: var(--saffron); }
.streak[data-m="2"] svg { color: var(--saffron); transform: scale(1.1); }
.streak[data-m="3"] { color: var(--espresso); background: var(--saffron); border-color: var(--cream); }
.streak[data-m="3"] svg { color: var(--tomato); transform: scale(1.25); }
.streak[data-m="4"], .streak[data-m="5"] { color: var(--cream); background: var(--tomato); border-color: var(--saffron); box-shadow: 0 0 18px rgba(244, 166, 35, 0.7); }
.streak[data-m="4"] svg, .streak[data-m="5"] svg { color: var(--saffron); transform: scale(1.4); animation: flame 0.35s ease-in-out infinite alternate; }
.streak.pop { transform: scale(1.35); }
@keyframes flame { from { transform: scale(1.3) rotate(-6deg); } to { transform: scale(1.5) rotate(6deg); } }

.dish { display: flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px; background: rgba(43, 26, 16, 0.55); max-width: 100%; }
.dish-name { font-family: var(--display); font-size: 12px; letter-spacing: 0.04em; color: var(--cream); text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.pips { display: flex; gap: 3px; flex: none; }
.pips i { width: 8px; height: 8px; border-radius: 50%; background: rgba(255, 241, 214, 0.18); box-shadow: inset 0 0 0 1.5px rgba(255, 241, 214, 0.35); transition: background 0.2s, transform 0.25s cubic-bezier(.3, 1.6, .5, 1); }
.pips i.on { background: var(--saffron); box-shadow: inset 0 0 0 1.5px var(--cream); transform: scale(1.15); }

.right { display: flex; justify-content: flex-end; gap: 8px; }
.icon-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--panel);
  border: 2px solid var(--panel-line);
  color: var(--cream);
  transition: transform 0.15s ease, background 0.2s;
}
.icon-btn:active { transform: scale(0.9); }
.slash { display: none; }
.muted .slash { display: inline; }
.muted .wave { display: none; }

#kudos {
  position: absolute;
  left: 50%; top: 30%;
  transform: translate(-50%, -50%) scale(0.6);
  font-family: var(--display);
  font-size: clamp(34px, 9vw, 64px);
  color: var(--saffron);
  -webkit-text-stroke: 3px var(--espresso);
  paint-order: stroke fill;
  text-shadow: 0 5px 0 var(--espresso);
  opacity: 0;
  white-space: nowrap;
  pointer-events: none;
}
#kudos.show { animation: kudos 1.1s cubic-bezier(.2, 1.4, .4, 1) forwards; }
@keyframes kudos {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.4) rotate(-6deg); }
  18% { opacity: 1; transform: translate(-50%, -50%) scale(1.12) rotate(2deg); }
  30% { transform: translate(-50%, -50%) scale(1) rotate(0); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -64%) scale(1); }
}

#flash { position: absolute; inset: 0; background: var(--tomato); opacity: 0; pointer-events: none; }
#flash.hit { animation: flash 0.45s ease-out; }
@keyframes flash { 0% { opacity: 0.28; } 100% { opacity: 0; } }

/* dish card */
#dishCard {
  position: absolute;
  left: 50%; top: 42%;
  transform: translate(-50%, -50%);
  min-width: min(84vw, 360px);
  padding: 18px 26px 20px;
  border-radius: 26px;
  text-align: center;
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(244, 166, 35, 0.25), transparent 60%),
    linear-gradient(180deg, #4a2a16, #2b1a10);
  border: 3px solid var(--saffron);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45), inset 0 0 0 3px rgba(255, 241, 214, 0.08);
  animation: cardIn 0.45s cubic-bezier(.2, 1.4, .4, 1);
}
#dishCard[hidden] { display: none; }
#dishCard.out { animation: cardOut 0.35s ease-in forwards; }
@keyframes cardIn { from { opacity: 0; transform: translate(-50%, -30%) scale(0.7) rotate(-4deg); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }
@keyframes cardOut { to { opacity: 0; transform: translate(-50%, -80%) scale(0.9); } }
.dc-kicker { font-family: var(--display); font-size: 14px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--saffron); }
.dc-title { font-family: var(--display); font-size: clamp(34px, 9vw, 52px); line-height: 1.05; color: var(--cream); -webkit-text-stroke: 2px var(--espresso); paint-order: stroke fill; text-shadow: 0 4px 0 #120a05; }
.dc-lines { margin-top: 8px; display: flex; flex-direction: column; gap: 3px; font-weight: 800; font-size: 15px; color: var(--ink-dim); }
.dc-lines b { color: var(--saffron); font-family: var(--display); font-weight: 400; font-size: 18px; }
.dc-lines .good { color: #9fe06a; }

/* ---------------- overlays ---------------- */
.overlay {
  position: fixed; inset: 0;
  z-index: 10;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: calc(var(--safe-t) + 20px) calc(var(--safe-r) + 18px) calc(var(--safe-b) + 20px) calc(var(--safe-l) + 18px);
  animation: fadeIn 0.35s ease;
}
.overlay[hidden] { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.menu.leaving { animation: menuOut 0.26s ease forwards; pointer-events: none; }
@keyframes menuOut { to { opacity: 0; transform: scale(1.04); } }
.menu { justify-content: space-between; background: linear-gradient(180deg, rgba(43, 26, 16, 0.62) 0%, rgba(43, 26, 16, 0.05) 32%, rgba(43, 26, 16, 0) 55%, rgba(43, 26, 16, 0.78) 100%); }
.menu-top { margin-top: 3vh; text-align: center; }
.title {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(64px, 17vw, 128px);
  line-height: 0.92;
  color: var(--saffron);
  -webkit-text-stroke: 4px var(--espresso);
  paint-order: stroke fill;
  text-shadow: 0 7px 0 var(--espresso), 0 14px 30px rgba(0, 0, 0, 0.4);
  letter-spacing: 0.01em;
}
.title span { display: inline-block; animation: bob 2.4s ease-in-out infinite; }
.title span + span { animation-delay: -1.2s; color: var(--cream); }
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-8px) rotate(2deg); } }
.tagline { text-wrap: balance; margin-top: 12px; font-weight: 800; font-size: clamp(15px, 3.8vw, 20px); color: var(--cream); text-shadow: 0 2px 8px rgba(0, 0, 0, 0.7); }

.menu-actions { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 3vh; width: min(100%, 380px); }
.primary {
  width: 100%;
  min-height: 64px;
  border-radius: 22px;
  font-family: var(--display);
  font-size: 30px;
  letter-spacing: 0.03em;
  color: var(--espresso);
  background: linear-gradient(180deg, #ffc65a, var(--saffron) 55%, #e08a12);
  box-shadow: 0 6px 0 #8a4a10, 0 14px 30px rgba(0, 0, 0, 0.35), inset 0 2px 0 rgba(255, 255, 255, 0.5);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}
.primary:active { transform: translateY(4px); box-shadow: 0 2px 0 #8a4a10, 0 8px 18px rgba(0, 0, 0, 0.35); }
#playBtn { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 6px 0 #8a4a10, 0 14px 30px rgba(0, 0, 0, 0.35), inset 0 2px 0 rgba(255, 255, 255, 0.5), 0 0 0 0 rgba(244, 166, 35, 0.55); }
  50% { box-shadow: 0 6px 0 #8a4a10, 0 14px 30px rgba(0, 0, 0, 0.35), inset 0 2px 0 rgba(255, 255, 255, 0.5), 0 0 0 12px rgba(244, 166, 35, 0); }
}
.ghost {
  min-height: 48px;
  padding: 0 22px;
  border-radius: 16px;
  font-weight: 900;
  font-size: 16px;
  color: var(--cream);
  background: var(--panel);
  border: 2px solid var(--panel-line);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.ghost.small { min-height: 40px; font-size: 14px; padding: 0 16px; }
.best { font-weight: 800; font-size: 15px; color: var(--cream); text-shadow: 0 2px 6px rgba(0, 0, 0, 0.8); text-align: center; }
.best b { color: var(--saffron); font-family: var(--display); font-weight: 400; font-size: 19px; }
.hints {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 7px 14px; border-radius: 14px;
  background: var(--panel); border: 1.5px solid var(--panel-line);
  font-size: 13px; font-weight: 800; color: var(--cream); text-align: center;
}
@media (pointer: coarse) { .hints .kb { display: none; } }

.card {
  width: min(92vw, 400px);
  padding: 26px 24px 22px;
  border-radius: 28px;
  background:
    radial-gradient(120% 70% at 50% 0%, rgba(244, 166, 35, 0.18), transparent 60%),
    linear-gradient(180deg, rgba(74, 42, 22, 0.97), rgba(43, 26, 16, 0.97));
  border: 3px solid rgba(244, 166, 35, 0.55);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  text-align: center;
  animation: cardPop 0.4s cubic-bezier(.2, 1.4, .4, 1);
}
@keyframes cardPop { from { opacity: 0; transform: translateY(24px) scale(0.92); } to { opacity: 1; transform: none; } }
.card .ghost { width: 100%; }
.card-title { font-family: var(--display); font-weight: 400; font-size: 42px; color: var(--saffron); -webkit-text-stroke: 2px var(--espresso); paint-order: stroke fill; text-shadow: 0 4px 0 #120a05; }
.sub { font-weight: 700; color: var(--ink-dim); }

#pause { background: rgba(30, 16, 8, 0.55); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }

/* game over: keep the top ~130px clear for the platform's score card */
.over { justify-content: flex-end; padding-top: calc(var(--safe-t) + 132px); background: linear-gradient(180deg, rgba(30, 16, 8, 0) 0%, rgba(30, 16, 8, 0.45) 40%, rgba(30, 16, 8, 0.8) 100%); }
.over-card { gap: 8px; margin-bottom: max(2vh, 8px); }
.over-kicker { font-family: var(--display); font-size: 16px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--saffron); }
.over-score {
  font-family: var(--display);
  font-size: clamp(64px, 18vw, 96px);
  line-height: 1;
  color: var(--cream);
  font-variant-numeric: tabular-nums;
  -webkit-text-stroke: 3px var(--espresso);
  paint-order: stroke fill;
  text-shadow: 0 6px 0 #120a05;
}
.stamp {
  font-family: var(--display);
  font-size: 22px;
  color: var(--cream);
  background: var(--tomato);
  padding: 4px 16px;
  border-radius: 10px;
  border: 3px solid var(--cream);
  transform: rotate(-6deg);
  animation: stamp 0.5s cubic-bezier(.2, 1.6, .4, 1);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}
.stamp[hidden] { display: none; }
@keyframes stamp { from { transform: rotate(-20deg) scale(2.4); opacity: 0; } to { transform: rotate(-6deg) scale(1); opacity: 1; } }
.over-delta { font-weight: 900; font-size: 16px; color: var(--saffron); min-height: 20px; }
.over-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: 100%; margin: 4px 0; }
.over-stats div { display: flex; flex-direction: column; align-items: center; padding: 8px 4px; border-radius: 14px; background: rgba(255, 241, 214, 0.07); }
.over-stats b { font-family: var(--display); font-weight: 400; font-size: 24px; color: var(--cream); }
.over-stats span { font-size: 11.5px; font-weight: 800; color: var(--ink-dim); text-transform: uppercase; letter-spacing: 0.05em; }
.trail { display: flex; gap: 4px; width: 100%; justify-content: center; flex-wrap: wrap; }
.trail span {
  font-family: var(--display); font-size: 12.5px; letter-spacing: 0.03em; text-transform: uppercase;
  padding: 4px 9px; border-radius: 999px;
  color: rgba(255, 241, 214, 0.38); background: rgba(255, 241, 214, 0.06); border: 1.5px solid rgba(255, 241, 214, 0.12);
}
.trail span.done { color: var(--espresso); background: var(--saffron); border-color: var(--cream); }
.trail span.here { color: var(--cream); border-color: var(--saffron); background: rgba(244, 166, 35, 0.18); }
.dish.clean { box-shadow: 0 0 0 1.5px rgba(244, 166, 35, 0.75), 0 0 12px rgba(244, 166, 35, 0.35); }
.over-quip { font-weight: 800; font-style: italic; color: var(--cream); opacity: 0.9; margin-bottom: 4px; }

/* loader */
#loader {
  position: fixed; inset: 0;
  z-index: 20;
  display: grid; place-items: center;
  background: radial-gradient(80% 60% at 50% 40%, #5a2f16, var(--espresso));
  transition: opacity 0.5s ease;
}
#loader.done { opacity: 0; pointer-events: none; }
.loader-inner { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.loader-pot { animation: bob 1.4s ease-in-out infinite; }
.loader-pot .steam { animation: steam 1.2s ease-in-out infinite; opacity: 0.8; }
.loader-pot .s2 { animation-delay: -0.4s; }
.loader-pot .s3 { animation-delay: -0.8s; }
@keyframes steam { 0% { transform: translateY(6px); opacity: 0; } 50% { opacity: 0.9; } 100% { transform: translateY(-8px); opacity: 0; } }
.loader-title { font-family: var(--display); font-size: 40px; color: var(--saffron); -webkit-text-stroke: 2px var(--espresso); paint-order: stroke fill; }
.loader-sub { font-weight: 800; color: var(--ink-dim); }

/* landscape: keep the counter (pot + slingshot) clear, actions sit on the wall */
@media (min-aspect-ratio: 5/4) {
  .menu { justify-content: flex-start; gap: 18px; background: linear-gradient(180deg, rgba(43, 26, 16, 0.6) 0%, rgba(43, 26, 16, 0.25) 45%, rgba(43, 26, 16, 0) 62%); }
  .menu-top { margin-top: 2vh; }
  .menu-actions {
    width: min(100%, 480px);
    margin-bottom: 0; padding: 16px 18px 14px; border-radius: 26px;
    background: rgba(43, 26, 16, 0.58); border: 2px solid rgba(244, 166, 35, 0.35);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  }
  .hints { margin-top: 2px; background: none; border: none; padding: 2px 4px; color: var(--ink-dim); white-space: nowrap; }
}
@media (max-height: 560px) {
  .menu-top { margin-top: 0; }
  .title { font-size: 56px; }
  .hints { display: none; }
  .over { padding-top: calc(var(--safe-t) + 100px); }
  .trail { display: flex; gap: 4px; width: 100%; justify-content: center; flex-wrap: wrap; }
.trail span {
  font-family: var(--display); font-size: 12.5px; letter-spacing: 0.03em; text-transform: uppercase;
  padding: 4px 9px; border-radius: 999px;
  color: rgba(255, 241, 214, 0.38); background: rgba(255, 241, 214, 0.06); border: 1.5px solid rgba(255, 241, 214, 0.12);
}
.trail span.done { color: var(--espresso); background: var(--saffron); border-color: var(--cream); }
.trail span.here { color: var(--cream); border-color: var(--saffron); background: rgba(244, 166, 35, 0.18); }
.dish.clean { box-shadow: 0 0 0 1.5px rgba(244, 166, 35, 0.75), 0 0 12px rgba(244, 166, 35, 0.35); }
.over-quip { display: none; }
}
@media (max-width: 400px) {
  .trail { gap: 3px; flex-wrap: nowrap; }
  .trail span { font-size: 11px; padding: 3px 6px; letter-spacing: 0.01em; }
  .plates { gap: 4px; }
  .plate { width: 25px; height: 25px; }
  .icon-btn { width: 40px; height: 40px; }
  .right { gap: 6px; }
  #topbar { gap: 6px; left: calc(var(--safe-l) + 10px); right: calc(var(--safe-r) + 10px); }
  .score { font-size: 36px; }
}
@media (min-width: 900px) {
  .score { font-size: 48px; }
  .plate { width: 36px; height: 36px; }
  .dish-name { font-size: 15px; }
  .pips i { width: 10px; height: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  .title span, #playBtn, .loader-pot { animation: none; }
}
