:root {
  --bg: #03040a;
  --ink: #e8f1ff;
  --ink-2: #a9b8d6;
  --muted: #6f7fa3;
  --line: rgba(160, 200, 255, 0.14);
  --glass: rgba(10, 16, 34, 0.55);
  --glass-strong: rgba(10, 16, 34, 0.82);
  --accent: #7cd4ff;
  --accent-2: #b69cff;
  --cf: #f38020;
  --good: #6cf2b5;
  --warn: #ffb35c;
  --radius: 14px;
  --font: "Space Grotesk", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
}

button { font: inherit; color: inherit; }

#sky {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(1200px 900px at 50% 45%, rgba(40, 70, 140, 0.22), transparent 60%),
    radial-gradient(800px 600px at 85% 10%, rgba(120, 60, 180, 0.12), transparent 60%),
    radial-gradient(900px 700px at 10% 90%, rgba(20, 110, 160, 0.10), transparent 60%),
    var(--bg);
}
#sky::before, #sky::after {
  content: "";
  position: absolute;
  inset: -50%;
  background-image:
    radial-gradient(1px 1px at 20px 30px, rgba(255,255,255,0.7), transparent 60%),
    radial-gradient(1px 1px at 140px 80px, rgba(255,255,255,0.45), transparent 60%),
    radial-gradient(1.4px 1.4px at 90px 160px, rgba(200,220,255,0.6), transparent 60%),
    radial-gradient(1px 1px at 260px 210px, rgba(255,255,255,0.35), transparent 60%),
    radial-gradient(1.2px 1.2px at 330px 40px, rgba(255,230,200,0.5), transparent 60%),
    radial-gradient(1px 1px at 400px 300px, rgba(255,255,255,0.4), transparent 60%);
  background-size: 420px 340px;
  animation: drift 240s linear infinite;
  opacity: 0.55;
}
#sky::after {
  background-size: 610px 520px;
  animation-duration: 420s;
  opacity: 0.35;
  transform: rotate(33deg);
}
@keyframes drift { to { transform: translate3d(-420px, -170px, 0); } }
@media (prefers-reduced-motion: reduce) { #sky::before, #sky::after { animation: none; } }

#globe, #ring {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
}
#ring { cursor: crosshair; }
#ring.over-globe { cursor: grab; }
#ring.dragging { cursor: grabbing; }

#labels { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.label {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate3d(-9999px, 0, 0);
  white-space: nowrap;
  font-size: 11px;
  line-height: 1.25;
  color: var(--ink);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.9);
  transition: opacity 0.35s ease;
  will-change: transform, opacity;
}
.label b { font-weight: 600; }
.label small { display: block; color: var(--ink-2); font-size: 10px; }
.label.home { color: #ffd9b3; }
.label.home b { color: #ffb066; letter-spacing: 0.04em; }
.label.you b::after { content: " · you"; color: var(--accent); font-weight: 500; }
.label.ghost { opacity: 0.7; font-style: italic; }

.hud {
  position: fixed;
  z-index: 5;
  pointer-events: none;
}
.hud > * { pointer-events: auto; }

.hud-top-left { top: 18px; left: 20px; display: flex; flex-direction: column; gap: 14px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 50%;
  background:
    radial-gradient(circle at 35% 35%, #bff0ff, transparent 45%),
    conic-gradient(from 200deg, var(--accent), var(--accent-2), var(--cf), var(--accent));
  box-shadow: 0 0 24px rgba(124, 212, 255, 0.45);
  animation: spin 18s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.brand h1 { margin: 0; font-size: 20px; letter-spacing: 0.32em; font-weight: 600; }
.tagline { margin: 1px 0 0; color: var(--ink-2); font-size: 12px; letter-spacing: 0.08em; }

.harmony {
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px 10px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  min-width: 210px;
}
.harmony-key { font-size: 22px; font-weight: 600; letter-spacing: 0.01em; }
.harmony-key .muted { font-size: 15px; font-weight: 400; }
.harmony-sun { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-2); margin-top: 2px; }
.sun-dot { width: 9px; height: 9px; border-radius: 50%; background: #ffd27a; box-shadow: 0 0 10px #ffb347; }
.chapter { margin-top: 8px; height: 2px; background: rgba(255,255,255,0.08); border-radius: 2px; overflow: hidden; }
#chapter-bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width 0.4s linear; }

.hud-top-right {
  top: 18px; right: 20px;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 16px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  min-width: 220px;
}
.live-row { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.12em; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); box-shadow: 0 0 8px var(--warn); }
.live-dot.live { background: var(--good); box-shadow: 0 0 10px var(--good); animation: breathe 2.4s ease-in-out infinite; }
.live-dot.offline { background: var(--accent-2); box-shadow: 0 0 10px var(--accent-2); }
@keyframes breathe { 50% { opacity: 0.45; } }
.big-number { margin-top: 6px; font-size: 13px; }
.big-number #online-count { font-size: 30px; font-weight: 600; font-variant-numeric: tabular-nums; vertical-align: -3px; }
.stats { display: grid; grid-template-columns: repeat(3, auto); gap: 12px; margin: 8px 0 0; }
.stats div { display: flex; flex-direction: column-reverse; }
.stats dt { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.stats dd { margin: 0; font-family: var(--mono); font-size: 14px; font-variant-numeric: tabular-nums; }
.room-row { margin-top: 8px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; }
.room-row strong { color: var(--ink); text-transform: none; letter-spacing: 0; font-weight: 500; }

.muted { color: var(--muted); }

.hud-feed {
  left: 20px;
  bottom: calc(120px + var(--safe-bottom));
  display: flex;
  flex-direction: column-reverse;
  gap: 6px;
  max-width: min(440px, 60vw);
  pointer-events: none;
}
.feed-item {
  font-size: 12px;
  color: var(--ink-2);
  background: rgba(8, 12, 26, 0.45);
  border: 1px solid rgba(160, 200, 255, 0.08);
  border-radius: 10px;
  padding: 6px 10px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: feedIn 0.35s ease-out;
  transition: opacity 1.2s ease, transform 1.2s ease;
}
.feed-item .who { color: var(--ink); font-weight: 500; }
.feed-item .path { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.feed-item .path b { color: var(--cf); font-weight: 500; }
.feed-item.fade { opacity: 0; transform: translateY(6px); }
.swatch { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }
@keyframes feedIn { from { opacity: 0; transform: translateY(8px); } }

.hud-bottom {
  left: 16px; right: 16px;
  bottom: calc(14px + var(--safe-bottom));
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 16px;
}
.you {
  justify-self: start;
  display: flex; align-items: center; gap: 12px;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  max-width: 100%;
  min-width: 0;
}
.you-dot { flex: none; width: 14px; height: 14px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.you-text { min-width: 0; }
.you-name { background: none; border: 0; padding: 0; font-weight: 600; font-size: 15px; cursor: text; text-align: left; }
.you-name:hover { text-decoration: underline dotted rgba(255,255,255,0.4); }
.you-meta { font-size: 12px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.you-route { font-family: var(--mono); font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.you-route b { color: var(--cf); font-weight: 500; }

.controls {
  display: flex; gap: 6px;
  background: var(--glass-strong);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.ctl {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: transparent; border: 0; border-radius: 999px;
  padding: 7px 12px 5px;
  color: var(--ink-2);
  cursor: pointer;
  font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase;
  transition: background 0.2s, color 0.2s;
}
.ctl svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.ctl:hover { background: rgba(255,255,255,0.07); color: var(--ink); }
.ctl:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.ctl[aria-pressed="true"] { color: var(--accent); background: rgba(124, 212, 255, 0.1); }
#btn-mute[aria-pressed="true"] { color: var(--warn); }
#btn-mute[aria-pressed="true"] .waves { opacity: 0; }
.ctl-capture svg circle { fill: #ff5a7a; stroke: none; }
.ctl-capture.recording svg circle { animation: rec 1s ease-in-out infinite; }
.ctl-capture.recording { color: #ff8aa0; }
@keyframes rec { 50% { opacity: 0.25; } }

.latency {
  justify-self: end;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px;
  min-width: 200px;
  font-size: 12px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.latency-row { display: flex; justify-content: space-between; gap: 16px; }
.latency-row strong { font-family: var(--mono); font-weight: 500; font-variant-numeric: tabular-nums; }
.latency-bar { margin-top: 8px; height: 3px; border-radius: 3px; background: rgba(255,255,255,0.08); overflow: hidden; }
#latency-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--cf), #ffd27a); transition: width 0.6s ease; }

.keys-hint {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-bottom)); transform: translateX(-50%);
  font-size: 11px; letter-spacing: 0.06em; color: var(--muted); z-index: 4; pointer-events: none;
  transition: opacity 1s ease; white-space: nowrap;
}
.keys-hint.gone { opacity: 0; }

/* Overlays */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  display: grid; place-items: center;
  background: radial-gradient(circle at 50% 50%, rgba(3, 4, 10, 0.35), rgba(3, 4, 10, 0.82));
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  transition: opacity 0.6s ease, visibility 0.6s;
  padding: 20px;
}
.overlay.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.intro-card { max-width: 620px; text-align: left; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.24em; font-size: 11px; color: var(--accent); margin: 0 0 12px; }
.eyebrow::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--good); box-shadow: 0 0 8px var(--good); margin-right: 8px; vertical-align: 1px; animation: breathe 2s infinite; }
.intro-card h2 { font-size: clamp(30px, 5.4vw, 54px); line-height: 1.04; margin: 0 0 18px; font-weight: 600; letter-spacing: -0.02em; }
.grad { background: linear-gradient(90deg, var(--accent), var(--accent-2) 55%, var(--cf)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.intro-body { color: var(--ink-2); font-size: 16px; line-height: 1.6; margin: 0 0 26px; max-width: 560px; }
.intro-body strong { color: var(--ink); font-weight: 500; }
.intro-actions { display: flex; gap: 12px; flex-wrap: wrap; }
.primary {
  display: inline-flex; align-items: center; gap: 10px;
  background: linear-gradient(135deg, #8fdcff, #b69cff);
  color: #07091a; border: 0; border-radius: 999px;
  padding: 13px 24px; font-weight: 600; font-size: 16px; cursor: pointer;
  box-shadow: 0 8px 40px rgba(124, 212, 255, 0.35);
  text-decoration: none;
  transition: transform 0.15s, box-shadow 0.2s;
}
.primary:hover { transform: translateY(-1px); box-shadow: 0 10px 50px rgba(124, 212, 255, 0.5); }
.ghost-btn {
  background: rgba(255,255,255,0.04); border: 1px solid var(--line); border-radius: 999px;
  padding: 12px 20px; cursor: pointer; color: var(--ink-2);
}
.ghost-btn:hover { color: var(--ink); background: rgba(255,255,255,0.08); }
.intro-foot { margin-top: 22px; font-size: 12px; color: var(--muted); }

.help-card {
  position: relative;
  max-width: 980px; width: 100%;
  max-height: calc(100vh - 40px); overflow: auto;
  background: var(--glass-strong);
  border: 1px solid var(--line); border-radius: 20px;
  padding: 28px 30px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.5);
  touch-action: pan-y;
}
.help-card h2 { margin: 0 0 18px; font-size: 26px; font-weight: 600; }
.help-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 22px; }
.help-grid h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.14em; color: var(--accent); }
.help-grid p { margin: 0 0 10px; color: var(--ink-2); font-size: 14px; line-height: 1.55; }
.help-grid b { color: var(--ink); font-weight: 500; }
kbd { font-family: var(--mono); font-size: 12px; background: rgba(255,255,255,0.08); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; }
.close {
  position: absolute; top: 14px; right: 16px;
  width: 34px; height: 34px; border-radius: 50%;
  background: rgba(255,255,255,0.06); border: 1px solid var(--line);
  cursor: pointer; font-size: 20px; line-height: 1; color: var(--ink-2);
}
.close:hover { color: var(--ink); background: rgba(255,255,255,0.12); }

.panel {
  position: fixed; z-index: 15;
  top: 16px; bottom: calc(96px + var(--safe-bottom)); right: 16px;
  width: min(400px, calc(100vw - 32px));
  background: var(--glass-strong);
  border: 1px solid var(--line); border-radius: 18px;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  padding: 18px 18px 8px;
  display: flex; flex-direction: column;
  transition: transform 0.4s cubic-bezier(.2,.8,.2,1), opacity 0.3s;
  box-shadow: 0 20px 60px rgba(0,0,0,0.45);
}
.panel.hidden { transform: translateX(30px); opacity: 0; pointer-events: none; visibility: hidden; }
.panel header { position: relative; }
.panel h2 { margin: 0; font-size: 20px; font-weight: 600; }
.panel .close { top: -4px; right: -2px; }
.panel-sub { font-size: 13px; line-height: 1.5; margin: 6px 0 14px; }
.sky-list { overflow: auto; display: flex; flex-direction: column; gap: 10px; padding-bottom: 12px; touch-action: pan-y; }
.sky-item {
  display: grid; grid-template-columns: 54px 1fr; gap: 12px; align-items: center;
  text-decoration: none; color: inherit;
  background: rgba(255,255,255,0.03); border: 1px solid rgba(160, 200, 255, 0.08);
  border-radius: 12px; padding: 10px;
  transition: background 0.2s, border-color 0.2s;
}
.sky-item:hover { background: rgba(124, 212, 255, 0.07); border-color: rgba(124, 212, 255, 0.25); }
.sky-item canvas { width: 54px; height: 54px; }
.sky-item h3 { margin: 0 0 3px; font-size: 14px; font-weight: 500; line-height: 1.3; }
.sky-item p { margin: 0; font-size: 11.5px; color: var(--muted); line-height: 1.45; }
.sky-empty { color: var(--muted); font-size: 13px; padding: 20px 4px; text-align: center; }

.playback {
  position: fixed; z-index: 6; left: 50%; top: 18px; transform: translateX(-50%);
  text-align: center; max-width: min(640px, calc(100vw - 32px));
  background: var(--glass); border: 1px solid var(--line); border-radius: 18px;
  padding: 14px 22px 16px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.playback.hidden { display: none; }
.playback .eyebrow::before { background: var(--accent-2); box-shadow: 0 0 8px var(--accent-2); }
.playback h2 { margin: 0 0 4px; font-size: 22px; font-weight: 600; }
.playback p { margin: 0; font-size: 12.5px; }
.pb-actions { display: flex; gap: 10px; justify-content: center; margin-top: 12px; flex-wrap: wrap; }
.pb-actions .primary { padding: 9px 18px; font-size: 14px; }
.pb-actions .ghost-btn { padding: 8px 16px; font-size: 14px; }
.hidden { display: none; }
body.playback-mode .hud-top-left .harmony, body.playback-mode #presence, body.playback-mode #btn-capture, body.playback-mode #btn-room { display: none; }

.toast {
  position: fixed; z-index: 30; left: 50%; top: 20px; transform: translate(-50%, -20px);
  background: var(--glass-strong); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 16px; font-size: 14px; max-width: calc(100vw - 32px);
  opacity: 0; transition: opacity 0.3s, transform 0.3s; pointer-events: none;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast a { color: var(--accent); }

.noscript { position: fixed; inset: 0; display: grid; place-items: center; color: var(--ink-2); }

/* Globe view: hide the ring, let the planet breathe. */
body.globe-mode .keys-hint { opacity: 0; }

@media (max-width: 860px) {
  .hud-top-left { top: 12px; left: 12px; gap: 8px; }
  .brand h1 { font-size: 16px; }
  .brand-mark { width: 26px; height: 26px; }
  .tagline { display: none; }
  .harmony { min-width: 0; padding: 7px 10px; }
  .harmony-key { font-size: 16px; }
  .harmony-key .muted { font-size: 12px; }
  .harmony-sun { font-size: 11px; }
  .hud-top-right { top: 12px; right: 12px; padding: 8px 10px; min-width: 0; }
  .big-number #online-count { font-size: 22px; }
  .big-number { font-size: 11px; }
  .stats { display: none; }
  .room-row { display: none; }
  .hud-bottom { grid-template-columns: 1fr; left: 10px; right: 10px; gap: 8px; bottom: calc(10px + var(--safe-bottom)); }
  .controls { justify-self: center; order: 3; }
  .ctl { padding: 6px 9px 4px; }
  .you { order: 1; justify-self: stretch; padding: 7px 10px; }
  .latency { display: none; }
  .hud-feed { display: none; }
  .keys-hint { display: none; }
  .panel { top: auto; bottom: calc(80px + var(--safe-bottom)); height: 60vh; right: 10px; width: calc(100vw - 20px); }
  .playback { top: 70px; padding: 10px 14px; }
  .playback h2 { font-size: 17px; }
}

.narration {
  position: fixed; left: 50%; top: 20px; transform: translate(-50%, -6px);
  z-index: 4; max-width: min(560px, calc(100vw - 560px)); text-align: center;
  opacity: 0; transition: opacity 1.4s ease, transform 1.4s ease; pointer-events: none;
}
.narration.show { opacity: 1; transform: translate(-50%, 0); }
.narration-text { display: block; font-size: 14.5px; line-height: 1.5; font-style: italic; color: var(--ink); text-shadow: 0 2px 12px rgba(0,0,0,0.9); }
.narration-by { display: block; margin-top: 4px; font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--muted); }
body.playback-mode .narration { display: none; }
@media (max-width: 860px) {
  .narration { top: auto; bottom: calc(172px + var(--safe-bottom)); max-width: calc(100vw - 32px); }
  .narration-text { font-size: 12.5px; }
}

#sky-stars { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; animation: twinkle 9s ease-in-out infinite; }
@keyframes twinkle { 50% { opacity: 0.7; } }
@media (prefers-reduced-motion: reduce) { #sky-stars { animation: none; } }
#ring:focus { outline: none; }
#ring:focus-visible { outline: none; }

/* Kiosk: a big-screen spectator view. */
body.kiosk .hud-bottom, body.kiosk .keys-hint, body.kiosk #intro { display: none; }
body.kiosk .hud-feed { bottom: 24px; }
.kiosk-sound {
  position: fixed; right: 20px; bottom: 20px; z-index: 8;
  background: var(--glass-strong); border: 1px solid var(--line); border-radius: 999px;
  padding: 10px 16px; color: var(--ink-2); cursor: pointer; font-size: 13px;
}
