:root {
  --bg: #0b0d12;
  --panel: #12151c;
  --panel-2: #181c26;
  --line: #232837;
  --text: #e6e9f2;
  --muted: #8b93a7;
  --accent: #7aa2ff;
  --radius: 10px;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--text); overflow: hidden; }
body {
  display: grid;
  grid-template-rows: 52px 1fr;
  grid-template-columns: 310px 1fr;
  grid-template-areas: "header header" "sidebar stage";
  font-size: 14px;
  line-height: 1.4;
}
body.no-sidebar { grid-template-columns: 0 1fr; }
body.no-sidebar #sidebar { display: none; }
a { color: var(--accent); text-decoration: none; cursor: pointer; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.pad { padding: 16px; }

/* ---------- header */
#header {
  grid-area: header;
  display: flex; align-items: center; gap: 14px;
  padding: 0 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  z-index: 5;
}
.brand { font-weight: 700; font-size: 17px; letter-spacing: -0.01em; white-space: nowrap; }
.brand span { color: var(--accent); }
.icon { background: none; border: 1px solid var(--line); border-radius: 8px; width: 32px; height: 32px; cursor: pointer; }
.icon:hover { background: var(--panel-2); }
.search-wrap { flex: 0 1 380px; }
#search {
  width: 100%; height: 34px; padding: 0 12px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; font: inherit; outline: none;
}
#search:focus { border-color: var(--accent); }
.color-by { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.color-by select { background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 8px; height: 30px; padding: 0 6px; font: inherit; }
.meta { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.header-link { color: var(--muted); font-size: 12px; padding: 5px 10px; border: 1px solid var(--line); border-radius: 8px; white-space: nowrap; }
.header-link:hover { color: var(--text); background: var(--panel-2); text-decoration: none; }

/* ---------- sidebar */
#sidebar { grid-area: sidebar; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; z-index: 4; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tab { flex: 1; background: none; border: 0; padding: 11px 0; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tabpane { display: none; overflow-y: auto; flex: 1; min-height: 0; }
.tabpane.active { display: block; }

.outline { padding: 6px 0 24px; }
.o-region, .o-topic { display: flex; align-items: center; gap: 8px; padding: 6px 12px; cursor: pointer; position: relative; }
.o-region { font-weight: 600; margin-top: 2px; }
.o-region:hover, .o-topic:hover { background: var(--panel-2); }
.o-region.selected, .o-topic.selected { background: #1d2332; }
.o-topic { padding-left: 38px; font-size: 13px; color: #cdd3e3; overflow: hidden; }
.o-topic .bar { position: absolute; left: 0; top: 0; bottom: 0; z-index: 0; pointer-events: none; }
.o-topic > *:not(.bar) { position: relative; z-index: 1; }
.o-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.o-n { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; font-weight: 400; }
.chev { background: none; border: 0; color: var(--muted); width: 16px; padding: 0; cursor: pointer; font-size: 16px; transition: transform .12s; }
.chev.open { transform: rotate(90deg); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; }

/* ---------- stage */
#stage { grid-area: stage; position: relative; overflow: hidden; min-width: 0; min-height: 0; }
#gl, #overlay { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#overlay { cursor: grab; touch-action: none; }
#status { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); pointer-events: none; }
#status.error { color: #ff8f8f; padding: 40px; text-align: center; }

#tooltip {
  display: none; position: absolute; z-index: 6; max-width: 340px; pointer-events: none;
  background: rgba(18, 21, 28, 0.96); border: 1px solid #2c3347; border-radius: var(--radius);
  padding: 9px 11px; box-shadow: 0 8px 28px rgba(0,0,0,.45); font-size: 13px;
}
.tip-head { margin-bottom: 3px; }
.tip-text { color: #d6dbea; white-space: pre-wrap; word-break: break-word; }
.tip-foot { margin-top: 5px; font-size: 11.5px; }

.zoom-controls { position: absolute; right: 14px; bottom: 134px; display: flex; flex-direction: column; gap: 6px; z-index: 3; transition: right .2s; }
.zoom-controls button { width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line); background: rgba(18,21,28,.9); cursor: pointer; font-size: 17px; }
.zoom-controls button:hover { background: var(--panel-2); }

/* ---------- timeline */
#timeline-wrap {
  position: absolute; left: 0; right: 0; bottom: 0; height: 120px; z-index: 3;
  background: linear-gradient(to top, rgba(11,13,18,.96) 70%, rgba(11,13,18,0));
  padding: 0 0 0 0;
}
#timeline { position: absolute; left: 40px; right: 0; bottom: 0; top: 14px; }
.timeline-canvas { width: 100%; height: 100%; display: block; cursor: crosshair; touch-action: none; }
#play { position: absolute; left: 10px; bottom: 34px; width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); cursor: pointer; font-size: 11px; z-index: 2; }
#play:hover { background: var(--panel-2); }
#range-info { position: absolute; left: 52px; top: 0; font-size: 11.5px; color: var(--muted); }

/* ---------- drawer */
#drawer {
  position: absolute; top: 0; right: 0; bottom: 0; width: 410px; max-width: 92vw; z-index: 5;
  background: var(--panel); border-left: 1px solid var(--line);
  transform: translateX(102%); transition: transform .2s ease;
  overflow-y: auto; box-shadow: -10px 0 30px rgba(0,0,0,.35);
}
#drawer.open { transform: none; }
.drawer-body { padding: 16px 18px 40px; }
.close { position: absolute; top: 8px; right: 10px; width: 30px; height: 30px; background: none; border: 0; color: var(--muted); font-size: 22px; cursor: pointer; border-radius: 8px; }
.close:hover { background: var(--panel-2); color: var(--text); }
.crumbs { display: flex; flex-wrap: wrap; gap: 6px; font-size: 12px; color: var(--muted); margin-bottom: 8px; padding-right: 30px; text-transform: uppercase; letter-spacing: .05em; }
.crumbs .sep { opacity: .5; }
h2 { margin: 2px 0 6px; font-size: 21px; line-height: 1.2; letter-spacing: -0.01em; display: flex; align-items: center; gap: 10px; }
h2 .dot { width: 13px; height: 13px; }
h2.thread-h { font-size: 16px; font-weight: 600; display: block; }
h3 { margin: 22px 0 8px; font-size: 11.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.summary { color: #c9cfe0; margin: 4px 0 12px; }
.kw { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 12px; }
.kw-chip { background: var(--panel-2); border: 1px solid var(--line); color: #b8c0d6; padding: 1px 8px; border-radius: 99px; font-size: 12px; }
.stats { display: flex; gap: 8px; margin: 12px 0; }
.stat { flex: 1; background: var(--panel-2); border-radius: 8px; padding: 8px 10px; display: flex; flex-direction: column; min-width: 0; }
.stat b { font-size: 17px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11.5px; color: var(--muted); }
.stats.big { flex-wrap: wrap; padding: 0 14px; }
.stats.big .stat { flex: 1 1 28%; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--panel-2); border: 1px solid var(--line); padding: 2px 9px; border-radius: 99px; font-size: 12.5px; color: var(--text); }
.chip:hover { border-color: var(--accent); text-decoration: none; }
.chip-wrap small { color: var(--muted); margin-left: 4px; font-size: 11px; }
.btn { margin-top: 14px; width: 100%; padding: 9px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.btn:hover { border-color: var(--accent); }

.topics { display: flex; flex-direction: column; }
.topic-row { display: flex; gap: 10px; align-items: flex-start; padding: 7px 8px; margin: 0 -8px; border-radius: 8px; cursor: pointer; }
.topic-row:hover { background: var(--panel-2); }
.topic-row .dot { margin-top: 5px; }
.topic-row > div { flex: 1; min-width: 0; }
.topic-row .o-n { margin-left: auto; }

.posts { display: flex; flex-direction: column; gap: 2px; }
.post { padding: 8px 10px; margin: 0 -10px; border-radius: 8px; cursor: pointer; }
.post:hover { background: var(--panel-2); }
.post-head { display: flex; align-items: center; gap: 7px; font-size: 12.5px; flex-wrap: wrap; }
.post-head .dot { width: 8px; height: 8px; }
.post-head .eng { margin-left: auto; color: var(--muted); font-size: 12px; white-space: pre; }
.post-text { margin-top: 3px; color: #cfd5e6; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; word-break: break-word; white-space: pre-wrap; }
.post-text.full { -webkit-line-clamp: unset; display: block; }
.big-text { font-size: 15.5px; margin: 10px 0; white-space: pre-wrap; word-break: break-word; }
.who { margin-top: 2px; }
.embed { background: var(--panel-2); border-radius: 8px; padding: 9px 11px; margin: 8px 0; font-size: 13px; }
.threads { display: flex; flex-direction: column; gap: 2px; }
.thread { padding: 8px 10px; margin: 0 -10px; border-radius: 8px; cursor: pointer; }
.thread:hover { background: var(--panel-2); }
.thread-title { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- activity */
.activity { padding-bottom: 30px; }
.live { display: flex; align-items: center; gap: 8px; padding: 12px 14px; font-size: 12px; color: var(--muted); }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: #4ade80; box-shadow: 0 0 0 0 rgba(74,222,128,.6); animation: pulse 2s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 7px rgba(74,222,128,0); } 100% { box-shadow: 0 0 0 0 rgba(74,222,128,0); } }
.activity section { padding: 0 14px; }
.series { margin-bottom: 10px; }
.series-head { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 2px; }
.spark { display: block; width: 100%; }
.poster { display: flex; justify-content: space-between; gap: 10px; padding: 7px 8px; margin: 0 -8px; border-radius: 8px; cursor: pointer; }
.poster:hover { background: var(--panel-2); }
.coll { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.coll td { padding: 3px 0; border-bottom: 1px solid var(--line); }

@media (max-width: 800px) {
  body { grid-template-columns: 0 1fr; }
  #sidebar { display: none; }
  body:not(.no-sidebar) #sidebar { display: flex; position: fixed; top: 52px; bottom: 0; left: 0; width: 82vw; z-index: 20; }
  .meta, .color-by, .header-link { display: none; }
  #drawer { width: 100%; max-width: 100%; top: 38%; border-left: 0; border-top: 1px solid var(--line); }
  .zoom-controls { display: none; }
}
