@font-face {
  font-family: "Newsreader";
  src: url("fonts/Newsreader.woff2") format("woff2");
  font-weight: 400 500;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Inter";
  src: url("fonts/Inter.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Inter";
  src: url("fonts/Inter-500.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Inter";
  src: url("fonts/Inter-600.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

/* W04 covers both 400 body and 500 headings; upgrade to W05 when available */
@font-face {
  font-family: "TsangerJinKai02";
  src: url("fonts/TsangerJinKai02-W04.ttf") format("truetype");
  font-weight: 400 500;
  font-display: swap;
}

:root {
  /* kami parchment surfaces */
  --bg: #f5f4ed;
  --bg-accent: #e8e6dc;
  --surface: rgba(250, 249, 245, 0.92);
  --surface-strong: #faf9f5;
  --surface-muted: #f5f4ed;

  /* kami solid borders (no rgba — consistent with spec) */
  --border: #e8e6dc;
  --border-strong: #e5e3d8;

  /* kami olive-warm text palette */
  --text: #141413;
  --text-soft: #504e49;
  --text-muted: #6b6a64;

  /* single ink-blue accent — kami invariant #2 */
  --link: #1B365D;
  --link-hover: #2D5A8A;
  --accent: #1B365D;
  --accent-strong: #1B365D;
  --accent-soft: #EEF2F7;    /* 0.08 solid equivalent over parchment */

  /* kami whisper shadows */
  --shadow-soft: 0 4px 24px rgba(0, 0, 0, 0.05);
  --shadow-card: 0 6px 32px rgba(0, 0, 0, 0.08);

  --broken-link: #b53333;

  --font-sans: "Inter", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  --font-serif: "TsangerJinKai02", Charter, "Newsreader", "Source Han Serif SC", "Noto Serif CJK SC", "Songti SC", Georgia, serif;
  --font-mono: "JetBrains Mono", "SF Mono", "Fira Code", "SFMono-Regular", "Cascadia Code", ui-monospace, "TsangerJinKai02", "Source Han Serif SC", monospace;

  --sidebar-w: 272px;
  --content-max: 960px;
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --header-h: 64px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-serif);
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  background: linear-gradient(180deg, #f8f7f0 0%, var(--bg) 30%, #eeece3 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 15% 8%, rgba(27, 54, 93, 0.04), transparent 32%),
    radial-gradient(circle at 82% 18%, rgba(27, 54, 93, 0.03), transparent 24%);
  z-index: -1;
}

a {
  color: var(--link);
  text-decoration: none;
  text-decoration-thickness: 0.08em;
  text-underline-offset: 0.18em;
}

a:hover {
  color: var(--link-hover);
  text-decoration: underline;
}

.site-header {
  backdrop-filter: blur(16px);
  background: rgba(250, 249, 245, 0.82);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  min-height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 0.9rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.site-header .brand {
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: 1.05rem;
  letter-spacing: 0.01em;
  color: var(--text);
}

.site-header .brand a { color: inherit; }

.site-header .header-sep {
  color: var(--accent);
  opacity: 0.45;
}

.site-header .breadcrumb {
  font-family: var(--font-sans);
  color: var(--text-muted);
  font-size: 0.88rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.site-header .breadcrumb a { color: inherit; }
.site-header .breadcrumb a:hover { color: var(--link); }

.layout {
  display: flex;
  min-height: calc(100vh - var(--header-h));
}

.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: linear-gradient(180deg, rgba(248, 247, 241, 0.96), rgba(240, 238, 230, 0.92));
  border-right: 1px solid var(--border);
  padding: 1.5rem 0.9rem 1.8rem;
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
  flex-shrink: 0;
}

.sidebar-section {
  margin-bottom: 1.2rem;
}

.sidebar-section-label {
  font-family: var(--font-sans);
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-muted);
  padding: 0.25rem 0.8rem 0.45rem;
}

.sidebar-link {
  display: block;
  padding: 0.5rem 0.8rem;
  font-family: var(--font-sans);
  font-size: 0.92rem;
  color: var(--text-soft);
  border-radius: 999px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background-color 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.sidebar-link:hover {
  background: rgba(255, 255, 255, 0.72);
  color: var(--text);
  text-decoration: none;
  transform: translateX(2px);
}

.sidebar-link.active {
  background: linear-gradient(135deg, rgba(27, 54, 93, 0.10), rgba(27, 54, 93, 0.06));
  box-shadow: inset 0 0 0 1px rgba(27, 54, 93, 0.12);
  font-weight: 600;
  color: var(--link);
}

.sidebar-subgroup {
  margin: 0.15rem 0 0.5rem;
}

.sidebar-subgroup-label {
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: 0.2rem 0.95rem 0.15rem;
}

.sidebar-link-nested {
  margin-left: 0.55rem;
  padding-left: 1rem;
  font-size: 0.88rem;
  border-left: 1px solid var(--border);
  border-radius: 0 999px 999px 0;
}

.sidebar-link-nested:hover {
  transform: translateX(1px);
}

.main {
  flex: 1;
  min-width: 0;
  padding: 2rem clamp(1.2rem, 4vw, 4rem) 4rem;
}

.page-layout {
  display: grid;
  grid-template-columns: minmax(0, var(--content-max)) minmax(240px, 300px);
  gap: 1.6rem;
  align-items: start;
}

.prose {
  min-width: 0;
  background: var(--surface-strong);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-soft);
  padding: clamp(1.4rem, 3vw, 2.5rem);
}

.page-rail {
  min-width: 0;
  position: sticky;
  top: calc(var(--header-h) + 1rem);
}

.page-header,
.section-page-header,
.homepage-hero {
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(27, 54, 93, 0.05), rgba(255, 255, 255, 0) 45%),
    rgba(250, 249, 245, 0.94);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius-xl) + 4px);
  box-shadow: var(--shadow-soft);
  padding: clamp(1.5rem, 4vw, 2.4rem);
  margin-bottom: 1.5rem;
}

.page-header::after,
.section-page-header::after,
.homepage-hero::after {
  content: "";
  position: absolute;
  width: 14rem;
  height: 14rem;
  border-radius: 50%;
  top: -8rem;
  right: -4rem;
  background: radial-gradient(circle, rgba(27, 54, 93, 0.07), rgba(27, 54, 93, 0));
}

.page-title,
.section-page-header h1,
.homepage-hero h1 {
  font-family: var(--font-serif);
  font-size: clamp(2rem, 4vw, 3.15rem);
  font-weight: 500;
  line-height: 1.1;
  letter-spacing: -0.02em;
  margin-bottom: 0.55rem;
}

.page-meta,
.section-page-meta,
.homepage-hero .subtitle {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem 0.9rem;
  align-items: center;
  font-family: var(--font-sans);
  color: var(--text-muted);
  font-size: 0.92rem;
  max-width: 60rem;
}

.section-page-meta,
.homepage-hero .subtitle {
  margin-top: 0.25rem;
}

.homepage-hero .subtitle {
  display: block;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-family: var(--font-sans);
  background: var(--accent-soft);   /* #EEF2F7 solid, kami-compliant */
  color: var(--accent);
  border: 1px solid #E4ECF5;
  border-radius: 999px;
  padding: 0.2rem 0.65rem;
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.prose h1 { display: none; }

.prose > * + * {
  margin-top: 0.9rem;
}

.prose h2,
.prose h3,
.prose h4 {
  font-family: var(--font-serif);
  font-weight: 500;
  color: var(--text);
  line-height: 1.22;
}

.prose h2 {
  font-size: 1.55rem;
  margin-top: 2.2rem;
  padding-left: 0.7rem;
  border-left: 2px solid var(--accent);
  border-radius: 1px;
}

.prose h3 {
  font-size: 1.18rem;
  margin-top: 1.6rem;
}

.prose h4 {
  font-size: 1rem;
  margin-top: 1.25rem;
}

.prose p,
.prose li,
.prose td,
.prose th {
  color: var(--text-soft);
}

.prose strong {
  color: var(--text);
}

.prose ul,
.prose ol {
  margin-left: 1.4rem;
  padding-left: 0.2rem;
}

.prose li + li {
  margin-top: 0.35rem;
}

.prose blockquote {
  margin: 1.2rem 0;
  padding: 0.95rem 1.1rem;
  border-left: 2px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-soft);
}

.prose code {
  font-family: var(--font-mono);
  font-size: 0.84em;
  background: var(--surface-strong);
  border: 1px solid var(--border);
  color: var(--link);
  border-radius: 0.3rem;
  padding: 0.12em 0.4em;
}

.prose pre {
  background: #1e2327;
  color: #eef2f4;
  border-radius: var(--radius-md);
  padding: 1rem 1.1rem;
  overflow-x: auto;
  margin: 1.1rem 0;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  font-size: 0.9rem;
}

.prose pre code {
  background: none;
  color: inherit;
  padding: 0;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 1.25rem 0;
  background: linear-gradient(180deg, #fffdf8 0%, var(--surface-strong) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
}

.prose table,
.kami-table {
  width: auto;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 0.94rem;
  font-variant-numeric: tabular-nums;
}

.prose th,
.prose td {
  padding: 0.68rem 0.85rem;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--border-strong);
  vertical-align: top;
}

.prose th {
  background: #EEF2F7;
  color: var(--text-soft);
  font-family: var(--font-sans);
  font-size: 0.73rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.prose tr:nth-child(even) td {
  background: #fbfaf6;
}

.prose tr:last-child td {
  border-bottom: 0;
}

.prose hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2rem 0;
}

.broken-link {
  color: var(--broken-link);
  text-decoration: underline dotted;
  cursor: help;
}

.page-rail .block-card:first-child {
  margin-top: 0;
}

.block-card,
.section-block {
  background: var(--surface-strong);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
}

.block-card {
  padding: 1.1rem 1.15rem;
  margin-bottom: 1rem;
}

.block-card-title,
.section-block h2 {
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--text-muted);
  margin-bottom: 0.85rem;
}

.section-block {
  padding: 1.15rem 1.2rem;
  margin-bottom: 1.2rem;
}

.section-block h2 a {
  color: inherit;
}

.section-table-wrap {
  background: linear-gradient(180deg, #fffdf8 0%, var(--surface-strong) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
}

.section-table {
  width: 100%;
  min-width: 100%;
  border-collapse: collapse;
}

.section-table th,
.section-table td {
  padding: 0.85rem 1rem;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--border-strong);
  vertical-align: top;
}

.section-table th {
  background: #EEF2F7;
  color: var(--text-soft);
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.section-table td {
  color: var(--text-soft);
  background: transparent;
}

.section-table tbody tr:nth-child(even) td {
  background: #fbfaf6;
}

.section-table tbody tr:last-child td {
  border-bottom: 0;
}

.section-table td:first-child {
  width: 52%;
}

.papers-table {
  min-width: 980px;
  table-layout: fixed;
}

.papers-table .paper-col {
  width: 36%;
}

.papers-table .source-col {
  width: 18%;
}

.papers-table .affiliation-col {
  width: 25%;
}

.papers-table .domain-col {
  width: 21%;
}

.section-table.papers-table td:first-child {
  width: auto;
}

.papers-table .paper-cell a {
  color: var(--text);
  font-family: var(--font-serif);
  font-size: 1.02rem;
  font-weight: 500;
  line-height: 1.32;
  overflow-wrap: anywhere;
}

.papers-table .paper-cell a:hover {
  color: var(--link);
}

.papers-table .affiliation-cell {
  line-height: 1.5;
}

.source-pill {
  display: inline-block;
  max-width: 100%;
  background: #EEF2F7;
  border: 1px solid #E4ECF5;
  border-radius: 999px;
  color: var(--accent);
  font-family: var(--font-sans);
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.35;
  overflow-wrap: anywhere;
  padding: 0.22rem 0.58rem;
}

.domain-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.table-tag {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-soft);
  font-family: var(--font-sans);
  font-size: 0.76rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
  padding: 0.18rem 0.5rem;
}

.related-grid,
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.85rem;
}

.related-card,
.card {
  display: block;
  border-radius: var(--radius-md);
  padding: 0.95rem 1rem;
  background: rgba(250, 249, 245, 0.72);
  border: 1px solid var(--border);
  color: inherit;
  text-decoration: none;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease, background-color 0.18s ease;
}

.related-card:hover,
.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-card);
  border-color: rgba(27, 54, 93, 0.22);
  background: rgba(250, 249, 245, 0.96);
  text-decoration: none;
}

.related-card .related-title,
.card .card-title {
  color: var(--text);
  font-family: var(--font-serif);
  font-size: 1.02rem;
  font-weight: 500;
  line-height: 1.25;
}

.related-card .related-summary,
.card .card-summary,
.card .card-meta {
  color: var(--text-muted);
  font-size: 0.86rem;
  line-height: 1.6;
}

.related-card .related-summary,
.card .card-summary {
  margin-top: 0.35rem;
}

.card .card-meta {
  margin-top: 0.65rem;
}

.tags-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.page-rail .related-grid {
  grid-template-columns: 1fr;
}

.backlinks-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.backlinks-list li a {
  display: inline-flex;
  align-items: center;
  min-height: 2rem;
  background: rgba(250, 249, 245, 0.8);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.2rem 0.75rem;
  font-size: 0.85rem;
  color: var(--text-soft);
}

.backlinks-list li a:hover {
  background: var(--accent-soft);
  color: var(--link);
  text-decoration: none;
}

.section-list {
  list-style: none;
}

.section-list li + li {
  border-top: 1px solid var(--border);
}

.section-list li a.sl-row {
  display: grid;
  grid-template-columns: minmax(180px, 240px) minmax(0, 1fr);
  gap: 0.85rem;
  align-items: start;
  padding: 0.85rem 0.2rem;
  color: inherit;
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: background-color 0.18s ease, padding-left 0.18s ease;
}

.section-list li a.sl-row:hover {
  background: rgba(250, 249, 245, 0.64);
  padding-left: 0.55rem;
  text-decoration: none;
}

.section-list .sl-title {
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: 1rem;
  color: var(--text);
  line-height: 1.35;
}

.section-list a.sl-row:hover .sl-title {
  color: var(--link);
}

.section-list .sl-summary {
  font-size: 0.88rem;
  color: var(--text-muted);
}

.section-page-header h1 {
  margin-bottom: 0.35rem;
  max-width: none;
}

@media (max-width: 1100px) {
  .page-layout {
    grid-template-columns: 1fr;
  }

  .page-rail {
    position: static;
  }
}

@media (max-width: 780px) {
  :root {
    --header-h: 58px;
  }

  .sidebar {
    display: none;
  }

  .main {
    padding: 1rem 0.9rem 2.5rem;
  }

  .site-header {
    padding: 0 1rem;
  }

  .page-title,
  .section-page-header h1,
  .homepage-hero h1 {
    max-width: none;
    font-size: clamp(1.8rem, 8vw, 2.5rem);
  }

  .section-list li a.sl-row {
    grid-template-columns: 1fr;
    gap: 0.2rem;
  }

  .related-grid,
  .card-grid {
    grid-template-columns: 1fr;
  }

  .section-table-wrap {
    background: transparent;
    border: 0;
    box-shadow: none;
    overflow: visible;
  }

  .papers-table {
    display: block;
    min-width: 0;
    max-width: 100%;
    table-layout: auto;
  }

  .papers-table colgroup,
  .papers-table thead {
    display: none;
  }

  .papers-table tbody,
  .papers-table tr,
  .papers-table td {
    display: block;
    width: 100%;
  }

  .papers-table tr {
    background: var(--surface-strong);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    max-width: 100%;
    box-shadow: var(--shadow-soft);
    padding: 0.85rem;
  }

  .papers-table tr + tr {
    margin-top: 0.8rem;
  }

  .papers-table td,
  .papers-table tbody tr:nth-child(even) td {
    background: transparent;
    border-bottom: 0;
    min-width: 0;
    overflow-wrap: anywhere;
    padding: 0.28rem 0;
  }

  .domain-tags {
    min-width: 0;
  }

  .papers-table td::before {
    content: attr(data-label);
    display: block;
    color: var(--text-muted);
    font-family: var(--font-sans);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    margin-bottom: 0.18rem;
    text-transform: uppercase;
  }

  .papers-table .paper-cell::before {
    display: none;
  }

  .papers-table .paper-cell a {
    display: block;
    font-size: 1.08rem;
    margin-bottom: 0.35rem;
    white-space: normal;
    word-break: break-all;
  }

  .source-pill,
  .table-tag {
    word-break: break-all;
  }
}
