/* 电讯台 — the wire desk. 昼刊 light / 夜盘 dark, one typographic system.
   Light reads as a hot-paper newsroom; dark as a night trading desk.
   System CJK stacks only: the site must load instantly inside China, so the
   identity is carried by rules, ink and composition — never webfonts.
   Theme contract: default follows prefers-color-scheme via media query; an
   explicit html[data-theme="light"|"dark"] set by the toggle always wins. */

:root {
  color-scheme: light;
  --paper: #f6f1e5;
  --paper-raised: #fdfaf1;
  --paper-sunken: #ece5d2;
  --ink: #1b1810;
  --ink-soft: #5d564a;
  --ink-faint: #746c5d;
  --hairline: #d3c8af;
  --rule: #1b1810;
  --accent: #b23722;
  --accent-soft: rgba(178, 55, 34, 0.07);
  --brand-dot: #b23722;
  --link: #2c4a78;
  --link-soft: rgba(44, 74, 120, 0.08);
  --grain-a: rgba(27, 24, 16, 0.013);
  --grain-b: rgba(27, 24, 16, 0.008);
  --lift: 0 1px 0 rgba(27, 24, 16, 0.04);
  --serif: Georgia, "Times New Roman", "Songti SC", "Noto Serif CJK SC", SimSun, serif;
  --sans: "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Consolas, "Courier New", monospace;
}

/* Dark tokens exist twice on purpose: once for the OS preference, once for the
   explicit override. No preprocessor, and light-dark() is too new for the older
   Chromium cores common in domestic browsers. Keep both blocks identical. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --paper: #14120c;
    --paper-raised: #1c1912;
    --paper-sunken: #0e0c08;
    --ink: #e9e1cd;
    --ink-soft: #a89d85;
    --ink-faint: #89816c;
    --hairline: #37311f;
    --rule: #d8cfb6;
    --accent: #e0603f;
    --accent-soft: rgba(224, 96, 63, 0.12);
    --brand-dot: #d9a441;
    --link: #92b0d8;
    --link-soft: rgba(146, 176, 216, 0.1);
    --grain-a: rgba(233, 225, 205, 0.012);
    --grain-b: rgba(233, 225, 205, 0.007);
    --lift: 0 1px 0 rgba(0, 0, 0, 0.35);
  }
  :root:not([data-theme="light"]) .only-light { display: none; }
  :root:not([data-theme="light"]) .only-dark { display: inline; }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #14120c;
  --paper-raised: #1c1912;
  --paper-sunken: #0e0c08;
  --ink: #e9e1cd;
  --ink-soft: #a89d85;
  --ink-faint: #89816c;
  --hairline: #37311f;
  --rule: #d8cfb6;
  --accent: #e0603f;
  --accent-soft: rgba(224, 96, 63, 0.12);
  --brand-dot: #d9a441;
  --link: #92b0d8;
  --link-soft: rgba(146, 176, 216, 0.1);
  --grain-a: rgba(233, 225, 205, 0.012);
  --grain-b: rgba(233, 225, 205, 0.007);
  --lift: 0 1px 0 rgba(0, 0, 0, 0.35);
}
:root[data-theme="dark"] .only-light { display: none; }
:root[data-theme="dark"] .only-dark { display: inline; }
.only-dark { display: none; }

html { background: var(--paper); }
body {
  margin: 0;
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.6;
  /* Paper grain: two faint interleaved gradients, no image request. */
  background:
    repeating-linear-gradient(0deg, transparent 0 2px, var(--grain-a) 2px 3px),
    repeating-linear-gradient(90deg, transparent 0 3px, var(--grain-b) 3px 4px),
    var(--paper);
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
::selection { background: var(--accent); color: var(--paper); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.shell { max-width: 72rem; margin: 0 auto; padding: 0 1.25rem 4rem; }

/* ---- masthead: broadsheet nameplate, double rule drawn in on load ---- */
.masthead { padding: 1.5rem 0 0; }
.masthead-row {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap;
}
.brand { margin: 0; font-family: var(--serif); font-size: 2.1rem; font-weight: 700; letter-spacing: 0.32em; }
.brand a { color: var(--ink); }
.brand a:hover { text-decoration: none; }
.brand em { font-style: normal; color: var(--brand-dot); }
.masthead-side { display: flex; align-items: center; gap: 0.75rem; }
.masthead-meta {
  font-family: var(--mono); font-size: 0.7rem; letter-spacing: 0.14em;
  color: var(--ink-faint); overflow-wrap: anywhere;
}
.masthead-action { display: contents; }
.masthead-link {
  font-family: var(--mono); font-size: 0.7rem; letter-spacing: 0.14em;
  color: var(--ink-soft); background: none; border: 0; padding: 0;
  cursor: pointer; text-decoration: none;
}
.masthead-link:hover { color: var(--ink); text-decoration: underline; }
.theme-toggle {
  border: 1px solid var(--hairline); background: var(--paper-raised); color: var(--ink-soft);
  font-size: 0.85rem; line-height: 1; padding: 0.3rem 0.5rem; border-radius: 2px; cursor: pointer;
  transition: border-color 0.12s, color 0.12s;
}
.theme-toggle:hover { border-color: var(--ink); color: var(--ink); }
.masthead::after {
  content: ""; display: block; margin-top: 0.75rem; height: 3px;
  border-top: 3px solid var(--rule); border-bottom: 1px solid var(--rule);
  animation: rule-draw 0.6s ease-out both;
}
@keyframes rule-draw { from { transform: scaleX(0); transform-origin: left; } }

/* ---- console: search + filters, kept in reach while the wire scrolls ---- */
.console {
  position: sticky; top: 0; z-index: 20;
  margin: 0 -1.25rem; padding: 0.85rem 1.25rem 0.65rem;
  background: var(--paper);
  background: color-mix(in srgb, var(--paper) 90%, transparent);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--hairline);
}
.search { display: flex; border: 1.5px solid var(--ink); background: var(--paper-raised); }
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.search input {
  flex: 1; border: 0; background: transparent; padding: 0.5rem 0.75rem;
  font: inherit; color: var(--ink); outline: none;
}
.search input::placeholder { color: var(--ink-faint); }
.search button {
  border: 0; background: var(--ink); color: var(--paper); font: inherit; font-size: 0.85rem;
  padding: 0 1.2rem; cursor: pointer; letter-spacing: 0.3em; text-indent: 0.3em;
}
.search button:hover { background: var(--accent); }

.filter-row { display: flex; gap: 0.35rem 0.4rem; flex-wrap: wrap; align-items: center; padding-top: 0.55rem; }
.filter-label {
  font-family: var(--mono); font-size: 0.64rem; letter-spacing: 0.22em;
  color: var(--ink-faint); margin-right: 0.2rem;
}
.chip {
  font-family: inherit; font-size: 0.74rem; padding: 0.13rem 0.6rem;
  border: 1px solid var(--hairline); background: var(--paper-raised);
  color: var(--ink-soft); border-radius: 2px; cursor: pointer;
  transition: border-color 0.12s, color 0.12s, background-color 0.12s;
}
.chip:hover { border-color: var(--ink); color: var(--ink); text-decoration: none; }
.chip.on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.date-input {
  font-family: var(--mono); font-size: 0.74rem; color: var(--ink-soft);
  border: 1px solid var(--hairline); background: var(--paper-raised);
  border-radius: 2px; padding: 0.08rem 0.35rem;
}
.date-input:focus { border-color: var(--accent); outline: none; color: var(--ink); }
.date-sep { color: var(--ink-faint); font-size: 0.74rem; }

.wire-status {
  display: flex; justify-content: flex-end; align-items: center; gap: 0.4rem;
  padding: 0.55rem 0 0; font-family: var(--mono); font-size: 0.66rem;
  letter-spacing: 0.14em; color: var(--ink-faint);
}
.live-dot {
  width: 0.5rem; height: 0.5rem; border-radius: 50%; background: var(--accent);
  animation: pulse 2s ease-in-out infinite;
}
/* Once the reader pages back in time, polling stops (feed.html trigger
   condition) — the live promise must disappear with it. */
body[data-paged] .wire-status { display: none; }
@keyframes pulse { 50% { opacity: 0.25; } }

/* ---- the wire: time gutter | rule | entry ---- */
.wire { list-style: none; margin: 0; padding: 0; }
.wire-row {
  display: grid; grid-template-columns: 4.8rem 1px minmax(0, 1fr); gap: 0 1rem;
  margin: 0 -0.5rem; padding: 0.55rem 0.5rem 0.6rem;
  border-bottom: 1px solid var(--hairline);
  transition: background-color 0.12s;
  animation: row-in 0.28s ease-out both;
}
.wire-row:hover { background: var(--paper-raised); }
.wire-row:nth-child(2) { animation-delay: 30ms; }
.wire-row:nth-child(3) { animation-delay: 60ms; }
.wire-row:nth-child(4) { animation-delay: 90ms; }
.wire-row:nth-child(5) { animation-delay: 120ms; }
.wire-row:nth-child(6) { animation-delay: 150ms; }
.wire-row:nth-child(7) { animation-delay: 180ms; }
.wire-row:nth-child(8) { animation-delay: 210ms; }
@keyframes row-in { from { opacity: 0; } }

.wire-time {
  display: flex; flex-direction: column; align-items: flex-end;
  padding-top: 0.15rem; font-family: var(--mono); white-space: nowrap;
}
.wire-date { font-size: 0.62rem; letter-spacing: 0.08em; color: var(--ink-faint); }
.wire-clock { font-size: 0.86rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.wire-rule { background: var(--hairline); }
.wire-row:hover .wire-rule { background: var(--accent); }

.wire-title { font-family: var(--serif); font-size: 1rem; font-weight: 600; line-height: 1.45; overflow-wrap: anywhere; }
.wire-title a { color: var(--ink); }
.wire-title a:hover { color: var(--accent); text-decoration: none; }
.wire-title .untranslated { color: var(--ink-soft); font-weight: 400; font-family: var(--sans); font-size: 0.92rem; }
.wire-meta { display: flex; gap: 0.3rem 0.5rem; flex-wrap: wrap; align-items: center; margin-top: 0.3rem; }

/* seal-style source stamp */
.stamp {
  font-family: var(--mono); font-size: 0.64rem; letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--accent); border: 1px solid var(--accent); border-radius: 2px;
  padding: 0 0.35rem; background: var(--accent-soft);
}
.badge {
  font-family: var(--mono); font-size: 0.62rem; letter-spacing: 0.16em; text-indent: 0.16em;
  padding: 0.05rem 0.4rem; border-radius: 2px; background: var(--ink); color: var(--paper);
}
.badge.infer { background: transparent; color: var(--accent); border: 1px dashed var(--accent); }
.badge.failed { background: transparent; color: var(--ink-faint); border: 1px solid var(--rule); }
.symbol {
  font-family: var(--mono); font-size: 0.7rem; color: var(--link);
  background: var(--link-soft); padding: 0 0.3rem; border-radius: 2px;
}
.symbol:hover { text-decoration: none; box-shadow: inset 0 0 0 1px var(--link); }
.category { font-size: 0.68rem; color: var(--ink-faint); }
.category::before { content: "·"; margin-right: 0.3rem; color: var(--hairline); }

.load-more {
  display: block; width: 100%; margin: 1.3rem 0; padding: 0.6rem;
  font: inherit; font-family: var(--mono); font-size: 0.8rem;
  letter-spacing: 0.5em; text-indent: 0.5em; cursor: pointer;
  border: 1.5px solid var(--ink); background: transparent; color: var(--ink);
  transition: background-color 0.12s, color 0.12s;
}
.load-more:hover { background: var(--ink); color: var(--paper); }
.wire-empty { padding: 3.5rem 0; text-align: center; color: var(--ink-soft); font-family: var(--serif); }

/* ---- detail ---- */
.detail-title {
  font-family: var(--serif); font-size: 1.75rem; line-height: 1.4;
  margin: 1.5rem 0 0.45rem; overflow-wrap: anywhere;
}
.detail-meta {
  display: flex; gap: 0.4rem 0.5rem; flex-wrap: wrap; align-items: center;
  margin-bottom: 1.4rem; padding-bottom: 1rem; border-bottom: 1px solid var(--hairline);
}
.detail-time { font-family: var(--mono); font-size: 0.8rem; letter-spacing: 0.06em; color: var(--ink-soft); }

.columns { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 2.4rem; align-items: start; }
@media (max-width: 52rem) { .columns { grid-template-columns: minmax(0, 1fr); } }

/* Long-form: two columns turn a 30,000-character article into two narrow towers, so it
   reads as one column instead — the Chinese first, the source record under it, both
   held to a measure rather than the full 72rem shell. */
.columns.stacked { grid-template-columns: minmax(0, 1fr); gap: 2.6rem; }
/* Source first, Chinese under it — the reading order of a record, and the order the
   markup is already in. The measure is held by the whole column, not by the text inside
   it: clamping only the paragraph leaves a full-width card with type in its left half. */
.columns.stacked > section { max-width: 64rem; }

.source-fold > summary {
  font-family: var(--mono); font-size: 0.72rem; letter-spacing: 0.08em;
  color: var(--link); cursor: pointer; padding: 0.2rem 0;
}
.source-fold > summary:hover { color: var(--accent); }
.source-fold[open] > summary { color: var(--ink-faint); margin-bottom: 0.5rem; }
.col-label {
  font-family: var(--mono); font-size: 0.68rem; letter-spacing: 0.3em; color: var(--ink-faint);
  border-bottom: 2px solid var(--rule); padding-bottom: 0.35rem; margin-bottom: 0.9rem;
}
.source-block {
  border: 1px solid var(--hairline); background: var(--paper-raised);
  padding: 0.85rem 1rem; margin-bottom: 0.9rem; box-shadow: var(--lift);
}
.source-block header { display: flex; gap: 0.5rem; align-items: baseline; flex-wrap: wrap; margin-bottom: 0.45rem; }
.source-block .when { font-family: var(--mono); font-size: 0.68rem; color: var(--ink-faint); }
.source-block .who { font-size: 0.74rem; color: var(--ink-soft); }
.source-block .revised { font-family: var(--mono); font-size: 0.66rem; color: var(--ink-faint); font-style: italic; }
.source-text { margin: 0 0 0.4rem; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 0.9rem; line-height: 1.65; }
.source-link { font-family: var(--mono); font-size: 0.72rem; }
.translation {
  font-family: var(--serif); font-size: 1.02rem; line-height: 1.8;
  white-space: pre-wrap; overflow-wrap: anywhere; margin: 0 0 0.5rem;
}

.panel {
  border: 1px solid var(--hairline); background: var(--paper-raised);
  padding: 1rem 1.1rem; margin-top: 1.1rem; box-shadow: var(--lift);
}
.panel-label {
  font-family: var(--mono); font-size: 0.66rem; letter-spacing: 0.26em;
  color: var(--ink-faint); margin-bottom: 0.5rem;
}
.panel.summary { border-left: 3px solid var(--rule); }
/* Inference must look different from record: dashed vermilion, tinted field. */
.panel.inference { border: 1.5px dashed var(--accent); background: var(--accent-soft); }
.panel.inference .panel-label { color: var(--accent); }
.note { font-size: 0.78rem; color: var(--ink-soft); font-style: italic; }

.symbol-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.symbol-table th {
  font-family: var(--mono); font-size: 0.64rem; letter-spacing: 0.15em; text-align: left;
  color: var(--ink-faint); border-bottom: 1px solid var(--rule); padding: 0.2rem 0.4rem;
}
.symbol-table td { border-bottom: 1px solid var(--hairline); padding: 0.32rem 0.4rem; }
.conf {
  display: inline-block; width: 5rem; height: 0.4rem; margin-right: 0.4rem;
  background: var(--paper-sunken); border-radius: 2px; overflow: hidden; vertical-align: middle;
}
.conf i { display: block; height: 100%; background: var(--link); }

.backlink { display: inline-block; margin-top: 1.8rem; font-family: var(--mono); font-size: 0.76rem; letter-spacing: 0.1em; }

.auth { max-width: 24rem; margin: 3rem auto 0; }
.auth .panel { margin-top: 0; }
.auth form { display: grid; gap: 0.3rem; margin-bottom: 0.8rem; }
.auth label {
  font-family: var(--mono); font-size: 0.66rem; letter-spacing: 0.2em;
  color: var(--ink-faint); margin-top: 0.5rem;
}
.auth input {
  border: 1.5px solid var(--ink); background: var(--paper-raised);
  padding: 0.5rem 0.75rem; font: inherit; color: var(--ink); outline: none;
}
.auth input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.auth button {
  margin-top: 0.9rem; border: 0; background: var(--ink); color: var(--paper);
  font: inherit; font-size: 0.85rem; padding: 0.55rem 1.2rem; cursor: pointer;
  letter-spacing: 0.3em; text-indent: 0.3em;
}
.auth button:hover { background: var(--accent); }
.auth-lead { margin: 0 0 0.6rem; font-size: 0.9rem; }
.auth-error {
  border: 1.5px dashed var(--accent); background: var(--accent-soft); color: var(--accent);
  padding: 0.5rem 0.7rem; margin: 0 0 0.7rem; font-size: 0.82rem;
}
.footer {
  margin-top: 3.2rem; padding-top: 0.9rem; border-top: 3px double var(--hairline);
  font-family: var(--mono); font-size: 0.68rem; letter-spacing: 0.08em; color: var(--ink-faint);
}

@media (max-width: 40rem) {
  .shell { padding: 0 0.9rem 3rem; }
  .console { margin: 0 -0.9rem; padding: 0.7rem 0.9rem 0.55rem; }
  .brand { font-size: 1.6rem; }
  .wire-row { grid-template-columns: 3.6rem 1px minmax(0, 1fr); gap: 0 0.7rem; }
  .detail-title { font-size: 1.4rem; }
}

@media (prefers-reduced-motion: reduce) {
  .masthead::after, .wire-row, .live-dot { animation: none; }
}
