:root {
  --bg: light-dark(#f6f7f9, #12161c);
  --surface: light-dark(#ffffff, #1a2028);
  --surface-2: light-dark(#f0f2f5, #222a34);
  --text: light-dark(#1c2430, #e6eaf0);
  --muted: light-dark(#5b6676, #9aa5b4);
  --line: light-dark(#dde2e8, #2e3744);
  --accent: light-dark(#2456c7, #7aa2ff);
  --accent-text: light-dark(#ffffff, #0d1320);
  --note: light-dark(#1f7a4d, #6fd3a0);
  --note-bg: light-dark(#e3f4ea, #173326);
  --structure: light-dark(#475569, #b4bfcd);
  --structure-bg: light-dark(#e9edf2, #28313d);
  --decide: light-dark(#a14b00, #ffb46b);
  --decide-bg: light-dark(#fdeedc, #3a2614);
  --bad: light-dark(#b42318, #ff8f86);
  --bad-bg: light-dark(#fde8e7, #3d1a18);
  --ai: light-dark(#6534b8, #c9a8ff);
  --ai-bg: light-dark(#efe7fb, #2b2140);
  --s1: light-dark(#2a78d6, #3987e5);
  --s2: light-dark(#eb6834, #d95926);
  --s3: light-dark(#1baf7a, #199e70);
  --s4: light-dark(#eda100, #c98500);
  --s5: light-dark(#e87ba4, #d55181);
  --s6: light-dark(#008300, #0ca30c);
  --s7: light-dark(#6250d6, #9085e9);
  --radius: 10px;
  color-scheme: light dark;
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
.wrap { max-width: 1040px; margin: 0 auto; padding: 0 16px; }
h1 { font-size: 1.4rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
.lede { margin: 2px 0 0; color: var(--muted); }

.top { background: var(--surface); border-bottom: 1px solid var(--line); }
.top-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding-top: 20px; padding-bottom: 12px; }
.engine { color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
.tabs { display: flex; gap: 4px; }
.tabs button { background: none; border: 0; border-bottom: 3px solid transparent; padding: 10px 14px; font: inherit; color: var(--muted); cursor: pointer; }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

main { padding-top: 20px; padding-bottom: 32px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.form { display: grid; grid-template-columns: minmax(180px, 240px) 1fr auto; gap: 12px; align-items: end; }
#read-form { grid-template-columns: 1fr auto; }
.field { display: grid; gap: 4px; font-weight: 600; font-size: 0.9rem; }
select, button { font: inherit; }
select { padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); }
.drop { position: relative; display: grid; gap: 2px; padding: 12px 14px; border: 2px dashed var(--line); border-radius: var(--radius); cursor: pointer; }
.drop.over, .drop:focus-within { border-color: var(--accent); }
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.drop-title { font-weight: 600; }
.drop-hint { color: var(--muted); font-size: 0.88rem; overflow-wrap: anywhere; }
.primary { background: var(--accent); color: var(--accent-text); border: 0; border-radius: 8px; padding: 10px 18px; font-weight: 600; cursor: pointer; }
.primary:disabled { opacity: 0.6; cursor: progress; }
.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; cursor: pointer; }
.secondary:disabled { opacity: 0.5; cursor: not-allowed; }
.status { min-height: 1.5em; margin: 0 0 12px; color: var(--muted); }
.status.error { color: var(--bad); }

.banner { border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; font-weight: 600; }
.banner.ok { background: var(--note-bg); color: var(--note); }
.banner.bad { background: var(--bad-bg); color: var(--bad); }
.banner.ai { background: var(--ai-bg); color: var(--ai); font-weight: 500; }
.banner.info { background: var(--surface-2); color: var(--muted); font-weight: 500; }
.modes { grid-column: 1 / -1; border: 0; margin: 0; padding: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; }
.modes legend { font-weight: 600; font-size: 0.9rem; padding: 0; margin-bottom: 4px; float: left; margin-right: 10px; }
.switch { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.switch label { display: flex; align-items: center; gap: 6px; padding: 6px 14px; cursor: pointer; font-size: 0.9rem; border-left: 1px solid var(--line); }
.switch label:first-child { border-left: 0; }
.switch input { accent-color: var(--accent); margin: 0; }
.switch label:has(input:checked) { background: var(--accent); color: var(--accent-text); }
.switch label:has(input:disabled) { opacity: 0.5; cursor: not-allowed; }
.mode-hint { color: var(--muted); font-size: 0.85rem; flex-basis: 100%; }
.filters { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.tile b { display: block; font-size: 1.4rem; font-variant-numeric: tabular-nums; }
.tile span { color: var(--muted); font-size: 0.85rem; }
.downloads { display: flex; flex-wrap: wrap; gap: 8px; }

.group { border-top: 1px solid var(--line); padding: 8px 0; }
.group:first-of-type { border-top: 0; }
.group summary { cursor: pointer; font-weight: 600; }
.count { display: inline-block; min-width: 1.8em; text-align: center; background: var(--surface-2); border-radius: 999px; padding: 0 8px; margin-left: 6px; font-size: 0.85rem; }
ul.points { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; }
ul.points li { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; }
.where { color: var(--muted); font-size: 0.85rem; }
.excerpt { font-style: italic; }
.empty { color: var(--muted); margin: 0; }

.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.toolbar h2 { margin: 0; }
.toolbar label { color: var(--muted); font-size: 0.9rem; }
.lesson > summary { font-weight: 700; padding: 8px 0; cursor: pointer; }
.children { margin-left: 14px; padding-left: 12px; border-left: 2px solid var(--line); display: grid; gap: 6px; padding-bottom: 6px; }
.section-title { font-weight: 600; margin-top: 6px; }
.block { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; background: var(--surface-2); border-radius: 8px; padding: 8px 10px; }
.block .text { overflow-wrap: anywhere; }
.block .meta { grid-column: 2; color: var(--muted); font-size: 0.85rem; }
.block .detail { grid-column: 2; font-size: 0.9rem; overflow-wrap: anywhere; }
.block .detail.warn { color: var(--decide); font-weight: 600; }
.chip { display: inline-block; font-size: 0.78rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; height: fit-content; }
.chip.note { background: var(--note-bg); color: var(--note); }
.chip.structure { background: var(--structure-bg); color: var(--structure); }
.chip.needs-decision { background: var(--decide-bg); color: var(--decide); }
.chip.ai { background: var(--ai-bg); color: var(--ai); }
.kind { font-weight: 700; margin-right: 6px; }
.only-decide .block:not(.needs-decision) { display: none; }
.only-ai .block:not(.ai) { display: none; }
.foot { color: var(--muted); font-size: 0.85rem; padding-bottom: 24px; }

@media (max-width: 720px) {
  .form, #read-form { grid-template-columns: 1fr; }
  .top-row { flex-direction: column; }
}

/* Workflow views: series colours are the validated categorical palette, in fixed order; text never takes a series colour. */
.c1 { --c: var(--s1); } .c2 { --c: var(--s2); } .c3 { --c: var(--s3); } .c4 { --c: var(--s4); } .c5 { --c: var(--s5); } .c6 { --c: var(--s6); } .c7 { --c: var(--s7); } .c0 { --c: var(--structure); }
.m-rules { --c: var(--s1); } .m-hybrid { --c: var(--s3); } .m-ai { --c: var(--s7); }
svg .c0, svg .c1, svg .c2, svg .c3, svg .c4, svg .c5, svg .c6, svg .c7, svg .m-rules, svg .m-hybrid, svg .m-ai { fill: var(--c); }
svg text { fill: var(--text); font: 12px system-ui, -apple-system, "Segoe UI", sans-serif; }
svg text.small { fill: var(--muted); font-size: 11px; }
svg text.big { font-size: 20px; font-weight: 700; }
svg text.mode { font-weight: 600; }
svg text.inbar { font-weight: 600; stroke: var(--surface); stroke-width: 3px; paint-order: stroke; }
svg { width: 100%; height: auto; display: block; }
.pipeline .band { fill: var(--surface); } .pipeline .band.alt { fill: var(--surface-2); }
.pipeline .head, .pipeline .cell { cursor: pointer; }
.pipeline .head rect { fill: var(--surface-2); stroke: var(--line); }
.pipeline .head text { font-weight: 600; }
.pipeline .head.selected rect, .pipeline .cell.selected rect { stroke: var(--accent); stroke-width: 2; }
.pipeline .cell rect { fill: var(--surface); stroke: var(--line); }
.pipeline .cell.skipped rect { fill: var(--surface-2); stroke-dasharray: 4 3; }
.pipeline .cell.skipped text.big { font-size: 13px; font-weight: 500; fill: var(--muted); }
.pipeline .cell.failed rect { stroke: var(--bad); stroke-width: 2; }
.link { stroke: var(--muted); fill: none; stroke-width: 1.5; } .arrowhead { fill: var(--muted); }
.stage-panel { border-top: 1px solid var(--line); margin-top: 8px; padding-top: 8px; }
.stage-panel h3, .format-card h3, .card h3 { font-size: 1rem; margin: 12px 0 6px; }
table.facts, table.trace { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
table.facts th, table.facts td, table.trace th, table.trace td { border-bottom: 1px solid var(--line); padding: 5px 8px; text-align: left; vertical-align: top; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.diff { background: var(--decide-bg); font-weight: 600; }
.scroll { overflow-x: auto; }
tr.differs { background: var(--decide-bg); }
table.trace summary { cursor: pointer; }
.why { font-size: 0.85rem; color: var(--muted); margin: 4px 0 0 16px; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); border-left: 5px solid var(--c); font-size: 0.82rem; white-space: nowrap; }
.nav-graph .nav-item rect, .nav-graph .nav-file rect, .nav-graph .nav-media rect { fill: var(--surface-2); stroke: var(--line); }
.nav-graph .nav-item.module rect { fill: var(--structure-bg); }
.nav-graph .nav-item.module text { font-weight: 600; }
.nav-graph .nav-media text, .nav-graph .nav-file text { font-size: 11px; }
.format-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.format-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 14px 14px; background: var(--surface); }
.checks { list-style: none; padding: 0; margin: 8px 0; font-size: 0.88rem; }
.check { display: flex; gap: 8px; margin: 3px 0; } .check .mark { font-weight: 700; width: 1.2em; flex: none; }
.check.ok .mark { color: var(--note); } .check.warn .mark { color: var(--decide); } .check.fail .mark { color: var(--bad); }
ul.choices { list-style: none; margin: 4px 0; padding-left: 8px; font-size: 0.9rem; } ul.choices li.right { color: var(--note); font-weight: 600; }
.meta.warn { color: var(--decide); font-weight: 600; } .quiz > p { margin: 10px 0 0; }
pre.code { max-height: 320px; overflow: auto; background: var(--surface-2); padding: 8px; font-size: 12px; border-radius: 6px; }
.row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin: 8px 0; }
.meta { color: var(--muted); font-size: 0.88rem; }
.pill { border-radius: 5px; }
.form > .meta { grid-column: 1 / -1; margin: 0; }
#rise-sign-in input, #rise-text { padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; font: inherit; }
.rise-screen { display: block; width: 100%; margin: 8px 0; border: 1px solid var(--line); border-radius: 8px; cursor: crosshair; }
.rise-type { display: flex; gap: 8px; flex-wrap: wrap; }
.rise-job { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; }
.rise-job progress { grid-column: 1 / -1; width: 100%; }
.rise-job .where { grid-column: 1 / -1; }
.rise-job .links { display: flex; gap: 14px; }
.rise-uat, #rise-uat-why { grid-column: 1 / -1; }
#rise-file-list label { display: flex; gap: 8px; align-items: center; }
.rise-job .uat { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px 14px; }

#rise-sign-in[hidden], #rise-build[hidden] { display: none; }
.history-title { margin: 28px 0 4px; font-size: 1.1rem; }

.who-box { display: grid; justify-items: end; gap: 6px; }
.who { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; }
.sign-in { max-width: 420px; margin: 40px auto; }
body.signed-out .tabs, body.signed-out main > section[role="tabpanel"], body.signed-out .foot { display: none; }
table.facts a { white-space: nowrap; margin-right: 8px; }
.who[hidden], .sign-in[hidden] { display: none; }
.form.stacked { grid-template-columns: 1fr; max-width: 420px; align-items: stretch; }
.form.stacked h2 { margin: 0; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.page-title { font-size: 1.6rem; margin: 12px 0 6px; }
.table-card { padding: 0; overflow-x: auto; }
.table-card table.facts th, .table-card table.facts td { padding: 12px 16px; vertical-align: middle; }
.table-card td:last-child { text-align: right; }
.text-button { background: none; border: 0; padding: 4px 0; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer; }
.form.stacked .primary:disabled { cursor: not-allowed; }
dialog { width: min(420px, 92vw); padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgb(0 0 0 / 0.4); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
dialog .status { margin: 0; }
.form.stacked input { padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit; font-weight: 400; }
.top-tools { display: flex; align-items: center; gap: 12px; }
.theme-switch { position: relative; display: inline-flex; align-items: center; justify-content: space-between; width: 56px; height: 28px; padding: 0 6px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface-2); cursor: pointer; }
.theme-switch svg { position: relative; z-index: 1; width: 16px; height: 16px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: stroke 0.2s; }
.theme-switch .knob { position: absolute; top: 2px; left: 2px; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); transition: transform 0.2s; }
.theme-switch[aria-checked="true"] .knob { transform: translateX(28px); }
.theme-switch[aria-checked="false"] .sun, .theme-switch[aria-checked="true"] .moon { stroke: var(--accent-text); }
.theme-switch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .theme-switch .knob, .theme-switch svg { transition: none; } }
