:root {
  --panel: rgba(20, 28, 20, 0.78);
  --panel-solid: #1f2a1f;
  --text: #f4f1e6;
  --muted: #b9c2b0;
  --accent: #f2b632;
  --accent-text: #2b2100;
  --good: #6fcf73;
  --bad: #ff7a6b;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #8fc4e8; color: var(--text);
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  user-select: none; -webkit-user-select: none; touch-action: none;
}
canvas { display: block; position: fixed; inset: 0; }
[hidden] { display: none !important; }

button {
  font: inherit; font-weight: 600; color: var(--accent-text); background: var(--accent);
  border: 0; border-radius: 12px; padding: 12px 18px; cursor: pointer;
}
button:active { transform: scale(0.97); }
button:disabled { opacity: 0.45; }
button.ghost { background: transparent; color: var(--text); padding: 6px 12px; }

.overlay {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(10, 20, 10, 0.55); z-index: 20; padding: 16px;
}
.card {
  background: var(--panel-solid); border-radius: 18px; padding: 24px; width: min(380px, 100%);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}
.card.wide { width: min(640px, 100%); max-height: 86vh; display: flex; flex-direction: column; }
.card h1, .card h2 { margin: 0 0 8px; }
.card p { color: var(--muted); margin: 0 0 16px; }
.card label { display: block; margin-bottom: 12px; color: var(--muted); font-size: 14px; }
.card input {
  display: block; width: 100%; margin-top: 4px; padding: 12px; font: inherit; font-size: 18px;
  border-radius: 10px; border: 1px solid #45553f; background: #10170f; color: var(--text);
  user-select: text; -webkit-user-select: text;
}
.card > button { width: 100%; margin-top: 8px; }
.error { color: var(--bad) !important; margin-top: 12px !important; min-height: 1em; }

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud > * { pointer-events: auto; }

#topbar {
  position: absolute; top: max(10px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  display: flex; gap: 16px; flex-wrap: wrap; justify-content: center;
  background: var(--panel); padding: 8px 16px; border-radius: 14px; font-weight: 600;
  max-width: calc(100% - 32px); pointer-events: none;
}
#money { color: var(--accent); }
#storage, #players-online { color: var(--muted); font-weight: 500; }

#vehicle-info {
  position: absolute; top: max(64px, calc(env(safe-area-inset-top) + 54px)); left: 16px;
  background: var(--panel); padding: 10px 14px; border-radius: 12px; min-width: 200px; pointer-events: none;
}
#vehicle-info .bar { height: 8px; background: #37452f; border-radius: 4px; margin-top: 6px; overflow: hidden; }
#vehicle-info .bar > div { height: 100%; background: var(--accent); }
#vehicle-info .on { color: var(--good); }

#toasts {
  position: absolute; top: max(64px, calc(env(safe-area-inset-top) + 54px)); right: 16px;
  display: flex; flex-direction: column; gap: 6px; align-items: flex-end; pointer-events: none;
}
.toast {
  background: var(--panel); padding: 8px 12px; border-radius: 10px; max-width: 320px;
  animation: fade 4.5s forwards;
}
@keyframes fade { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }

#joystick {
  position: absolute; left: max(24px, env(safe-area-inset-left)); bottom: max(24px, env(safe-area-inset-bottom));
  width: 150px; height: 150px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.12); border: 2px solid rgba(255, 255, 255, 0.35);
}
#stick {
  position: absolute; left: 50%; top: 50%; width: 64px; height: 64px; margin: -32px 0 0 -32px;
  border-radius: 50%; background: rgba(255, 255, 255, 0.55);
}

#actions {
  position: absolute; right: max(20px, env(safe-area-inset-right)); bottom: max(24px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 10px; align-items: flex-end;
}
#actions button { min-width: 170px; min-height: 54px; font-size: 17px; box-shadow: 0 4px 14px rgba(0,0,0,0.3); }
#actions button.secondary { background: #e8e4d6; }

#hint {
  position: absolute; bottom: max(24px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  color: var(--text); background: var(--panel); padding: 6px 12px; border-radius: 10px; font-size: 14px;
  pointer-events: none; max-width: 40%; text-align: center;
}
#hint:empty { display: none; }

.shop-head { display: flex; justify-content: space-between; align-items: center; }
.tabs { display: flex; gap: 6px; margin: 8px 0 12px; flex-wrap: wrap; }
.tabs button { background: #34422f; color: var(--text); padding: 8px 12px; }
.tabs button.active { background: var(--accent); color: var(--accent-text); }
#shop-list { overflow-y: auto; display: flex; flex-direction: column; gap: 8px; -webkit-overflow-scrolling: touch; touch-action: pan-y; }
.shop-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: #2a3827; padding: 10px 12px; border-radius: 12px;
}
.shop-item .info small { display: block; color: var(--muted); }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

@media (max-width: 700px) {
  #joystick { width: 120px; height: 120px; }
  #actions button { min-width: 140px; }
  #hint { display: none; }
}
