:root {
  color-scheme: dark;
  --bg: #0f1014;
  --bg-soft: #15171d;
  --surface: #1a1c23;
  --surface-2: #20232b;
  --border: #2d313b;
  --text: #f0f1f5;
  --muted: #999faa;
  --accent: #b4a1ff;
  --accent-strong: #8c72ff;
  --good: #82d8aa;
  --warn: #e7c16d;
  --danger: #ff858f;
  --radius: 16px;
  --shadow: 0 16px 42px rgba(0,0,0,.28);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input, textarea, select { font: inherit; }
button, a, input, textarea, select { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
a { color: inherit; text-decoration: none; }
.app-shell { min-height: 100dvh; display: grid; grid-template-columns: 250px minmax(0,1fr); }
.sidebar { position: sticky; top: 0; height: 100dvh; border-right: 1px solid var(--border); padding: 22px 16px; display: flex; flex-direction: column; gap: 20px; background: #111218; z-index: 20; }
.brand-row { display: flex; align-items: center; gap: 10px; min-height: 48px; }
.brand { font-weight: 760; font-size: 1.25rem; letter-spacing: -.02em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; }
.eyebrow { color: var(--muted); font-size: .7rem; letter-spacing: .16em; font-weight: 700; }
.primary-nav { display: flex; flex-direction: column; gap: 4px; }
.primary-nav a { padding: 10px 12px; border-radius: 10px; color: #c7cad2; font-size: .94rem; }
.primary-nav a:hover, .primary-nav a.active { background: var(--surface-2); color: white; }
.sidebar-footer { margin-top: auto; display: grid; gap: 12px; }
.main-shell { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 15; min-height: 70px; display: flex; align-items: center; gap: 12px; padding: 12px 22px; background: rgba(15,16,20,.88); backdrop-filter: blur(14px); border-bottom: 1px solid var(--border); }
.search-wrap { position: relative; display: flex; align-items: center; gap: 8px; flex: 1; max-width: 840px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 0 12px; }
.search-wrap input { flex: 1; min-width: 0; background: transparent; border: 0; color: var(--text); height: 42px; outline: 0; }
.search-popover { position: absolute; top: calc(100% + 8px); left: 0; right: 0; border: 1px solid var(--border); background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); max-height: 420px; overflow: auto; padding: 6px; }
.search-result { display: flex; justify-content: space-between; gap: 12px; padding: 10px 12px; border-radius: 10px; cursor: pointer; }
.search-result:hover { background: var(--surface-2); }
.main-content { width: min(1500px, 100%); margin: 0 auto; padding: 26px; }
.page-header { display: flex; justify-content: space-between; gap: 18px; align-items: flex-start; margin-bottom: 22px; }
.page-header h1 { margin: 3px 0 6px; font-size: clamp(1.7rem,3vw,2.4rem); letter-spacing: -.04em; }
.page-header p { margin: 0; color: var(--muted); max-width: 760px; line-height: 1.55; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.button { border: 1px solid var(--border); background: var(--surface-2); color: var(--text); padding: 9px 13px; border-radius: 10px; cursor: pointer; font-weight: 650; }
.button:hover { filter: brightness(1.08); }
.button.primary { background: var(--accent-strong); border-color: transparent; color: white; }
.button.ghost { background: transparent; }
.button.danger { color: var(--danger); }
.button.full { width: 100%; }
.icon-btn { width: 38px; height: 38px; display: inline-grid; place-items: center; border: 0; background: transparent; color: var(--text); border-radius: 9px; cursor: pointer; font-size: 1.25rem; }
.icon-btn:hover { background: var(--surface-2); }
.grid { display: grid; gap: 16px; }
.grid.stats { grid-template-columns: repeat(4, minmax(0,1fr)); }
.grid.two { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0,1fr)); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; min-width: 0; }
.card h2, .card h3 { margin: 0 0 10px; letter-spacing: -.02em; }
.card h2 { font-size: 1.05rem; }
.card h3 { font-size: 1rem; }
.stat-value { font-size: 2rem; font-weight: 760; letter-spacing: -.04em; margin-top: 8px; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.section { margin-top: 18px; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.section-title h2 { margin: 0; font-size: 1.02rem; }
.list { display: grid; gap: 8px; }
.list-item { border: 1px solid var(--border); background: var(--bg-soft); border-radius: 12px; padding: 12px 13px; cursor: pointer; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.list-item:hover { border-color: #434856; background: #191b22; }
.list-title { font-weight: 700; }
.list-meta { color: var(--muted); font-size: .8rem; margin-top: 3px; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 4px 8px; border-radius: 999px; background: #272a33; color: #cfd2da; font-size: .74rem; border: 1px solid #343844; }
.badge.canon { color: var(--good); }
.badge.concept, .badge.provisional { color: var(--warn); }
.badge.contradicted { color: var(--danger); }
.entry-layout { display: grid; grid-template-columns: minmax(280px, 410px) minmax(0,1fr); gap: 16px; align-items: start; }
.list-panel { position: sticky; top: 88px; max-height: calc(100dvh - 112px); overflow: auto; }
.detail-panel { min-height: 380px; }
.filter-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.filter-row input, .filter-row select { min-width: 140px; }
input, textarea, select { width: 100%; border: 1px solid var(--border); background: #12141a; color: var(--text); border-radius: 9px; padding: 10px 11px; }
textarea { resize: vertical; min-height: 92px; line-height: 1.45; }
label { display: grid; gap: 6px; color: #d8dbe3; font-size: .88rem; font-weight: 650; }
.form-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.form-section { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 16px; }
.form-section h3 { margin: 0 0 12px; font-size: .95rem; }
.detail-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; border-bottom: 1px solid var(--border); padding-bottom: 14px; }
.detail-head h2 { font-size: 1.8rem; margin: 4px 0 8px; }
.detail-section { padding-top: 18px; }
.detail-section h3 { margin: 0 0 8px; font-size: 1rem; }
.prose { white-space: pre-wrap; color: #d2d5dc; line-height: 1.65; }
.knowledge-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px; }
.knowledge-card { padding: 14px; border: 1px solid var(--border); border-radius: 12px; background: #15171d; }
.knowledge-card h4 { margin: 0 0 8px; font-size: .86rem; color: var(--accent); }
.empty-state { text-align: center; padding: 48px 18px; color: var(--muted); }
.empty-state strong { display: block; color: var(--text); font-size: 1.05rem; margin-bottom: 6px; }
.editor-dialog, .small-dialog { border: 1px solid var(--border); border-radius: 18px; padding: 0; color: var(--text); background: var(--surface); box-shadow: var(--shadow); width: min(900px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); }
.small-dialog { width: min(560px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(5,6,8,.72); backdrop-filter: blur(2px); }
.editor-dialog form, .small-dialog form { display: flex; flex-direction: column; max-height: calc(100dvh - 32px); }
.dialog-header, .dialog-footer { flex: 0 0 auto; display: flex; align-items: center; gap: 12px; padding: 15px 18px; border-color: var(--border); }
.dialog-header { justify-content: space-between; border-bottom: 1px solid var(--border); }
.dialog-header h2 { margin: 2px 0 0; font-size: 1.2rem; }
.dialog-footer { border-top: 1px solid var(--border); }
.dialog-body { overflow: auto; padding: 18px; }
.dialog-body.compact { display: grid; gap: 14px; }
.spacer { flex: 1; }
.hidden { display: none !important; }
.toast-region { position: fixed; right: 18px; bottom: 18px; z-index: 99; display: grid; gap: 8px; }
.toast { background: #252933; border: 1px solid #3a3f4c; border-radius: 11px; padding: 11px 13px; box-shadow: var(--shadow); max-width: 340px; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill,minmax(180px,1fr)); gap: 14px; }
.media-card { border: 1px solid var(--border); border-radius: 14px; overflow: hidden; background: var(--surface); }
.media-card img { display: block; width: 100%; height: 160px; object-fit: cover; background: #0b0c10; }
.media-card-body { padding: 10px; }
.timeline { display: grid; gap: 12px; border-left: 2px solid var(--border); padding-left: 18px; margin-left: 6px; }
.timeline-item { position: relative; }
.timeline-item::before { content: ''; position: absolute; left: -25px; top: 10px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent-strong); }
.quick-capture { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 8px; }
.code-note { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .82rem; background: #111218; border: 1px solid var(--border); padding: 12px; border-radius: 10px; overflow: auto; }
.mobile-only { display: none; }
@media (max-width: 980px) {
  .grid.stats { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .grid.three { grid-template-columns: 1fr; }
  .entry-layout { grid-template-columns: 1fr; }
  .list-panel { position: static; max-height: none; }
}
@media (max-width: 760px) {
  .mobile-only { display: inline-grid; }
  .app-shell { display: block; }
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-105%); transition: transform .2s ease; width: min(84vw, 300px); box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .topbar { padding: 10px 12px; }
  .main-content { padding: 18px 13px 32px; }
  .page-header { flex-direction: column; }
  .page-header .actions { width: 100%; }
  .page-header .actions .button { flex: 1; }
  .grid.stats, .grid.two, .knowledge-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: auto; }
  .editor-dialog, .small-dialog { width: 100vw; max-width: none; height: 100dvh; max-height: 100dvh; border-radius: 0; border: 0; }
  .editor-dialog form, .small-dialog form { max-height: 100dvh; height: 100dvh; }
  .dialog-footer { padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  .quick-capture { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}

/* V1 roadmap-complete working views */
.sidebar { overflow-y: auto; }
.inline-link { border: 0; background: transparent; color: var(--accent); padding: 0; font: inherit; cursor: pointer; text-align: left; }
.inline-link:hover { text-decoration: underline; }
.breadcrumbs { margin-bottom: 12px; color: var(--muted); font-size: .82rem; display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.archive-banner { border: 1px solid #5b4031; background: #271d18; color: #efc6a8; border-radius: 12px; padding: 11px 13px; margin-bottom: 14px; }
.archived-item { opacity: .82; }
.trilogy-overview { border-color: #414761; }
.tracking-list { display: grid; gap: 8px; }
.tracking-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; border: 1px solid var(--border); background: var(--bg-soft); border-radius: 11px; padding: 11px 12px; }
.era-band { margin: 16px 0 28px; }
.era-band:first-child { margin-top: 4px; }
.era-band-title { font-size: .75rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); margin-bottom: 10px; }
.reveal-board { display: grid; gap: 10px; position: relative; }
.reveal-node { position: relative; border: 1px solid var(--border); border-radius: 13px; padding: 13px 14px 13px 18px; background: #15171d; display: grid; gap: 4px; }
.reveal-node::before { content: ''; position: absolute; left: 0; top: 12px; bottom: 12px; width: 3px; border-radius: 3px; background: var(--accent-strong); }
.reveal-kind { color: var(--accent); font-size: .72rem; text-transform: uppercase; letter-spacing: .09em; font-weight: 750; }
.map-layout { display: grid; grid-template-columns: minmax(250px,340px) minmax(0,1fr); gap: 16px; align-items: start; }
.map-workspace { min-height: 520px; }
.version-strip { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 12px; }
.version-chip { border: 1px solid var(--border); background: var(--bg-soft); color: var(--text); border-radius: 10px; padding: 8px 10px; min-width: 130px; cursor: pointer; text-align: left; }
.version-chip span { display: block; font-size: .72rem; color: var(--muted); margin-top: 3px; }
.version-chip.active { border-color: var(--accent-strong); background: #242734; }
.map-toolbar { display: grid; grid-template-columns: minmax(180px,300px) auto minmax(180px,1fr); gap: 10px; align-items: end; margin: 8px 0 12px; }
.map-stage { position: relative; overflow: hidden; border: 1px solid var(--border); border-radius: 14px; background: #0a0b0e; min-height: 240px; cursor: crosshair; }
.map-stage > img { display: block; width: 100%; height: auto; max-height: 72vh; object-fit: contain; }
.map-marker { position: absolute; transform: translate(-50%,-100%); background: transparent; border: 0; color: white; cursor: pointer; display: grid; justify-items: center; gap: 2px; padding: 0; z-index: 3; }
.map-marker span { width: 14px; height: 14px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); background: var(--accent-strong); border: 2px solid white; box-shadow: 0 2px 8px #0009; }
.map-marker b { transform: translateY(4px); background: #0c0d11dd; border: 1px solid #ffffff22; border-radius: 6px; padding: 2px 5px; font-size: .68rem; white-space: nowrap; max-width: 150px; overflow: hidden; text-overflow: ellipsis; }
.graph-scroll { overflow: auto; border: 1px solid var(--border); border-radius: 12px; background: #111319; min-height: 240px; }
.graph-svg { display: block; width: 100%; min-width: 640px; min-height: 320px; }
.graph-edge { stroke: #555d70; stroke-width: 1.5; }
.graph-edge-label { fill: #8f96a8; font-size: 10px; text-anchor: middle; paint-order: stroke; stroke: #111319; stroke-width: 4px; }
.graph-node { fill: #262a35; stroke: #666f86; stroke-width: 1.5; }
.graph-node-root { fill: #32384c; stroke: var(--accent); stroke-width: 2; }
.graph-label { fill: #f2f4f8; font-size: 11px; text-anchor: middle; dominant-baseline: middle; pointer-events: none; }
.graph-click { cursor: pointer; }
.graph-click:hover .graph-node, .graph-click:hover .graph-node-root { stroke: white; }
.graph-family-node { fill: #252933; stroke: #626b80; stroke-width: 1.5; }
.graph-family-root { fill: #32384c; stroke: var(--accent); stroke-width: 2; }
.marker-list { margin-top: 14px; }
@media (max-width: 980px) {
  .map-layout { grid-template-columns: 1fr; }
  .map-toolbar { grid-template-columns: 1fr; align-items: stretch; }
}
@media (max-width: 760px) {
  .graph-svg { min-width: 560px; }
  .map-marker b { display: none; }
}

/* V1.1 reliability/accessibility and visual atlas */
.entry-list-button { width: 100%; color: inherit; text-align: left; font: inherit; }
.entry-list-button > span:first-child { display: grid; min-width: 0; }
.search-result { width: 100%; border: 0; background: transparent; color: inherit; text-align: left; font: inherit; align-items: flex-start; }
.search-result > span:first-child { display: grid; min-width: 0; }
.field-help { display: block; font-weight: 400; line-height: 1.4; }

.atlas-panel { max-height: calc(100dvh - 112px); overflow: auto; }
.atlas-list, .atlas-grid { display: grid; gap: 8px; }
.atlas-grid { grid-template-columns: repeat(auto-fill,minmax(220px,1fr)); }
.atlas-map-item { width: 100%; border: 1px solid var(--border); background: var(--bg-soft); color: inherit; border-radius: 12px; padding: 8px; display: grid; grid-template-columns: 76px minmax(0,1fr); gap: 10px; align-items: center; text-align: left; cursor: pointer; }
.atlas-map-item:hover, .atlas-map-item.active { border-color: var(--accent-strong); background: #1b1e27; }
.atlas-map-thumb { height: 54px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; display: grid; place-items: center; background: #0b0c10; }
.atlas-map-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.map-thumb-empty { color: var(--muted); font-size: 1.4rem; }
.atlas-map-copy { min-width: 0; display: grid; gap: 4px; }
.atlas-map-copy strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.atlas-map-copy > span { color: var(--muted); font-size: .76rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.atlas-breadcrumbs { margin-top: -2px; }
.version-chip-wrap { display: inline-grid; grid-template-columns: minmax(130px,1fr) 30px; border: 1px solid transparent; border-radius: 10px; flex: 0 0 auto; }
.version-chip-wrap .version-chip { min-width: 0; border-radius: 10px 0 0 10px; }
.version-delete { border: 1px solid var(--border); border-left: 0; background: var(--bg-soft); color: var(--muted); border-radius: 0 10px 10px 0; cursor: pointer; }
.version-delete:hover { color: var(--danger); background: #24181b; }
.map-toolbar { grid-template-columns: minmax(220px,320px) auto auto minmax(220px,1fr); }
.map-zoom-controls { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.map-zoom-controls .button { padding-inline: 10px; }
.map-help { align-self: center; }
.map-stage { overflow: auto; max-height: 72vh; cursor: default; }
.map-canvas { position: relative; min-width: 100%; background: #0a0b0e; }
.map-canvas > img { display: block; width: 100%; height: auto; user-select: none; }
.map-marker.has-drilldown b { border-color: var(--accent); }
.graph-click:focus-visible .graph-node, .graph-click:focus-visible .graph-node-root, .graph-click:focus-visible .graph-family-node, .graph-click:focus-visible .graph-family-root { stroke: white; stroke-width: 3; }

@media (max-width: 1180px) {
  .map-toolbar { grid-template-columns: minmax(220px,1fr) auto auto; }
  .map-help { grid-column: 1 / -1; }
}
@media (max-width: 980px) {
  .atlas-panel { max-height: none; }
  .map-toolbar { grid-template-columns: 1fr; }
  .map-zoom-controls { justify-content: flex-start; }
  .map-help { grid-column: auto; }
}

/* V1.1 keyboard-accessible relation/timeline rows */
.related-row{gap:10px}.related-open{appearance:none;border:0;background:transparent;color:inherit;text-align:left;display:flex;flex:1;min-width:0;flex-direction:column;gap:3px;padding:0;cursor:pointer}.related-open:focus-visible{outline:2px solid var(--accent);outline-offset:4px;border-radius:8px}.timeline-summary{display:block;margin-top:7px;text-align:left}
