:root {
  --bg: oklch(0.09 0 0);
  --surface: oklch(0.14 0.008 140);
  --raised: oklch(0.19 0.012 140);
  --ink: oklch(0.94 0.008 140);
  --muted: oklch(0.7 0.012 140);
  --faint: oklch(0.42 0.012 140);
  --primary: oklch(0.75 0.09 140);
  --accent: oklch(0.74 0.13 55);
  --critical: oklch(0.65 0.18 25);
  --line: oklch(0.27 0.012 140);
  --focus: oklch(0.82 0.11 140);
  --detail: 328px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); }
body { overflow: hidden; }
button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, a:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.app-shell {
  display: grid;
  grid-template: 58px calc(100vh - 58px) / minmax(0, 1fr) var(--detail);
  min-height: 100vh;
}

.topbar {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 190px minmax(280px, 620px) 1fr;
  gap: 18px;
  align-items: center;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 680; letter-spacing: -0.02em; }
.brand-mark { width: 15px; height: 15px; border-radius: 50%; background: var(--primary); box-shadow: inset 0 0 0 4px oklch(0.18 0.02 140); }
.search { height: 36px; display: grid; grid-template-columns: 22px 1fr auto; align-items: center; gap: 6px; padding: 0 10px; background: var(--surface); border-radius: 10px; color: var(--muted); }
.search:focus-within { box-shadow: 0 0 0 1px var(--primary); }
.search input { min-width: 0; border: 0; outline: 0; color: var(--ink); background: transparent; }
.search input::placeholder { color: var(--muted); }
kbd { font: 11px ui-monospace, SFMono-Regular, Menlo, monospace; padding: 2px 6px; border: 1px solid var(--line); border-radius: 5px; color: var(--muted); }
.view-toggle { justify-self: end; display: flex; padding: 3px; background: var(--surface); border-radius: 10px; }
.view-toggle button { border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; color: var(--muted); cursor: pointer; }
.view-toggle button.active { color: var(--ink); background: var(--raised); }

.sidebar { padding: 18px 12px; border-right: 1px solid var(--line); overflow-y: auto; }
.sidebar-heading { display: flex; justify-content: space-between; align-items: center; padding: 0 6px 12px; font-size: 13px; font-weight: 650; }
.text-button { border: 0; background: transparent; color: var(--muted); font-size: 12px; cursor: pointer; }
.text-button:hover { color: var(--ink); }
.source-filters { display: flex; flex-direction: column; gap: 3px; }
.source-filter { display: grid; grid-template-columns: 10px 1fr auto; gap: 9px; align-items: center; padding: 8px 7px; border-radius: 8px; cursor: pointer; color: var(--muted); font-size: 13px; }
.source-filter:hover { background: var(--surface); color: var(--ink); }
.source-filter:has(input:checked) { color: var(--ink); }
.source-filter input { position: absolute; opacity: 0; pointer-events: none; }
.source-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--source-color); opacity: 0.35; }
.source-filter:has(input:checked) .source-dot { opacity: 1; box-shadow: 0 0 0 3px color-mix(in oklch, var(--source-color) 18%, transparent); }
.source-count { font: 11px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--faint); }
.collection-summary { margin: 26px 7px 0; display: grid; grid-template-columns: 1fr; gap: 2px; }
.collection-summary > span { font: 600 22px ui-monospace, SFMono-Regular, Menlo, monospace; }
.collection-summary small { color: var(--muted); }
.summary-rule { height: 1px; background: var(--line); margin: 12px 0; }

.workspace { grid-column: 1; min-width: 0; min-height: 0; position: relative; }
.graph-view, .list-view { width: 100%; height: 100%; position: relative; }
#graph { display: block; width: 100%; height: 100%; cursor: grab; touch-action: none; }
#graph.dragging { cursor: grabbing; }
.graph-help { position: absolute; left: 18px; bottom: 14px; color: var(--muted); font: 11px ui-monospace, SFMono-Regular, Menlo, monospace; pointer-events: none; }
.graph-stats { position: absolute; right: 18px; bottom: 14px; color: var(--muted); font: 11px ui-monospace, SFMono-Regular, Menlo, monospace; pointer-events: none; }
.graph-stats strong { color: var(--ink); font-size: 13px; }
.topic-legend { position: absolute; z-index: 2; left: 18px; top: 16px; display: flex; flex-wrap: wrap; gap: 6px; max-width: min(700px, 78%); }
.topic-chip { min-height: 30px; display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px; border: 0; border-radius: 999px; background: oklch(0.12 0 0 / 0.88); color: var(--muted); font: 10px ui-monospace, SFMono-Regular, Menlo, monospace; cursor: pointer; }
.topic-chip:hover { color: var(--ink); background: var(--raised); }
.topic-chip[aria-pressed="true"] { color: var(--ink); background: oklch(0.22 0.025 140); box-shadow: inset 0 0 0 1px var(--topic-color); }
.topic-chip i { width: 6px; height: 6px; border-radius: 50%; background: var(--topic-color); }
.touch-help { display: none; }
.empty-state { position: absolute; inset: 0; place-content: center; text-align: center; gap: 6px; color: var(--muted); }
.empty-state:not([hidden]) { display: grid; }
.empty-state strong { color: var(--ink); }

.list-view { overflow: auto; padding: 8px 18px 60px; }
.list-row { display: grid; grid-template-columns: 12px minmax(0, 1fr) auto; gap: 12px; align-items: center; width: 100%; padding: 13px 6px; border: 0; border-bottom: 1px solid var(--line); background: transparent; text-align: left; cursor: pointer; }
.list-row:hover { background: var(--surface); }
.list-row-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--source-color); }
.list-row-copy { min-width: 0; }
.list-row-title { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 14px; }
.list-row-url { display: block; margin-top: 4px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: var(--muted); font: 11px ui-monospace, SFMono-Regular, Menlo, monospace; }
.list-row-source { color: var(--faint); font: 11px ui-monospace, SFMono-Regular, Menlo, monospace; }

.detail-panel { grid-column: 2; border-left: 1px solid var(--line); padding: 18px; overflow-y: auto; background: var(--surface); }
.detail-empty { min-height: 100%; display: grid; place-content: center; justify-items: center; text-align: center; color: var(--muted); }
.detail-empty p { max-width: 28ch; line-height: 1.5; font-size: 13px; }
.detail-orbit { width: 40px; height: 40px; margin-bottom: 18px; border: 1px solid var(--faint); border-radius: 50%; position: relative; }
.detail-orbit::after { content: ""; position: absolute; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); top: -4px; left: 16px; }
.detail-kicker { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; color: var(--muted); font: 11px ui-monospace, SFMono-Regular, Menlo, monospace; }
.detail-kicker i { width: 8px; height: 8px; border-radius: 50%; background: var(--source-color); }
.detail-panel h1 { margin: 0; font-size: 20px; line-height: 1.25; letter-spacing: -0.025em; text-wrap: balance; }
.detail-close { float: right; width: 36px; height: 36px; margin: -8px -8px 8px 8px; border: 0; border-radius: 9px; background: var(--raised); cursor: pointer; }
.detail-url { display: block; margin: 10px 0 18px; overflow-wrap: anywhere; color: var(--primary); font: 11px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; }
.detail-section { padding: 16px 0; border-top: 1px solid var(--line); }
.detail-section h2 { margin: 0 0 9px; color: var(--muted); font-size: 12px; font-weight: 650; }
.detail-section p { margin: 0; white-space: pre-wrap; color: var(--ink); font-size: 13px; line-height: 1.55; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { padding: 4px 8px; border-radius: 999px; background: var(--raised); color: var(--muted); font: 11px ui-monospace, SFMono-Regular, Menlo, monospace; }
.open-link { display: inline-flex; justify-content: center; width: 100%; margin-top: 18px; padding: 10px 12px; border-radius: 10px; background: var(--primary); color: oklch(0.13 0.02 140); text-decoration: none; font-weight: 700; }

@media (max-width: 980px) {
  :root { --detail: 290px; }
}

@media (max-width: 760px) {
  body { overflow: auto; }
  .app-shell { grid-template: auto minmax(0, 1fr) / 1fr; min-height: 100dvh; height: 100dvh; }
  .topbar { grid-column: 1; grid-template-columns: 1fr auto; padding: 10px 12px; }
  .brand { display: none; }
  .search { min-width: 0; }
  .search { height: 44px; }
  .workspace { min-height: 0; }
  .topic-legend { left: 10px; right: 10px; top: 10px; max-width: none; flex-wrap: nowrap; overflow-x: auto; padding: 0 0 8px; scrollbar-width: none; touch-action: pan-x; }
  .topic-legend::-webkit-scrollbar { display: none; }
  .topic-chip { flex: 0 0 auto; min-height: 44px; padding-inline: 13px; font-size: 11px; }
  .graph-help { left: 12px; bottom: 12px; }
  .graph-stats { right: 12px; top: 68px; bottom: auto; padding: 4px 7px; border-radius: 7px; background: oklch(0.1 0 0 / 0.72); }
  .desktop-help { display: none; }
  .touch-help { display: inline; }
  .view-toggle button { min-height: 44px; min-width: 52px; }
  .detail-panel { display: none; position: fixed; z-index: 20; inset: auto 0 0; max-height: 58dvh; min-height: 220px; border-left: 0; border-top: 1px solid var(--primary); padding: 18px 18px calc(18px + env(safe-area-inset-bottom)); overflow-y: auto; }
  body.detail-open .detail-panel { display: block; }
  .detail-close { width: 44px; height: 44px; }
}

@media (pointer: coarse) {
  .desktop-help { display: none; }
  .touch-help { display: inline; }
  .topic-chip { min-height: 44px; padding-inline: 13px; }
  .view-toggle button { min-height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
