:root {
  color-scheme: light;

  /* Committed World: Archival Institutional Research Desk
     Crisp cool-slate archival paper, pure white elevated sheets, deep slate ink,
     and sovereign navy accent — deliberate contrast, zero warm AI beige. */
  --color-bg: oklch(97.5% 0.004 252);
  --color-bg-soft: oklch(94.8% 0.007 252);
  --color-surface: oklch(100% 0 0);
  --color-surface-raised: oklch(100% 0 0);
  --color-border: oklch(90.5% 0.009 252);
  --color-border-strong: oklch(81.5% 0.014 252);
  --color-accent: oklch(40% 0.125 255);
  --color-accent-strong: oklch(31% 0.115 255);
  --color-text: oklch(19% 0.022 256);
  --color-text-soft: oklch(32% 0.022 256);
  --color-muted: oklch(44% 0.022 256);
  --color-dim: oklch(48% 0.020 256);

  /* Semantic Five-Layer Cake palette — restrained, high-contrast */
  --layer-1: oklch(49% 0.145 62);
  --layer-2: oklch(42% 0.155 255);
  --layer-3: oklch(41% 0.135 158);
  --layer-4: oklch(45% 0.155 308);
  --layer-5: oklch(47% 0.155 28);

  --radius-sm: 3px;
  --radius-md: 6px;
  --radius-lg: 10px;
  --radius-pill: 999px;

  /* Commit to crisp edges over wide diffuse ghost-card shadows */
  --shadow-sm: 0 1px 2px oklch(19% 0.022 256 / 0.04);
  --shadow-md: 0 8px 20px -12px oklch(19% 0.022 256 / 0.16);

  --font-sans: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-serif: "Songti SC", "Noto Serif SC", Georgia, "Times New Roman", serif;
  --font-mono: "SFMono-Regular", "SF Mono", ui-monospace, Menlo, Monaco, Consolas, monospace;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;

  --header-h: 56px;
  --page-x: clamp(16px, 2.5vw, 32px);
  --content-max: 1280px;

  /* Semantic token aliases */
  --bg: var(--color-bg);
  --paper: var(--color-surface);
  --surface: var(--color-surface-raised);
  --surface2: var(--color-bg-soft);
  --surface3: oklch(91.8% 0.010 252);
  --border: var(--color-border);
  --border-hair: var(--color-border);
  --border-ink: var(--color-border-strong);
  --ink: var(--color-text);
  --text: var(--color-text);
  --text-muted: var(--color-muted);
  --text-dim: var(--color-dim);
  --text-faint: oklch(64% 0.014 252);
  --accent: var(--color-accent);
  --font: var(--font-sans);
  --display: var(--font-serif);
  --mono: var(--font-mono);
  --font-body: var(--font-sans);
  --font-display: var(--font-serif);
  --radius: var(--radius-sm);
  --max-w: 880px;
  --l1: var(--layer-1);
  --l2: var(--layer-2);
  --l3: var(--layer-3);
  --l4: var(--layer-4);
  --l5: var(--layer-5);
}

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

html {
  min-height: 100%;
  background: var(--color-bg);
  scroll-behavior: smooth;
  scrollbar-gutter: stable;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.65;
  color: var(--color-text);
  background: var(--color-bg);
  caret-color: var(--color-accent);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Browser surfaces authored to the palette */
::selection {
  background: oklch(40% 0.125 255 / 0.16);
  color: var(--color-text);
}

button,
input,
textarea,
select {
  font: inherit;
}

button,
a,
[role="button"],
summary {
  -webkit-tap-highlight-color: transparent;
}

a {
  color: inherit;
  text-underline-offset: 3px;
}

:focus {
  outline: none;
}

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

::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: oklch(76% 0.012 252);
  border-radius: var(--radius-pill);
}

::-webkit-scrollbar-thumb:hover {
  background: oklch(62% 0.016 252);
}

.page-shell {
  min-height: 100dvh;
  position: relative;
  z-index: 1;
}

.page-container {
  width: min(100%, var(--content-max));
  margin-inline: auto;
  padding-inline: var(--page-x);
}

/* ── Global Navigation Header ── */
.nav-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  width: 100%;
  height: var(--header-h);
  padding: 0 max(var(--page-x), calc(50% - var(--content-max) / 2 + var(--page-x)));
  line-height: 1;
  background: oklch(100% 0 0 / 0.97);
  border-bottom: 1px solid var(--color-border);
  box-shadow: 0 1px 0 oklch(19% 0.022 256 / 0.03);
  backdrop-filter: saturate(180%) blur(10px);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
}

@keyframes nav-header-elevate {
  from {
    background: oklch(100% 0 0 / 0.98);
    border-bottom-color: var(--color-border);
    box-shadow: 0 1px 0 oklch(19% 0.022 256 / 0.02);
  }
  to {
    background: oklch(100% 0 0 / 0.92);
    border-bottom-color: var(--color-border-strong);
    box-shadow: 0 6px 20px -14px oklch(19% 0.022 256 / 0.22);
  }
}

@supports (animation-timeline: scroll()) {
  .nav-header {
    animation: nav-header-elevate linear both;
    animation-timeline: scroll(root);
    animation-range: 0px 48px;
  }
}

.mr-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  height: 100%;
  color: var(--color-text);
  text-decoration: none;
  flex: 0 0 auto;
}

.mr-brand:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: -3px;
  border-radius: var(--radius-sm);
}

.brand-mark,
.mr-logo {
  width: 24px;
  height: 24px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 2.5px;
  flex: 0 0 auto;
}

.brand-mark span,
.mr-logo span {
  display: block;
  border-radius: 1.5px;
  background: var(--color-text);
}

.brand-mark span:nth-child(2),
.mr-logo span:nth-child(2) {
  background: var(--color-accent);
}

.brand-mark span:nth-child(3),
.mr-logo span:nth-child(3) {
  background: oklch(54% 0.065 252);
}

.brand-mark span:nth-child(4),
.mr-logo span:nth-child(4) {
  background: var(--color-border-strong);
}

.mr-brand-copy {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  line-height: 1;
}

.mr-brand-text {
  font-family: var(--font-serif);
  font-size: 17.5px;
  font-weight: 700;
  line-height: 1;
  color: var(--color-text);
  white-space: nowrap;
  letter-spacing: -0.01em;
  transition: color 140ms ease;
}

@media (hover: hover) {
  .mr-brand:hover .mr-brand-text {
    color: var(--color-accent-strong);
  }
}

.mr-brand-sub {
  font-family: var(--font-sans);
  font-size: 11.5px;
  font-weight: 500;
  line-height: 1;
  letter-spacing: 0.02em;
  color: var(--color-muted);
  white-space: nowrap;
}

.nav {
  display: flex;
  align-items: stretch;
  justify-content: flex-end;
  gap: 2px;
  height: 100%;
  margin-left: auto;
  padding-left: 16px;
  position: relative;
  flex-wrap: nowrap;
  min-width: 0;
}

.nav::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  width: 1px;
  height: 16px;
  background: var(--color-border);
  transform: translateY(-50%);
}

.nav-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 0 11px;
  border: 0;
  border-radius: 0;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  color: var(--color-muted);
  position: relative;
  transition: color 140ms ease, background-color 140ms ease;
}

.nav-link::after {
  content: "";
  position: absolute;
  bottom: -1px;
  left: 8px;
  right: 8px;
  height: 2px;
  border-radius: 1px 1px 0 0;
  background: var(--color-border-strong);
  opacity: 0;
  transform: scaleX(0.65);
  transform-origin: center;
  transition: opacity 150ms ease, transform 160ms ease, background-color 150ms ease;
}

@media (hover: hover) {
  .nav-link:hover {
    color: var(--color-text);
    background: oklch(96.5% 0.005 252 / 0.72);
  }
  .nav-link:hover::after {
    opacity: 0.55;
    transform: scaleX(1);
  }
}

.nav-link:active {
  background: oklch(94.8% 0.007 252 / 0.85);
}

.nav-link:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: -3px;
  border-radius: var(--radius-sm);
}

.nav-link.active,
.nav-link[aria-current="page"] {
  color: var(--color-text);
  font-weight: 500;
  text-shadow: 0 0 0.35px currentColor;
  background: transparent;
}

.nav-link.active::after,
.nav-link[aria-current="page"]::after {
  left: 6px;
  right: 6px;
  background: var(--color-accent);
  opacity: 1;
  transform: scaleX(1);
}

@media (hover: hover) {
  .nav-link.active:hover,
  .nav-link[aria-current="page"]:hover {
    color: var(--color-accent-strong);
    background: transparent;
  }
  .nav-link.active:hover::after,
  .nav-link[aria-current="page"]:hover::after {
    opacity: 1;
    background: var(--color-accent-strong);
  }
}

/* ── Shared Surface Primitives ── */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}

.tag,
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-muted);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
}

.tag {
  padding: 3px 7px;
  border-radius: var(--radius-sm);
}

.pill {
  padding: 4px 10px;
  border-radius: var(--radius-pill);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 34px;
  padding: 7px 13px;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease;
}

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

.btn-primary {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--color-accent-strong);
  border-color: var(--color-accent-strong);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: var(--space-3);
}

.report-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.report-item,
.report-list button {
  width: 100%;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--color-muted);
  text-align: left;
}

.report-item:hover,
.report-list button:hover,
.report-list button.active {
  background: var(--color-surface);
  border-color: var(--color-border);
}

.report-list button.active {
  border-color: var(--color-accent);
  color: var(--color-text);
}

.report-card {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  transition: background-color 140ms ease, border-color 140ms ease;
}

.report-card:hover,
.report-card.active {
  background: var(--color-surface);
  border-color: var(--color-border);
}

.report-card.active {
  border-color: var(--color-accent);
}

.report-card button {
  border-color: transparent;
  background: transparent;
}

.report-card button:hover,
.report-card button.active {
  border-color: transparent;
  background: transparent;
}

.report-export-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 12px 10px;
  color: var(--color-dim);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
}

.report-export-links a {
  color: var(--color-muted);
  text-decoration: none;
}

.report-export-links a:hover {
  color: var(--color-accent);
}

.report-header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
}

.download-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-2);
  padding-top: 2px;
}

.download-btn {
  white-space: nowrap;
}

.footer-watermark {
  color: var(--color-muted);
  font-family: var(--font-mono);
  font-size: 12px;
}

.mr-watermark {
  position: relative;
  z-index: 1;
  width: 100%;
  padding: 16px var(--page-x) calc(16px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--color-border);
  color: var(--color-muted);
  background: var(--color-surface);
  font-family: var(--font-sans);
  font-size: 12px;
  line-height: 1.4;
  text-align: center;
}

.desktop-only { display: initial; }
.mobile-only { display: none; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .nav-header { animation: none !important; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 1180px) {
  .nav-header { gap: 12px; }
  .nav { padding-left: 12px; gap: 0; }
  .nav-link { padding: 0 8.5px; font-size: 12.5px; }
  .nav-link::after { left: 6px; right: 6px; }
}

@media (max-width: 1020px) {
  .mr-brand-sub { display: none; }
  .nav-link { padding: 0 7.5px; }
}

@media (max-width: 840px) {
  :root { --page-x: 16px; }

  .desktop-only { display: none !important; }
  .mobile-only { display: initial; }

  .nav-header {
    height: auto;
    min-height: 0;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 12px;
    padding-block: 10px 8px;
    overflow-x: clip;
  }

  .mr-brand { width: 100%; height: auto; }
  .mr-brand-copy { flex-wrap: wrap; gap: 4px 8px; }
  .mr-brand-text { font-size: 17px; }
  .mr-brand-sub { display: inline; font-size: 11px; }

  .nav {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    width: 100%;
    height: auto;
    margin-left: 0;
    justify-content: stretch;
    gap: 2px;
    padding-left: 0;
  }
  .nav::before { display: none; }

  .nav-link {
    min-width: 0;
    height: 34px;
    padding: 0 3px;
    font-size: 12px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .nav-link::after,
  .nav-link.active::after,
  .nav-link[aria-current="page"]::after {
    left: 8px;
    right: 8px;
    bottom: 1px;
  }

  .stats-grid { grid-template-columns: 1fr 1fr; }
  .report-header-top { flex-direction: column; }
  .download-actions { justify-content: flex-start; }
}

@media (max-width: 420px) {
  .nav-link {
    flex: initial;
    min-width: 0;
    padding-inline: 4px;
  }
  .stats-grid { grid-template-columns: 1fr; }
}
