:root {
  --bg: #16181d;
  --panel: rgba(22, 24, 30, 0.94);
  --line: rgba(255, 255, 255, 0.12);
  --text: #f4f2ee;
  --muted: #a8a59e;
  --accent: #ff3b30;
  --fries: #ffcc33;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); }
body { -webkit-user-select: none; user-select: none; }
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }

#scene { position: fixed; inset: 0; }
#scene canvas { display: block; }
#fade { position: fixed; inset: 0; z-index: 30; background: #000; opacity: 0; pointer-events: none; transition: opacity 0.3s; }
#fade.on { opacity: 1; }

/* ── Screens ─────────────────────────────────────────────────────────────── */

.screen {
  position: fixed; inset: 0; z-index: 20; overflow-y: auto;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) 16px 24px;
  background: rgba(10, 10, 14, 0.45);
}
#menu { background: linear-gradient(180deg, rgba(10, 10, 14, 0.2), rgba(10, 10, 14, 0.7)); }
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 22px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.menu-panel { width: min(480px, 100%); display: flex; flex-direction: column; gap: 10px; text-align: center; }
.menu-panel > button {
  padding: 11px 10px; border-radius: 10px; font-weight: 600;
  background: rgba(255, 255, 255, 0.06); border: 1px solid var(--line);
}
button.primary { background: linear-gradient(180deg, #ff5a4f, #e0261b) !important; border: 0 !important; color: #fff; font-weight: 800; }
button.big { font-size: 20px; padding: 14px; letter-spacing: 0.08em; }
h2 { margin: 0; font-size: 26px; letter-spacing: 0.05em; }
.logo { margin: 0; font-size: clamp(36px, 9vw, 54px); font-weight: 900; letter-spacing: 0.06em; color: var(--accent); line-height: 1; }
.logo span { display: block; font-size: 0.42em; letter-spacing: 0.4em; color: var(--text); margin-top: 6px; }
.tag { margin: 0; color: var(--muted); }
.warn { margin: 0; font-weight: 900; font-size: 20px; color: var(--fries); letter-spacing: 0.04em; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { transform: scale(1.06); } }
.career { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.career div { background: rgba(255, 255, 255, 0.05); border-radius: 8px; padding: 6px 4px; }
.career small, #stats small { display: block; font-size: 10px; color: var(--muted); letter-spacing: 0.08em; }
.career b { font-size: 15px; }
.help { text-align: left; color: var(--muted); font-size: 14px; }
.help summary { cursor: pointer; color: var(--text); text-align: center; }
.help ol { padding-left: 20px; }
.help b { color: var(--text); }

/* ── HUD ─────────────────────────────────────────────────────────────────── */

#hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
#hud button { pointer-events: auto; }
#stats {
  position: absolute; top: max(10px, env(safe-area-inset-top)); right: 10px; display: flex; gap: 6px;
}
#stats div { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 5px 10px; text-align: center; min-width: 70px; }
#stats b { font-size: 18px; }
#hunger {
  position: absolute; top: calc(max(10px, env(safe-area-inset-top)) + 54px); right: 10px; width: 236px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 7px 10px;
}
.hunger-head { display: flex; justify-content: space-between; font-size: 11px; letter-spacing: 0.06em; color: var(--muted); }
.bar { height: 8px; border-radius: 4px; background: rgba(255, 255, 255, 0.1); margin-top: 4px; overflow: hidden; }
#hunger-fill { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #6fcf62, var(--fries), #ff5a3c); transition: width 0.2s; }
#hunger.starving { border-color: #ff5a3c; animation: shake 0.4s infinite; }
@keyframes shake { 25% { transform: translateX(-2px); } 75% { transform: translateX(2px); } }
#dont-eat { margin-top: 5px; text-align: center; font-weight: 900; color: var(--fries); font-size: 14px; animation: pulse 0.9s infinite; }
#eat-btn {
  margin-top: 6px; width: 100%; border-radius: 8px; padding: 4px; font-size: 12px;
  background: rgba(255, 204, 51, 0.12); border: 1px dashed rgba(255, 204, 51, 0.5); color: var(--fries);
}

#phone {
  position: absolute; top: max(10px, env(safe-area-inset-top)); left: 10px; width: 290px; max-height: calc(100% - 260px);
  background: #0d0e11; border: 3px solid #2c2f36; border-radius: 22px; padding: 8px; overflow: hidden;
  display: flex; flex-direction: column; gap: 6px; pointer-events: auto; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
#phone.buzz { animation: shake 0.12s 4; }
#phone.collapsed #texts { display: none; }
.phone-bar { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); padding: 0 6px; }
#texts { overflow-y: auto; display: flex; flex-direction: column; gap: 5px; }
.text { background: #24272e; border-radius: 12px 12px 12px 4px; padding: 6px 9px; font-size: 13px; }
.text.app { background: #3a1614; }
.text small { color: var(--muted); font-size: 11px; }
.text p { margin: 2px 0 0; }
#order-card { background: #fff; color: #191a1d; border-radius: 12px; padding: 9px 10px; font-size: 13px; }
.oc-step { display: flex; justify-content: space-between; font-weight: 800; font-size: 11px; letter-spacing: 0.06em; color: var(--accent); }
.oc-step .late { color: #fff; background: var(--accent); border-radius: 4px; padding: 0 4px; }
.oc-rest { font-weight: 700; margin-top: 3px; }
.oc-items { margin: 3px 0; padding-left: 18px; color: #555; }
.oc-items li:last-child { color: #b07a00; font-weight: 700; }
.oc-dest { background: #f1f1f3; border-radius: 8px; padding: 6px 8px; }
.oc-bld { display: block; font-size: 15px; }
.oc-addr { color: #666; font-size: 12px; }
.oc-fu { display: flex; gap: 12px; margin-top: 3px; font-size: 11px; color: #666; }
.oc-fu b { font-size: 20px; color: #191a1d; }
.oc-note { color: #666; font-style: italic; margin-top: 4px; font-size: 12px; }
.oc-pay { margin-top: 3px; font-weight: 700; color: #1a7f37; }
#order-card button { width: 100%; margin-top: 6px; padding: 8px; border-radius: 8px; }

#minimap {
  position: absolute; right: 10px; bottom: max(10px, env(safe-area-inset-bottom)); width: 190px; height: 190px;
  border-radius: 12px; border: 2px solid rgba(255, 255, 255, 0.25); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}
#where {
  position: absolute; right: 10px; bottom: calc(max(10px, env(safe-area-inset-bottom)) + 198px);
  background: var(--panel); border-radius: 8px; padding: 3px 9px; font-size: 13px; font-weight: 600;
}
#prompt {
  position: absolute; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 16px; font-weight: 700;
  white-space: nowrap; max-width: calc(100% - 32px); overflow: hidden; text-overflow: ellipsis;
}
#toast {
  position: absolute; left: 50%; top: 32%; transform: translateX(-50%); width: min(560px, calc(100% - 32px));
  text-align: center; font-size: 19px; font-weight: 800; text-shadow: 0 2px 6px #000; opacity: 0;
}
#toast.show { animation: toast 3.2s forwards; }
@keyframes toast { 0% { opacity: 0; transform: translate(-50%, 10px); } 8%, 80% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; } }

/* ── Elevator ────────────────────────────────────────────────────────────── */

#elevator { background: rgba(10, 10, 14, 0.55); }
.elevator-panel {
  width: min(320px, 100%); text-align: center; display: flex; flex-direction: column; gap: 10px;
  background: linear-gradient(160deg, #c9ced3, #8d949b); color: #15171a; border: 0;
}
.elevator-panel .tag { color: #3d4247; font-size: 13px; }
#elev-display {
  align-self: center; min-width: 90px; background: #0b0b0b; color: #ff5a3c; font: 700 34px monospace;
  border-radius: 6px; padding: 4px 12px; box-shadow: inset 0 0 8px #000;
}
#elev-buttons { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; justify-items: center; }
#elev-buttons button {
  width: 58px; height: 58px; border-radius: 50%; font-weight: 800; font-size: 20px;
  background: radial-gradient(circle at 40% 35%, #f4f4f4, #a7adb3); border: 3px solid #6c7379; color: #2a2d31;
}
#elev-buttons button.here { border-color: #2f7bd8; }
#elev-buttons button.lit { color: #ff5a3c; box-shadow: 0 0 0 3px #ff5a3c, 0 0 14px #ff5a3c; }
#elev-close { padding: 9px; border-radius: 10px; border: 0; background: rgba(0, 0, 0, 0.25); font-weight: 700; color: #15171a; }

/* ── Touch ───────────────────────────────────────────────────────────────── */

#touch-ui { position: fixed; inset: 0; z-index: 12; pointer-events: none; }
#touch-ui > * { pointer-events: auto; }
#stick {
  position: absolute; left: 22px; bottom: max(22px, env(safe-area-inset-bottom)); width: 140px; height: 140px;
  border-radius: 50%; background: rgba(255, 255, 255, 0.12); border: 2px solid rgba(255, 255, 255, 0.3); touch-action: none;
}
#stick-knob {
  position: absolute; left: 50%; top: 50%; width: 60px; height: 60px; margin: -30px 0 0 -30px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
}
#touch-right { position: absolute; right: 214px; bottom: max(22px, env(safe-area-inset-bottom)); display: flex; gap: 12px; align-items: flex-end; }
#touch-top { position: absolute; left: 50%; transform: translateX(-50%); top: max(8px, env(safe-area-inset-top)); display: flex; gap: 8px; }
.tb {
  border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.4); background: rgba(20, 20, 24, 0.6); color: #fff;
  width: 64px; height: 64px; font-size: 26px; font-weight: 800; touch-action: none;
}
.tb.act { width: 84px; height: 84px; background: rgba(224, 38, 27, 0.8); }
.tb.act.dim { opacity: 0.4; }
.tb.eat { font-size: 28px; border-style: dashed; border-color: rgba(255, 204, 51, 0.7); }
.tb.small { width: 44px; height: 44px; font-size: 18px; }

body.touch #phone { width: 230px; font-size: 12px; max-height: calc(100% - 200px); }
body.touch #phone.collapsed #order-card .oc-items, body.touch #phone.collapsed #order-card .oc-note { display: none; }
body.touch #hunger { width: 180px; }
body.touch #stats div { min-width: 56px; padding: 4px 6px; }
body.touch #stats b { font-size: 15px; }
body.touch #minimap { width: 130px; height: 130px; }
body.touch #where { bottom: calc(max(10px, env(safe-area-inset-bottom)) + 138px); }
body.touch #touch-right { right: 150px; }
body.touch #prompt { bottom: 170px; font-size: 13px; }

@media (max-width: 640px) {
  #phone { width: calc(100% - 20px); max-height: 42%; top: calc(max(10px, env(safe-area-inset-top)) + 54px); }
  body.touch #phone { width: calc(100% - 20px); }
  #stats { left: 10px; right: auto; }
  #hunger { top: auto; bottom: calc(max(10px, env(safe-area-inset-bottom)) + 160px); right: 10px; }
  #toast { top: 58%; font-size: 16px; }
  .career { grid-template-columns: repeat(2, 1fr); }
  body.touch #touch-top { left: auto; right: 10px; transform: none; }
  body.touch #stick { left: 16px; }
  body.touch #touch-right { right: 10px; bottom: calc(max(10px, env(safe-area-inset-bottom)) + 176px); }
  body.touch #hunger { left: 10px; right: auto; width: calc(100% - 200px); max-width: 200px; bottom: calc(max(22px, env(safe-area-inset-bottom)) + 150px); }
  body.touch #prompt { bottom: calc(max(10px, env(safe-area-inset-bottom)) + 270px); }
}
