:root {
  --page: #0d0c0a;
  --bg: #161513;
  --surface-1: #201e1c;
  --surface-2: #2a2724;
  --line: rgba(244, 240, 233, 0.11);
  --line-strong: rgba(244, 240, 233, 0.24);
  --text: rgba(248, 245, 239, 0.97);
  --text-2: rgba(248, 245, 239, 0.72);
  --text-3: rgba(248, 245, 239, 0.52);
  --accent: #ff5c00;
  --accent-soft: rgba(255, 92, 0, 0.13);
  --accent-line: rgba(255, 92, 0, 0.50);
  --mark-bg: #ff5c00;
  --mark-fg: #000000;
  --link: #89aadc;
  --link-hover: #a2bce2;

  --swatch-1: var(--surface-2);
  --swatch-2: var(--surface-2);
  --swatch-3: var(--surface-2);
  --swatch-4: var(--surface-2);

  --sb-track: #0d0c0a;
  --sb-thumb: #4a463f;
  --sb-thumb-hi: #6a635a;

  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --serif: "Songti SC", "Noto Serif CJK SC", "Source Han Serif SC", "SimSun", Georgia, serif;
  --mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", Menlo, Consolas, "Liberation Mono", "Noto Sans Mono CJK SC", monospace;

  --fs-label: 11px;
  --fs-micro: 11px;
  --fs-small: 13px;
  --fs-base: 13px;
  --fs-prose: 13px;
  --fs-h3: 16px;
  --fs-h2: 16px;
  --fs-title: 24px;
  --fs-hero: 40px;

  --radius: 0;
  --sidebar-width: 264px;

  --t-state: 0.12s;
  --t-open: 0.18s;
  --t-reflow: 0.24s;
  --ease: cubic-bezier(0.2, 0, 0, 1);
}

[data-theme="light"] {
  --page: #e4e4df;
  --bg: #f2f2f0;
  --surface-1: #eaeae6;
  --surface-2: #deded8;
  --line: rgba(17, 17, 16, 0.10);
  --line-strong: rgba(17, 17, 16, 0.22);
  --text: #111110;
  --text-2: #6b6b68;
  --text-3: #a3a3a0;
  --accent: #c2410c;
  --accent-soft: rgba(194, 65, 12, 0.10);
  --accent-line: rgba(194, 65, 12, 0.50);
  --mark-bg: #e6cb74;
  --mark-fg: #111110;
  --link: #3f6acf;
  --link-hover: #2f57b8;

  --swatch-1: #eee6d6;
  --swatch-2: #d7e3ee;
  --swatch-3: #dce6d2;
  --swatch-4: #f2d8dc;

  --sb-track: #e4e4df;
  --sb-thumb: #b5b2a8;
  --sb-thumb-hi: #8d8a80;
}



* {
  box-sizing: border-box;
  scrollbar-width: none;
}

::-webkit-scrollbar { width: 0; height: 0; display: none; }

.sb {
  position: absolute;
  background: var(--sb-track);
  z-index: 30;
  user-select: none;
}
.sb.hidden { display: none; }
.sb-v { top: 0; right: 0; bottom: 0; width: 11px; border-left: 1px solid var(--line); }
.sb-h { left: 0; right: 0; bottom: 0; height: 11px; border-top: 1px solid var(--line); }
.sb-window {
  position: fixed;
  top: 52px;
  right: 0;
  bottom: 0;
}
.sb-thumb {
  position: absolute;
  background: var(--sb-thumb);
  border: 1px solid var(--sb-thumb-hi);
}
.sb-v .sb-thumb { left: 1px; right: 1px; min-height: 28px; }
.sb-h .sb-thumb { top: 1px; bottom: 1px; min-width: 28px; }
.sb-thumb:hover,
.sb-thumb.dragging { background: var(--sb-thumb-hi); cursor: grab; }
.sb-thumb.dragging { cursor: grabbing; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font-family: var(--sans);
  font-size: var(--fs-prose);
  line-height: 1.62;
  letter-spacing: -0.01em;
  font-feature-settings: "tnum" 1;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--mark-bg); color: var(--mark-fg); }
::-moz-selection { background: var(--mark-bg); color: var(--mark-fg); }

a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }

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

code {
  font-family: var(--mono);
  font-size: var(--fs-small);
  color: var(--text);
  padding: 0 4px;
  border: 1px solid var(--line);
  border-radius: 0;
}

mark {
  background: var(--mark-bg);
  color: var(--mark-fg);
  padding: 0 2px;
  border-radius: 0;
}

[id^="row-"],
[id^="seg-"],
.page-title,
.table-anchor {
  scroll-margin-top: 110px;
}

/* ---------- labels: the only decorative device ---------- */

.label,
.sidebar-head,
.refs h2,
.home-grid h2,
.suggest-label,
.search-count,
.home-stats,
.links-group h3 {
  font-family: var(--mono);
  font-size: var(--fs-label);
  font-weight: 400;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-3);
}

.home-grid { counter-reset: swiss; }
.home-grid h2::before {
  counter-increment: swiss;
  content: counter(swiss, decimal-leading-zero) " / ";
  color: var(--text-3);
}

/* ---------- topbar: first row of the mosaic ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: stretch;
  height: 52px;
  padding: 0;
  background: var(--bg);
  border-bottom: 2px solid var(--page);
}

.brand {
  display: flex;
  align-items: center;
  padding: 0 20px;
  border-right: 1px solid var(--line);
  font-family: var(--mono);
  font-size: var(--fs-small);
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text);
  white-space: nowrap;
}
.brand:hover { color: var(--text); text-decoration: none; }

.search-form {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  border-right: 1px solid var(--line);
}

.search-form input {
  width: 100%;
  height: 100%;
  padding: 0 20px;
  border: none;
  border-radius: 0;
  background: transparent;
  font-family: var(--mono);
  font-size: var(--fs-small);
  color: var(--text);
  outline: none;
}
.search-form input::placeholder { color: var(--text-3); }
.search-form:focus-within {
  background: var(--surface-1);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.sidebar-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  padding: 0;
  border: none;
  border-right: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
}
.sidebar-toggle:hover { background: var(--surface-1); }

.theme-switch {
  display: flex;
  align-self: stretch;
}

.theme-cell {
  padding: 0 14px;
  border: none;
  border-right: 1px solid var(--line);
  background: var(--bg);
  color: var(--text-3);
  font-family: var(--mono);
  font-size: var(--fs-micro);
  letter-spacing: 0.08em;
  cursor: pointer;
}
.theme-cell:last-child { border-right: none; }
.theme-cell:hover { color: var(--text); background: var(--surface-1); }
.theme-cell.active { color: var(--accent); background: var(--accent-soft); }

/* ---------- suggest ---------- */

.suggest { position: absolute; top: 53px; left: 0; right: 0; z-index: 50; }

.suggest-panel {
  background: var(--bg);
  border: 1px solid var(--line-strong);
  padding: 0;
  max-height: 60vh;
  overflow: auto;
}

.suggest-group + .suggest-group {
  border-top: 1px solid var(--line-strong);
}

.suggest-label {
  display: block;
  padding: 6px 12px;
  background: var(--surface-1);
  border-top: 1px solid var(--line);
}

.suggest-item {
  display: block;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  color: var(--text-2);
  font-family: var(--mono);
  font-size: var(--fs-small);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background-color var(--t-state) var(--ease), color var(--t-state) var(--ease);
}
.suggest-item:hover {
  background: var(--surface-2);
  color: var(--text);
}
.suggest-item.active {
  background: var(--accent-soft);
  color: var(--accent);
}

/* ---------- mosaic layout ---------- */

.layout {
  display: flex;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
}

.sidebar {
  position: sticky;
  top: 52px;
  width: var(--sidebar-width);
  flex: 0 0 var(--sidebar-width);
  height: calc(100vh - 52px);
  overflow: auto;
  background: var(--bg);
  padding: 16px 0 2px;
}

@media (min-width: 901px) {
  body.sidebar-collapsed .sidebar { display: none; }
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 24px;
  margin: 0 0 12px;
  padding: 0 10px;
}

.toc { display: flex; flex-direction: column; gap: 0; }

.toc-item {
  display: flex;
  align-items: center;
  min-height: 32px;
  padding: 6px 10px;
  border-top: 1px solid var(--line);
  border-left: 2px solid transparent;
  color: var(--text-2);
  font-size: var(--fs-base);
  line-height: 1.5;
  transition: background-color var(--t-state) var(--ease), color var(--t-state) var(--ease);
}
.toc-item:hover {
  color: var(--text);
  background: var(--surface-1);
}
.toc-item.active {
  color: var(--text);
  background: var(--surface-2);
  border-left-color: var(--accent);
}
.toc-ref {
  font-family: var(--mono);
  font-size: var(--fs-small);
  color: var(--text);
  background: var(--surface-1);
  border-left: 2px solid var(--line-strong);
}
.toc-ref:hover {
  background: var(--surface-2);
  color: var(--text);
}

.content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 0 calc(2px + env(safe-area-inset-bottom));
}

.page-title,
.section-nav,
.page-body,
.refs,
.home-hero,
.home-grid,
.search-head,
.search-tabs,
.search-empty,
.more-bar,
.search-more,
.search-results,
.suggest-panel {
  background: var(--bg);
}

/* ---------- content modules ---------- */

.page-title {
  font-family: var(--serif);
  font-size: var(--fs-title);
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1.35;
  margin: 0;
  padding: 22px 14px;
}

.section-nav {
  position: sticky;
  top: 52px;
  z-index: 20;
  display: flex;
  width: 100%;
  margin: 0;
  padding: 0;
}

.section-nav-item {
  flex: 1 1 0;
  min-width: 0;
  padding: 14px 12px;
  background: var(--surface-1);
  color: var(--text-2);
  font-family: var(--mono);
  font-size: var(--fs-small);
  letter-spacing: 0.06em;
  text-align: center;
  line-height: 1.55;
  border-right: 1px solid var(--line-strong);
  border-bottom: 2px solid var(--line-strong);
}
.section-nav-item:last-child { border-right: none; }
.section-nav-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.page-body {
  margin: 0;
  padding: 8px 0 24px;
}

.sheet-heading {
  font-family: var(--serif);
  font-size: var(--fs-h2);
  font-weight: 700;
  letter-spacing: 0;
  margin: 40px 14px 16px;
}

.sheet-subheading {
  font-family: var(--serif);
  font-size: var(--fs-h3);
  font-weight: 700;
  letter-spacing: 0;
  margin: 32px 14px 12px;
  padding-left: 14px;
  border-left: 1px solid var(--line-strong);
}

.sheet-prose {
  color: var(--text-2);
  margin: 12px 14px;
  max-width: 920px;
  line-height: 1.75;
}

.table-anchor { display: block; height: 0; margin: 16px 0 8px; }

/* ---------- tables: excel grid inside the module ---------- */

.table-scroll {
  position: relative;
  overflow-x: auto;
  margin: 12px 0;
}

.data-table {
  border-collapse: collapse;
  table-layout: fixed;
  width: max-content;
  min-width: 100%;
  font-family: var(--mono);
  font-size: var(--fs-base);
  line-height: 1.55;
}

.data-table td {
  padding: 8px 12px;
  border: 1px solid var(--line);
  vertical-align: middle;
  overflow-wrap: break-word;
  color: var(--cell-fg, inherit);
  background-color: var(--cell-bg, transparent);
}

[data-theme="light"] .data-table td {
  color: var(--cell-fg-l, inherit);
  background-color: var(--cell-bg-l, transparent);
}

.data-table tbody tr:nth-child(even):not(.has-fill) td { background: var(--surface-1); }
.data-table tbody tr:hover:not(.has-fill) td { background: var(--surface-2); }

.data-table tr.row-kind-header:not(.has-fill) td,
.data-table td.th {
  background: var(--surface-2);
  font-size: var(--fs-micro);
  letter-spacing: 0.1em;
  color: var(--text-2);
  text-align: center;
}

.data-table thead td {
  border-bottom: 1px solid var(--line-strong);
}

.data-table tr.row-kind-title:not(.has-fill) td { font-weight: 700; color: var(--text); }

.data-table tr.row-kind-total:not(.has-fill) td {
  background: var(--surface-2);
  font-weight: 700;
  border-top: 1px solid var(--line-strong);
}

.data-table tr.row-kind-note td {
  color: var(--text-3);
  font-size: var(--fs-small);
}

.data-table td.code {
  color: var(--text);
  letter-spacing: 0.02em;
}

.data-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.banner-cell { text-align: center; color: var(--text-2); }

tr.row-highlight > td {
  background: var(--accent-soft) !important;
  transition: background var(--t-open) var(--ease);
}

.cell-link {
  color: inherit;
  border-bottom: 1px dotted var(--link);
  transition: border-color var(--t-state) var(--ease);
}
.cell-link:hover {
  border-bottom-style: solid;
  border-bottom-color: var(--link-hover);
}
.cell-link.image-link { border-bottom-style: solid; }

.image-thumb img {
  max-width: 220px;
  max-height: 160px;
  border: 1px solid var(--line);
  display: block;
}

/* ---------- refs module ---------- */

.refs {
  margin: 0;
  padding: 20px 0 12px;
}
.refs h2 {
  margin: 0 0 14px;
  padding: 0 14px;
  font-weight: 400;
}
.refs ul { margin: 0; padding: 0; list-style: none; }
.refs li {
  position: relative;
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 8px 14px;
  border-top: 1px solid var(--line);
}
.refs li:hover { background: var(--surface-1); }
.refs li a {
  color: var(--text-2);
  border-bottom: 1px dotted var(--link);
}
.refs li a:hover {
  color: var(--text);
  border-bottom-style: solid;
  border-bottom-color: var(--link-hover);
}
.refs li a::after {
  content: "";
  position: absolute;
  inset: 0;
}
.ref-label {
  color: var(--text-3);
  font-family: var(--mono);
  font-size: var(--fs-micro);
  margin-left: auto;
  white-space: nowrap;
}

/* ---------- home modules ---------- */

.home-hero {
  padding: 40px 14px;
}
.home-hero h1 {
  margin: 0 0 16px;
  font-family: var(--serif);
  font-size: var(--fs-hero);
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1.18;
  max-width: 18em;
}
.home-hero p {
  margin: 0 0 24px;
  color: var(--text-2);
  max-width: 42em;
  line-height: 1.75;
}
.home-stats { letter-spacing: 0.12em; }

.home-grid {
  padding: 28px 0 0;
}
.home-grid h2 {
  margin: 0 0 18px;
  padding: 0 14px;
  font-weight: 400;
}

.home-links {
  display: flex;
  width: 100%;
  padding: 0;
  background: transparent;
}

.home-link {
  flex: 1 1 0;
  min-width: 0;
  padding: 16px 12px;
  background: var(--surface-1);
  color: var(--text);
  font-family: var(--mono);
  font-size: var(--fs-prose);
  letter-spacing: 0.06em;
  text-align: center;
  line-height: 1.55;
  border-right: 1px solid var(--line-strong);
  border-bottom: 2px solid var(--line-strong);
}
.home-link:last-child { border-right: none; }
.home-link:hover {
  background: var(--surface-2);
  color: var(--text);
}

.home-list {
  margin: 0;
  padding: 0;
  list-style: none;
  columns: 2;
  column-gap: 2px;
}
.home-list li {
  break-inside: avoid;
  border-top: 1px solid var(--line);
}
.home-list a {
  display: block;
  padding: 6px 14px;
  color: var(--text-2);
  font-size: var(--fs-small);
}
.home-list a:hover {
  color: var(--text);
  background: var(--surface-1);
}

/* ---------- search modules ---------- */

.search-head {
  display: flex;
  align-items: baseline;
  gap: 16px;
  margin: 0;
  padding: 20px 14px;
}
.search-head h1 {
  font-family: var(--mono);
  font-size: var(--fs-h3);
  font-weight: 700;
  margin: 0;
}
.search-count { letter-spacing: 0.12em; }

.search-tabs {
  position: sticky;
  top: 52px;
  z-index: 20;
  display: flex;
  width: 100%;
  margin: 0;
  padding: 0;
}
.search-tabs a {
  flex: 1 1 0;
  min-width: 0;
  padding: 14px 12px;
  background: var(--surface-1);
  color: var(--text-2);
  font-family: var(--mono);
  font-size: var(--fs-small);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-align: center;
  border-right: 1px solid var(--line-strong);
  border-bottom: 2px solid var(--line-strong);
}
.search-tabs a:last-child { border-right: none; }
.search-tabs a:hover {
  background: var(--surface-1);
  color: var(--text);
}
.search-tabs a.active {
  background: var(--accent-soft);
  color: var(--accent);
}
.search-tabs span { color: var(--text-3); margin-left: 4px; }

#search-more-region {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: transparent;
}

.search-results {
  margin: 0;
  padding: 0;
  list-style: none;
}
.search-results li {
  position: relative;
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 20px;
  padding: 16px 14px;
  border-top: 1px solid var(--line);
}
.search-results li:hover { background: var(--surface-1); }
.search-results li .result-title::after {
  content: "";
  position: absolute;
  inset: 0;
}

.result-meta {
  font-family: var(--mono);
  font-size: var(--fs-micro);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-3);
  padding-top: 3px;
  align-self: start;
  justify-self: start;
  padding: 2px 8px;
}
[data-theme="light"] .result-meta.rm-business { background: var(--swatch-1); color: var(--text); }
[data-theme="light"] .result-meta.rm-subject { background: var(--swatch-2); color: var(--text); }
[data-theme="light"] .result-meta.rm-category { background: var(--swatch-3); color: var(--text); }

.result-body { min-width: 0; }
.result-title {
  font-family: var(--serif);
  font-size: var(--fs-h3);
  font-weight: 700;
  letter-spacing: 0;
  color: var(--text);
  border-bottom: 1px dotted var(--link);
}
.result-title:hover {
  border-bottom-style: solid;
  border-bottom-color: var(--link-hover);
}
.result-snippet {
  margin: 8px 0 0;
  color: var(--text-2);
  font-family: var(--mono);
  font-size: var(--fs-small);
  line-height: 1.8;
}

.badge {
  display: inline-block;
  padding: 0;
  border: none;
  font-family: var(--mono);
  font-size: var(--fs-label);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-3);
}

.search-empty {
  padding: 32px 14px;
  color: var(--text-3);
}

.search-more {
  margin: 0;
  padding: 12px 14px;
  color: var(--text-3);
  font-family: var(--mono);
  font-size: var(--fs-micro);
  letter-spacing: 0.1em;
}

.more-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin: 0;
  padding: 18px 14px;
  background: var(--surface-1);
  border-bottom: 2px solid var(--line-strong);
  color: var(--text-2);
  font-family: var(--mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-align: center;
  transition: background-color var(--t-state) var(--ease), color var(--t-state) var(--ease);
}
.more-bar:hover {
  background: var(--surface-1);
  color: var(--text);
  text-decoration: none;
}
.more-main { font-size: var(--fs-small); }
.more-sub {
  font-size: var(--fs-micro);
  letter-spacing: 0.1em;
  color: var(--text-3);
  text-transform: none;
}
.more-bar:hover .more-sub { color: var(--text-2); }

.links-group { padding: 0 14px; margin-bottom: 20px; }
.links-group h3 { margin: 0 0 10px; }
.links-group ul { margin: 0; padding: 0; list-style: none; }
.links-group li {
  padding: 6px 0;
  border-top: 1px solid var(--line);
  font-size: var(--fs-base);
}
.links-group li a {
  color: var(--text-2);
  border-bottom: 1px dotted var(--link);
}
.links-group li a:hover {
  color: var(--text);
  border-bottom-style: solid;
  border-bottom-color: var(--link-hover);
}

/* ---------- skip / accessibility ---------- */

.skip:not(:focus) {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.skip:focus {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 100;
  padding: 8px 14px;
  background: var(--bg);
  border: 1px solid var(--line-strong);
  font-family: var(--mono);
  font-size: var(--fs-small);
}

/* ---------- responsive / motion ---------- */

@media (max-width: 900px) {
  .layout { display: block; }
  .sidebar {
    position: fixed;
    top: 52px;
    left: 0;
    bottom: 0;
    z-index: 45;
    background: var(--bg);
    transform: translateX(-100%);
    transition: transform var(--t-open) var(--ease);
  }
  .sidebar.open { transform: translateX(0); }
  .home-list { columns: 1; }
  .home-hero h1 { font-size: 26px; }
  .home-hero { padding: 28px 14px; }
  .search-results li { grid-template-columns: 1fr; gap: 6px; }
}

@media (max-width: 479px) {
  .search-form input { font-size: 16px; }
}

@media (prefers-contrast: more) {
  :root {
    --line: rgba(244, 240, 233, 0.34);
    --line-strong: rgba(244, 240, 233, 0.58);
  }
  [data-theme="light"] {
    --line: rgba(17, 17, 16, 0.32);
    --line-strong: rgba(17, 17, 16, 0.55);
  }
}

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