:root {
  color-scheme: dark;
  --ape-cyan: #00cfe6;
  --ape-pink: #ff3ea5;
  --ape-paper: #e9edf2;
  --ape-ink: rgba(4, 6, 14, 0.72);
  --ape-line: rgba(0, 207, 230, 0.35);
  --mono: "IBM Plex Mono", "SFMono-Regular", ui-monospace, Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: #02040d; color: var(--ape-paper); }
body { font-family: var(--mono); -webkit-font-smoothing: antialiased; }

#viewport { position: fixed; inset: 0; touch-action: none; }
#viewport canvas { display: block; }

/* Brand + place, top left. Squared, brutalist, no cards. */
.hud-top {
  position: fixed;
  top: calc(18px + env(safe-area-inset-top, 0px));
  left: 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  pointer-events: none;
  z-index: 5;
}
.brand-mark { pointer-events: auto; }
.brand-mark img { display: block; height: 26px; width: auto; filter: drop-shadow(0 0 10px rgba(0, 207, 230, 0.35)); }
.hud-home { pointer-events: auto; font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ape-cyan); text-decoration: none; border: 1px solid var(--ape-line); padding: 5px 8px; background: var(--ape-ink); }
.hud-home:hover { border-color: var(--ape-cyan); }
.hud-place {
  margin: 0;
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: rgba(233, 237, 242, 0.7);
  border-left: 2px solid var(--ape-pink);
  padding-left: 10px;
}

/* Actions, top right. */
.hud-actions {
  position: fixed;
  top: calc(16px + env(safe-area-inset-top, 0px));
  right: 20px;
  display: flex;
  gap: 8px;
  z-index: 5;
}
.hud-actions button {
  font: inherit;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ape-paper);
  background: var(--ape-ink);
  border: 1px solid var(--ape-line);
  border-radius: 0;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: 3px 3px 0 rgba(0, 207, 230, 0.18);
  transition: background 150ms ease, border-color 150ms ease;
}
.hud-actions button:hover,
.hud-actions button:focus-visible { border-color: var(--ape-cyan); outline: none; }
.hud-actions button[aria-pressed='true'] {
  background: rgba(0, 207, 230, 0.16);
  border-color: var(--ape-cyan);
  box-shadow: 3px 3px 0 rgba(255, 62, 165, 0.45);
}

kbd {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--ape-cyan);
  border: 1px solid rgba(0, 207, 230, 0.5);
  padding: 0 4px;
  line-height: 1.5;
}

/* Key hints, bottom left, one line. */
.hud-keys {
  position: fixed;
  left: 20px;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  font-size: 11px;
  color: rgba(233, 237, 242, 0.72);
  pointer-events: none;
  z-index: 4;
  max-width: calc(100vw - 40px);
}
.hud-keys span { display: inline-flex; gap: 4px; align-items: center; }

.hud-status {
  position: fixed;
  left: 50%;
  bottom: calc(56px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  margin: 0;
  background: var(--ape-ink);
  border: 1px solid var(--ape-line);
  padding: 9px 16px;
  font-size: 12px;
  letter-spacing: 0.04em;
  z-index: 10;
  white-space: nowrap;
  max-width: calc(100vw - 32px);
  overflow: hidden;
  text-overflow: ellipsis;
  transition: opacity 500ms ease;
  pointer-events: none;
}
.hud-status.hidden { opacity: 0; }
.hud-status.error { border-color: var(--ape-pink); color: #ffc2e0; }

.hud-keys,
.hud-actions,
.hud-top { transition: opacity 900ms ease; }
html[data-chrome='hidden'] .hud-keys { opacity: 0; }
html[data-chrome='hidden'] .hud-actions,
html[data-chrome='hidden'] .hud-top { opacity: 0.35; }
html[data-chrome='hidden'] .hud-actions:hover { opacity: 1; }

/* Data attribution (DATA.GOV.HK terms require it on screen). */
.hud-attribution {
  position: fixed;
  right: 12px;
  bottom: calc(6px + env(safe-area-inset-bottom, 0px));
  margin: 0;
  font-size: 9px;
  letter-spacing: 0.04em;
  color: rgba(233, 237, 242, 0.45);
  pointer-events: none;
  z-index: 3;
  max-width: calc(100vw - 24px);
  text-align: right;
}

.hud-stats {
  position: fixed;
  right: 20px;
  top: calc(60px + env(safe-area-inset-top, 0px));
  margin: 0;
  font-size: 10px;
  letter-spacing: 0.08em;
  color: rgba(233, 237, 242, 0.75);
  background: var(--ape-ink);
  border: 1px solid var(--ape-line);
  padding: 4px 8px;
  z-index: 5;
  pointer-events: none;
}
.hud-stats.hidden { display: none; }
.hud-streaming {
  position: fixed;
  left: 20px;
  top: calc(64px + env(safe-area-inset-top, 0px));
  margin: 0;
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ape-cyan);
  z-index: 5;
  transition: opacity 600ms ease;
  pointer-events: none;
}
.hud-streaming.hidden { opacity: 0; }

/* Minimap, bottom right: north up, where you are. */
.hud-map {
  position: fixed;
  right: 20px;
  bottom: calc(26px + env(safe-area-inset-bottom, 0px));
  width: clamp(190px, 16vw, 260px);
  z-index: 5;
  background: var(--ape-ink);
  border: 1px solid var(--ape-line);
  box-shadow: 3px 3px 0 rgba(0, 207, 230, 0.18);
}
.hud-map[hidden] { display: none; }
.hud-map-place {
  margin: 0;
  padding: 6px 8px 5px;
  display: flex;
  gap: 8px;
  align-items: baseline;
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  border-left: 2px solid var(--ape-pink);
}
.hud-map-place b { font-weight: 600; color: var(--ape-paper); overflow: hidden; text-overflow: ellipsis; }
.hud-map-place span { letter-spacing: 0.06em; color: var(--ape-cyan); }
.hud-map canvas { display: block; width: 100%; aspect-ratio: 1; cursor: pointer; }

.world-labels { position: fixed; inset: 0; pointer-events: none; z-index: 2; }
.world-labels span {
  position: absolute; left: 0; top: 0; white-space: nowrap;
  font-size: 10px; letter-spacing: 0.08em; color: #e9edf2;
  background: rgba(4, 6, 14, 0.7); border-left: 2px solid var(--ape-cyan); padding: 2px 6px;
}

/* Offline render harness hides all chrome. */
html[data-capture='true'] .hud-top,
html[data-capture='true'] .hud-actions,
html[data-capture='true'] .hud-keys,
html[data-capture='true'] .hud-status,
html[data-capture='true'] .hud-stats,
html[data-capture='true'] .hud-streaming,
html[data-capture='true']:not([data-map='true']) .hud-map { display: none; }

@media (max-width: 720px) {
  .hud-map { top: calc(58px + env(safe-area-inset-top, 0px)); bottom: auto; right: 12px; width: 148px; }
  .hud-place { display: none; }
  .hud-actions { top: auto; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); right: 16px; flex-direction: column; }
  .hud-actions kbd { display: none; }
  .hud-keys { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .hud-keys, .hud-actions, .hud-top, .hud-status { transition: none; }
}

/* ---------------------------------------------------------------- loader ---
   Full-screen, brutalist: the city streams in behind a dark scrim, then the
   overlay lifts and the arrival seal takes over. */
.loader {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  align-items: center;
  padding: calc(40px + env(safe-area-inset-top, 0px)) clamp(20px, 7vw, 120px) calc(40px + env(safe-area-inset-bottom, 0px));
  background:
    radial-gradient(120% 90% at 78% 50%, rgba(0, 207, 230, 0.08), transparent 60%),
    linear-gradient(180deg, rgba(2, 4, 13, 0.9), rgba(2, 4, 13, 0.97));
  transition: opacity 700ms ease, visibility 0s linear 700ms;
  overflow: hidden;
}
.loader.done { opacity: 0; visibility: hidden; pointer-events: none; }
.loader-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(0, 207, 230, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 207, 230, 0.06) 1px, transparent 1px),
    repeating-linear-gradient(180deg, rgba(255, 255, 255, 0.025) 0 1px, transparent 1px 3px);
  background-size: 48px 48px, 48px 48px, 100% 3px;
  mask-image: linear-gradient(90deg, #000 0%, rgba(0, 0, 0, 0.35) 70%);
  pointer-events: none;
}
.loader-body { position: relative; max-width: 560px; z-index: 1; }
.loader-kicker {
  margin: 0 0 22px;
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: rgba(233, 237, 242, 0.7);
  border-left: 2px solid var(--ape-pink);
  padding-left: 10px;
}
.loader-kicker span { color: var(--ape-cyan); margin: 0 4px; }
.loader-title {
  margin: 0 0 28px;
  font-size: clamp(34px, 6.2vw, 76px);
  line-height: 0.92;
  font-weight: 700;
  letter-spacing: -0.02em;
  text-transform: uppercase;
  color: var(--ape-paper);
}
.loader-title em { font-style: normal; color: var(--ape-cyan); text-shadow: 4px 4px 0 rgba(255, 62, 165, 0.55); }
.loader-readout { display: flex; align-items: baseline; gap: 18px; margin-bottom: 12px; }
.loader-pct {
  margin: 0;
  font-size: clamp(40px, 6vw, 64px);
  font-weight: 700;
  line-height: 1;
  color: var(--ape-cyan);
  font-variant-numeric: tabular-nums;
}
.loader-pct small { font-size: 0.4em; color: var(--ape-pink); margin-left: 4px; }
.loader-phase { margin: 0; font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; color: rgba(233, 237, 242, 0.75); }
.loader-phase::after { content: '_'; color: var(--ape-pink); animation: loader-blink 900ms steps(1) infinite; }
.loader-bar {
  position: relative;
  height: 10px;
  border: 1px solid var(--ape-line);
  background: rgba(4, 6, 14, 0.8);
  box-shadow: 4px 4px 0 rgba(255, 62, 165, 0.35);
  margin-bottom: 22px;
}
.loader-bar i {
  position: absolute;
  inset: 1px auto 1px 1px;
  width: 0;
  background: repeating-linear-gradient(90deg, var(--ape-cyan) 0 10px, rgba(0, 207, 230, 0.55) 10px 12px);
  transition: width 300ms ease;
}
.loader-bar i::after { content: ''; position: absolute; right: -3px; top: -3px; bottom: -3px; width: 6px; background: var(--ape-pink); box-shadow: 0 0 12px var(--ape-pink); }
.loader-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; }
.loader-steps li { display: grid; grid-template-columns: 30px 110px 1fr auto; gap: 10px; align-items: baseline; color: rgba(233, 237, 242, 0.45); border-bottom: 1px dashed rgba(0, 207, 230, 0.14); padding-bottom: 5px; }
.loader-steps b { color: var(--ape-pink); font-weight: 400; }
.loader-steps span { color: rgba(233, 237, 242, 0.45); text-transform: none; letter-spacing: 0.04em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.loader-steps em { font-style: normal; color: rgba(233, 237, 242, 0.4); font-variant-numeric: tabular-nums; }
.loader-steps li[data-state='busy'] { color: var(--ape-paper); }
.loader-steps li[data-state='busy'] em { color: var(--ape-cyan); }
.loader-steps li[data-state='done'] { color: rgba(233, 237, 242, 0.8); }
.loader-steps li[data-state='done'] em { color: var(--ape-cyan); }
/* A slowly turning seal, echoing the arrival circle. */
.loader-seal { position: absolute; right: clamp(-160px, -6vw, -40px); top: 50%; width: min(62vh, 620px); aspect-ratio: 1; transform: translateY(-50%); pointer-events: none; opacity: 0.9; }
.loader-seal i { position: absolute; inset: 0; border-radius: 50%; border: 1px solid rgba(0, 207, 230, 0.45); }
.loader-seal i:nth-child(1) { border-width: 2px; border-style: dashed; animation: loader-spin 36s linear infinite; box-shadow: 0 0 40px rgba(0, 207, 230, 0.12), inset 0 0 40px rgba(0, 207, 230, 0.08); }
.loader-seal i:nth-child(2) { inset: 12%; border-color: rgba(255, 62, 165, 0.55); border-style: dotted; border-width: 3px; animation: loader-spin 22s linear infinite reverse; }
.loader-seal i:nth-child(3) { inset: 27%; border-color: rgba(0, 207, 230, 0.35); animation: loader-pulse 2.4s ease-in-out infinite; }
.loader-seal i:nth-child(3)::before, .loader-seal i:nth-child(3)::after { content: ''; position: absolute; inset: 14%; border: 1px solid rgba(0, 207, 230, 0.4); transform: rotate(45deg); }
.loader-seal i:nth-child(3)::after { transform: rotate(0deg); border-color: rgba(255, 62, 165, 0.45); }
@keyframes loader-spin { to { transform: rotate(360deg); } }
@keyframes loader-pulse { 50% { opacity: 0.4; transform: scale(0.97); } }
@keyframes loader-blink { 50% { opacity: 0; } }
@media (max-width: 720px) {
  .loader-seal { right: -45%; opacity: 0.4; width: 110vw; }
  .loader-steps li { grid-template-columns: 26px 1fr auto; }
  .loader-steps span { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .loader, .loader-bar i { transition: none; }
  .loader-seal i, .loader-phase::after { animation: none; }
}
