:root {
  --bg: #f7f5f0;
  --paper: #fdfcf9;
  --ink: #1b1a17;
  --ink-2: #4a4740;
  --muted: #7a766c;
  --rule: #e2ded4;
  --rule-strong: #cfc9bc;
  --accent: #1f4d3a;
  --accent-soft: #e6eee9;
  --accent-ink: #163b2c;
  --bad: #8c2f25;
  --bad-soft: #f5e7e4;
  --hl: #f0e3c4;
  --serif: "Newsreader", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Songti SC", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Noto Sans SC", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --radius: 4px;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.55 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
code { font-family: var(--mono); font-size: .86em; background: #efece4; padding: .05em .3em; border-radius: 3px; }
.wrap { max-width: 1280px; margin: 0 auto; padding: 0 32px; }
.zh { font-family: var(--sans); font-size: .62em; font-weight: 400; color: var(--muted); letter-spacing: .04em; margin-left: .4em; vertical-align: middle; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--bad); font-size: 13px; margin: 8px 0 0; }
[hidden] { display: none !important; }

/* masthead */
.masthead { border-bottom: 1px solid var(--rule); background: var(--bg); position: sticky; top: 0; z-index: 10; }
.masthead-inner { display: flex; align-items: center; justify-content: space-between; height: 60px; gap: 16px; }
.brand { display: flex; align-items: baseline; gap: 14px; text-decoration: none; color: var(--ink); min-width: 0; }
.brand-mark { font-family: var(--serif); font-weight: 600; font-size: 22px; letter-spacing: .14em; }
.brand-sub { font-size: 13px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav { display: flex; gap: 26px; }
.nav a { color: var(--ink-2); text-decoration: none; font-size: 14px; padding: 4px 0; border-bottom: 1px solid transparent; white-space: nowrap; }
.nav a:hover { color: var(--ink); border-bottom-color: var(--ink); }

/* hero */
.hero { padding: 44px 32px 26px; }
section[id] { scroll-margin-top: 72px; }
.trace-panel { scroll-margin-top: 72px; }
.eyebrow { text-transform: uppercase; letter-spacing: .14em; font-size: 11.5px; color: var(--accent); margin: 0 0 14px; font-weight: 600; }
h1 { font-family: var(--serif); font-weight: 400; font-size: 46px; line-height: 1.1; margin: 0 0 18px; max-width: 22em; letter-spacing: -.01em; }
.lead { font-size: 17px; color: var(--ink-2); max-width: 46em; margin: 0; }
.small-lead { font-size: 15px; }

/* panels */
.demo { padding-bottom: 40px; }
.demo-grid { display: grid; grid-template-columns: minmax(340px, 5fr) minmax(0, 7fr); gap: 28px; align-items: start; }
.panel { background: var(--paper); border: 1px solid var(--rule); border-radius: var(--radius); padding: 22px 24px 24px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.panel h2 { font-family: var(--serif); font-weight: 500; font-size: 22px; margin: 0; }
.stepnum { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; border: 1px solid var(--ink); border-radius: 50%; font: 600 12px var(--sans); margin-right: 8px; vertical-align: 3px; }
.run-head { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--rule); }
.input-panel { position: sticky; top: 76px; }

.seg { display: inline-flex; border: 1px solid var(--rule-strong); border-radius: 999px; padding: 2px; background: var(--bg); }
.seg-btn { font: 500 13px var(--sans); color: var(--ink-2); background: none; border: 0; padding: 5px 14px; border-radius: 999px; cursor: pointer; white-space: nowrap; }
.seg-btn.active { background: var(--ink); color: var(--paper); }
.seg-btn:focus-visible, button:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.filters input { grid-column: 1 / -1; }
input[type=search], select, textarea { font: 14px var(--sans); color: var(--ink); background: var(--paper); border: 1px solid var(--rule-strong); border-radius: var(--radius); padding: 7px 10px; min-width: 0; }
select { padding-right: 26px; }
textarea { width: 100%; resize: vertical; }

.thumb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; max-height: 300px; overflow-y: auto; padding: 2px 4px 2px 2px; scrollbar-width: thin; }
.thumb { background: #ecebe6; border: 1px solid transparent; border-radius: 3px; padding: 6px 0 4px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.thumb img { width: 48px; height: 64px; object-fit: contain; display: block; }
.thumb span { font: 10.5px var(--mono); color: var(--muted); }
.thumb:hover { border-color: var(--rule-strong); }
.thumb.active { border-color: var(--ink); background: #e4e2db; }
.thumb.active span { color: var(--ink); }

.drop { display: block; border: 1px dashed var(--rule-strong); border-radius: var(--radius); padding: 18px; text-align: center; cursor: pointer; margin-bottom: 14px; font-size: 14px; }
.drop:hover { border-color: var(--ink-2); }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.field-label { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 6px; }
.check { display: flex; align-items: flex-start; gap: 8px; font-size: 13.5px; color: var(--ink-2); margin: 12px 0; cursor: pointer; }
.check input { margin-top: 3px; accent-color: var(--accent); }

.selected { display: flex; gap: 18px; align-items: center; margin-top: 16px; padding: 14px; border: 1px solid var(--rule); background: var(--bg); border-radius: var(--radius); }
.sel-img { flex: 0 0 auto; width: 104px; height: 136px; background: #ecebe6; display: flex; align-items: center; justify-content: center; border-radius: 3px; }
.sel-img img { width: 90px; height: 120px; object-fit: contain; image-rendering: auto; }
.sel-img img:not([src]) { visibility: hidden; }
.kicker { font: 600 11px var(--sans); letter-spacing: .12em; text-transform: uppercase; color: var(--accent); margin: 0 0 4px; }
.sel-name { font-family: var(--serif); font-size: 18px; margin: 0 0 6px; line-height: 1.3; word-break: break-word; }
.sel-meta p:last-child { margin: 0; }

.run-controls select { width: 100%; }
.btn-primary { width: 100%; font: 600 15px var(--sans); background: var(--accent); color: #fff; border: 0; border-radius: var(--radius); padding: 12px 18px; cursor: pointer; margin-top: 4px; letter-spacing: .02em; }
.btn-primary:hover:not(:disabled) { background: var(--accent-ink); }
.btn-primary:disabled { background: #a9b5ad; cursor: not-allowed; }
.btn-ghost { font: 500 13px var(--sans); background: none; border: 1px solid var(--rule-strong); border-radius: var(--radius); padding: 6px 12px; cursor: pointer; color: var(--ink); }
.btn-ghost:hover { border-color: var(--ink); }
#version-desc { margin: 6px 0 0; min-height: 1.2em; }

/* trace */
.trace-total { font: 13px var(--mono); color: var(--ink-2); }
.steps { list-style: none; margin: 0; padding: 0; }
.step { border-top: 1px solid var(--rule); padding: 14px 0; }
.step:first-child { border-top: 0; padding-top: 4px; }
.step-head { display: grid; grid-template-columns: 30px 1fr auto; align-items: center; gap: 10px; }
.dot { width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--rule-strong); display: flex; align-items: center; justify-content: center; font: 600 12px var(--sans); color: var(--muted); background: var(--paper); }
.step-title { font-weight: 600; font-size: 14.5px; color: var(--ink-2); }
.step-title .zh { font-size: 12px; }
.step-time { font: 12.5px var(--mono); color: var(--muted); white-space: nowrap; }
.step-body { margin: 10px 0 0 40px; font-size: 14px; min-width: 0; }
.step-body:empty { display: none; }
.step[data-status=pending] .step-title { color: var(--muted); font-weight: 500; }
.step[data-status=running] .dot { border-color: var(--accent); color: var(--accent); }
.step[data-status=running] .dot::after { content: ""; position: absolute; }
.step[data-status=running] .dot { position: relative; }
.step[data-status=running] .dot::before { content: ""; position: absolute; inset: -4px; border-radius: 50%; border: 2px solid transparent; border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
.step[data-status=done] .dot { background: var(--accent); border-color: var(--accent); color: #fff; }
.step[data-status=done] .step-title { color: var(--ink); }
.step[data-status=skipped] .dot { border-style: dashed; }
.step[data-status=skipped] .step-title { color: var(--muted); }
.step[data-status=error] .dot { background: var(--bad); border-color: var(--bad); color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .step[data-status=running] .dot::before { animation: none; border-color: var(--accent); } }

.skip-note { color: var(--muted); font-size: 13.5px; margin: 0; font-style: italic; }
.textflow { display: grid; grid-template-columns: 70px 1fr; gap: 6px 12px; align-items: baseline; margin: 0; }
.textflow dt { font-size: 11.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.textflow dd { margin: 0; font-family: var(--serif); font-size: 16.5px; word-break: break-word; }
mark.m-out { background: var(--hl); color: var(--ink); text-decoration: line-through; text-decoration-color: rgba(27,26,23,.45); padding: 0 2px; border-radius: 2px; }
mark.m-in { background: var(--accent-soft); color: var(--accent-ink); font-family: var(--mono); font-size: .8em; padding: 1px 4px; border-radius: 2px; }
mark.m-hit { background: var(--hl); color: var(--ink); padding: 0 2px; border-radius: 2px; font-weight: 600; }
.note { color: var(--muted); font-size: 13px; margin: 8px 0 0; }
.facts { display: flex; flex-wrap: wrap; gap: 6px 22px; margin: 0 0 8px; font-size: 13.5px; }
.facts b { font-weight: 600; font-family: var(--mono); font-size: 13px; }
details.collapse { border: 1px solid var(--rule); border-radius: var(--radius); background: var(--bg); margin-top: 8px; }
details.collapse summary { cursor: pointer; padding: 8px 12px; font-size: 13px; color: var(--ink-2); }
details.collapse[open] summary { border-bottom: 1px solid var(--rule); }
pre.code { margin: 0; padding: 12px; font: 12px/1.5 var(--mono); white-space: pre-wrap; word-break: break-word; max-height: 360px; overflow: auto; color: var(--ink); }
.img-block { display: inline-block; font: 11.5px var(--mono); background: var(--accent-soft); color: var(--accent-ink); padding: 2px 6px; border-radius: 3px; margin: 4px 0; }
.spinner-line { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.spinner-line .elapsed { font: 600 20px var(--mono); color: var(--ink); }

table.data { border-collapse: collapse; width: 100%; font-size: 13.5px; }
table.data th, table.data td { text-align: left; padding: 6px 10px 6px 0; border-bottom: 1px solid var(--rule); vertical-align: top; }
table.data th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 600; }
table.data td.num, table.data th.num { text-align: right; font-family: var(--mono); font-size: 13px; padding-right: 0; padding-left: 10px; }
table.data tr:last-child td { border-bottom: 0; }
.ok { color: var(--accent); font-weight: 600; }
.bad { color: var(--bad); font-weight: 600; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.table-scroll { overflow-x: auto; }

/* final tags */
.tags { display: grid; grid-template-columns: 1fr; gap: 0; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--paper); }
.tag-row { display: grid; grid-template-columns: 112px 1fr auto; gap: 10px; align-items: center; padding: 10px 14px; border-top: 1px solid var(--rule); }
.tag-row:first-child { border-top: 0; }
.tag-field { font-size: 11.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--ink); border-radius: 999px; padding: 3px 12px; font-size: 14px; background: var(--paper); }
.chip.none { border-style: dashed; border-color: var(--rule-strong); color: var(--muted); }
.chip .conf { font: 11px var(--mono); color: var(--muted); }
.swatch { width: 12px; height: 12px; border-radius: 50%; border: 1px solid rgba(0,0,0,.2); display: inline-block; }
.swatch.multi { background: conic-gradient(#b4382f 0 25%, #2d5fa8 0 50%, #d9a52b 0 75%, #3f7a4f 0); }
.gt { font-size: 13px; white-space: nowrap; text-align: right; }
.gt .mark { display: inline-block; width: 18px; text-align: center; font-weight: 700; }
.gt.right .mark { color: var(--accent); }
.gt.wrong .mark { color: var(--bad); }
.gt.wrong .gt-val { color: var(--bad); }
.gt .label { color: var(--muted); }
.score { font-family: var(--serif); font-size: 20px; margin: 0 0 10px; }
.score b { font-weight: 600; }

/* sections */
.section { padding: 56px 32px 24px; border-top: 1px solid var(--rule); }
.section-head { margin-bottom: 22px; }
.section-title { font-family: var(--serif); font-weight: 400; font-size: 34px; margin: 0 0 10px; letter-spacing: -.01em; }
.h3 { font-family: var(--serif); font-weight: 500; font-size: 19px; margin: 26px 0 6px; }
.controls-row { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 18px; }
.results-grid { display: grid; grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); gap: 28px; align-items: start; }
.chart-card, .table-card { background: var(--paper); border: 1px solid var(--rule); border-radius: var(--radius); padding: 22px 24px; margin: 0; position: relative; }
.chart-title { font-family: var(--serif); font-size: 18px; margin-bottom: 8px; }
.legend { display: flex; flex-wrap: wrap; gap: 16px; font-size: 13px; color: var(--ink-2); margin-bottom: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { font-family: var(--sans); }
.chart .bar { cursor: default; }
.chart .bar:hover, .chart .hit:hover + .bar { opacity: .85; }
.tooltip { position: absolute; pointer-events: none; background: var(--ink); color: var(--paper); font-size: 12.5px; padding: 6px 9px; border-radius: 3px; white-space: nowrap; z-index: 5; }
.fig-details { margin-top: 20px; }
.fig-details summary { cursor: pointer; font-size: 14px; color: var(--ink-2); }
.fig-details img { max-width: 100%; margin-top: 12px; border: 1px solid var(--rule); background: #fff; }

/* pipeline */
.pipeline { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--paper); }
.stage { padding: 22px 22px 24px; border-left: 1px solid var(--rule); min-width: 0; }
.stage:first-child { border-left: 0; }
.stage-n { font: 600 11px var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--accent); }
.stage h3 { font-family: var(--serif); font-weight: 500; font-size: 21px; margin: 6px 0 8px; }
.stage p { font-size: 13.5px; color: var(--ink-2); margin: 0 0 12px; }
.funnel { list-style: none; padding: 0; margin: 0; font-size: 12.5px; }
.funnel li { margin-bottom: 7px; }
.funnel .f-top { display: flex; justify-content: space-between; gap: 8px; }
.funnel .f-step { color: var(--ink-2); font-family: var(--mono); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.funnel .f-n { font-family: var(--mono); font-size: 12px; }
.funnel .f-bar { height: 4px; background: var(--rule); border-radius: 2px; margin-top: 3px; }
.funnel .f-bar span { display: block; height: 100%; background: var(--accent); border-radius: 2px; min-width: 2px; }
.mini { list-style: none; margin: 0 0 12px; padding: 0; font-size: 13px; }
.mini li { display: flex; justify-content: space-between; border-bottom: 1px solid var(--rule); padding: 5px 0; gap: 8px; }
.mini li > span:last-child { font-family: var(--mono); font-size: 12.5px; color: var(--ink-2); white-space: nowrap; }
.ver { border-top: 1px solid var(--rule); padding-top: 10px; margin-top: 10px; }
.ver:first-of-type { border-top: 0; margin-top: 0; padding-top: 0; }
.ver-name { font-weight: 600; font-size: 14px; }
.ver ul { margin: 4px 0 0; padding-left: 18px; font-size: 13px; color: var(--ink-2); }
.ver ul li { margin-bottom: 3px; }
.tagline { display: inline-block; font-size: 11px; border: 1px solid var(--rule-strong); border-radius: 999px; padding: 0 7px; color: var(--muted); margin-left: 6px; vertical-align: 1px; }

/* doc dialog */
.doc-dialog { overflow: hidden; border: 1px solid var(--rule-strong); border-radius: var(--radius); padding: 0; width: min(920px, 94vw); max-height: 88vh; background: var(--paper); color: var(--ink); }
.doc-dialog::backdrop { background: rgba(27,26,23,.35); }
.doc-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 22px; border-bottom: 1px solid var(--rule); position: sticky; top: 0; background: var(--paper); }
.doc-head h2 { font-family: var(--serif); font-weight: 500; margin: 0; font-size: 22px; }
.doc-body { padding: 8px 22px 22px; overflow: auto; max-height: calc(88vh - 60px); }
.md h1 { font-size: 28px; } .md h2 { font-family: var(--serif); font-weight: 500; font-size: 21px; margin: 24px 0 8px; } .md h3 { font-size: 15px; margin: 18px 0 6px; }
.md table { border-collapse: collapse; width: 100%; font-size: 13px; margin: 6px 0 12px; }
.md th, .md td { border-bottom: 1px solid var(--rule); padding: 5px 10px 5px 0; text-align: left; vertical-align: top; }
.md th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.md p { font-size: 14px; color: var(--ink-2); }

.footer { border-top: 1px solid var(--rule); margin-top: 48px; padding: 28px 0 40px; font-size: 13.5px; color: var(--ink-2); }
.footer p { max-width: 60em; }

/* responsive */
@media (max-width: 1080px) {
  .demo-grid, .results-grid { grid-template-columns: minmax(0, 1fr); }
  .input-panel { position: static; }
  .pipeline { grid-template-columns: 1fr 1fr; }
  .stage:nth-child(3) { border-left: 0; }
  .stage:nth-child(n+3) { border-top: 1px solid var(--rule); }
}
@media (max-width: 640px) {
  body { font-size: 14.5px; }
  .wrap { padding: 0 16px; }
  .hero { padding: 32px 16px 18px; }
  h1 { font-size: 32px; }
  .lead { font-size: 15.5px; }
  .section { padding: 40px 16px 16px; }
  .section-title { font-size: 27px; }
  .masthead { position: static; }
  section[id], .trace-panel { scroll-margin-top: 12px; }
  .tag-row { padding: 8px 12px; gap: 4px 10px; }
  .masthead-inner { height: auto; padding-top: 10px; padding-bottom: 8px; flex-direction: column; align-items: flex-start; gap: 4px; }
  .nav { gap: 18px; }
  .brand-sub { font-size: 12px; }
  .panel { padding: 16px; }
  .chart-card, .table-card { padding: 16px; }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters input { grid-column: 1 / -1; }
  .thumb-grid { grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); max-height: 230px; }
  .step-body { margin-left: 0; }
  .textflow { grid-template-columns: 1fr; gap: 2px; }
  .textflow dd { margin-bottom: 8px; }
  .tag-row { grid-template-columns: 1fr auto; }
  .tag-row .tag-field { grid-column: 1 / -1; }
  .pipeline { grid-template-columns: 1fr; }
  .stage { border-left: 0; border-top: 1px solid var(--rule); }
  .stage:first-child { border-top: 0; }
}
