: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-avatar { pointer-events: auto; font: inherit; font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ape-paper); background: rgba(4, 8, 16, 0.38); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); border: 1px solid rgba(233, 237, 242, 0.2); border-radius: 999px; padding: 6px 12px; cursor: pointer; }
.hud-avatar:hover, .hud-avatar:focus-visible { border-color: var(--ape-cyan); outline: none; }
.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: one small translucent pill; the six actions drop out of it. */
.hud-actions {
  position: fixed;
  top: calc(16px + env(safe-area-inset-top, 0px));
  right: 20px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  z-index: 5;
}
.hud-menu {
  font: inherit;
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(233, 237, 242, 0.9);
  background: rgba(4, 8, 16, 0.38);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(233, 237, 242, 0.2);
  border-radius: 999px;
  padding: 9px 14px;
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: background 150ms ease, border-color 150ms ease;
}
.hud-menu i { width: 3px; height: 3px; border-radius: 50%; background: currentColor; }
.hud-menu span { margin-left: 6px; }
.hud-menu:hover, .hud-menu:focus-visible, .hud-menu[aria-expanded='true'] { border-color: var(--ape-cyan); background: rgba(4, 8, 16, 0.6); outline: none; }
.hud-drawer {
  display: flex;
  flex-direction: column;
  min-width: 168px;
  padding: 6px;
  background: rgba(4, 8, 16, 0.5);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border: 1px solid rgba(233, 237, 242, 0.16);
  border-radius: 14px;
}
.hud-drawer[hidden] { display: none; }
.hud-drawer button {
  font: inherit;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ape-paper);
  background: transparent;
  border: 0;
  border-radius: 9px;
  padding: 9px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  cursor: pointer;
  transition: background 150ms ease;
}
.hud-drawer button:hover, .hud-drawer button:focus-visible { background: rgba(233, 237, 242, 0.1); outline: none; }
.hud-drawer button[aria-pressed='true'] { color: var(--ape-cyan); }
.hud-drawer kbd { border-color: rgba(233, 237, 242, 0.25); color: rgba(233, 237, 242, 0.7); border-radius: 4px; }

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: a small toggle; the list opens above it. */
.hud-keys {
  position: fixed;
  left: 20px;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column-reverse;
  align-items: flex-start;
  gap: 8px;
  z-index: 4;
  max-width: calc(100vw - 40px);
}
.hud-keys-toggle {
  font: inherit;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(233, 237, 242, 0.85);
  background: rgba(4, 8, 16, 0.38);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(233, 237, 242, 0.2);
  border-radius: 999px;
  padding: 8px 13px;
  cursor: pointer;
}
.hud-keys-toggle b { color: var(--ape-cyan); margin-right: 4px; }
.hud-keys-toggle:hover, .hud-keys-toggle:focus-visible, .hud-keys-toggle[aria-expanded='true'] { border-color: var(--ape-cyan); outline: none; }
.hud-keys-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 12px 14px;
  font-size: 11px;
  color: rgba(233, 237, 242, 0.85);
  background: rgba(4, 8, 16, 0.5);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border: 1px solid rgba(233, 237, 242, 0.16);
  border-radius: 14px;
}
.hud-keys-list[hidden] { display: none; }
.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; }

/* Depth while diving: a quiet readout under the top bar, in the HUD's ink and cyan. */
.hud-depth {
  position: fixed;
  left: 50%;
  top: calc(64px + env(safe-area-inset-top, 0px));
  transform: translateX(-50%);
  margin: 0;
  background: var(--ape-ink);
  border: 1px solid var(--ape-line);
  border-left: 2px solid var(--ape-cyan, #00cfe6);
  padding: 6px 12px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  z-index: 10;
  white-space: nowrap;
  transition: opacity 400ms ease;
  pointer-events: none;
}
.hud-depth.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.35; }
html[data-chrome='hidden'] .hud-keys:hover { opacity: 1; }
html[data-chrome='hidden'] .hud-actions,
html[data-chrome='hidden'] .hud-top { opacity: 0.35; }
html[data-chrome='hidden'] .hud-actions:hover { opacity: 1; }

/* Source credits stay accessible without covering the city view. */
.hud-credits {
  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: auto;
  text-decoration: underline;
  z-index: 3;
  max-width: calc(100vw - 24px);
  text-align: right;
}

.hud-stats {
  position: fixed;
  right: 136px;
  top: calc(20px + env(safe-area-inset-top, 0px));
  border-radius: 999px;
  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-depth,
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 { right: 12px; }
  .hud-drawer kbd { display: none; }
  .hud-keys { display: none; }
  .hud-avatar { padding: 5px 9px; }
}

@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; }
}

/* Your avatar: name, character and skin tone, on a card over the world. The ape behind it changes as you pick. */
.identity { position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: flex-end; padding: 20px clamp(16px, 5vw, 72px); background: linear-gradient(90deg, rgba(2, 4, 13, 0) 30%, rgba(2, 4, 13, 0.55)); }
.identity[hidden] { display: none; }
.identity-card { width: min(430px, 100%); max-height: calc(100vh - 40px); overflow: auto; padding: 0 22px 20px; color: var(--ape-paper); background: rgba(6, 10, 20, 0.78); -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px); border: 1px solid rgba(233, 237, 242, 0.18); border-radius: 18px; box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55); }
.identity-card header { display: flex; justify-content: space-between; align-items: center; margin: 0 -22px; padding: 14px 22px 12px; border-bottom: 1px solid rgba(233, 237, 242, 0.12); font-size: 10px; letter-spacing: 0.2em; text-transform: uppercase; color: var(--ape-cyan); }
.identity-x { font: inherit; font-size: 20px; line-height: 1; color: var(--ape-paper); background: none; border: 0; padding: 2px 6px; cursor: pointer; }
.identity-card h2 { margin: 16px 0 4px; font-size: 26px; line-height: 1.1; letter-spacing: -0.01em; }
.identity-k, .identity-card label.identity-k { display: block; margin: 16px 0 8px; font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase; color: rgba(233, 237, 242, 0.62); }
.identity-card input { width: 100%; box-sizing: border-box; font: inherit; font-size: 15px; color: var(--ape-paper); background: rgba(233, 237, 242, 0.07); border: 1px solid rgba(233, 237, 242, 0.22); border-radius: 10px; padding: 11px 12px; }
.identity-card input:focus-visible { border-color: var(--ape-cyan); outline: none; }
.identity-card small, .identity-visitor { display: block; margin: 7px 0 0; font-size: 11px; line-height: 1.45; color: rgba(233, 237, 242, 0.55); }
.identity-group { margin: 0 0 6px; font-size: 9px; letter-spacing: 0.16em; text-transform: uppercase; color: rgba(233, 237, 242, 0.4); }
.identity-looks { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; margin-bottom: 10px; }
.identity-looks button, .identity-skins button { font: inherit; color: var(--ape-paper); background: rgba(233, 237, 242, 0.05); border: 1px solid rgba(233, 237, 242, 0.14); border-radius: 10px; padding: 4px 3px 6px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.identity-looks img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 7px; display: block; background: rgba(233, 237, 242, 0.08); }
.identity-looks span, .identity-skins span { font-size: 9px; line-height: 1.15; text-align: center; color: rgba(233, 237, 242, 0.75); }
.identity-skins { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.identity-skins i { width: 26px; height: 26px; border-radius: 50%; display: block; margin-top: 3px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25); }
.identity-looks button:hover, .identity-skins button:hover, .identity-looks button:focus-visible, .identity-skins button:focus-visible { border-color: rgba(0, 207, 230, 0.6); outline: none; }
.identity-looks button[aria-pressed='true'], .identity-skins button[aria-pressed='true'] { border-color: var(--ape-cyan); background: rgba(0, 207, 230, 0.14); }
.identity-go { width: 100%; margin-top: 18px; font: inherit; font-size: 12px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: #02040d; background: var(--ape-cyan); border: 0; border-radius: 999px; padding: 13px; cursor: pointer; }
.identity-go:hover, .identity-go:focus-visible { filter: brightness(1.1); outline: 2px solid rgba(233, 237, 242, 0.5); outline-offset: 2px; }
.identity-go[disabled], .identity-looks button[disabled], .identity-skins button[disabled] { opacity: 0.55; cursor: progress; }
.identity-note { min-height: 16px; margin: 10px 0 0; font-size: 11px; text-align: center; color: rgba(233, 237, 242, 0.6); }
.identity-note.bad { color: var(--ape-pink); }
html[data-capture='true'] .identity { display: none; }
@media (max-width: 720px) { .identity { justify-content: center; align-items: flex-end; padding: 12px; background: rgba(2, 4, 13, 0.35); } .identity-card { max-height: 70vh; } .identity-looks { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
