:root {
  --bg: #0e1015;
  --panel: #161922;
  --panel-2: #1d2130;
  --line: #2a2f40;
  --text: #e8eaf1;
  --muted: #8b91a7;
  --accent: #8a4bff;
  --accent-2: #19b04a;
  --warn: #ff8a1f;
  --radius: 14px;
  font-family: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Inter, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
a { color: inherit; text-decoration: none; }
button {
  font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 14px; cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: white; }

/* ---- top nav ---------------------------------------------------------- */
.nav {
  position: fixed; top: 0; left: 0; right: 0; height: 52px; z-index: 20;
  display: flex; align-items: center; gap: 18px; padding: 0 18px;
  background: rgba(14, 16, 21, 0.72); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.nav .brand { font-weight: 800; letter-spacing: 0.4px; display: flex; align-items: center; gap: 10px; }
.nav .brand .dot { width: 16px; height: 16px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 14px var(--accent); }
.nav .tabs { display: flex; gap: 4px; }
.nav .tabs a { padding: 6px 12px; border-radius: 999px; color: var(--muted); }
.nav .tabs a.active, .nav .tabs a:hover { color: var(--text); background: var(--panel-2); }
.nav .spacer { flex: 1; }
.nav .status { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); font-size: 12px; }
.pill .led { width: 8px; height: 8px; border-radius: 50%; background: #555; }
.pill.ok .led { background: var(--accent-2); box-shadow: 0 0 8px var(--accent-2); }
.pill.bad .led { background: var(--warn); box-shadow: 0 0 8px var(--warn); }

/* ---- 3D world --------------------------------------------------------- */
#world { position: fixed; inset: 0; }
#world canvas { display: block; }
.bubble {
  max-width: 260px; padding: 10px 14px; border-radius: 16px; background: #fff; color: #14151a;
  font-size: 14px; line-height: 1.35; box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  transform: translateY(-16px); opacity: 0; transition: opacity 0.25s, transform 0.25s; pointer-events: none;
  position: relative;
}
.bubble.show { opacity: 1; transform: translateY(0); }
.bubble::after {
  content: ''; position: absolute; left: 50%; bottom: -8px; width: 16px; height: 16px; background: #fff;
  transform: translateX(-50%) rotate(45deg); border-radius: 3px;
}
.bubble .who { font-weight: 800; font-size: 11px; letter-spacing: 0.5px; text-transform: uppercase; margin-bottom: 2px; }
.nametag {
  font-size: 12px; font-weight: 800; letter-spacing: 0.4px; color: #fff; pointer-events: none;
  padding: 3px 9px; border-radius: 999px; background: rgba(10, 12, 18, 0.62); border: 1.5px solid var(--c, #fff);
  text-shadow: 0 1px 2px rgba(0,0,0,0.6); backdrop-filter: blur(4px); white-space: nowrap;
}
.letterbox {
  position: fixed; left: 0; right: 0; height: 0; background: #000; z-index: 15; pointer-events: none;
  transition: height 0.9s cubic-bezier(0.4, 0, 0.2, 1);
}
.letterbox.top { top: 0; } .letterbox.bottom { bottom: 0; }
body.cinematic .letterbox { height: 7vh; }
#cutflash { position: fixed; inset: 0; background: #000; opacity: 0; pointer-events: none; z-index: 14; transition: opacity 0.35s ease-out; }
#cutflash.flash { opacity: 1; transition: none; }
.beacon-label { font-size: 11px; color: #fff; background: rgba(0,0,0,0.5); padding: 3px 8px; border-radius: 999px; cursor: pointer; white-space: nowrap; pointer-events: auto; border: 1px solid rgba(255,255,255,0.15); }
.beacon-label:hover { background: var(--accent); }
body.cinematic .beacon-label { opacity: 0 !important; pointer-events: none; transition: opacity 0.4s; }

.side {
  position: fixed; top: 64px; right: 12px; bottom: 12px; width: 340px; z-index: 16;
  display: flex; flex-direction: column; gap: 10px;
}
.card { background: rgba(22, 25, 34, 0.85); backdrop-filter: blur(10px); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.card h3 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--muted); }
.transcript { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 10px; }
.transcript .line { display: flex; gap: 10px; align-items: flex-start; font-size: 13.5px; line-height: 1.35; }
.transcript .line img { width: 28px; height: 28px; flex: none; }
.transcript .line b { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; }
.transcript .sys { color: var(--muted); font-size: 12px; text-align: center; padding: 4px 0; }
.transcript .sys a { color: var(--accent); }
.residents { display: flex; flex-wrap: wrap; gap: 6px; }
.residents .res { display: flex; align-items: center; gap: 6px; padding: 3px 8px 3px 3px; border-radius: 999px; background: var(--panel-2); font-size: 12px; cursor: pointer; border: 1px solid transparent; }
.residents .res img { width: 22px; height: 22px; }
.residents .res.talking { border-color: var(--accent); box-shadow: 0 0 10px rgba(138, 75, 255, 0.4); }
.controls { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.controls label { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
#loading {
  position: fixed; inset: 0; z-index: 30; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: var(--bg); transition: opacity 0.5s;
}
#loading.hide { opacity: 0; pointer-events: none; }
#loading .bar { width: 260px; height: 6px; background: var(--panel-2); border-radius: 999px; overflow: hidden; }
#loading .bar i { display: block; height: 100%; width: 0%; background: var(--accent); transition: width 0.2s; }
#loading .orbs { display: flex; gap: 10px; }
#loading .orbs span { width: 26px; height: 26px; border-radius: 50%; animation: bob 1.4s ease-in-out infinite; }
#loading .orbs span:nth-child(2) { animation-delay: 0.15s; }
#loading .orbs span:nth-child(3) { animation-delay: 0.3s; }
#loading .orbs span:nth-child(4) { animation-delay: 0.45s; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }

/* ---- board ------------------------------------------------------------ */
.page { max-width: 1180px; margin: 0 auto; padding: 72px 18px 40px; }
.board { display: grid; grid-template-columns: 230px 1fr; gap: 18px; }
@media (max-width: 800px) { .board { grid-template-columns: 1fr; } }
.rooms { display: flex; flex-direction: column; gap: 6px; }
.rooms a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; color: var(--muted); }
.rooms a.active, .rooms a:hover { background: var(--panel); color: var(--text); }
.rooms a .cnt { margin-left: auto; font-size: 12px; color: var(--muted); }
.rooms a .glow { width: 8px; height: 8px; border-radius: 50%; background: #3a3f52; }
.rooms a .glow.live { background: var(--accent-2); box-shadow: 0 0 10px var(--accent-2); }
.rooms h4 { margin: 14px 12px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--muted); }
.residents-list { display: flex; flex-direction: column; gap: 4px; }
.residents-list .r { display: flex; align-items: center; gap: 10px; padding: 6px 12px; border-radius: 10px; font-size: 13px; }
.residents-list .r img { width: 26px; height: 26px; }
.residents-list .r small { color: var(--muted); margin-left: auto; }

.thread-list { display: flex; flex-direction: column; gap: 10px; }
.thread-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: grid; grid-template-columns: 1fr auto; gap: 8px 14px; cursor: pointer; transition: border-color 0.15s, transform 0.15s; }
.thread-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.thread-card.live { border-color: var(--accent-2); }
.thread-card h2 { margin: 0; font-size: 16px; }
.thread-card .meta { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12.5px; flex-wrap: wrap; }
.thread-card .meta .room { color: var(--text); background: var(--panel-2); padding: 2px 8px; border-radius: 999px; }
.thread-card .preview { grid-column: 1 / -1; color: #c8ccda; font-size: 14px; line-height: 1.4; display: flex; gap: 10px; align-items: flex-start; }
.thread-card .preview img { width: 30px; height: 30px; flex: none; }
.faces { display: flex; }
.faces img { width: 28px; height: 28px; margin-left: -8px; border-radius: 50%; border: 2px solid var(--panel); }
.faces img:first-child { margin-left: 0; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

.thread-view .back { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); margin-bottom: 12px; }
.thread-view h1 { margin: 0 0 6px; font-size: 24px; }
.thread-view .meta { color: var(--muted); font-size: 13px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
.posts { display: flex; flex-direction: column; gap: 12px; }
.post { display: grid; grid-template-columns: 44px 1fr; gap: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; animation: pop 0.3s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } }
.post img { width: 44px; height: 44px; }
.post .head { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); margin-bottom: 4px; flex-wrap: wrap; }
.post .head b { color: var(--text); font-size: 14px; }
.post .body { font-size: 15px; line-height: 1.45; }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; padding: 2px 7px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); }
.badge.key { color: #e6c86a; }
.post .reply-to { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.typing { display: flex; gap: 10px; align-items: center; color: var(--muted); font-size: 13px; padding: 8px 14px; }
.typing img { width: 28px; height: 28px; }
.typing i { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: bob 1s infinite; margin-right: 3px; }
.typing i:nth-child(2) { animation-delay: 0.15s; } .typing i:nth-child(3) { animation-delay: 0.3s; }

/* ---- town ------------------------------------------------------------- */
.town-wrap { display: grid; grid-template-columns: 1fr 300px; gap: 18px; }
@media (max-width: 900px) { .town-wrap { grid-template-columns: 1fr; } }
#townmap { width: 100%; aspect-ratio: 1 / 1; background: radial-gradient(circle at 50% 50%, #1a2a1f 0%, #0f1a14 60%, #0c1210 100%); border-radius: var(--radius); border: 1px solid var(--line); display: block; }
.legend { display: flex; flex-direction: column; gap: 10px; }
.legend .item { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.legend .sw { width: 14px; height: 14px; border-radius: 3px; }
.town-feed { display: flex; flex-direction: column; gap: 8px; max-height: 60vh; overflow: auto; }
.town-feed .line { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; line-height: 1.35; }
.town-feed .line img { width: 24px; height: 24px; flex: none; }
.town-feed .line b { color: var(--muted); font-weight: 600; }
