:root {
  --sand: #e9dcb8;
  --ink: #2b2b2b;
  --panel: #fffaf0;
  --accent: #ff7a45;
  --good: #2f9e57;
  --warn: #d1483d;
  --info: #2b78c9;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #111;
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#app {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  background: var(--sand);
}

/* ---------- top HUD ---------- */
#hud-top {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  background: rgba(20, 20, 30, 0.85);
  color: #fff;
  flex-wrap: wrap;
  z-index: 5;
}
.hud-chip {
  background: rgba(255,255,255,0.12);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 13px;
  white-space: nowrap;
}
.hud-chip b { color: #ffd27a; }
.spacer { flex: 1; }
.icon-btn {
  background: rgba(255,255,255,0.14);
  border: none; color: #fff;
  width: 32px; height: 32px; border-radius: 50%;
  font-size: 16px; cursor: pointer;
}
.icon-btn:active { background: rgba(255,255,255,0.3); }

#bars {
  display: flex; gap: 14px;
  padding: 4px 10px;
  background: rgba(20,20,30,0.7);
  z-index: 5;
}
.bar-row { display: flex; align-items: center; gap: 6px; flex: 1; color: #fff; font-size: 12px; }
.bar { flex: 1; height: 8px; border-radius: 6px; background: rgba(255,255,255,0.2); overflow: hidden; }
.bar i { display: block; height: 100%; width: 100%; background: var(--info); transition: width 0.2s; }
.bar-val { width: 40px; text-align: right; }

#unlock-track {
  background: rgba(20,20,30,0.55);
  color: #fff;
  padding: 4px 10px;
  font-size: 12px;
  z-index: 5;
}
.unlock-label { margin-bottom: 2px; }
#unlock-track .bar { height: 6px; }
#unlock-track .bar i { background: var(--accent); }

/* ---------- stage ---------- */
#stage { position: relative; flex: 1; min-height: 0; }
#game-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* ---------- sell bar ---------- */
#sell-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px;
  background: rgba(20,20,30,0.85);
  z-index: 5;
}
#sell-slots { display: flex; gap: 6px; flex: 1; overflow-x: auto; }
.food-chip {
  position: relative;
  background: rgba(255,255,255,0.14);
  border: 2px solid transparent;
  border-radius: 12px;
  font-size: 20px;
  padding: 4px 8px;
  cursor: pointer;
  flex: none;
}
.food-chip.active { border-color: var(--accent); background: rgba(255,122,69,0.35); }
.chip-qty {
  position: absolute; bottom: -4px; right: -4px;
  background: #222; color: #fff; border-radius: 8px;
  font-size: 10px; padding: 0 4px;
}
#quick-actions { display: flex; gap: 8px; }
.pill {
  background: rgba(255,255,255,0.14); color: #fff;
  border: none; border-radius: 999px; padding: 6px 12px;
  font-size: 13px; cursor: pointer; white-space: nowrap;
}

/* ---------- controls ---------- */
#controls {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px 16px;
  background: rgba(20,20,30,0.85);
  z-index: 5;
}
#dpad {
  display: grid;
  grid-template-columns: 44px 44px 44px;
  grid-template-rows: 44px 44px;
  gap: 4px;
}
.dpad-btn {
  border: none; border-radius: 10px;
  background: rgba(255,255,255,0.2);
  color: #fff; font-size: 16px;
  touch-action: none;
}
.dpad-btn.held { background: var(--accent); }
.dpad-btn.up { grid-column: 2; grid-row: 1; }
.dpad-btn.left { grid-column: 1; grid-row: 2; }
.dpad-btn.right { grid-column: 3; grid-row: 2; }
.dpad-btn.down { grid-column: 2; grid-row: 2; }

#actions { display: flex; gap: 10px; }
.action-btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  border: none; border-radius: 14px;
  background: rgba(255,255,255,0.18); color: #fff;
  font-size: 20px; padding: 8px 14px;
  min-width: 64px;
}
.action-btn span { font-size: 11px; }
.action-btn.primary { background: var(--accent); }
.action-btn:active { filter: brightness(1.2); }

/* ---------- toasts ---------- */
#toast-layer {
  position: absolute; top: 90px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 6px;
  z-index: 20; pointer-events: none;
  align-items: center;
  width: 90%; max-width: 480px;
}
.toast {
  background: rgba(20,20,30,0.92); color: #fff;
  padding: 8px 16px; border-radius: 10px;
  font-size: 13px; text-align: center;
  opacity: 0; transform: translateY(-8px);
  transition: opacity 0.25s, transform 0.25s;
  box-shadow: 0 4px 14px rgba(0,0,0,0.3);
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-good { border-left: 4px solid var(--good); }
.toast-warn { border-left: 4px solid var(--warn); }
.toast-info { border-left: 4px solid var(--info); }
.toast-event { border-left: 4px solid #ffd27a; }

/* ---------- panels ---------- */
#panel-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 30;
}
#panel-box {
  position: relative;
  background: var(--panel);
  border-radius: 16px;
  padding: 20px;
  width: min(560px, 92vw);
  max-height: 82vh;
  overflow-y: auto;
}
#panel-close {
  position: absolute; top: 10px; right: 10px;
  border: none; background: #eee; border-radius: 50%;
  width: 30px; height: 30px; font-size: 14px; cursor: pointer;
}
#panel-content h2 { margin-top: 0; }
#panel-content h3 { margin-bottom: 6px; }
#panel-content .muted { color: #777; font-size: 12px; }
#panel-content .warn { color: var(--warn); font-weight: bold; }
#panel-content button {
  background: var(--accent); color: #fff; border: none;
  border-radius: 8px; padding: 8px 12px; margin: 4px 4px 4px 0;
  font-size: 13px; cursor: pointer;
}
#panel-content button:disabled { background: #ccc; cursor: not-allowed; }
#panel-content select { padding: 6px; border-radius: 8px; margin-right: 6px; }
.shop-grid { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.shop-item {
  display: flex; justify-content: space-between; align-items: center;
  gap: 10px; background: #fff; border-radius: 10px; padding: 8px 12px;
  border: 1px solid #eee;
}
.qty-btns { display: flex; flex-wrap: wrap; }
.food-icon { font-size: 18px; }

@media (min-width: 900px) {
  #dpad { display: none; }
}
