:root {
  --ink: #1b1410;
  --panel: rgba(27, 20, 16, 0.9);
  --panel-solid: #221913;
  --cream: #fff6e5;
  --muted: #cbb9a3;
  --ketchup: #e63946;
  --ketchup-dark: #b8232f;
  --mustard: #ffcf4a;
  --bun: #f4a261;
  --lettuce: #6ab04c;
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--ink);
  color: var(--cream);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--mustard); outline-offset: 2px; }
[hidden] { display: none !important; }

#app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  max-width: 900px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
}

/* ------------------------------------------------------------------ HUD */

#hud {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(6px + env(safe-area-inset-top, 0px)) 10px 6px 12px;
  background: var(--panel-solid);
  border-bottom: 3px solid var(--ketchup);
  z-index: 5;
}

#hud-toggle {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  background: none;
  border: 0;
  padding: 2px 0;
  text-align: left;
}

.brand {
  font-weight: 900;
  letter-spacing: 0.08em;
  font-size: 17px;
  color: var(--mustard);
  text-shadow: 2px 2px 0 var(--ketchup-dark);
}

.hud-line {
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.hud-line b { color: var(--cream); font-variant-numeric: tabular-nums; }
.hud-line .dot { margin: 0 5px; opacity: 0.6; }

.hud-right { display: flex; align-items: center; gap: 4px; }

.online {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--muted);
  padding: 0 6px;
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #888;
  display: inline-block;
}
.online[data-status="live"] .status-dot { background: var(--lettuce); box-shadow: 0 0 6px var(--lettuce); }
.online[data-status="polling"] .status-dot { background: var(--mustard); }
.online[data-status="offline"] .status-dot { background: var(--ketchup); }

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 0;
  background: rgba(255, 255, 255, 0.08);
  font-size: 18px;
  line-height: 1;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.16); }

/* ---------------------------------------------------------------- stage */

#stage {
  position: relative;
  overflow: hidden;
  min-height: 0;
  background: #f3e6cf;
}

#game {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}
#game:active { cursor: grabbing; }

#altimeter {
  position: absolute;
  left: 10px;
  bottom: 10px;
  display: flex;
  flex-direction: column;
  padding: 5px 9px;
  border-radius: 10px;
  background: rgba(27, 20, 16, 0.72);
  font-size: 11px;
  line-height: 1.3;
  pointer-events: none;
}
#alt-zone { font-weight: 800; color: var(--mustard); text-transform: uppercase; letter-spacing: 0.06em; }
#alt-height { font-variant-numeric: tabular-nums; }

#camera-nav {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#camera-nav button {
  min-width: 78px;
  padding: 8px 10px;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  background: rgba(27, 20, 16, 0.78);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
#camera-nav button:hover { border-color: var(--mustard); }
#camera-nav button[data-active="true"] { background: var(--ketchup); border-color: var(--ketchup); }

#milestone-menu {
  position: absolute;
  right: 96px;
  top: 50%;
  transform: translateY(-50%);
  max-height: 70%;
  overflow: auto;
  width: min(240px, 60vw);
  background: var(--panel);
  border-radius: var(--radius);
  padding: 6px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  z-index: 3;
}
#milestone-menu button {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 9px;
  background: none;
  text-align: left;
  font-size: 13px;
}
#milestone-menu button:hover { background: rgba(255, 255, 255, 0.1); }
#milestone-menu small { color: var(--muted); white-space: nowrap; }
#milestone-menu h4 {
  margin: 8px 10px 4px;
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--mustard);
  text-transform: uppercase;
}

#toasts {
  position: absolute;
  left: 50%;
  top: 10px;
  transform: translateX(-50%);
  width: min(92%, 420px);
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
  z-index: 4;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--panel);
  font-size: 13px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  animation: toast-in 0.25s ease-out;
}
.toast.leaving { animation: toast-out 0.3s ease-in forwards; }
.toast.big { border: 2px solid var(--mustard); font-weight: 700; }
.toast button {
  margin-left: auto;
  border: 0;
  border-radius: 8px;
  padding: 4px 8px;
  background: var(--ketchup);
  font-size: 12px;
  font-weight: 800;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-8px); } }

#zone-banner {
  position: absolute;
  top: 38%;
  left: 0;
  right: 0;
  text-align: center;
  font-weight: 900;
  font-size: clamp(22px, 7vw, 40px);
  letter-spacing: 0.08em;
  color: #fff;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.45), 0 0 20px rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s;
}
#zone-banner small { display: block; font-size: 0.4em; letter-spacing: 0.3em; color: var(--mustard); }
#zone-banner.show { opacity: 1; }

#celebration {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 20px;
  pointer-events: none;
  font-weight: 900;
  font-size: clamp(26px, 8vw, 48px);
  color: var(--mustard);
  text-shadow: 3px 3px 0 var(--ketchup-dark), 0 0 30px rgba(0, 0, 0, 0.4);
  animation: celebrate 3.2s ease-out forwards;
  z-index: 4;
}
@keyframes celebrate {
  0% { opacity: 0; transform: scale(0.6); }
  12% { opacity: 1; transform: scale(1.08); }
  20% { transform: scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; }
}

#cooking {
  position: absolute;
  left: 50%;
  top: 22%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--panel);
  font-size: 14px;
  white-space: nowrap;
  max-width: 90%;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  z-index: 3;
}
#cooking b { color: var(--mustard); overflow: hidden; text-overflow: ellipsis; max-width: 180px; display: inline-block; vertical-align: bottom; }
.pan { font-size: 24px; display: inline-block; animation: sizzle 0.5s ease-in-out infinite alternate; }
@keyframes sizzle { from { transform: rotate(-12deg); } to { transform: rotate(10deg) translateY(-2px); } }

#loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  background: var(--ink);
  z-index: 6;
  transition: opacity 0.4s;
}
#loading.done { opacity: 0; pointer-events: none; }
.loading-burger { font-size: 64px; animation: bounce 0.8s ease-in-out infinite alternate; }
@keyframes bounce { to { transform: translateY(-14px) rotate(6deg); } }
#loading p { color: var(--muted); }

/* --------------------------------------------------------------- drawer */

#drawer {
  position: absolute;
  inset: 0 0 auto 0;
  max-height: 88%;
  overflow: auto;
  padding: 14px 16px 18px;
  background: var(--panel);
  backdrop-filter: blur(6px);
  border-bottom: 3px solid var(--mustard);
  border-radius: 0 0 20px 20px;
  z-index: 5;
  animation: drawer-in 0.22s ease-out;
}
@keyframes drawer-in { from { transform: translateY(-20px); opacity: 0; } }
#drawer h2 {
  margin: 0 0 10px;
  font-size: 15px;
  letter-spacing: 0.14em;
  color: var(--mustard);
}
#drawer h3 { margin: 18px 0 6px; font-size: 13px; letter-spacing: 0.1em; color: var(--muted); text-transform: uppercase; }

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0;
}
.stats > div {
  background: rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  padding: 8px 10px;
  min-width: 0;
}
.stats .wide { grid-column: 1 / -1; }
.stats dt { font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.stats dd { margin: 2px 0 0; font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stats small { display: block; font-size: 12px; font-weight: 500; color: var(--muted); margin-top: 2px; }

.linklike {
  background: none;
  border: 0;
  padding: 0;
  font-weight: 800;
  font-size: 18px;
  text-decoration: underline dotted rgba(255, 255, 255, 0.4);
  text-underline-offset: 4px;
}

#feed { list-style: none; margin: 0; padding: 0; font-size: 13.5px; }
#feed li {
  display: grid;
  grid-template-columns: 62px 1fr;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}
#feed time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
#feed li.milestone { color: var(--mustard); font-weight: 700; }
#feed li.raccoon, #feed li.mouse { color: #f6b8a8; }
#feed li.spoilage { color: #b8d68a; }

.big-btn {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 13px;
  border: 0;
  border-radius: 12px;
  background: var(--ketchup);
  font-weight: 900;
  letter-spacing: 0.05em;
  box-shadow: 0 4px 0 var(--ketchup-dark);
}
.big-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--ketchup-dark); }
.ghost-btn {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 10px;
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  background: none;
  font-weight: 700;
}
.fine-print { font-size: 11px; color: var(--muted); margin: 14px 0 0; }

/* ----------------------------------------------------------------- form */

#add-form {
  padding: 10px 12px calc(10px + var(--safe-bottom));
  background: var(--panel-solid);
  border-top: 3px solid var(--mustard);
  z-index: 5;
}
#add-form label {
  display: block;
  font-weight: 900;
  font-size: 20px;
  letter-spacing: 0.02em;
  margin-bottom: 6px;
}
#add-form .row { display: flex; gap: 8px; }
#ingredient-input {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.18);
  background: #120d0a;
  font-size: 17px;
}
#ingredient-input:focus { border-color: var(--mustard); outline: none; }
#add-btn {
  padding: 0 18px;
  border: 0;
  border-radius: 12px;
  background: var(--ketchup);
  font-weight: 900;
  font-size: 16px;
  letter-spacing: 0.06em;
  box-shadow: 0 4px 0 var(--ketchup-dark);
  white-space: nowrap;
}
#add-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--ketchup-dark); }
#add-btn:disabled { opacity: 0.6; cursor: wait; }
#add-btn { min-width: 104px; }
#add-btn.cooling { opacity: 0.75; cursor: not-allowed; font-variant-numeric: tabular-nums; }
#suggestions button:disabled { opacity: 0.5; cursor: not-allowed; }

#suggestions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}
#suggestions::-webkit-scrollbar { display: none; }
#suggestions button {
  flex: none;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.06);
  font-size: 13px;
  font-weight: 600;
}
#suggestions button:hover { border-color: var(--mustard); }
#suggestions .mystery { border-color: var(--mustard); color: var(--mustard); }

#form-error {
  min-height: 0;
  margin: 6px 0 0;
  font-size: 13px;
  color: #ff9aa2;
}
#form-error:empty { display: none; }
#turnstile-box { margin-top: 8px; }

/* ---------------------------------------------------------------- dialog */

#export-dialog {
  width: min(94vw, 460px);
  max-height: 92vh;
  border: 0;
  border-radius: 20px;
  padding: 16px;
  background: var(--panel-solid);
  color: var(--cream);
}
#export-dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; }
.dialog-head h2 { margin: 0; font-size: 18px; }
.tabs { display: flex; gap: 6px; margin: 12px 0 8px; }
.tabs button {
  flex: 1;
  padding: 8px;
  border-radius: 10px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  background: none;
  font-weight: 700;
  font-size: 13px;
}
.tabs button[aria-pressed="true"] { background: var(--mustard); color: var(--ink); border-color: var(--mustard); }
.tabs button:disabled { opacity: 0.4; cursor: not-allowed; }
#export-nav { display: flex; align-items: center; justify-content: center; gap: 14px; }
#export-nav button { width: 40px; height: 40px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, 0.1); font-size: 22px; }
#export-status { text-align: center; color: var(--muted); min-height: 1em; }
#export-hint { margin: 0 0 6px; text-align: center; font-size: 12px; color: var(--muted); }
.dialog-actions button:disabled { opacity: 0.5; cursor: wait; }
#export-preview {
  display: block;
  width: 100%;
  max-height: 52vh;
  object-fit: contain;
  border-radius: 12px;
  background: #000;
}
.dialog-actions { display: flex; gap: 8px; align-items: center; }
.dialog-actions .big-btn, .dialog-actions .ghost-btn { margin-top: 12px; }
.dialog-actions .ghost-btn { width: auto; padding: 12px 18px; }

@media (min-width: 700px) {
  .brand { font-size: 20px; }
  .hud-line { font-size: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
