:root {
  color-scheme: light;
  --canvas: #f3f0e8; --paper: #fbfaf6; --ink: #171714; --muted: #6d6960; --rule: #c9c3b6;
  --accent: #c43d24; --focus: #126b77; --danger: #9c2e20; --rail: 248px; --detail: 420px;
  --serif: Georgia, 'Noto Serif SC', 'Songti SC', serif;
  --sans: 'Aptos', 'Segoe UI Variable', 'Microsoft YaHei UI', sans-serif;
  --mono: 'Cascadia Mono', 'SFMono-Regular', Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--canvas); color: var(--ink); font-family: var(--sans); }
body { min-width: 320px; overflow: hidden; }
button, input, select { font: 600 14px/1.4 var(--sans); color: inherit; }
button, select { min-height: 44px; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .38; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--focus) 70%, transparent); outline-offset: 2px; }
.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; }
.app-shell { height: 100vh; height: 100dvh; display: grid; grid-template-rows: 52px minmax(0, 1fr); }
.top-rail { z-index: 30; display: grid; grid-template-columns: var(--rail) minmax(0,1fr) auto; align-items: center; border-bottom: 1px solid var(--ink); background: var(--paper); }
.wordmark { height: 100%; display: flex; gap: 11px; align-items: center; padding: 0 18px; color: var(--ink); text-decoration: none; font: 700 18px/1 var(--serif); border-right: 1px solid var(--rule); }
.wordmark-mark { display: grid; place-items: center; width: 25px; height: 25px; color: var(--paper); background: var(--accent); font: 700 15px/1 var(--serif); }
.archive-state { display: flex; align-items: center; gap: 20px; padding: 0 20px; color: var(--muted); font: 600 12px/1 var(--mono); text-transform: uppercase; letter-spacing: .04em; }
.health { display: inline-flex; gap: 7px; align-items: center; }
.health::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: #39734f; }
.health--warn::before { background: #b06826; }
.language { padding-right: 14px; }
.language select { border: 0; background: transparent; padding: 0 28px 0 8px; }
.workspace { min-height: 0; display: grid; grid-template-columns: var(--rail) minmax(360px, 1fr) var(--detail); }
.filter-rail, .detail-panel { min-height: 0; background: var(--paper); display: flex; flex-direction: column; }
.filter-rail { border-right: 1px solid var(--rule); padding: 0 18px 18px; }
.detail-panel { border-left: 1px solid var(--ink); }
.panel-heading { flex: 0 0 60px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--rule); }
.panel-heading h2 { margin: 0; font: 700 12px/1 var(--mono); text-transform: uppercase; letter-spacing: .08em; }
.text-button { align-self: flex-start; border: 0; padding: 0; min-height: 44px; color: var(--accent); background: transparent; font-size: 12px; }
.filter-scroll { overflow: auto; padding: 4px 4px 40px 0; scrollbar-width: thin; }
.filter-group { margin: 0; padding: 15px 0 13px; border: 0; border-bottom: 1px solid var(--rule); }
.filter-group legend { padding: 0; margin-bottom: 7px; color: var(--muted); font: 700 11px/1 var(--mono); text-transform: uppercase; letter-spacing: .09em; }
.filter-options { display: grid; }
.filter-option { position: relative; min-height: 32px; display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 8px; align-items: center; padding: 4px 6px 4px 20px; font-size: 13px; cursor: pointer; }
.filter-option input { position: absolute; left: 2px; width: 12px; height: 12px; accent-color: var(--accent); }
.filter-option span:first-of-type { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filter-option:hover, .filter-option.is-selected { background: #e9e4d8; }
.facet-count { color: var(--muted); font: 11px/1 var(--mono); }
.result-ledger { min-width: 0; min-height: 0; display: grid; grid-template-rows: 74px 54px minmax(0,1fr) 55px; background: var(--canvas); }
.search-band { display: flex; align-items: center; padding: 14px 22px; border-bottom: 1px solid var(--rule); }
.search-box { width: 100%; height: 44px; display: grid; grid-template-columns: 24px 1fr; align-items: center; gap: 9px; padding: 0 12px; border: 1px solid var(--ink); background: var(--paper); }
.search-box input { min-width: 0; width: 100%; height: 100%; padding: 0; border: 0; outline: 0; background: transparent; font-size: 15px; font-weight: 500; }
.icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: square; stroke-linejoin: miter; pointer-events: none; }
.filter-trigger { display: none; width: 44px; margin-right: 8px; border: 1px solid var(--ink); background: var(--paper); }
.ledger-heading { display: flex; align-items: baseline; justify-content: space-between; padding: 15px 22px 10px; }
.ledger-heading h1 { margin: 0; font: 700 12px/1 var(--mono); letter-spacing: .08em; text-transform: uppercase; }
.result-range { color: var(--muted); font: 11px/1 var(--mono); }
.ledger-list { min-height: 0; overflow: auto; border-top: 1px solid var(--rule); background: var(--paper); }
.ledger-list.is-updating { opacity: .55; pointer-events: none; }
.pattern-row { position: relative; width: 100%; min-height: 112px; display: grid; grid-template-columns: 38px 142px minmax(180px,1fr) minmax(110px,.55fr) 22px; gap: 12px; align-items: center; padding: 12px 20px 12px 16px; text-align: left; border: 0; border-bottom: 1px solid var(--rule); background: transparent; animation: reveal .28s both; animation-delay: calc(var(--row-index) * 22ms); }
.pattern-row::before { content: ''; position: absolute; inset: 0 auto 0 0; width: 4px; background: transparent; }
.pattern-row:hover { background: #f1ede3; }
.pattern-row.is-selected { background: #ebe5d9; }
.pattern-row.is-selected::before { background: var(--accent); }
.row-index { color: var(--rule); font: 12px/1 var(--mono); }
.row-preview { width: 142px; aspect-ratio: 16/10; display: grid; place-items: center; overflow: hidden; border: 1px solid var(--rule); color: var(--rule); background: repeating-linear-gradient(135deg, #ebe6dc 0 1px, transparent 1px 10px); font: 18px/1 var(--serif); }
.row-preview img { width: 100%; height: 100%; object-fit: cover; }
.row-body { min-width: 0; }
.row-body h2, .detail-title h2 { margin: 0 0 5px; font: 700 20px/1.16 var(--serif); }
.row-body h2 { display: -webkit-box; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.row-id { overflow-wrap: anywhere; color: var(--muted); font: 11px/1.45 var(--mono); }
.tag-list { display: flex; flex-wrap: wrap; gap: 5px 12px; margin-top: 9px; color: var(--muted); font-size: 12px; font-weight: 500; }
.tag-list span + span::before { content: '·'; margin-right: 12px; color: var(--accent); }
.row-match { min-width: 0; display: grid; gap: 8px; justify-items: end; text-align: right; }
.row-match strong { color: var(--accent); font: 700 11px/1 var(--mono); }
.row-match span { max-width: 100%; color: var(--muted); font: 10px/1.45 var(--mono); overflow-wrap: anywhere; }
.pagination { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 14px; padding: 5px 18px; border-top: 1px solid var(--ink); background: var(--paper); }
.pagination button { display: flex; align-items: center; gap: 5px; border: 0; background: transparent; }
.pagination button:last-child { justify-self: end; }
.pagination > span { color: var(--muted); font: 10px/1 var(--mono); }
.pagination .icon { width: 17px; }
.detail-heading { padding: 0 18px; }
.icon-button { width: 44px; border: 0; display: grid; place-items: center; background: transparent; }
.detail-panel:not(.has-entry) .detail-heading .icon-button { visibility: hidden; }
.detail-content { min-height: 0; overflow: auto; padding-bottom: 36px; }
.preview-frame { aspect-ratio: 16/10; display: grid; place-items: center; overflow: hidden; border-bottom: 1px solid var(--ink); color: var(--muted); background: repeating-linear-gradient(135deg, #ebe6dc 0 1px, transparent 1px 12px); font: 12px/1 var(--mono); }
.preview-frame img { width: 100%; height: 100%; object-fit: cover; }
.detail-title, .detail-section, .prompt-panel { padding: 20px; border-bottom: 1px solid var(--rule); }
.detail-title h2 { margin-top: 7px; font-size: 25px; }
.detail-section h3, .prompt-panel h3 { margin: 0 0 13px; color: var(--muted); font: 700 11px/1 var(--mono); text-transform: uppercase; letter-spacing: .08em; }
.detail-section p { margin: 0; font-size: 14px; line-height: 1.65; }
.metadata { margin: 0; display: grid; grid-template-columns: 88px minmax(0,1fr); gap: 9px 14px; font-size: 13px; line-height: 1.5; }
.metadata dt { color: var(--muted); }
.metadata dd { margin: 0; overflow-wrap: anywhere; }
.prompt-panel pre { max-height: 320px; overflow: auto; margin: 0 0 14px; padding: 14px; border-left: 3px solid var(--accent); white-space: pre-wrap; overflow-wrap: anywhere; background: #eee9df; font: 12px/1.65 var(--mono); }
.primary-button { min-height: 44px; border: 1px solid var(--ink); padding: 8px 16px; background: var(--ink); color: var(--paper); }
.primary-button:hover { background: var(--accent); border-color: var(--accent); }
.detail-idle, .state-block { height: 100%; min-height: 220px; display: grid; place-content: center; justify-items: center; gap: 10px; padding: 24px; text-align: center; color: var(--muted); }
.detail-idle > span { color: var(--rule); font: 100px/.8 var(--serif); }
.detail-idle p { font: 12px/1 var(--mono); text-transform: uppercase; letter-spacing: .1em; }
.state-block { background: var(--paper); }
.state-block h2 { margin: 0; color: var(--ink); font: 700 21px/1.2 var(--serif); }
.state-block p { margin: 0; font-size: 14px; }
.state-mark { width: 42px; height: 42px; display: grid; place-items: center; border: 1px solid var(--rule); color: var(--accent); font: 24px/1 var(--serif); }
.toast { position: fixed; z-index: 80; right: 22px; bottom: 22px; max-width: 320px; padding: 13px 17px; background: var(--ink); color: var(--paper); border-left: 4px solid var(--accent); font-size: 14px; }
.scrim { display: none; }
.mobile-only { display: none; }
@keyframes reveal { from { opacity: 0; transform: translateY(5px); } }

@media (max-width: 1199px) {
  :root { --detail: 390px; }
  .top-rail { grid-template-columns: 190px minmax(0,1fr) auto; }
  .wordmark { border-right: 0; }
  .workspace { grid-template-columns: minmax(360px,1fr) var(--detail); }
  .filter-trigger { display: grid; place-items: center; flex: 0 0 44px; }
  .filter-rail { position: fixed; z-index: 60; inset: 52px auto 0 0; width: 280px; transform: translateX(-102%); transition: transform .18s ease; box-shadow: 12px 0 40px rgba(23,23,20,.14); }
  .filter-rail.is-open { transform: translateX(0); }
  .scrim { display: block; position: fixed; z-index: 50; inset: 52px 0 0; width: 100%; height: auto; min-height: 0; border: 0; background: rgba(23,23,20,.38); }
  .mobile-only { display: grid; }
  .filter-option { min-height: 44px; }
}
@media (max-width: 899px) {
  body { overflow: hidden; }
  .app-shell { grid-template-rows: 48px minmax(0,1fr); }
  .top-rail { grid-template-columns: 1fr auto; }
  .wordmark { padding-left: 14px; }
  .archive-state { display: none; }
  .language { padding-right: 6px; }
  .workspace { display: block; }
  .result-ledger { height: 100%; grid-template-rows: 66px 46px minmax(0,1fr) 52px; }
  .search-band { padding: 10px 12px; }
  .ledger-heading { padding: 13px 14px 8px; }
  .pattern-row { min-height: 112px; grid-template-columns: 94px minmax(0,1fr) 18px; gap: 10px; padding: 12px 12px 12px 14px; }
  .pattern-row .row-index, .row-match { display: none; }
  .row-preview { width: 94px; }
  .row-body h2 { font-size: 18px; }
  .tag-list { max-height: 35px; overflow: hidden; }
  .pagination { grid-template-columns: 1fr 1fr; padding: 4px 8px; }
  .pagination > span { display: none; }
  .filter-rail { top: 48px; }
  .detail-panel { position: fixed; z-index: 60; inset: 48px 0 0; width: 100%; transform: translateX(102%); transition: transform .18s ease; border-left: 0; }
  .detail-panel.is-open { transform: translateX(0); }
  .detail-panel:not(.has-entry) { display: none; }
  .scrim { top: 48px; }
  .metadata { grid-template-columns: 78px minmax(0,1fr); }
}
@media (max-width: 420px) {
  .wordmark-mark { width: 23px; height: 23px; }
  .search-box { padding: 0 9px; }
  .result-range { max-width: 190px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .detail-title, .detail-section, .prompt-panel { padding: 17px 16px; }
}
@media (min-width: 1600px) { :root { --rail: 270px; --detail: 460px; } .pattern-row { min-height: 112px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; } }
