:root {
  --ink: #fff8ee;
  --panel: rgba(22, 16, 38, 0.86);
  --line: rgba(255, 255, 255, 0.14);
  --hot: #ff5a1f;
  --gold: #ffd54f;
  --font: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #1b1230;
  color: var(--ink);
  font-family: var(--font);
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

#game {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: block;
}

[hidden] { display: none !important; }

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  padding: max(12px, env(safe-area-inset-top)) 16px 0;
  pointer-events: none;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.45);
}
.hud-city { font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; opacity: 0.9; }
.hud-score { font-size: 34px; font-weight: 800; line-height: 1.1; }
.hud-sub { font-size: 15px; display: flex; align-items: center; gap: 6px; }
.coin-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--gold); box-shadow: inset 0 0 0 2px #e6a100; }
.mult { margin-left: 8px; font-size: 18px; color: var(--gold); vertical-align: middle; }
.hud-right { display: flex; gap: 8px; pointer-events: auto; }

/* Combo meter */
.hud-combo {
  position: fixed;
  top: max(100px, env(safe-area-inset-top) + 40px);
  right: 16px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  pointer-events: none;
  font-family: var(--font);
  transition: opacity 0.3s;
}
.combo-label { font-size: 10px; letter-spacing: 0.15em; text-transform: uppercase; color: var(--gold); }
.combo-count { font-size: 28px; font-weight: 900; color: var(--hot); text-shadow: 0 0 12px rgba(255, 90, 31, 0.6); }
.combo-nearmiss { font-size: 13px; color: var(--gold); opacity: 0.9; }

.icon-btn {
  width: 42px; height: 42px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.35);
  color: var(--ink);
  font-size: 18px;
  cursor: pointer;
}

/* ---------- banners ---------- */
.banner {
  position: fixed;
  top: 22%;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  padding: 10px 22px;
  background: rgba(200, 30, 30, 0.82);
  border: 2px solid rgba(255, 255, 255, 0.6);
  border-radius: 14px;
  pointer-events: none;
  animation: pulse 0.9s ease-in-out infinite alternate;
  max-width: calc(100vw - 32px);
}
.banner strong { display: block; font-size: 22px; letter-spacing: 0.06em; text-transform: uppercase; }
.banner span { font-size: 14px; }
@keyframes pulse { from { transform: translateX(-50%) scale(1); } to { transform: translateX(-50%) scale(1.05); } }

.toast {
  position: fixed;
  left: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  max-width: min(360px, calc(100vw - 32px));
  padding: 12px 14px;
  background: var(--panel);
  border-left: 4px solid var(--gold);
  border-radius: 10px;
  pointer-events: none;
  display: grid;
  gap: 2px;
  animation: slidein 0.35s ease-out;
}
.toast-kicker { font-size: 11px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--gold); }
.toast strong { font-size: 17px; }
.toast span:last-child { font-size: 13px; opacity: 0.9; }
@keyframes slidein { from { transform: translateY(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- overlays ---------- */
.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(10, 6, 20, 0.45);
  overflow-y: auto;
  touch-action: pan-y;
}
.panel {
  width: min(360px, 100%);
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  text-align: center;
  backdrop-filter: blur(6px);
}
.panel.wide { width: min(980px, 100%); }
.panel h2 { margin: 0 0 6px; font-size: 28px; }

.logo {
  margin: 0;
  font-size: clamp(40px, 9vw, 72px);
  font-weight: 900;
  letter-spacing: 0.04em;
  line-height: 1;
  color: var(--gold);
  text-shadow: 0 4px 0 #b3380f;
}
.logo span { color: var(--hot); margin-left: 0.2em; text-shadow: 0 4px 0 #6e1a00; }
.lede { margin: 10px 0 18px; opacity: 0.9; }

.cities {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.city-card {
  display: grid;
  gap: 4px;
  padding: 0 0 12px;
  text-align: left;
  color: var(--ink);
  font: inherit;
  background: rgba(255, 255, 255, 0.06);
  border: 2px solid transparent;
  border-radius: 14px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
}
.city-card:hover, .city-card:focus-visible { transform: translateY(-3px); border-color: var(--accent); outline: none; }
.city-card > span { padding: 0 12px; }
.thumb { width: 100%; height: 120px; display: block; margin-bottom: 6px; object-fit: cover; background: #2a2140; }
.no-webgl { padding: 40px 16px; text-align: center; font-size: 18px; }
.city-name { font-size: 20px; font-weight: 800; }
.city-name small { font-size: 12px; font-weight: 400; opacity: 0.75; margin-left: 6px; text-transform: uppercase; letter-spacing: 0.08em; }
.city-tag { font-size: 13px; opacity: 0.85; }
.city-challenge { font-size: 13px; color: var(--accent); font-weight: 700; }
.city-best { font-size: 12px; opacity: 0.7; }

.controls { margin: 18px 0 0; font-size: 13px; opacity: 0.8; line-height: 1.9; }
kbd {
  display: inline-block;
  min-width: 22px;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-bottom-width: 3px;
  border-radius: 6px;
  font: inherit;
  font-size: 12px;
}

.muted { opacity: 0.75; margin: 0; }
.big-score { font-size: 56px; font-weight: 900; color: var(--gold); margin: 8px 0; }
.stats { display: flex; justify-content: space-around; margin: 0 0 18px; }
.stats dt { font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; opacity: 0.7; }
.stats dd { margin: 2px 0 0; font-size: 18px; font-weight: 700; }

.btn {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 13px;
  font: inherit;
  font-size: 17px;
  font-weight: 700;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
}
.btn.primary { background: var(--hot); border-color: transparent; box-shadow: 0 4px 0 #9c2a00; }
.btn:active { transform: translateY(2px); }

.btn.small { display: inline-block; width: auto; padding: 8px 16px; font-size: 14px; margin-top: 14px; }
.loading { grid-column: 1 / -1; padding: 40px 0; opacity: 0.8; }

.sponsors { margin: 0 0 12px; font-size: 12px; opacity: 0.85; }
.sponsors ul { list-style: none; padding: 0; margin: 6px 0 0; display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.sponsors li { padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px; }
.sponsors a { color: var(--gold); text-decoration: none; }
.advertise { margin: 10px 0 0; font-size: 13px; }
.advertise a { color: var(--gold); }
.ad-debug { position: fixed; right: 8px; bottom: 8px; z-index: 50; max-width: calc(100vw - 16px); padding: 8px 10px; background: rgba(0,0,0,0.75); border-radius: 8px; font: 12px/1.4 monospace; color: #fff; pointer-events: none; }
.ad-debug table { border-collapse: collapse; margin-top: 4px; }
.ad-debug td, .ad-debug th { padding: 1px 8px 1px 0; text-align: left; }

.overlay.ready { background: rgba(10, 6, 20, 0.25); align-items: end; padding-bottom: max(24px, env(safe-area-inset-bottom)); }
.ready-challenge { color: var(--gold); font-size: 14px; margin: 10px 0; }
.btn.big { font-size: 22px; padding: 16px; }
.btn:disabled { opacity: 0.6; cursor: progress; }
.countdown { position: fixed; top: 38%; left: 50%; transform: translate(-50%, -50%); font-size: clamp(72px, 18vw, 160px); font-weight: 900; color: var(--gold); text-shadow: 0 6px 0 #b3380f, 0 0 30px rgba(0,0,0,0.4); pointer-events: none; }

.menu-row, .btn-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.btn-row .btn { flex: 1; margin-top: 10px; text-align: center; text-decoration: none; }
.hud-target { font-size: 13px; color: var(--gold); margin-top: 2px; }
.ready-beat, .over-beat { color: var(--gold); font-weight: 700; margin: 6px 0; }
.over-rank { font-size: 16px; font-weight: 700; margin: 4px 0 8px; }
.name-form { margin: 6px 0 4px; text-align: left; font-size: 13px; }
.name-row { display: flex; gap: 8px; margin-top: 6px; }
.name-row input { flex: 1; min-width: 0; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255,255,255,0.08); color: var(--ink); font: inherit; font-size: 16px; }
.name-row .btn { margin-top: 0; }
.overlay.top { z-index: 30; background: rgba(10, 6, 20, 0.7); }
.panel.board { width: min(460px, 100%); max-height: calc(100dvh - 32px); display: flex; flex-direction: column; }
.board-filters { display: flex; gap: 8px; margin: 8px 0; }
.board-filters select { flex: 1; padding: 8px; border-radius: 10px; background: rgba(255,255,255,0.08); color: var(--ink); border: 1px solid var(--line); font: inherit; }
.board-filters select option { color: #111; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { background: none; border: 0; color: var(--ink); padding: 8px 10px; font: inherit; font-size: 13px; cursor: pointer; }
.seg button.on { background: var(--hot); }
.board-list { list-style: none; padding: 0; margin: 0; overflow-y: auto; text-align: left; flex: 1; min-height: 120px; }
.board-list li { display: grid; grid-template-columns: 36px 1fr auto; gap: 8px; padding: 8px 6px; border-bottom: 1px solid var(--line); align-items: center; }
.board-list li.mine { background: rgba(255, 213, 79, 0.14); border-radius: 8px; }
.board-list .rk { font-weight: 800; color: var(--gold); }
.board-list .who small { display: block; opacity: 0.65; font-size: 11px; }
.board-list .sc { font-weight: 800; font-variant-numeric: tabular-nums; }
.board-me { font-size: 12px; margin: 8px 0 0; }
.board-me a { color: var(--gold); }
.share-preview { width: 100%; border-radius: 10px; margin: 8px 0; aspect-ratio: 1200 / 630; object-fit: cover; background: #000; }
.share-links { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.share-links a { padding: 10px 4px; border-radius: 10px; background: rgba(255,255,255,0.1); color: var(--ink); text-decoration: none; font-size: 13px; font-weight: 700; }

/* Game-over screen: bigger and easier to read at a glance. */
.panel.over-panel { width: min(520px, 100%); padding: 32px 28px; }
.over-panel h2 { font-size: clamp(34px, 7vw, 46px); margin-bottom: 8px; }
.over-cause { font-size: 18px; line-height: 1.4; margin: 0 0 4px; opacity: 0.9; }
.over-newbest { display: inline-block; margin: 8px 0 0; padding: 4px 14px; border-radius: 999px; background: var(--gold); color: #1b1230; font-weight: 800; font-size: 15px; }
.over-panel .big-score { font-size: clamp(64px, 16vw, 92px); margin: 12px 0 10px; }
.over-panel .stats { margin-bottom: 22px; }
.over-panel .stats dt { font-size: 13px; }
.over-panel .stats dd { font-size: 24px; }
.over-panel .over-rank { font-size: 18px; }
.over-panel .btn { font-size: 19px; padding: 15px; }
.over-panel .btn-row .btn { font-size: 17px; }
.over-panel .sponsors { font-size: 14px; }
.postcard-list { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 10px 0; }
.postcard-chip { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--gold); background: rgba(255, 213, 79, 0.12); font-size: 13px; color: var(--ink); }
.postcard-chip .pc-emoji { font-size: 18px; }
.postcard-complete { font-size: 14px; color: var(--gold); margin: 8px 0; font-weight: 700; }

/* Rival flash */
.rival-flash { position: fixed; top: 15%; left: 50%; transform: translateX(-50%); font-size: 18px; font-weight: 800; color: var(--gold); pointer-events: none; animation: rival-pop 1s ease-out forwards; text-shadow: 0 0 16px rgba(255, 213, 79, 0.7); }
@keyframes rival-pop { 0% { transform: translateX(-50%) scale(0.5); opacity: 0; } 30% { transform: translateX(-50%) scale(1.2); opacity: 1; } 100% { transform: translateX(-50%) scale(1); opacity: 0; } }

@media (max-width: 420px) {
  .over-panel { padding: 26px 18px; }
  .over-panel .btn-row .btn { font-size: 15px; padding: 13px 8px; white-space: nowrap; }
}

/* One-line gameplay tip (vendors ahead) */
.hint {
  position: fixed; left: 50%; bottom: calc(18% + env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: min(92vw, 560px); padding: 8px 14px; border-radius: 999px; z-index: 6; pointer-events: none;
  background: rgba(12, 10, 20, 0.78); color: #fff; font-weight: 700; font-size: 14px; text-align: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35); animation: hint-in 0.25s ease-out;
}
@keyframes hint-in { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ---------- Meso Radio ---------- */
.np {
  position: fixed; left: max(10px, env(safe-area-inset-left)); bottom: max(10px, env(safe-area-inset-bottom)); z-index: 20;
  display: flex; align-items: center; gap: 4px; max-width: min(360px, calc(100vw - 20px)); overflow: hidden;
  background: rgba(12, 8, 24, 0.78); border: 1px solid var(--line); border-radius: 14px; padding: 4px 6px 6px 4px;
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.np-main { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; background: none; border: 0; color: var(--ink); font: inherit; text-align: left; cursor: pointer; padding: 2px 4px; }
.np-icon { font-size: 20px; }
.np-text { display: flex; flex-direction: column; min-width: 0; }
.np-station { font-size: 11px; color: var(--gold); text-transform: uppercase; letter-spacing: 0.06em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.np-title { font-size: 13px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.np.ad .np-station { color: #9ad0ff; }
.np-btn { width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255,255,255,0.06); color: var(--ink); font-size: 15px; cursor: pointer; flex: none; }
.np-btn:disabled { opacity: 0.35; cursor: default; }
.np-link { font-size: 12px; font-weight: 700; color: #9ad0ff; white-space: nowrap; padding: 0 4px; }
.np-bar { position: absolute; left: 0; bottom: 0; height: 3px; width: 0; background: var(--hot); border-radius: 0 2px 2px 0; }
.np.ad .np-bar { background: #9ad0ff; }
body.playing .np { opacity: 0.85; }

.panel.radio { width: min(480px, 100%); max-height: calc(100dvh - 32px); overflow-y: auto; text-align: left; }
.radio-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.radio-head h2 { margin: 0; }
.switch { display: flex; align-items: center; gap: 6px; font-weight: 700; cursor: pointer; }
.switch input { width: 20px; height: 20px; accent-color: var(--hot); }
.panel.radio h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--gold); margin: 16px 0 6px; }
.radio-now { margin-top: 12px; padding: 12px; border-radius: 12px; background: rgba(255,255,255,0.06); display: flex; flex-direction: column; gap: 2px; }
.rn-kicker { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--gold); }
.radio-now.ad .rn-kicker { color: #9ad0ff; }
.rn-bar { height: 4px; background: rgba(255,255,255,0.12); border-radius: 2px; margin: 8px 0; overflow: hidden; }
.rn-bar i { display: block; height: 100%; width: 0; background: var(--hot); }
.rn-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.rn-controls .btn { margin: 0; text-decoration: none; }
.vol { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.vol input { width: 110px; accent-color: var(--hot); }
.radio-stations { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.radio-stations button {
  width: 100%; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; text-align: left;
  padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255,255,255,0.04); color: var(--ink); font: inherit; cursor: pointer;
}
.radio-stations button.on { border-color: var(--hot); background: rgba(255, 90, 31, 0.16); }
.rs-freq { font-size: 12px; font-weight: 800; color: var(--gold); min-width: 64px; }
.rs-name { font-weight: 700; }
.rs-genre { display: block; font-size: 12px; opacity: 0.7; font-weight: 400; }
.rs-tag { font-size: 11px; padding: 2px 6px; border-radius: 999px; background: rgba(255,255,255,0.1); white-space: nowrap; }
.radio-next { margin: 0; padding-left: 20px; }
.radio-next li { padding: 3px 0; }
.radio-next li.ad { color: #9ad0ff; }
.radio-note { font-size: 12px; margin-top: 14px; }
@media (max-width: 420px) { .vol { margin-left: 0; width: 100%; } .vol input { flex: 1; } }
.radio-note a { color: #9ad0ff; font-weight: 700; }
/* keep menus clear of the radio mini player */
.overlay { padding-bottom: max(72px, calc(env(safe-area-inset-bottom) + 64px)); }
.overlay.top { padding-bottom: 16px; }
.overlay.ready { padding-bottom: max(76px, calc(env(safe-area-inset-bottom) + 68px)); }

/* ---------- Landmark offer and tours ---------- */
.lm-offer {
  position: fixed; top: calc(max(10px, env(safe-area-inset-top)) + 64px); left: 50%; transform: translateX(-50%); z-index: 12;
  display: flex; align-items: center; gap: 10px; width: min(440px, calc(100vw - 20px)); overflow: hidden;
  padding: 8px 8px 10px 12px; border-radius: 14px; border: 1px solid rgba(255, 213, 79, 0.6);
  background: rgba(14, 10, 26, 0.82); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  animation: offer-in 0.3s ease-out;
}
@keyframes offer-in { from { opacity: 0; transform: translate(-50%, -10px); } }
.lm-offer-icon { font-size: 22px; }
.lm-offer-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.lm-offer-text b { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lm-offer-text small { font-size: 11px; opacity: 0.75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lm-offer .btn { margin: 0; flex: none; }
.lm-offer-bar { position: absolute; left: 0; bottom: 0; height: 3px; width: 100%; background: var(--gold); }

.tour { position: fixed; inset: 0; z-index: 25; display: flex; align-items: flex-end; justify-content: flex-start; padding: 16px; pointer-events: none; }
.tour-card {
  pointer-events: auto; width: min(420px, 100%); max-height: calc(100dvh - 32px); overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 14px 16px 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  animation: tour-in 0.35s ease-out;
}
@keyframes tour-in { from { opacity: 0; transform: translateY(16px); } }
.tour-guide { display: flex; align-items: center; gap: 10px; }
.tour-avatar { width: 46px; height: 46px; flex: none; display: grid; place-items: center; font-size: 30px; border-radius: 50%; background: rgba(255, 213, 79, 0.18); border: 2px solid var(--gold); }
.tour-who { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.tour-who b { font-size: 14px; }
.tour-who small { font-size: 12px; color: var(--gold); text-transform: uppercase; letter-spacing: 0.06em; }
.tour-guide .icon-btn { width: 36px; height: 36px; font-size: 15px; }
.tour-step { display: block; margin-top: 12px; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; opacity: 0.6; }
.tour-card h3 { margin: 2px 0 6px; font-size: 20px; }
.tour-card p { margin: 0; font-size: 15px; line-height: 1.5; }
.tour-dots { display: flex; gap: 6px; margin: 12px 0 10px; }
.tour-dots i { width: 8px; height: 8px; border-radius: 50%; background: rgba(255, 255, 255, 0.25); }
.tour-dots i.on { background: var(--gold); width: 22px; border-radius: 4px; }
.tour-btns { display: flex; gap: 8px; }
.tour-btns .btn { margin: 0; }
.tour-btns #tour-next { flex: 1; }
@media (max-width: 600px) { .lm-offer { top: calc(env(safe-area-inset-top) + 108px); } }
@media (min-width: 900px) { .tour { align-items: center; padding-left: 28px; } }
@media (max-width: 480px) {
  .tour { padding: 10px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .tour-card { width: 100%; max-height: 52dvh; }
  .tour-card h3 { font-size: 18px; }
  .tour-card p { font-size: 14px; }
}

.tour-photo { position: relative; margin: 12px -16px 0; background: #0b0814; aspect-ratio: 16 / 9; max-height: 230px; width: calc(100% + 32px); overflow: hidden; }
.tour-photo img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity 0.35s; }
.tour-photo img.loaded { opacity: 1; }
.tour-photo figcaption {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 10px 4px; font-size: 10px; line-height: 1.3; color: rgba(255, 255, 255, 0.85);
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.65)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tour-photo figcaption a { color: inherit; }
@media (max-width: 480px) { .tour-photo { max-height: 150px; } .tour-card { max-height: 64dvh; } }
@media (max-height: 640px) and (min-width: 481px) { .tour-photo { max-height: 170px; } .tour-card p { font-size: 14px; } }
