:root {
  --dust: #c4a574;
  --ink: #2a2118;
  --cream: #f3e6c8;
  --panel: rgba(28, 22, 16, 0.55);
  --panel-solid: rgba(28, 22, 16, 0.8);
  --edge: rgba(255, 230, 180, 0.22);
  --accent: #e0a54a;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body, #app {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #c9a56a;
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; }
#view {
  display: block;
  width: 100%;
  height: 100%;
}

/* Controls and HUD only exist once you've ridden out. */
#app:not(.playing) #hud,
#app:not(.playing) #joyRoot,
#app:not(.playing) #lookZone { display: none; }

#hud {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}
.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) calc(14px + env(safe-area-inset-right)) 0 calc(14px + env(safe-area-inset-left));
}
.plaque, #posse, .buttons button, #status, .toast {
  background: var(--panel);
  border: 1px solid var(--edge);
  color: var(--cream);
  border-radius: 8px;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.plaque {
  padding: 8px 12px;
  min-width: 140px;
}
.plaque .label {
  font-size: 10px;
  letter-spacing: 0.22em;
  opacity: 0.7;
}
.plaque .name {
  font-size: 16px;
  letter-spacing: 0.04em;
}
.plaque .found {
  margin-top: 2px;
  font-size: 13px;
  color: #7fe0d2;
}
.plaque .clock {
  font-size: 12px;
  opacity: 0.75;
}
.right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}
.buttons {
  display: flex;
  gap: 8px;
}
.buttons button {
  pointer-events: auto;
  padding: 8px 10px;
  font-size: 11px;
  letter-spacing: 0.12em;
}
#posse {
  padding: 6px 10px;
  min-width: 150px;
  max-width: 200px;
  font-size: 13px;
}
#posse .head {
  font-size: 10px;
  letter-spacing: 0.2em;
  opacity: 0.7;
  margin-bottom: 2px;
}
#posse .row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 1px 0;
}
#posse .row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#posse .row.me { color: #ffd98a; }

#center {
  position: absolute;
  left: 50%;
  top: calc(12px + env(safe-area-inset-top));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: min(60%, 440px);
}
#status, #quest {
  padding: 6px 12px;
  font-size: 13px;
  white-space: nowrap;
}
#quest {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(60, 20, 12, 0.6);
  border: 1px solid rgba(255, 190, 120, 0.4);
  border-radius: 8px;
  color: #ffe2b8;
  font-size: 14px;
  letter-spacing: 0.04em;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
#questArrow {
  display: inline-block;
  color: #ff8a5a;
  font-size: 16px;
  line-height: 1;
}
#toasts {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
}
.toast {
  padding: 7px 14px;
  font-size: 15px;
  text-align: center;
  border-width: 2px;
  animation: toast-in 0.25s ease-out;
  transition: opacity 0.5s ease;
}
.toast.fade { opacity: 0; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px) scale(0.96); }
}

#hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(28px + env(safe-area-inset-bottom));
  padding: 0 170px;
  text-align: center;
  color: rgba(48, 32, 16, 0.8);
  font-size: 13px;
  text-shadow: 0 1px 0 rgba(255, 240, 210, 0.35);
  transition: opacity 0.6s ease;
}
#hint.fade { opacity: 0; }

#actions {
  position: absolute;
  right: calc(22px + env(safe-area-inset-right));
  bottom: calc(26px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}
#actions .pair {
  display: flex;
  align-items: flex-end;
  gap: 14px;
}
#actions button {
  pointer-events: auto;
  border-radius: 50%;
  background: rgba(30, 22, 14, 0.35);
  border: 2px solid rgba(255, 236, 200, 0.4);
  color: var(--cream);
  font-size: 12px;
  letter-spacing: 0.08em;
  touch-action: none;
  -webkit-touch-callout: none;
}
#actions button:active { background: rgba(30, 22, 14, 0.6); }
#altBtn { width: 64px; height: 64px; margin-bottom: 26px; }
#mainBtn { width: 84px; height: 84px; }
#actions #rideBtn {
  border-radius: 12px;
  padding: 12px 16px;
  min-width: 128px;
  font-size: 14px;
  font-weight: bold;
  background: var(--accent);
  border-color: #ffd98a;
  color: var(--ink);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
}
#actions #rideBtn:active { background: #c98f38; }

#joyRoot {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 46%;
  height: 42%;
  z-index: 1;
}
#joyBase {
  position: absolute;
  left: calc(28px + env(safe-area-inset-left));
  bottom: calc(28px + env(safe-area-inset-bottom));
  width: 118px;
  height: 118px;
  border-radius: 50%;
  background: rgba(30, 22, 14, 0.28);
  border: 2px solid rgba(255, 236, 200, 0.28);
}
#joyKnob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 54px;
  height: 54px;
  margin: -27px 0 0 -27px;
  border-radius: 50%;
  background: rgba(243, 230, 200, 0.82);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25);
}
#lookZone {
  position: absolute;
  right: 0;
  top: 0;
  width: 58%;
  height: 100%;
  z-index: 1;
}

#start {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(28, 22, 16, 0.5), rgba(28, 22, 16, 0) 60%);
}
#start .card {
  width: min(440px, 100%);
  background: var(--panel-solid);
  border: 1px solid var(--edge);
  border-radius: 14px;
  padding: 16px 18px;
  color: var(--cream);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
#start h1 {
  font-size: 24px;
  letter-spacing: 0.2em;
  color: #ffd98a;
}
#start h1 span {
  display: block;
  font-size: 13px;
  letter-spacing: 0.32em;
  color: var(--cream);
  opacity: 0.85;
}
#start p {
  margin: 4px 0 10px;
  font-size: 14px;
  line-height: 1.4;
  opacity: 0.85;
}
#start .who {
  color: #7fe0d2;
  font-size: 13px;
}
#start label {
  display: block;
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  opacity: 0.7;
  margin-bottom: 4px;
}
#start input {
  width: 100%;
  font: inherit;
  font-size: 18px; /* 16px+ stops iOS zooming into the field */
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--edge);
  background: rgba(255, 240, 210, 0.1);
  color: var(--cream);
  user-select: text;
  -webkit-user-select: text;
}
#start input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
#start .row {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}
#start .row button {
  flex: 1;
  padding: 12px;
  border-radius: 8px;
  font-size: 16px;
  border: 1px solid var(--edge);
  background: rgba(255, 240, 210, 0.1);
  color: var(--cream);
}
#start .row button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--ink);
  font-weight: bold;
}

@media (max-height: 460px) {
  #start p:not(.who) { display: none; }
  #start .card { padding: 12px 16px; }
  #posse { font-size: 12px; }
}
@media (max-width: 640px) and (orientation: portrait) {
  #center { top: calc(150px + env(safe-area-inset-top)); width: calc(100% - 32px); }
  .buttons button { padding: 8px 7px; font-size: 10px; }
  #hint { padding: 0 20px; bottom: auto; top: calc(250px + env(safe-area-inset-top)); }
}

/* ---------- Tickets, TALK ---------- */
.plaque .tickets {
  font-size: 13px;
  color: #ffd98a;
}
#talkBtn {
  position: absolute;
  left: calc(34px + env(safe-area-inset-left));
  bottom: calc(160px + env(safe-area-inset-bottom));
  pointer-events: auto;
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(30, 22, 14, 0.45);
  border: 2px solid rgba(255, 236, 200, 0.45);
  color: var(--cream);
  font-size: 14px;
  font-weight: bold;
  letter-spacing: 0.06em;
  touch-action: none;
  -webkit-touch-callout: none;
}
#talkBtn.on {
  background: #e0283c;
  border-color: #ffb3bd;
  color: #fff;
  animation: talk-pulse 0.9s ease-in-out infinite;
}
@keyframes talk-pulse {
  50% { transform: scale(1.06); }
}

/* ---------- Overlays: arcade, prizes, map ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: rgba(10, 6, 20, 0.72);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  touch-action: none;
}
.arcade-box, .map-box {
  max-width: 100%;
  background: #1b1233;
  border: 2px solid #6b4bd8;
  border-radius: 14px;
  box-shadow: 0 0 40px rgba(107, 75, 216, 0.5);
  overflow: hidden;
  color: #f3e6c8;
}
.arcade-head, .map-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: #251845;
  font-size: 15px;
}
.arcade-head .title { font-weight: bold; color: #ffd23a; letter-spacing: 0.06em; }
.arcade-head .score { margin-left: auto; font-size: 20px; font-weight: bold; color: #7fe0d2; }
.arcade-head .status { min-width: 48px; text-align: right; opacity: 0.85; }
.overlay .close {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 18px;
}
.arcade-stage { position: relative; }
.arcade-stage canvas { display: block; touch-action: none; }
.arcade-panel {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 16px;
  text-align: center;
  background: rgba(21, 10, 46, 0.88);
  overflow-y: auto;
}
.overlay.prizes .arcade-box { width: min(440px, 100%); }
.overlay.prizes .arcade-stage { min-height: 460px; }
.overlay.prizes .arcade-panel { position: static; background: none; }
.arcade-panel h2 { color: #ffd23a; font-size: 26px; letter-spacing: 0.06em; }
.arcade-panel h3 { margin-top: 6px; font-size: 13px; letter-spacing: 0.2em; opacity: 0.7; text-transform: uppercase; }
.arcade-panel p { font-size: 16px; max-width: 420px; }
.arcade-panel .small { font-size: 13px; opacity: 0.8; }
.arcade-panel .final { font-size: 24px; font-weight: bold; }
.arcade-panel .tickets { font-size: 22px; color: #ffd98a; font-weight: bold; }
.arcade-panel .highs { list-style: none; font-size: 15px; line-height: 1.5; }
.arcade-panel .row { display: flex; gap: 10px; margin-top: 8px; }
.arcade-panel button {
  padding: 12px 20px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 16px;
}
.arcade-panel button.big {
  background: #ff4fd8;
  border-color: #ff9be9;
  font-weight: bold;
  font-size: 20px;
  padding: 14px 30px;
}
.prize-list { display: flex; flex-direction: column; gap: 6px; width: 100%; max-width: 380px; margin: 6px 0; }
.prize {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
}
.prize.wearing { outline: 2px solid #7fe0d2; }
.prize .icon { font-size: 26px; width: 34px; }
.prize .name { flex: 1; text-align: left; font-size: 16px; }
.prize .tag { color: #7fe0d2; font-size: 13px; }
.prize button { padding: 8px 14px; font-size: 14px; }
.prize button.buy { background: #ffd23a; color: #2a2118; border-color: #ffd23a; font-weight: bold; }
.prize button.short { opacity: 0.5; }

.map-box { width: min(560px, 100%); max-height: 100%; overflow-y: auto; }
.map-head span { font-size: 13px; opacity: 0.7; margin-right: auto; }
.map-box canvas { display: block; width: 100%; height: auto; aspect-ratio: 1; }
.map-places { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px; }
.map-places button {
  flex: 1 1 30%;
  padding: 10px 6px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: #2d2152;
  color: #f3e6c8;
  font-size: 14px;
  font-weight: bold;
}
@media (max-height: 520px) {
  .map-box { display: grid; grid-template-columns: auto 1fr; width: min(820px, 100%); }
  .map-head { grid-column: 1 / -1; }
  .map-box canvas { width: calc(100vh - 90px); }
  .map-places { align-content: flex-start; }
  #talkBtn { bottom: calc(150px + env(safe-area-inset-bottom)); }
}

/* ---------- Siren Head ---------- */
#danger {
  padding: 7px 14px;
  border-radius: 8px;
  background: rgba(150, 12, 12, 0.85);
  border: 2px solid #ff6a6a;
  color: #fff;
  font-size: 15px;
  font-weight: bold;
  letter-spacing: 0.04em;
  text-align: center;
  white-space: nowrap;
  animation: danger-pulse 1s ease-in-out infinite;
}
@keyframes danger-pulse {
  50% { background: rgba(200, 20, 20, 0.95); }
}
#caught {
  position: absolute;
  inset: 0;
  z-index: 7;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: radial-gradient(circle, rgba(140, 0, 0, 0.55), rgba(90, 0, 0, 0.92));
  color: #fff;
  text-align: center;
  pointer-events: none;
  animation: caught-in 0.18s ease-out;
}
#caught span {
  font-size: clamp(28px, 8vw, 62px);
  font-weight: bold;
  letter-spacing: 0.08em;
  text-shadow: 0 0 22px #ff3b3b;
}
#caught small { font-size: 18px; opacity: 0.85; }
#caught.fade { opacity: 0; transition: opacity 0.7s ease; }
@keyframes caught-in {
  from { opacity: 0; transform: scale(1.06); }
}
