:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #f0f2f5;
  --text: #17191d;
  --muted: #6b7280;
  --border: #d9dde4;
  --accent: #5b4bd8;
  --accent-soft: #ebe9ff;
  --danger: #b42318;
  --shadow: 0 10px 30px rgba(20, 24, 40, .08);
}
* { box-sizing: border-box; }
html { font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
body { margin: 0; min-width: 320px; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 250px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; align-self: start; min-height: 100vh; padding: 18px 14px; background: #17191f; color: #f6f7fb; display: flex; flex-direction: column; gap: 18px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 10px; }
.brand-mark { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px; background: #fff; color: #17191f; font-weight: 800; }
.brand strong { display: block; font-size: 14px; }
.brand span { display: block; margin-top: 2px; color: #9ea4b2; font-size: 12px; }
.nav { display: grid; gap: 3px; }
.nav button { border: 0; border-radius: 8px; padding: 10px 11px; background: transparent; color: #c9ced8; text-align: left; }
.nav button:hover, .nav button.active { background: #272a32; color: #fff; }
.nav .nav-count { float: right; color: #858c9b; font-variant-numeric: tabular-nums; }
.sidebar-footer { margin-top: auto; display: grid; gap: 10px; }
.workspace { min-width: 0; }
.topbar { padding: 24px 28px 12px; display: flex; align-items: center; gap: 24px; justify-content: space-between; }
.project-heading h1 { margin: 0; font-size: 24px; }
.project-heading p { margin: 5px 0 0; color: var(--muted); }
.search-box { width: min(470px, 48vw); }
.search-box input { width: 100%; min-height: 42px; border: 1px solid var(--border); border-radius: 10px; padding: 0 14px; background: var(--panel); color: var(--text); }
.timebar { margin: 4px 28px 0; padding: 14px 16px; display: grid; grid-template-columns: minmax(210px, .7fr) minmax(260px, 2fr) auto; gap: 18px; align-items: center; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); }
.time-meta { min-width: 0; }
.time-meta strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.time-meta .muted { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12px; }
.time-actions { display: flex; gap: 6px; }
input[type="range"] { accent-color: var(--accent); width: 100%; }
.main { padding: 24px 28px 60px; }
.view-head { display: flex; justify-content: space-between; gap: 16px; align-items: end; margin-bottom: 18px; }
.view-head h2 { margin: 0; font-size: 22px; }
.view-head p { margin: 5px 0 0; color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.grid { display: grid; gap: 14px; }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card { border: 1px solid var(--border); border-radius: 12px; background: var(--panel); padding: 16px; min-width: 0; }
.card h3 { margin: 0 0 7px; font-size: 16px; }
.card p { margin: 0; color: var(--muted); line-height: 1.45; }
.metric { font-size: 30px; font-weight: 760; line-height: 1; margin-top: 8px; }
.metric-label { color: var(--muted); font-size: 13px; }
.split { display: grid; grid-template-columns: minmax(280px, .8fr) minmax(0, 1.5fr); gap: 16px; align-items: start; }
.list-panel { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--panel); }
.list-toolbar { padding: 10px; border-bottom: 1px solid var(--border); background: var(--panel-2); }
.list-toolbar input, .list-toolbar select { width: 100%; min-height: 38px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel); color: var(--text); padding: 0 10px; }
.entity-list { max-height: 68vh; overflow: auto; }
.entity-row { display: block; width: 100%; border: 0; border-bottom: 1px solid var(--border); background: var(--panel); text-align: left; padding: 12px 14px; color: var(--text); }
.entity-row:last-child { border-bottom: 0; }
.entity-row:hover, .entity-row.active { background: var(--accent-soft); }
.entity-row strong { display: block; }
.entity-row span { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.detail { min-height: 340px; }
.detail h2 { margin: 3px 0 6px; }
.detail .id { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); font-size: 12px; }
.detail-section { margin-top: 20px; }
.detail-section h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.kv { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 8px 14px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.kv:last-child { border-bottom: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--border); border-radius: 999px; padding: 4px 8px; background: var(--panel-2); font-size: 12px; }
.chip.active { background: var(--accent-soft); border-color: #c9c3ff; }
.badge { display: inline-block; width: fit-content; border-radius: 999px; padding: 4px 8px; font-size: 11px; background: rgba(255,255,255,.1); color: #d9dde7; }
.badge.local { background: #443d24; color: #ffe69c; }
.badge.github { background: #173b2c; color: #a7e8c5; }
.button, .icon-button { border: 1px solid var(--border); border-radius: 8px; min-height: 38px; background: var(--panel); color: var(--text); padding: 0 12px; }
.button.primary { border-color: var(--accent); background: var(--accent); color: white; }
.sidebar .button { border-color: #3a3e48; background: #242730; color: #fff; }
.sidebar .button.primary { background: #6b5cff; }
.icon-button { min-width: 38px; padding: 0 10px; }
.timeline { position: relative; display: grid; gap: 10px; }
.timeline::before { content: ""; position: absolute; left: 20px; top: 16px; bottom: 16px; width: 2px; background: var(--border); }
.event { position: relative; margin-left: 42px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel); padding: 12px 14px; }
.event::before { content: ""; position: absolute; left: -29px; top: 18px; width: 11px; height: 11px; border-radius: 50%; border: 3px solid var(--bg); background: #adb3bf; }
.event.past::before { background: var(--accent); }
.event.current { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.event.current::before { background: var(--accent); width: 14px; height: 14px; left: -31px; top: 16px; }
.event button { all: unset; cursor: pointer; display: block; width: 100%; }
.event-head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.event-head strong { font-size: 14px; }
.event-head span { color: var(--muted); font: 11px ui-monospace, monospace; }
.event p { margin: 5px 0 0; color: var(--muted); }
.story-act { margin: 28px 0 12px; display: flex; align-items: center; gap: 10px; }
.story-act::after { content: ""; height: 1px; flex: 1; background: var(--border); }
.story-scene { display: grid; grid-template-columns: 72px minmax(0,1fr); gap: 14px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.story-scene .order { color: var(--muted); font: 12px ui-monospace, monospace; }
.story-scene h3 { margin: 0 0 4px; }
.story-scene p { margin: 0; color: var(--muted); }
.dialogue-line { padding: 9px 0; border-bottom: 1px solid var(--border); }
.dialogue-line:last-child { border-bottom: 0; }
.dialogue-line strong { display: inline-block; min-width: 110px; font-size: 13px; }
.dialogue-line.inactive { opacity: .42; }
.graph-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); }
.graph { width: 100%; min-width: 900px; height: 560px; display: block; }
.graph line { stroke: #b8bec9; stroke-width: 1.5; }
.graph line.inactive { opacity: .18; }
.graph text { fill: var(--text); font-size: 11px; pointer-events: none; }
.graph .node circle { fill: var(--panel-2); stroke: #8f96a3; stroke-width: 1.5; }
.graph .node.active circle { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 2; }
.graph .node { cursor: pointer; }
.graph-label { font-size: 10px; fill: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.search-results { display: grid; gap: 10px; }
.search-result { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; background: var(--panel); }
.search-result button { all: unset; cursor: pointer; width: 100%; }
.search-result .type { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.search-result strong { display: block; margin: 3px 0; }
.search-result p { margin: 0; color: var(--muted); }
.editor-dialog { width: min(860px, calc(100vw - 24px)); max-height: 90vh; border: 0; border-radius: 14px; padding: 0; background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
.editor-dialog::backdrop { background: rgba(10,12,16,.55); }
.editor-card { display: grid; gap: 12px; padding: 18px; }
.editor-head { display: flex; justify-content: space-between; align-items: start; gap: 12px; }
.editor-head h2 { margin: 3px 0 0; }
.editor-card textarea { width: 100%; min-height: 54vh; resize: vertical; border: 1px solid var(--border); border-radius: 10px; padding: 12px; background: #111318; color: #eef0f5; font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; tab-size: 2; }
.editor-actions { display: flex; justify-content: flex-end; gap: 8px; }
.error { min-height: 18px; color: var(--danger); font-size: 13px; }
.toast { position: fixed; right: 20px; bottom: 20px; max-width: min(420px, calc(100vw - 40px)); border-radius: 10px; padding: 11px 14px; background: #17191f; color: #fff; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translateY(8px); transition: .15s ease; }
.toast.show { opacity: 1; transform: translateY(0); }
.muted { color: var(--muted); }
.eyebrow { display: block; color: var(--muted); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; }
.empty { padding: 28px; text-align: center; color: var(--muted); border: 1px dashed var(--border); border-radius: 10px; }
pre.data { overflow: auto; max-height: 60vh; margin: 0; padding: 14px; border-radius: 10px; background: #111318; color: #eef0f5; font: 12px/1.5 ui-monospace, monospace; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
@media (max-width: 980px) {
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split { grid-template-columns: 1fr; }
  .entity-list { max-height: 320px; }
  .timebar { grid-template-columns: 1fr auto; }
  .timebar input[type="range"] { grid-column: 1 / -1; grid-row: 2; }
}
@media (max-width: 720px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; min-height: auto; padding: 12px; }
  .brand { padding-bottom: 0; }
  .nav { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
  .nav button { white-space: nowrap; background: #22252c; }
  .nav .nav-count { display: none; }
  .sidebar-footer { margin: 0; grid-template-columns: 1fr auto; align-items: center; }
  .topbar { padding: 18px 16px 10px; display: grid; }
  .search-box { width: 100%; }
  .timebar { margin: 0 16px; }
  .main { padding: 18px 16px 50px; }
  .grid.cols-4, .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr; }
  .view-head { align-items: start; flex-direction: column; }
  .story-scene { grid-template-columns: 1fr; gap: 4px; }
  .kv { grid-template-columns: 1fr; gap: 3px; }
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1115; --panel: #17191f; --panel-2: #20232a; --text: #f1f3f7; --muted: #9da4b2; --border: #30343d; --accent: #8b7cff; --accent-soft: #2b2750; --shadow: 0 12px 36px rgba(0,0,0,.35); }
  .sidebar { background: #090a0d; }
  .brand-mark { background: #f1f3f7; }
}
