/* Ullr Builder — Ski Resort Simulator
   Responsive from iPhone (notch-safe) to 4K. */

:root {
  --bg: #0b1f3a;
  --panel: rgba(14, 26, 45, 0.82);
  --panel-solid: #11253f;
  --accent: #4fc3f7;
  --accent-2: #7ee787;
  --text: #eaf2fb;
  --muted: #9db3cc;
  --danger: #ff6b6b;
  --radius: 14px;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#gl, #game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
#gl { z-index: 0; }            /* WebGL terrain underneath */
#game {
  z-index: 1;                  /* transparent 2D overlay: entities, snow, HUD-draw */
  background: transparent;
  touch-action: none;          /* we handle orbit/zoom ourselves */
  cursor: grab;
}
#game:active { cursor: grabbing; }

/* ---- HUD ---- */
.hud-top {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + var(--safe-t)) 16px 10px;
  background: linear-gradient(180deg, rgba(6, 14, 28, 0.9), transparent);
  pointer-events: none;
  z-index: 10;
}
.brand {
  font-weight: 700;
  font-size: clamp(15px, 2.4vw, 22px);
  letter-spacing: 0.3px;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
}
.stats { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.chip {
  pointer-events: auto;
  background: var(--panel);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: clamp(11px, 1.6vw, 14px);
  font-variant-numeric: tabular-nums;
  box-shadow: var(--shadow);
  white-space: nowrap;
}
.chip.money { color: var(--accent-2); font-weight: 700; }
.chip.clock { color: var(--accent); font-weight: 600; }
.chip.visitors { color: var(--text); font-weight: 600; }
.chip.season { color: #cfe3ff; font-weight: 600; }
.chip.seed { color: var(--muted); }

/* Play button pulses while the resort is open. */
.btn.playing { background: var(--accent-2); color: #062033; border-color: transparent; font-weight: 700; }
.btn.playing:hover { filter: brightness(1.06); }

.hud-bottom {
  position: fixed;
  left: 50%;
  bottom: calc(14px + var(--safe-b));
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  padding: 8px;
  background: var(--panel);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 10;
  max-width: calc(100vw - 24px);
  overflow-x: auto;                 /* swipe to reach all buttons on phones */
  scrollbar-width: none;
}
.hud-bottom::-webkit-scrollbar { display: none; }
.hud-bottom .btn { flex: 0 0 auto; }

/* ---- build toolbar (left, vertical) ---- */
.toolbar {
  position: fixed;
  left: calc(10px + env(safe-area-inset-left, 0px));
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px;
  background: var(--panel);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 10;
}
.tool {
  appearance: none;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
}
.tool:hover { background: rgba(255, 255, 255, 0.14); }
.tool:active { transform: scale(0.94); }
.tool.active {
  background: var(--accent);
  border-color: transparent;
  box-shadow: 0 0 0 2px rgba(79, 195, 247, 0.4);
}

/* ---- tool hint ---- */
.build-hint {
  position: fixed;
  left: 50%;
  top: calc(56px + var(--safe-t));
  transform: translate(-50%, -6px);
  max-width: calc(100vw - 120px);
  background: var(--panel);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: clamp(12px, 1.6vw, 14px);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 9;
  white-space: nowrap;
}
.build-hint.show { opacity: 1; transform: translate(-50%, 0); }

/* ---- run drawing controls ---- */
.run-actions {
  position: fixed;
  left: 50%;
  bottom: calc(72px + var(--safe-b, 0px));
  transform: translate(-50%, 8px);
  display: none;
  gap: 10px;
  z-index: 11;
}
.run-actions.show { display: flex; transform: translate(-50%, 0); }

/* ---- lift-type picker ---- */
.lift-types {
  position: fixed;
  left: 50%;
  top: calc(98px + var(--safe-t));
  transform: translate(-50%, -6px);
  display: none;
  gap: 6px;
  max-width: calc(100vw - 24px);
  padding: 6px;
  background: var(--panel);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  box-shadow: var(--shadow);
  z-index: 9;
  overflow-x: auto;
  scrollbar-width: none;
}
.lift-types::-webkit-scrollbar { display: none; }
.lift-types.show { display: flex; transform: translate(-50%, 0); }
.lift-type {
  appearance: none;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 60px;
  padding: 7px 9px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s, transform 0.1s;
}
.lift-type:hover { background: rgba(255, 255, 255, 0.14); }
.lift-type:active { transform: scale(0.96); }
.lift-type.active {
  background: var(--accent);
  color: #062033;
  border-color: transparent;
  box-shadow: 0 0 0 2px rgba(79, 195, 247, 0.4);
}
.lt-emoji { font-size: 18px; line-height: 1; }
.lt-label { font-size: 11px; font-weight: 600; white-space: nowrap; }

/* ---- buttons ---- */
.btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font: inherit;
  font-size: clamp(13px, 1.8vw, 15px);
  padding: 10px 14px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, transform 0.1s;
  min-height: 44px;            /* touch target */
}
.btn:hover { background: rgba(255, 255, 255, 0.14); }
.btn:active { transform: scale(0.96); }
.btn.primary { background: var(--accent); color: #062033; border-color: transparent; font-weight: 700; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 36px; padding: 6px 14px; font-size: 13px; }

/* ---- modals ---- */
.modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(3, 9, 18, 0.6);
  backdrop-filter: blur(4px);
  z-index: 50;
  padding: 16px;
}
.modal.open { display: flex; }
.modal-card {
  width: min(440px, 100%);
  background: var(--panel-solid);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  max-height: 86vh;
  overflow: auto;
}
.modal-card h2 { font-size: 20px; margin-bottom: 16px; }
.modal-card label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 14px; }
.modal-card input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 12px;
  font: inherit;
  color: var(--text);
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
}
.modal-card input:focus { outline: none; border-color: var(--accent); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

.save-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; max-height: 50vh; overflow: auto; }
.save-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
}
.save-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.save-title { font-weight: 600; }
.save-thumb {
  flex: none;
  width: 56px; height: 56px;
  border-radius: 8px;
  object-fit: cover;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.12);
}
.save-thumb-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: var(--muted);
}
.save-row { gap: 10px; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); }

/* ---- toast ---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(80px + var(--safe-b));
  transform: translate(-50%, 20px);
  background: var(--panel-solid);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 60;
  font-size: 14px;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: var(--danger); color: #ffd5d5; }

/* ---- stats panel (right) ---- */
.panel {
  position: fixed;
  right: calc(12px + env(safe-area-inset-right, 0px));
  top: calc(64px + var(--safe-t));
  width: min(280px, calc(100vw - 24px));
  background: var(--panel);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  z-index: 11;
}
.panel[hidden] { display: none; }
.panel-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.panel-head h3 { font-size: 16px; font-weight: 700; flex: none; }
.rating { flex: 1; color: #ffd27a; font-size: 15px; letter-spacing: 1px; }
.panel-x {
  appearance: none;
  border: none;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  width: 28px; height: 28px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  flex: none;
}
.panel-x:hover { background: rgba(255, 255, 255, 0.16); }

.stat-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 12px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.stat-grid dt { color: var(--muted); white-space: nowrap; }
.stat-grid dd { text-align: right; font-weight: 600; }

.ticket {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}
.stepper { display: flex; align-items: center; gap: 8px; }
.stepper span {
  min-width: 56px;
  text-align: center;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent-2);
}
.stepper .btn.small { min-width: 36px; padding: 6px 0; }

/* ---- entity selection card ---- */
.sel-card {
  position: fixed;
  left: 50%;
  bottom: calc(78px + var(--safe-b));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: calc(100vw - 24px);
  background: var(--panel-solid);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 16px;
  z-index: 12;
}
.sel-card[hidden] { display: none; }
.sel-info { line-height: 1.45; }
.sel-actions { display: flex; align-items: center; gap: 8px; flex: none; }

/* Wider screens: roomier brand + chips */
@media (min-width: 1600px) {
  .hud-top { padding-left: 28px; padding-right: 28px; }
  .hud-bottom { gap: 12px; padding: 10px; }
}

/* ---- Kiosk display mode (?kiosk=1) ---------------------------------- */
/* Hide every piece of interactive chrome; leave only the moving scene. */
body.kiosk .hud-top,
body.kiosk .hud-bottom,
body.kiosk .toolbar,
body.kiosk .build-hint,
body.kiosk .lift-types,
body.kiosk .run-actions,
body.kiosk .panel,
body.kiosk .sel-card,
body.kiosk .modal,
body.kiosk .toast { display: none !important; }

/* Cinematic caption: resort name / day / crowd / season, bottom-centre. */
.kiosk-caption { display: none; }
body.kiosk .kiosk-caption {
  display: block;
  position: fixed;
  left: 50%;
  bottom: calc(28px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  padding: 10px 22px;
  font: 600 17px/1 system-ui, sans-serif;
  letter-spacing: 0.4px;
  color: #eaf2ff;
  white-space: nowrap;
  background: rgba(8, 22, 42, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  backdrop-filter: blur(6px);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
  z-index: 20;
  pointer-events: none;
}

/* ---- photo studio ---- */
.photo-card { width: min(720px, 100%); }
.photo-stage {
  margin: 14px 0;
  min-height: 220px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: #07101f;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 12px;
}
.photo-img {
  max-width: 100%;
  max-height: 56vh;
  border-radius: 8px;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.55);
}
.photo-empty { color: var(--muted); font-size: 14px; text-align: center; padding: 40px 12px; }
.photo-empty.error { color: var(--danger); }
.photo-dim { letter-spacing: 0.04em; }
.photo-controls { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; }
.chip-btn {
  padding: 8px 14px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  cursor: pointer;
  min-height: 36px;
}
.chip-btn:hover { border-color: var(--accent); }
.chip-btn.active { background: var(--accent); color: #062033; border-color: transparent; font-weight: 700; }
.photo-check {
  display: inline-flex !important;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text) !important;
  margin: 4px 0 0 !important;
  cursor: pointer;
}
.photo-check input { width: auto; margin: 0; }

/* ---- guest-feedback breakdown (stats panel) ---- */
.feedback { margin: 14px 0 4px; }
.feedback h4 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin: 0 0 8px;
}
.fb-item {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  padding: 8px 10px;
  margin-bottom: 7px;
  background: rgba(0, 0, 0, 0.22);
  border-left: 3px solid var(--muted);
  border-radius: 8px;
}
.fb-item.fb-bad { border-left-color: var(--danger); }
.fb-item.fb-warn { border-left-color: #f4b942; }
.fb-item.fb-ok { border-left-color: var(--accent-2); }
.fb-icon { font-size: 15px; line-height: 1.3; flex: 0 0 auto; }
.fb-body { min-width: 0; }
.fb-text { font-size: 13px; color: var(--text); font-weight: 600; }
.fb-fix { font-size: 12px; color: var(--muted); margin-top: 2px; line-height: 1.35; }

/* ---- lift upgrade (selection card) ---- */
.sel-upgrade { display: flex; flex-direction: column; gap: 5px; align-items: stretch; flex: none; }
.sel-upgrade[hidden] { display: none; }
.sel-upgrade .muted { margin-bottom: 1px; }
.up-btn { white-space: nowrap; }
