/* Bugology — 缺陷研究記錄
 *
 * The reference is a clinical observation chart, not a dashboard. That is not a
 * decorative conceit: the data model is the same shape. A differential diagnosis
 * is several readings of one patient held at once — the Perspective Lens. An
 * amended diagnosis is struck through, dated and initialled, never erased — the
 * classification interval. A confirmatory test decides — the executable gate.
 *
 * So the page is set like a record: monospace for anything an instrument
 * produced (identifiers, timestamps, intervals, confidences), serif for anything
 * a person or an agent asserted. The two faces mark the difference between what
 * was measured and what was claimed, which is the distinction the whole system
 * turns on.
 *
 * Colour is semantic and rationed. Red appears only on a reading that has been
 * superseded — the annotation ink of a corrected chart. Green appears only where
 * an executable gate passed. Ochre marks a validated result now contested.
 * Nothing else is coloured, so the coloured things mean something.
 */

:root {
  --ground:      #e9ede6;   /* pale eye-ease stock, the colour of ruled lab paper */
  --ground-deep: #dfe4db;
  --card:        #f4f6f2;
  --rule:        #c3cdbf;
  --rule-soft:   #d6ddd1;
  --ink:         #1b2420;   /* blue-black, register ink */
  --ink-soft:    #5c6b62;
  --ink-faint:   #8b9890;

  --amend:       #a8321f;   /* superseded reading */
  --amend-soft:  #f0dcd6;
  --gate:        #1f5d4c;   /* executable gate passed */
  --gate-soft:   #d7e6e0;
  --flag:        #8a6a12;   /* contested / regressed */
  --flag-soft:   #f0e6cd;

  --f-record: ui-monospace, "SFMono-Regular", "Cascadia Mono", "Roboto Mono", Consolas, "Noto Sans Mono CJK TC", monospace;
  --f-prose: "Noto Serif TC", "Source Han Serif TC", "Songti TC", Georgia, "Times New Roman", serif;

  --page: min(1180px, calc(100% - 40px));
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--f-record);
  font-size: 14px;
  line-height: 1.6;
  /* The faint horizontal ruling of chart paper. Low enough contrast that it
     reads as stock rather than as a grid the content has to sit on. */
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0 31px,
    rgba(27, 36, 32, .035) 31px 32px
  );
}

a { color: inherit; }

/* Utility label: the printed field name on a form. Used for every section
   header, so section headers read as parts of one document. */
.label {
  font-family: var(--f-record);
  font-size: 10px;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 600;
  margin: 0 0 8px;
}

/* ─────────────────────────── masthead ─────────────────────────── */

.masthead {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
  width: var(--page);
  margin: 0 auto;
  padding: 18px 0 14px;
  background: var(--ground);
  border-bottom: 2px solid var(--ink);
}

.wordmark { text-decoration: none; display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.wordmark-name { font-size: 17px; font-weight: 700; letter-spacing: .34em; }
.wordmark-sub { font-family: var(--f-prose); font-size: 13px; color: var(--ink-soft); letter-spacing: .02em; }

.tabs { display: flex; gap: 2px; }
.tabs a {
  text-decoration: none;
  font-size: 11px;
  letter-spacing: .14em;
  padding: 7px 13px;
  color: var(--ink-soft);
  border: 1px solid transparent;
  border-bottom: none;
}
.tabs a:hover { color: var(--ink); background: var(--ground-deep); }
.tabs a[aria-current="page"] {
  color: var(--ink);
  background: var(--card);
  border-color: var(--rule);
  font-weight: 700;
}

main { width: var(--page); margin: 0 auto; padding: 34px 0 90px; }
.view { display: none; }
.view.is-active { display: block; }

.view-head { max-width: 66ch; margin: 0 0 30px; }
.view-head h1 { font-family: var(--f-prose); font-size: clamp(26px, 3.4vw, 38px); line-height: 1.2; margin: 0 0 12px; letter-spacing: -.01em; }
.view-head p { font-family: var(--f-prose); font-size: 15.5px; line-height: 1.85; color: var(--ink-soft); margin: 0; }
.view-head code { font-family: var(--f-record); font-size: .85em; background: var(--ground-deep); padding: .1em .4em; }

/* ─────────────────────────── the opening ───────────────────────────
   A page of the record, not a claim about it. */

.opening {
  border: 1px solid var(--rule);
  background: var(--card);
  padding: clamp(20px, 3vw, 34px);
  margin: 0 0 26px;
}
.opening-lede {
  font-family: var(--f-prose);
  font-size: clamp(20px, 2.6vw, 29px);
  line-height: 1.42;
  margin: 0 0 4px;
  max-width: 24ch;
  letter-spacing: -.01em;
}
.opening-sub { font-family: var(--f-prose); color: var(--ink-soft); font-size: 15px; line-height: 1.8; margin: 14px 0 26px; max-width: 52ch; }
.opening-body { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, .85fr); gap: clamp(20px, 3vw, 40px); align-items: start; }
.opening-cite { margin: 18px 0 0; }
.opening-cite a { font-size: 11px; letter-spacing: .1em; border-bottom: 1px solid var(--rule); text-decoration: none; padding-bottom: 2px; }
.opening-cite a:hover { border-color: var(--ink); }

/* ─────────────────────────── the belief chart ───────────────────────────
   The signature. Each classification is an interval — valid_from to valid_to —
   so it is drawn as one. A reading that ended is a closed bar struck in
   annotation red; the reading that replaced it runs to an open edge. Two
   revisions on one case are two visible breaks, before a word is read. */

.chart { border-top: 1px solid var(--ink); }
.chart-row {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  padding: 11px 0;
  border-bottom: 1px solid var(--rule-soft);
}
.chart-key { font-size: 10.5px; letter-spacing: .06em; color: var(--ink-soft); text-align: right; }
.chart-key b { display: block; color: var(--ink); font-weight: 700; }
.chart-track { position: relative; height: 34px; }

.bar {
  position: absolute;
  top: 4px;
  height: 26px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border: 1px solid var(--gate);
  background: var(--gate-soft);
  color: var(--gate);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  min-width: 0;
}
.bar-value { font-weight: 700; overflow: hidden; text-overflow: ellipsis; }
.bar-conf { font-size: 10px; opacity: .8; flex: none; }

.bar.is-superseded {
  border-color: var(--amend);
  background: var(--amend-soft);
  color: var(--amend);
}
/* The strike is the point: the reading is still legible, and plainly withdrawn. */
.bar.is-superseded .bar-value { text-decoration: line-through; text-decoration-thickness: 1px; }
/* An open right edge means "still current" — the interval has no end yet. */
.bar.is-current { border-right-style: dashed; }

.bar.is-dim { opacity: .26; }
.bar { transition: opacity .18s ease; }

.chart-axis {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--ink-faint);
  padding: 7px 0 0;
  letter-spacing: .06em;
}

/* ─────────────────────────── corpus strip ─────────────────────────── */

.corpus { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1px; background: var(--rule); border: 1px solid var(--rule); margin: 0 0 34px; }
.corpus-cell { background: var(--card); padding: 15px 17px; }
.corpus-cell b { display: block; font-size: 27px; font-weight: 700; letter-spacing: -.03em; line-height: 1.1; }
.corpus-cell span { font-size: 10.5px; color: var(--ink-soft); letter-spacing: .06em; }
.corpus-cell p { font-family: var(--f-prose); font-size: 12.5px; color: var(--ink-faint); margin: 7px 0 0; line-height: 1.55; }
.corpus-cell.is-accent b { color: var(--amend); }

.tally { display: flex; flex-wrap: wrap; gap: 5px; margin: 9px 0 0; }
.tally span { font-size: 10px; padding: 2px 6px; border: 1px solid var(--rule); color: var(--ink-soft); }

/* ─────────────────────────── case index ─────────────────────────── */

.records-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; flex-wrap: wrap; margin: 0 0 12px; }
.records-head h2 { margin: 0; }
.filters { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field .label { margin: 0; }
.field input[type="search"], .field select {
  font: inherit;
  font-size: 12.5px;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--rule);
  padding: 7px 9px;
  min-width: 148px;
}
.field input[type="search"] { min-width: 210px; }
.field.checkbox { flex-direction: row; align-items: center; gap: 7px; font-size: 12px; color: var(--ink-soft); padding-bottom: 7px; }

.case-index { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--ink); }
.case-row {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr) 168px 118px;
  gap: 16px;
  align-items: baseline;
  padding: 15px 6px;
  border-bottom: 1px solid var(--rule-soft);
  text-decoration: none;
  color: inherit;
}
.case-row:hover { background: var(--card); }
.case-row:focus-visible { outline: 2px solid var(--ink); outline-offset: -2px; }
.case-id { font-size: 11.5px; color: var(--ink-soft); letter-spacing: .04em; }
.case-title { font-family: var(--f-prose); font-size: 16px; line-height: 1.45; }
.case-title small { display: block; font-family: var(--f-record); font-size: 10.5px; color: var(--ink-faint); margin-top: 5px; letter-spacing: .05em; }
.case-lenses { display: flex; flex-wrap: wrap; gap: 4px; }
.case-lenses span { font-size: 9.5px; letter-spacing: .07em; padding: 2px 5px; border: 1px solid var(--rule); color: var(--ink-soft); }
.case-meta { text-align: right; font-size: 10.5px; color: var(--ink-soft); }
.revised { color: var(--amend); display: block; margin-top: 4px; }

.state {
  display: inline-block;
  font-size: 10px;
  letter-spacing: .09em;
  padding: 3px 7px;
  border: 1px solid var(--rule);
  background: var(--ground-deep);
  color: var(--ink-soft);
  white-space: nowrap;
}
.state.is-validated { border-color: var(--gate); background: var(--gate-soft); color: var(--gate); }
.state.is-regressed, .state.is-unresolved { border-color: var(--flag); background: var(--flag-soft); color: var(--flag); }

.empty { font-family: var(--f-prose); color: var(--ink-soft); padding: 34px 6px; border-bottom: 1px solid var(--rule-soft); }

/* ─────────────────────────── case reader ─────────────────────────── */

.reader-top { border-bottom: 2px solid var(--ink); padding: 0 0 20px; margin: 0 0 26px; }
.backlink { font-size: 11px; letter-spacing: .1em; color: var(--ink-soft); text-decoration: none; }
.backlink:hover { color: var(--ink); }
.reader-title { font-family: var(--f-prose); font-size: clamp(24px, 3.2vw, 36px); line-height: 1.24; margin: 14px 0 12px; max-width: 26ch; letter-spacing: -.01em; }
.reader-facts { display: flex; flex-wrap: wrap; gap: 10px 22px; font-size: 11px; color: var(--ink-soft); }
.reader-facts b { color: var(--ink); font-weight: 600; }
.reader-summary { font-family: var(--f-prose); font-size: 16.5px; line-height: 1.85; color: var(--ink-soft); max-width: 62ch; margin: 18px 0 0; }

.reader-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 300px); gap: clamp(22px, 3.4vw, 46px); align-items: start; }

.block { margin: 0 0 34px; }
.block > h3 { margin: 0 0 12px; }

/* The lens switcher: the same defect, re-described. Canon invariant 8 says
   several readings hold at once, so this does not filter — it re-narrates. */
.lens-switch { display: flex; flex-wrap: wrap; gap: 4px; margin: 0 0 14px; }
.lens-switch button {
  font: inherit;
  font-size: 10.5px;
  letter-spacing: .08em;
  padding: 6px 11px;
  background: var(--card);
  color: var(--ink-soft);
  border: 1px solid var(--rule);
  cursor: pointer;
}
.lens-switch button:hover { color: var(--ink); border-color: var(--ink-faint); }
.lens-switch button[aria-pressed="true"] { background: var(--ink); color: var(--ground); border-color: var(--ink); font-weight: 700; }

.lens-said {
  font-family: var(--f-prose);
  font-size: 17px;
  line-height: 1.82;
  border-left: 3px solid var(--ink);
  padding: 2px 0 2px 20px;
  margin: 0;
  min-height: 4.4em;
}
.lens-said cite { display: block; font-family: var(--f-record); font-style: normal; font-size: 10.5px; color: var(--ink-faint); letter-spacing: .07em; margin-top: 12px; }
.lens-said.is-swapping { opacity: 0; }
.lens-said { transition: opacity .16s ease; }

/* Observation column — dated entries down a ruled spine. */
.observations { list-style: none; margin: 0; padding: 0 0 0 22px; border-left: 1px solid var(--rule); }
.observations li { position: relative; padding: 0 0 20px; }
.observations li::before {
  content: "";
  position: absolute;
  left: -26px;
  top: 7px;
  width: 7px;
  height: 7px;
  background: var(--ground);
  border: 1px solid var(--ink-soft);
  border-radius: 50%;
}
.observations li.is-turn::before { background: var(--amend); border-color: var(--amend); }
.obs-when { font-size: 10.5px; color: var(--ink-faint); letter-spacing: .05em; }
.obs-state { font-size: 10px; letter-spacing: .09em; color: var(--ink-soft); margin-left: 8px; }
.obs-text { font-family: var(--f-prose); font-size: 14.5px; line-height: 1.7; margin: 5px 0 0; }

.stack { list-style: none; margin: 0; padding: 0; }
.stack li { border-top: 1px solid var(--rule-soft); padding: 11px 0; }
.stack li:first-child { border-top: 1px solid var(--rule); }
.stack-kind { font-size: 9.5px; letter-spacing: .1em; color: var(--ink-faint); }
.stack-text { font-family: var(--f-prose); font-size: 14px; line-height: 1.68; margin: 4px 0 0; }
.stack .refuted .stack-text { color: var(--amend); }
.stack .refuted .stack-text::before { content: "已推翻 · "; font-family: var(--f-record); font-size: 10px; letter-spacing: .08em; }
.stack .rejected .stack-text::before { content: "未採用 · "; font-family: var(--f-record); font-size: 10px; letter-spacing: .08em; color: var(--amend); }

.gate-card { border: 1px solid var(--gate); background: var(--gate-soft); padding: 16px; }
.gate-card.is-contested { border-color: var(--flag); background: var(--flag-soft); }
.gate-line { display: flex; justify-content: space-between; gap: 12px; font-size: 11.5px; padding: 4px 0; }
.gate-line b { font-weight: 700; }
.gate-note { font-family: var(--f-prose); font-size: 13px; line-height: 1.65; margin: 12px 0 0; color: var(--flag); }

.side-note { font-family: var(--f-prose); font-size: 13px; line-height: 1.7; color: var(--ink-soft); border-top: 1px solid var(--rule); padding: 12px 0 0; }

.rel { list-style: none; margin: 0; padding: 0; font-size: 11.5px; }
.rel li { padding: 6px 0; border-bottom: 1px solid var(--rule-soft); display: flex; gap: 8px; }
.rel em { font-style: normal; color: var(--ink-faint); }

/* ─────────────────────────── units & patterns ─────────────────────────── */

.units { display: grid; gap: 1px; background: var(--rule); border: 1px solid var(--rule); }
.unit { background: var(--card); padding: clamp(18px, 2.4vw, 26px); display: grid; grid-template-columns: minmax(0, 1fr) 210px; gap: 26px; align-items: start; }
.unit h2 { font-family: var(--f-prose); font-size: 20px; line-height: 1.35; margin: 8px 0 10px; }
.unit p { font-family: var(--f-prose); font-size: 14.5px; line-height: 1.75; color: var(--ink-soft); margin: 0 0 10px; max-width: 62ch; }
.unit dl { display: grid; grid-template-columns: 76px minmax(0, 1fr); gap: 5px 14px; margin: 14px 0 0; font-size: 12.5px; }
.unit dt { font-size: 10px; letter-spacing: .09em; color: var(--ink-faint); padding-top: 3px; }
.unit dd { font-family: var(--f-prose); margin: 0; line-height: 1.6; }

.patterns { display: grid; gap: 20px; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.pattern { border: 1px solid var(--rule); background: var(--card); padding: clamp(18px, 2.4vw, 26px); }
.pattern h2 { font-family: var(--f-prose); font-size: 21px; line-height: 1.3; margin: 9px 0 12px; }
.pattern > p { font-family: var(--f-prose); font-size: 14.5px; line-height: 1.78; color: var(--ink-soft); margin: 0 0 16px; }
.pattern-part { border-top: 1px solid var(--rule-soft); padding: 12px 0 0; margin: 12px 0 0; }
.pattern-part ul { margin: 6px 0 0; padding-left: 17px; font-family: var(--f-prose); font-size: 13.5px; line-height: 1.7; color: var(--ink-soft); }
/* A pattern that cannot say where it stops has not been thought through. */
.pattern-part.is-exception ul { color: var(--amend); }

/* ─────────────────────────── report ─────────────────────────── */

.report-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 20px; align-items: start; }
.report-card { border: 1px solid var(--rule); background: var(--card); padding: clamp(18px, 2.4vw, 26px); }
.report-card h2 { font-family: var(--f-prose); font-size: 19px; margin: 8px 0 12px; }
.report-card p { font-family: var(--f-prose); font-size: 14.5px; line-height: 1.78; color: var(--ink-soft); margin: 0 0 12px; }
.report-card.is-wide { grid-column: 1 / -1; }

pre {
  font-family: var(--f-record);
  font-size: 12px;
  line-height: 1.65;
  background: var(--ground-deep);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--ink);
  padding: 15px 16px;
  overflow-x: auto;
  margin: 0 0 12px;
}
code { font-family: var(--f-record); }

.tools { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 1px; background: var(--rule); border: 1px solid var(--rule); }
.tool { background: var(--card); padding: 10px 12px; }
.tool b { display: block; font-size: 11.5px; font-weight: 700; }
.tool span { font-family: var(--f-prose); font-size: 12px; color: var(--ink-soft); line-height: 1.5; }

.warn { border-left: 3px solid var(--amend); padding: 2px 0 2px 16px; font-family: var(--f-prose); font-size: 14px; line-height: 1.75; color: var(--amend); margin: 16px 0 0; }

/* ─────────────────────────── colophon ─────────────────────────── */

.colophon {
  width: var(--page);
  margin: 0 auto;
  padding: 26px 0 60px;
  border-top: 2px solid var(--ink);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 28px;
}
.colophon p { font-family: var(--f-prose); font-size: 12.5px; line-height: 1.7; color: var(--ink-soft); margin: 0; max-width: 44ch; }
.colophon .label { font-family: var(--f-record); }
.endpoints { list-style: none; margin: 0; padding: 0; font-size: 11.5px; }
.endpoints a { text-decoration: none; border-bottom: 1px solid var(--rule); }
.endpoints a:hover { border-color: var(--ink); }

/* ─────────────────────────── quality floor ─────────────────────────── */

:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

@media (max-width: 900px) {
  .opening-body, .reader-grid, .unit { grid-template-columns: 1fr; }
  .case-row { grid-template-columns: 78px minmax(0, 1fr); }
  .case-lenses, .case-meta { grid-column: 2; text-align: left; }
  .chart-row { grid-template-columns: 104px minmax(0, 1fr); gap: 10px; }
}

@media (max-width: 560px) {
  :root { --page: calc(100% - 26px); }
  body { font-size: 13.5px; }
  .tabs { width: 100%; }
  .tabs a { flex: 1; text-align: center; padding: 8px 4px; }
  .filters { width: 100%; }
  .field, .field input[type="search"], .field select { width: 100%; min-width: 0; }
  .chart-row { grid-template-columns: 1fr; gap: 4px; }
  .chart-key { text-align: left; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

@media print {
  body { background: #fff; }
  .masthead, .tabs, .filters, .lens-switch { display: none; }
}
