:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #efede7;
  --text: #1b1c1f;
  --muted: #676a72;
  --faint: #9a9ca3;
  --line: #e2dfd7;
  --line-strong: #cfcbc0;
  --accent: #2f54d6;
  --accent-soft: #e5ebfd;
  --star: #c98a00;
  --open: #12805c;
  --open-soft: #e2f4ec;
  --unc: #a2541c;
  --unc-soft: #fbeee2;
  --shadow: 0 1px 2px rgb(20 20 30 / .06), 0 4px 14px rgb(20 20 30 / .04);
  --radius: 12px;
  --font: "Inter", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121316;
    --surface: #1a1c20;
    --surface-2: #23252b;
    --text: #ececef;
    --muted: #a1a4ad;
    --faint: #6f727b;
    --line: #2b2e35;
    --line-strong: #3b3f48;
    --accent: #8aa4ff;
    --accent-soft: #232c4a;
    --star: #f0b429;
    --open: #4fd1a1;
    --open-soft: #173328;
    --unc: #f0a36a;
    --unc-soft: #3a2618;
    --shadow: 0 1px 2px rgb(0 0 0 / .4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121316;
  --surface: #1a1c20;
  --surface-2: #23252b;
  --text: #ececef;
  --muted: #a1a4ad;
  --faint: #6f727b;
  --line: #2b2e35;
  --line-strong: #3b3f48;
  --accent: #8aa4ff;
  --accent-soft: #232c4a;
  --star: #f0b429;
  --open: #4fd1a1;
  --open-soft: #173328;
  --unc: #f0a36a;
  --unc-soft: #3a2618;
  --shadow: 0 1px 2px rgb(0 0 0 / .4);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 200px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 var(--font);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
a { color: var(--accent); }
.wrap { max-width: 980px; margin: 0 auto; padding: 0 16px; }

/* ---------- masthead ---------- */
.masthead { padding: 40px 0 20px; }
.eyebrow {
  margin: 0 0 4px;
  font: 600 12px/1 var(--mono);
  letter-spacing: .12em;
  color: var(--muted);
}
h1 {
  margin: 0;
  font-size: clamp(30px, 6vw, 44px);
  line-height: 1.15;
  letter-spacing: -.01em;
  font-weight: 800;
}
.lede { margin: 8px 0 22px; color: var(--muted); max-width: 46em; }

.histo {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 104px;
}
.histo button {
  flex: 1 1 0;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: stretch;
  gap: 4px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}
.histo .n { font: 600 11px/1 var(--mono); color: var(--muted); text-align: center; }
.histo .bar {
  display: block;
  flex: none;
  border-radius: 4px 4px 1px 1px;
  background: var(--accent);
  opacity: .78;
  min-height: 2px;
  transition: opacity .15s, transform .15s;
}
.histo .y { font: 500 11px/1 var(--mono); color: var(--faint); text-align: center; padding-top: 2px; }
.histo button:hover .bar, .histo button:focus-visible .bar { opacity: 1; }
.histo button:disabled { cursor: default; }
.histo button:disabled .bar { opacity: .2; }

/* ---------- toolbar ---------- */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
  padding: 10px 0 6px;
}
.row { display: flex; align-items: center; gap: 8px; }
.row + .row { margin-top: 8px; }
.row-main { flex-wrap: wrap; }
.search {
  flex: 1 1 220px;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 12px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
}
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search svg { width: 16px; height: 16px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; flex: none; }
.search input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: none;
  color: var(--text);
  font: inherit;
}
.seg {
  display: inline-flex;
  background: var(--surface-2);
  border-radius: 999px;
  padding: 3px;
}
.seg button {
  border: 0;
  background: none;
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
}
.seg button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }
.toggle {
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  cursor: pointer;
  font-size: 13.5px;
  white-space: nowrap;
}
.toggle[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }

.chips-row {
  overflow-x: auto;
  scrollbar-width: thin;
  padding-bottom: 4px;
  gap: 6px;
  mask-image: linear-gradient(90deg, #000 calc(100% - 24px), transparent);
  -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 24px), transparent);
  padding-right: 24px;
}
.chip {
  --c: var(--muted);
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
  color: var(--text);
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.chip small { color: var(--faint); font: 500 11px/1 var(--mono); }
.chip[aria-pressed="true"] {
  border-color: var(--c);
  background: color-mix(in srgb, var(--c) 16%, var(--surface));
  font-weight: 600;
}
.chip.type[aria-pressed="true"] { --c: var(--accent); }
.chip:disabled { opacity: .4; cursor: default; }
.chip-label { flex: none; font-size: 12px; color: var(--faint); margin-right: 2px; }
.status { justify-content: space-between; font-size: 13px; color: var(--muted); min-height: 22px; }
.link { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 0; font-size: 13px; }

/* ---------- timeline ---------- */
main { padding-top: 8px; padding-bottom: 40px; min-height: 50vh; }
.empty { color: var(--muted); padding: 40px 0; text-align: center; }
.year { margin-top: 28px; }
.year-h {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 0 0 4px;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -.01em;
  font-variant-numeric: tabular-nums;
}
.year-h span { font: 500 13px/1 var(--mono); color: var(--faint); }
.month-h {
  margin: 18px 0 6px 76px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: .04em;
}
.items { list-style: none; margin: 0; padding: 0; position: relative; }
.items::before {
  content: "";
  position: absolute;
  left: 66px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--line);
}
.item {
  --c: var(--muted);
  position: relative;
  display: grid;
  grid-template-columns: 54px 1fr;
  gap: 24px;
  padding: 5px 0;
}
.item::before {
  content: "";
  position: absolute;
  left: 61px;
  top: 21px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 0 3px var(--bg);
}
.item.key::before { width: 16px; height: 16px; left: 59px; top: 19px; box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px color-mix(in srgb, var(--c) 35%, transparent); }
.date {
  padding-top: 13px;
  text-align: right;
  font: 500 13px/1.3 var(--mono);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--c);
  border-radius: var(--radius);
  padding: 10px 14px 11px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.item.key .card { border-color: color-mix(in srgb, var(--c) 45%, var(--line)); border-left-color: var(--c); }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 5px 6px; margin-bottom: 2px; }
.lab {
  font-size: 12.5px;
  font-weight: 700;
  color: color-mix(in srgb, var(--c) 70%, var(--text));
}
.name { margin: 0; font-size: 16.5px; line-height: 1.4; font-weight: 700; overflow-wrap: anywhere; }
.name .star { color: var(--star); margin-left: 4px; font-size: 14px; }
.note { margin: 3px 0 0; color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.badge {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 7px;
  border-radius: 6px;
  font-size: 11.5px;
  line-height: 1;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}
.badge.open { background: var(--open-soft); color: var(--open); font-weight: 600; }
.badge.unc { background: var(--unc-soft); color: var(--unc); font-weight: 600; }
.badge.key { background: none; color: var(--star); padding: 0; font-size: 14px; }
.flash .card { animation: flash 1.6s ease-out; }
@keyframes flash {
  0%, 30% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--c) 45%, transparent); }
  100% { box-shadow: var(--shadow); }
}

/* ---------- lanes ---------- */
.lanes-note { color: var(--muted); font-size: 13px; margin: 14px 0 8px; }
.lanes-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.lanes { border-collapse: separate; border-spacing: 0; min-width: 100%; font-size: 12.5px; }
.lanes th, .lanes td { border-bottom: 1px solid var(--line); vertical-align: top; text-align: left; }
.lanes thead th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  font: 700 12px/1 var(--mono);
  padding: 10px 8px;
  color: var(--muted);
  white-space: nowrap;
}
.lanes tbody th {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--surface);
  padding: 10px 10px 10px 12px;
  font-weight: 700;
  white-space: nowrap;
  border-right: 1px solid var(--line);
  font-size: 13px;
}
.lanes thead th:first-child { left: 0; z-index: 2; position: sticky; border-right: 1px solid var(--line); }
.lanes tbody th .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--c); margin-right: 7px; }
.lanes tbody th small { display: block; color: var(--faint); font: 500 11px/1.4 var(--mono); padding-left: 16px; }
.lanes td { padding: 8px 6px; min-width: 132px; border-left: 1px solid var(--line); }
.lanes td:first-of-type { border-left: 0; }
.lanes tr:last-child th, .lanes tr:last-child td { border-bottom: 0; }
.pill {
  display: block;
  width: 100%;
  margin: 0 0 4px;
  padding: 3px 7px;
  border: 0;
  border-left: 3px solid var(--c);
  border-radius: 4px;
  background: color-mix(in srgb, var(--c) 9%, var(--surface));
  text-align: left;
  cursor: pointer;
  font-size: 12px;
  line-height: 1.35;
}
.pill:hover, .pill:focus-visible { background: color-mix(in srgb, var(--c) 20%, var(--surface)); }
.pill.key { font-weight: 700; }
.pill .m { display: block; font: 500 10.5px/1.2 var(--mono); color: var(--faint); }

/* ---------- footer ---------- */
.foot { padding-top: 24px; padding-bottom: 48px; border-top: 1px solid var(--line); color: var(--muted); font-size: 14px; }
.foot h2 { font-size: 15px; color: var(--text); margin: 18px 0 8px; }
.legend, .sources { margin: 0; padding-left: 18px; }
.legend li, .sources li { margin: 4px 0; }
.legend { list-style: none; padding-left: 0; }
.fine { font-size: 12.5px; color: var(--faint); }

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

@media (max-width: 640px) {
  html { scroll-padding-top: 12px; }
  .masthead { padding-top: 28px; }
  .toolbar { position: static; backdrop-filter: none; -webkit-backdrop-filter: none; background: var(--bg); }
  .histo { gap: 3px; }
  .histo .n, .histo .y { font-size: 10px; }
  .seg button { padding: 5px 10px; }
  .month-h { margin-left: 62px; }
  .items::before { left: 50px; }
  .item { grid-template-columns: 40px 1fr; gap: 22px; }
  .item::before { left: 45px; }
  .item.key::before { left: 43px; }
  .date { font-size: 12px; }
  .card { padding: 9px 12px 10px; }
  .name { font-size: 15.5px; }
  .note { font-size: 13.5px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
