:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Code", "Fira Code", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  --radius-sm: 4px;
  --radius-md: 6px;
  --transition: 160ms ease;
  --container-max: 1080px;
}

:root[data-theme="dark"] {
  --bg: #0b0c0e;
  --bg-surface: #111317;
  --bg-elevated: #16191f;
  --bg-subtle: #1c2028;

  --border: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.2);

  --text: #ededef;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;

  --accent: #e5e7eb;
  --accent-contrast: #0b0c0e;
  --header-bg: rgba(11, 12, 14, 0.88);

  /* Monochrome heatmap scale (dark) */
  --hm-0: #181b21;
  --hm-1: #323844;
  --hm-2: #5b6475;
  --hm-3: #9aa3b2;
  --hm-4: #e5e7eb;

  /* Monochrome language bar tones (dark) */
  --tone-0: #e5e7eb;
  --tone-1: #a1a8b5;
  --tone-2: #727a88;
  --tone-3: #505764;
  --tone-4: #383e48;
  --tone-5: #262b33;
}

:root[data-theme="light"] {
  --bg: #f8f8f7;
  --bg-surface: #ffffff;
  --bg-elevated: #ffffff;
  --bg-subtle: #f1f2f4;

  --border: rgba(15, 23, 42, 0.1);
  --border-strong: rgba(15, 23, 42, 0.22);

  --text: #111317;
  --text-secondary: #4b5563;
  --text-muted: #6b7280;

  --accent: #111317;
  --accent-contrast: #ffffff;
  --header-bg: rgba(248, 248, 247, 0.9);

  /* Monochrome heatmap scale (light) */
  --hm-0: #eceef1;
  --hm-1: #c9cfd8;
  --hm-2: #8f98a6;
  --hm-3: #4b5563;
  --hm-4: #111317;

  /* Monochrome language bar tones (light) */
  --tone-0: #111317;
  --tone-1: #454c57;
  --tone-2: #6f7785;
  --tone-3: #99a1ae;
  --tone-4: #c1c7d0;
  --tone-5: #dce0e6;
}

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

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  display: block;
  max-width: 100%;
}

.container {
  width: 100%;
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 24px;
}

/* Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--header-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.brand-logo {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  object-fit: contain;
  flex-shrink: 0;
}

.brand-sep,
.brand-sub {
  color: var(--text-muted);
  font-weight: 400;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 28px;
}

.nav-links a {
  font-size: 0.88rem;
  color: var(--text-secondary);
  transition: color var(--transition);
}

.nav-links a:hover {
  color: var(--text);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ctrl-btn {
  height: 32px;
  padding: 0 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition), background-color var(--transition);
}

.ctrl-btn:hover {
  color: var(--text);
  border-color: var(--border-strong);
  background: var(--bg-subtle);
}

.ctrl-btn:disabled {
  opacity: 0.55;
  cursor: default;
}

:root[data-theme="dark"] .theme-label-light {
  display: none;
}

:root[data-theme="light"] .theme-label-dark {
  display: none;
}

.mobile-menu-btn {
  display: none;
}

.mobile-drawer {
  border-top: 1px solid var(--border);
  padding: 12px 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--bg);
}

.mobile-drawer[hidden] {
  display: none;
}

.mobile-drawer a {
  font-size: 0.9rem;
  color: var(--text-secondary);
  padding: 4px 0;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 40px;
  padding: 0 18px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color var(--transition), border-color var(--transition), color var(--transition), opacity var(--transition);
}

.btn-sm {
  height: 34px;
  padding: 0 14px;
  font-size: 0.82rem;
}

.btn-solid {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
}

.btn-solid:hover {
  opacity: 0.88;
}

.btn-outline {
  background: transparent;
  color: var(--text);
  border-color: var(--border-strong);
}

.btn-outline:hover {
  background: var(--bg-subtle);
}

/* Hero */
.hero {
  padding: 68px 0 60px;
  border-bottom: 1px solid var(--border);
}

.hero-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.18fr) minmax(0, 0.82fr);
  gap: 44px;
  align-items: start;
}

.eyebrow {
  margin: 0 0 14px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.hero-title {
  margin: 0 0 18px;
  font-size: clamp(2rem, 3.8vw, 2.85rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.title-handle {
  font-family: var(--font-mono);
  font-weight: 400;
  font-size: 0.62em;
  color: var(--text-muted);
}

.hero-lead {
  margin: 0 0 28px;
  max-width: 56ch;
  font-size: 0.98rem;
  color: var(--text-secondary);
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* Dossier Panel */
.dossier-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  overflow: hidden;
}

.dossier-head {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}

.dossier-avatar {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  object-fit: cover;
  filter: grayscale(15%);
}

.dossier-name {
  font-size: 0.98rem;
  font-weight: 600;
  line-height: 1.3;
}

.dossier-handle {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.spec-list {
  margin: 0;
}

.spec-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
}

.spec-row:last-child {
  border-bottom: none;
}

.spec-row dt {
  color: var(--text-muted);
  flex-shrink: 0;
}

.spec-row dd {
  margin: 0;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 0.77rem;
  color: var(--text);
}

.spec-links a {
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: var(--border-strong);
}

.spec-links a:hover {
  text-decoration-color: var(--text);
}

.sep {
  color: var(--text-muted);
  margin: 0 4px;
}

/* Sections */
.section {
  padding: 68px 0;
}

.section-surface {
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.section-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
  margin-bottom: 30px;
}

.section-index {
  margin: 0 0 8px;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.section-title {
  margin: 0 0 8px;
  font-size: clamp(1.45rem, 2.4vw, 1.85rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.section-subtitle {
  margin: 0;
  max-width: 66ch;
  font-size: 0.92rem;
  color: var(--text-secondary);
}

/* Case Study Cards (2 Representative Systems) */
.case-stack {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.case-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  overflow: hidden;
  transition: border-color var(--transition);
}

.case-card:hover {
  border-color: var(--border-strong);
}

.case-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-subtle);
}

.case-head-left,
.case-head-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.num {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
}

.case-title {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.015em;
}

.case-title a:hover {
  text-decoration: underline;
  text-underline-offset: 4px;
}

.tag-status {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--text-secondary);
}

.ver,
.meta-chip {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--text-muted);
}

.case-body {
  display: grid;
  grid-template-columns: minmax(0, 0.92fr) minmax(0, 1.08fr);
}

.case-summary {
  padding: 24px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.case-lead {
  margin: 0;
  font-size: 0.92rem;
  color: var(--text-secondary);
  line-height: 1.7;
}

.case-kv {
  margin: 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 12px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.case-kv > div {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  font-size: 0.8rem;
}

.case-kv dt {
  color: var(--text-muted);
  flex-shrink: 0;
}

.case-kv dd {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text);
  text-align: right;
}

.tech-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tech-row span {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-secondary);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
}

.case-links {
  margin-top: auto;
  padding-top: 4px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.case-modules {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.module-item {
  padding: 20px 22px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.module-item:nth-child(2n) {
  border-right: none;
}

.module-item:nth-last-child(-n + 2) {
  border-bottom: none;
}

.module-item h4 {
  margin: 0 0 8px;
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.4;
}

.module-item p {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* Live GitHub Telemetry Section */
.telemetry-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.sync-status {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--text-muted);
}

.kpi-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
  margin-bottom: 20px;
  overflow: hidden;
}

.kpi-cell {
  padding: 18px 20px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.kpi-cell:last-child {
  border-right: none;
}

.kpi-label {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.kpi-value {
  font-family: var(--font-mono);
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.kpi-mono-sm {
  font-size: 1.05rem;
  line-height: 1.85;
}

.telemetry-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr);
  gap: 20px;
  margin-bottom: 20px;
}

.panel-box {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.panel-head h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.panel-meta {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--text-muted);
}

/* Language Bar & Table */
.lang-bar {
  display: flex;
  width: 100%;
  height: 10px;
  border-radius: 2px;
  overflow: hidden;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  margin-bottom: 16px;
  gap: 1px;
}

.lang-seg {
  height: 100%;
  min-width: 3px;
}

.tone-0 { background: var(--tone-0); }
.tone-1 { background: var(--tone-1); }
.tone-2 { background: var(--tone-2); }
.tone-3 { background: var(--tone-3); }
.tone-4 { background: var(--tone-4); }
.tone-5 { background: var(--tone-5); }

.lang-table {
  display: flex;
  flex-direction: column;
}

.lang-row {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.84rem;
}

.lang-row:last-child {
  border-bottom: none;
}

.lang-swatch {
  width: 9px;
  height: 9px;
  border-radius: 2px;
}

.lang-name {
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--text);
}

.lang-size {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.lang-pct {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 600;
  min-width: 52px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Activity Feed */
.activity-feed {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
}

.feed-item {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
  align-items: baseline;
}

.feed-item:last-child {
  border-bottom: none;
}

.feed-date {
  font-family: var(--font-mono);
  font-size: 0.73rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.feed-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.feed-top {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.feed-type {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text-secondary);
  background: var(--bg-subtle);
  flex-shrink: 0;
}

.feed-repo {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
}

.feed-repo:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.feed-msg {
  color: var(--text-secondary);
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.feed-empty {
  padding: 16px 0;
  color: var(--text-muted);
  font-size: 0.84rem;
}

/* Contribution Heatmap */
.heatmap-box {
  padding-bottom: 18px;
}

.heatmap-legend {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
}

.heatmap-scroll {
  overflow-x: auto;
  padding-bottom: 6px;
}

.heatmap-grid {
  display: grid;
  grid-template-rows: repeat(7, 11px);
  grid-auto-flow: column;
  grid-auto-columns: 11px;
  gap: 3px;
  width: max-content;
}

.hm-cell {
  display: block;
  width: 11px;
  height: 11px;
  border-radius: 2px;
  background: var(--hm-0);
}

.hm-cell.lv-0 { background: var(--hm-0); }
.hm-cell.lv-1 { background: var(--hm-1); }
.hm-cell.lv-2 { background: var(--hm-2); }
.hm-cell.lv-3 { background: var(--hm-3); }
.hm-cell.lv-4 { background: var(--hm-4); }

.heatmap-grid .hm-cell {
  cursor: crosshair;
}

.heatmap-grid .hm-cell:hover {
  outline: 1px solid var(--text);
  outline-offset: 1px;
}

.heatmap-foot {
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.heatmap-hover-readout {
  font-family: var(--font-mono);
  color: var(--text);
  min-height: 1.2em;
}

/* Principles Grid */
.principles-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.principle-cell {
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
}

.principle-key {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 10px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border-strong);
}

.principle-cell h3 {
  margin: 0 0 6px;
  font-size: 0.96rem;
  font-weight: 600;
}

.principle-cell p {
  margin: 0;
  font-size: 0.84rem;
  color: var(--text-secondary);
}

/* Footer */
.site-footer {
  padding: 28px 0 40px;
  border-top: 1px solid var(--border);
}

.footer-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.footer-brand {
  font-family: var(--font-mono);
  color: var(--text);
  font-weight: 600;
}

.footer-right a {
  font-family: var(--font-mono);
  color: var(--text-secondary);
}

.footer-right a:hover {
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* Responsive */
@media (max-width: 960px) {
  .hero-grid,
  .case-body,
  .telemetry-grid {
    grid-template-columns: 1fr;
  }
  .case-summary {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .kpi-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .kpi-cell:nth-child(2n) {
    border-right: none;
  }
  .kpi-cell:nth-child(-n + 2) {
    border-bottom: 1px solid var(--border);
  }
  .principles-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 740px) {
  .nav-links,
  .desktop-only {
    display: none;
  }
  .mobile-menu-btn {
    display: inline-flex;
  }
  .hero {
    padding: 46px 0 40px;
  }
  .section {
    padding: 48px 0;
  }
  .case-modules {
    grid-template-columns: 1fr;
  }
  .module-item {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .module-item:nth-last-child(-n + 2) {
    border-bottom: 1px solid var(--border);
  }
  .module-item:last-child {
    border-bottom: none;
  }
  .case-kv > div {
    flex-direction: column;
    gap: 2px;
  }
  .case-kv dd {
    text-align: left;
  }
}

@media (max-width: 520px) {
  .principles-grid,
  .kpi-strip {
    grid-template-columns: 1fr;
  }
  .kpi-cell {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .kpi-cell:last-child {
    border-bottom: none;
  }
}
