:root {
  color-scheme: light;
  --paper: #eee9df;
  --sheet: #f8f4eb;
  --ink: #1d1d1a;
  --muted: #747067;
  --rule: #cfc8bb;
  --rule-dark: #aaa295;
  --amber: #bd741f;
  --amber-soft: #ead4b3;
  --white: #fffdf8;
  --ease: cubic-bezier(.16, 1, .3, 1);
  --ui: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Noto Sans CJK SC", sans-serif;
  --serif: "Songti SC", "STSong", "Noto Serif CJK SC", Georgia, serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; overflow: hidden; background: var(--paper); color: var(--ink); font-family: var(--ui); }
button, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.sr-only { position: fixed; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.app-shell { height: 100%; display: grid; grid-template-rows: 64px 1fr 30px; }

.topbar { display: grid; grid-template-columns: 280px 1fr auto; align-items: center; gap: 24px; padding: 0 22px; border-bottom: 1px solid var(--rule-dark); background: rgba(248, 244, 235, .88); }
.brand { display: flex; align-items: baseline; gap: 11px; }
.brand strong { font: 700 22px/1 var(--serif); letter-spacing: .08em; }
.brand span, .kicker { color: var(--muted); font: 10px/1 var(--mono); letter-spacing: .16em; text-transform: uppercase; }
.case-control { justify-self: center; display: flex; align-items: center; gap: 10px; font: 11px var(--mono); color: var(--muted); }
.case-control select { width: min(330px, 32vw); min-height: 36px; border: 1px solid var(--rule-dark); border-radius: 0; background: var(--sheet); padding: 0 30px 0 10px; }
.primary-button, .secondary-button, .text-button { min-height: 36px; border: 1px solid var(--ink); border-radius: 0; padding: 0 14px; background: var(--ink); color: var(--white); transition: transform 180ms var(--ease), background 180ms var(--ease), color 180ms var(--ease); }
.secondary-button { background: transparent; color: var(--ink); border-color: var(--rule-dark); }
.text-button { border: 0; background: transparent; color: var(--ink); }
.secondary-button:hover { background: var(--white); }
button:active { transform: translateY(1px); }

.workbench { position: relative; display: grid; grid-template-columns: minmax(280px, 31%) minmax(390px, 1fr) minmax(270px, 25%); min-height: 0; }
.pane { position: relative; min-width: 0; min-height: 0; background: var(--sheet); }
.pane + .pane { border-left: 1px solid var(--rule-dark); }
.pane-heading { height: 78px; display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; padding: 17px 18px 12px; border-bottom: 1px solid var(--rule); }
.pane-heading h1, .pane-heading h2 { margin: 3px 0 0; font: 600 19px/1.1 var(--serif); }
.pane-heading > span { color: var(--amber); font: 10px var(--mono); }

.source-pane { display: grid; grid-template-rows: 78px 1fr 48px; background: #272724; color: #e9e4da; }
.source-pane .pane-heading { border-color: #4d4a43; }
.source-pane .kicker { color: #aaa59b; }
.source-scroll { overflow: auto; padding: 20px 36px 35px; scrollbar-color: #6b665e transparent; }
.film-frame { position: relative; width: min(100%, 330px); margin: auto; }
.film-frame::before, .film-frame::after { content: ""; position: absolute; z-index: 2; top: 0; bottom: 0; width: 12px; background: repeating-linear-gradient(to bottom, #171714 0 8px, transparent 8px 18px); }
.film-frame::before { left: -18px; }
.film-frame::after { right: -18px; }
.source-stage { position: relative; background: #e9e5dc; box-shadow: 0 18px 52px #0008; }
.source-stage img { display: block; width: 100%; height: auto; }
.source-highlight { position: absolute; z-index: 2; pointer-events: none; border: 2px solid var(--amber); background: rgba(189, 116, 31, .14); box-shadow: 0 0 0 1px rgba(255, 253, 248, .8), 0 0 24px rgba(189, 116, 31, .35); background-image: linear-gradient(90deg, transparent, rgba(255,255,255,.55), transparent); background-size: 220% 100%; animation: scan 680ms var(--ease) both; }
@keyframes scan { from { background-position: 180% 0; } to { background-position: 0 0; } }
.source-caption { display: flex; justify-content: space-between; gap: 12px; padding: 9px 18px; border-top: 1px solid #4d4a43; color: #b9b3a7; font: 9px/1.5 var(--mono); }

.graph-pane { display: grid; grid-template-rows: 78px 52px 1fr; background: var(--paper); }
.filters { display: flex; gap: 5px; overflow-x: auto; padding: 9px 16px; border-bottom: 1px solid var(--rule); }
.filter-button { flex: 0 0 auto; border: 0; background: transparent; padding: 5px 9px; color: var(--muted); font: 10px var(--mono); transition: background 160ms var(--ease), color 160ms var(--ease); }
.filter-button[aria-pressed="true"] { background: var(--ink); color: var(--white); }
.graph-stage { position: relative; min-height: 0; overflow: auto; }
#graph { display: block; width: 100%; height: 100%; min-width: 540px; min-height: 580px; }
.edge { fill: none; stroke: #9f988c; stroke-width: 1.25; vector-effect: non-scaling-stroke; }
.edge.active { stroke: var(--amber); stroke-width: 2; stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw 620ms var(--ease) forwards; }
.edge.dim { opacity: .16; }
@keyframes draw { to { stroke-dashoffset: 0; } }
.node-group { cursor: pointer; outline: none; transition: opacity 200ms var(--ease), filter 200ms var(--ease); }
.node-box { fill: #f8f4eb; stroke: #aaa295; stroke-width: 1; }
.node-group:hover .node-box, .node-group:focus-visible .node-box { stroke: var(--ink); stroke-width: 2; }
.node-group.active .node-box { fill: #fff9ee; stroke: var(--amber); stroke-width: 2; }
.node-group.dim { opacity: .27; filter: blur(.6px); }
.node-kind, .source-label { fill: #6f6a61; font: 9px var(--mono); letter-spacing: .08em; }
.node-copy { fill: #24231f; font: 600 12px var(--ui); }
.source-dot { fill: var(--amber); }
.state-panel { position: absolute; z-index: 4; inset: 0; display: grid; place-items: center; padding: 30px; background: var(--paper); text-align: center; }
.state-panel[hidden] { display: none; }
.state-panel h3 { margin: 0 0 8px; font: 500 24px var(--serif); }
.state-panel p { max-width: 330px; margin: 0 0 18px; color: var(--muted); font-size: 13px; line-height: 1.6; }

.review-pane { display: grid; grid-template-rows: 78px 1fr auto; transition: transform 320ms var(--ease); }
.review-body { overflow: auto; padding: 22px; }
.review-kind { color: var(--amber); font: 10px var(--mono); letter-spacing: .16em; }
.review-title { margin: 10px 0 20px; font: 600 clamp(19px, 2vw, 27px)/1.35 var(--serif); text-wrap: pretty; }
.review-fields { margin: 0; }
.review-field { padding: 14px 0; border-top: 1px solid var(--rule); }
.review-field dt { margin-bottom: 7px; color: var(--muted); font: 10px var(--mono); letter-spacing: .12em; text-transform: uppercase; }
.review-field dd { margin: 0; font-size: 13px; line-height: 1.65; white-space: pre-wrap; overflow-wrap: anywhere; }
.review-field .quote { font: 15px/1.65 var(--serif); }
.status-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.status-option { min-height: 38px; border: 1px solid var(--rule); background: transparent; font-size: 11px; }
.status-option.active { border-color: var(--ink); background: var(--ink); color: white; }
.review-footer { display: grid; gap: 8px; padding: 14px 18px; border-top: 1px solid var(--rule-dark); }
.review-footer p { margin: 0; color: var(--muted); font: 9px/1.45 var(--mono); }

.statusbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 0 18px; border-top: 1px solid var(--rule-dark); color: var(--muted); background: var(--paper); font: 9px var(--mono); letter-spacing: .1em; }
.dialog-backdrop { position: fixed; z-index: 20; inset: 0; display: grid; place-items: center; padding: 34px; background: rgba(29, 29, 26, .44); }
.dialog-backdrop[hidden] { display: none; }
.checklist-sheet { display: grid; grid-template-rows: auto auto 1fr auto; width: min(940px, 100%); height: min(800px, 100%); background: var(--white); box-shadow: 0 28px 80px #0005; }
.checklist-sheet > header { display: flex; justify-content: space-between; padding: 26px 30px 20px; border-bottom: 2px solid var(--ink); }
.checklist-sheet h2 { margin: 4px 0 0; font: 600 28px var(--serif); }
.checklist-summary { margin: 0; padding: 14px 30px; border-bottom: 1px solid var(--rule); font: 12px var(--mono); }
.checklist-items { overflow: auto; padding: 0 30px; }
.checklist-row { display: grid; grid-template-columns: 110px 1fr 84px; gap: 18px; padding: 15px 0; border-bottom: 1px solid var(--rule); font-size: 13px; line-height: 1.5; }
.checklist-kind { color: var(--amber); font: 10px var(--mono); }
.checklist-status { text-align: right; font: 10px var(--mono); }
.checklist-sheet > footer { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 30px; border-top: 1px solid var(--rule); }

:focus-visible { outline: 3px solid var(--amber); outline-offset: 3px; }
@media (max-width: 980px) {
  body { overflow: auto; }
  .app-shell { height: auto; min-height: 100%; grid-template-rows: 58px auto 30px; }
  .topbar { grid-template-columns: 1fr auto auto; gap: 10px; }
  .case-control span { display: none; }
  .workbench { grid-template-columns: 42% 58%; grid-template-rows: 650px auto; }
  #graph { min-width: 100%; }
  .review-pane { grid-column: 1 / -1; min-height: 470px; border-left: 0 !important; border-top: 1px solid var(--rule-dark); }
  .review-body { display: grid; grid-template-columns: 1fr 1fr; gap: 0 28px; }
  .review-kind, .review-title { grid-column: 1 / -1; }
}
@media (max-width: 767px) {
  .topbar { padding: 0 12px; }
  .brand span { display: none; }
  .case-control select { width: 210px; }
  .workbench { display: block; }
  .pane { min-height: 580px; }
  .source-pane { height: 660px; }
  .graph-pane { height: 690px; }
  .review-pane { min-height: 520px; }
  .review-body { display: block; }
  .pane + .pane { border-left: 0; border-top: 1px solid var(--rule-dark); }
  .source-caption span:last-child { display: none; }
  .dialog-backdrop { padding: 0; }
  .checklist-sheet { width: 100%; height: 100%; }
  .checklist-row { grid-template-columns: 84px 1fr; }
  .checklist-status { grid-column: 2; text-align: left; }
}
@media (max-width: 520px) {
  .topbar { grid-template-columns: minmax(0, 1fr) auto; }
  .topbar .brand { display: none; }
  .case-control { min-width: 0; justify-self: stretch; }
  .case-control select { width: 100%; min-width: 0; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
@media print {
  body { overflow: visible; background: white; }
  .topbar, .workbench, .statusbar, .checklist-sheet .text-button, .checklist-sheet > footer { display: none !important; }
  .dialog-backdrop { position: static; display: block !important; padding: 0; background: white; }
  .checklist-sheet { display: block; width: 100%; height: auto; box-shadow: none; }
  .checklist-items { overflow: visible; }
  .checklist-row { break-inside: avoid; }
  .checklist-sheet > header, .checklist-summary, .checklist-items { padding-left: 0; padding-right: 0; }
}
