/* ---------- Reset & base ---------- */
*, *::before, *::after { box-sizing: border-box; }

:root {
  --color-bg: #ffffff;
  --color-surface: #f7f8fa;
  --color-surface-2: #eef1f6;
  --color-border: #e3e7ee;
  --color-text: #1f2937;
  --color-muted: #5b6677;
  --color-primary: #1e3a8a;
  --color-primary-hover: #1d4ed8;
  --color-accent: #b91c1c;
  --color-success: #166534;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.06);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --maxw: 1100px;
  --maxw-narrow: 880px;
}

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.65;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--color-primary);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}
a:hover { color: var(--color-primary-hover); border-bottom-color: currentColor; }

h1, h2, h3, h4 {
  color: #0f172a;
  line-height: 1.25;
  margin: 0 0 0.6em;
  font-weight: 700;
}
h1 { font-size: 2.1rem; letter-spacing: -0.01em; }
h2 { font-size: 1.55rem; letter-spacing: -0.005em; margin-top: 2em; }
h3 { font-size: 1.2rem; margin-top: 1.6em; color: #1e293b; }
h4 { font-size: 1.02rem; margin-top: 1.2em; color: #334155; }

p { margin: 0 0 1em; }

ul, ol { padding-left: 1.4em; margin: 0 0 1em; }
li { margin-bottom: 0.35em; }

code, pre {
  font-family: "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.92em;
}
code {
  background: var(--color-surface-2);
  padding: 0.12em 0.4em;
  border-radius: 4px;
  color: #0f172a;
}

hr { border: none; border-top: 1px solid var(--color-border); margin: 2.5em 0; }

/* ---------- Layout ---------- */
.container {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 1.25rem;
}
.container-narrow {
  max-width: var(--maxw-narrow);
  margin: 0 auto;
  padding: 0 1.25rem;
}

main { padding: 2rem 0 4rem; }

/* ---------- Navbar ---------- */
.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--color-border);
}
.navbar-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0.75rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.nav-brand {
  font-weight: 700;
  font-size: 1rem;
  color: #0f172a;
  border-bottom: none;
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  line-height: 1.3;
  min-width: 0;
}
.nav-brand:hover { color: var(--color-primary); border-bottom: none; }
.nav-brand-tag {
  flex: 0 0 auto;
  align-self: flex-start;
  background: var(--color-primary);
  color: white;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 7px;
  border-radius: 4px;
  letter-spacing: 0.02em;
  line-height: 1.2;
  /* Sit on the first text line of the wrapped title */
  margin-top: 2px;
  white-space: nowrap;
}
.nav-brand-title {
  display: inline;
  min-width: 0;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  list-style: none;
  margin: 0;
  padding: 0;
}
.nav-links a {
  display: block;
  padding: 0.45rem 0.75rem;
  font-size: 0.92rem;
  font-weight: 500;
  color: #334155;
  border-radius: var(--radius-sm);
  border-bottom: none;
}
.nav-links a:hover {
  background: var(--color-surface);
  color: var(--color-primary);
  border-bottom: none;
}
.nav-links a.active {
  background: var(--color-surface-2);
  color: var(--color-primary);
}

.nav-toggle {
  display: none;
  background: transparent;
  border: 1px solid var(--color-border);
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 1rem;
}

@media (max-width: 980px) {
  .nav-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .nav-links {
    display: none;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    background: white;
    border-top: 1px solid var(--color-border);
    padding: 0.5rem 1.25rem 0.75rem;
  }
  .nav-links.open { display: flex; }
  .navbar-inner { flex-wrap: wrap; }
  .nav-links a { padding: 0.6rem 0.5rem; }
}

/* Tighten nav-link spacing slightly so 8 items fit comfortably on desktop */
@media (min-width: 981px) {
  .nav-links a { padding: 0.45rem 0.6rem; font-size: 0.9rem; }
}

/* ---------- Hero ---------- */
.hero {
  padding: 3rem 0 2.5rem;
  background: linear-gradient(180deg, #f8fafc 0%, #ffffff 100%);
  border-bottom: 1px solid var(--color-border);
}
.hero h1 {
  font-size: 2.4rem;
  margin-bottom: 0.4em;
  letter-spacing: -0.015em;
}
.hero .subtitle {
  font-size: 1.1rem;
  color: var(--color-muted);
  max-width: 820px;
  margin: 0 auto 1.5em;
  text-align: center;
}
.hero .authors {
  font-size: 1rem;
  color: #334155;
  margin-bottom: 0.4em;
}
.hero .affiliation {
  font-size: 0.95rem;
  color: var(--color-muted);
}
.hero-center { text-align: center; }

.hero-cta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: center;
  margin-top: 1.5rem;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.55rem 1.05rem;
  background: var(--color-primary);
  color: white;
  font-weight: 500;
  font-size: 0.92rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-primary);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
}
.btn:hover {
  background: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
  color: white;
  border-bottom: 1px solid var(--color-primary-hover);
}
.btn-secondary {
  background: white;
  color: var(--color-primary);
}
.btn-secondary:hover {
  background: var(--color-surface);
  color: var(--color-primary);
}
.btn-ghost {
  background: transparent;
  color: var(--color-primary);
  border-color: var(--color-border);
}
.btn-ghost:hover {
  background: var(--color-surface);
  border-color: var(--color-primary);
  color: var(--color-primary);
}

/* ---------- Section / cards ---------- */
.section { margin: 3rem 0; }
.section-title {
  font-size: 1.7rem;
  margin-bottom: 0.4em;
  letter-spacing: -0.005em;
}
.section-lead {
  font-size: 1.05rem;
  color: var(--color-muted);
  margin-bottom: 1.5em;
}

.card {
  background: white;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 1rem; }

.callout {
  border-left: 4px solid var(--color-primary);
  background: var(--color-surface);
  padding: 0.9rem 1.1rem;
  margin: 1.25rem 0;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.callout p:last-child { margin-bottom: 0; }
.callout-warn { border-left-color: #d97706; background: #fffbeb; }
.callout-success { border-left-color: var(--color-success); background: #f0fdf4; }
.callout-note { border-left-color: var(--color-muted); background: var(--color-surface); }

/* Highlight stat blocks */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin: 1.25rem 0;
}
.stat {
  background: white;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 1rem 1.1rem;
  text-align: center;
}
.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--color-primary);
  line-height: 1.1;
}
.stat-label {
  display: block;
  margin-top: 0.4em;
  font-size: 0.82rem;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; margin: 1.25rem 0; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.94rem;
  background: white;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--color-border);
}
th, td {
  text-align: left;
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid var(--color-border);
}
th {
  background: var(--color-surface);
  font-weight: 600;
  font-size: 0.85rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: #334155;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfd; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-caption {
  font-size: 0.88rem;
  color: var(--color-muted);
  margin-top: -0.5em;
  margin-bottom: 1.25em;
  text-align: center;
  font-style: italic;
}

/* ---------- Figures / images ---------- */
.figure {
  margin: 1.5rem 0 1.75rem;
}
.figure img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
}
.figure-caption {
  font-size: 0.88rem;
  color: var(--color-muted);
  margin-top: 0.6em;
  text-align: center;
  line-height: 1.5;
}

.figure-grid {
  display: grid;
  gap: 0.85rem;
  margin: 1.5rem 0 1.75rem;
}
.figure-grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.figure-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.figure-grid.cols-5 { grid-template-columns: repeat(5, 1fr); }
@media (max-width: 720px) {
  .figure-grid.cols-2,
  .figure-grid.cols-3,
  .figure-grid.cols-5 { grid-template-columns: 1fr; }
}
.figure-grid .figure { margin: 0; }
.figure-grid .figure img { background: white; }
.figure-grid .figure-caption { font-size: 0.8rem; }

.figure-zoom { cursor: zoom-in; transition: transform 0.18s ease; }
.figure-zoom:hover { transform: translateY(-1px); }

/* Lightbox overlay */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.92);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 2rem;
  cursor: zoom-out;
}
.lightbox.open { display: flex; }
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: var(--radius-md);
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}
.lightbox-close {
  position: absolute;
  top: 1rem; right: 1.25rem;
  color: white;
  font-size: 1.5rem;
  background: none;
  border: none;
  cursor: pointer;
}

/* ---------- Page hero (smaller, for non-home pages) ---------- */
.page-hero {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 2.25rem 0 1.75rem;
}
.page-hero h1 {
  font-size: 1.9rem;
  margin-bottom: 0.3em;
}
.page-hero .breadcrumb {
  font-size: 0.85rem;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.6em;
}
.page-hero p { color: var(--color-muted); margin: 0; max-width: 780px; }

/* ---------- Tags ---------- */
.tag {
  display: inline-block;
  padding: 0.2em 0.65em;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: 999px;
  background: var(--color-surface-2);
  color: #334155;
  letter-spacing: 0.02em;
}
.tag-primary { background: #dbeafe; color: #1d4ed8; }
.tag-accent { background: #fee2e2; color: var(--color-accent); }
.tag-success { background: #dcfce7; color: var(--color-success); }
.tag-warn { background: #fef3c7; color: #92400e; }

/* ---------- TOC (in-page table of contents) ---------- */
.toc {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
}
.toc h4 {
  margin: 0 0 0.5em;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-muted);
}
.toc ul,
.toc ol {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0.3em 1.25em;
}
.toc ol { counter-reset: toc-counter; }
.toc li { margin: 0; }
.toc ol > li {
  counter-increment: toc-counter;
  display: flex;
  align-items: baseline;
  gap: 0.5em;
}
.toc ol > li::before {
  content: counter(toc-counter) ".";
  flex: 0 0 auto;
  min-width: 1.5em;
  color: var(--color-muted);
  font-weight: 700;
  font-size: 0.85em;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.toc a {
  font-size: 0.92rem;
  border-bottom: none;
}
.toc a:hover { border-bottom: 1px solid currentColor; }

/* Multi-column hierarchical TOC (used on Results) */
.toc-multi .toc-cols {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem 2rem;
  align-items: start;
}
@media (max-width: 900px) {
  .toc-multi .toc-cols { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  .toc-multi .toc-cols { grid-template-columns: 1fr; }
}
.toc-multi .toc-col + .toc-col { padding-top: 0; }
.toc-multi .toc-section {
  margin: 0 0 0.35em;
  font-weight: 700;
  font-size: 0.95rem;
  color: #0f172a;
}
.toc-multi .toc-section a { color: #0f172a; }
.toc-multi .toc-section a:hover { color: var(--color-primary); }
.toc-multi .toc-sublist {
  list-style: none;
  padding: 0 0 0 0.25rem;
  margin: 0 0 0.85rem;
}
.toc-multi .toc-sublist li { margin: 0 0 0.18em; }
.toc-multi .toc-sublist a { font-size: 0.88rem; }
.toc-prefix {
  display: inline-block;
  min-width: 2.1em;
  margin-right: 0.35em;
  color: var(--color-muted);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 0.82em;
  text-align: right;
}
.toc-multi .toc-section .toc-prefix { color: var(--color-primary); font-size: 0.95em; }

/* ---------- PDF viewer ---------- */
.pdf-frame {
  width: 100%;
  height: 80vh;
  min-height: 600px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}
.pdf-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
  align-items: center;
}
.pdf-meta {
  font-size: 0.88rem;
  color: var(--color-muted);
  margin-left: auto;
}

/* ---------- Footer ---------- */
.footer {
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
  padding: 2rem 0;
  margin-top: 4rem;
  font-size: 0.9rem;
  color: var(--color-muted);
}
.footer-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 1.25rem;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: space-between;
  align-items: center;
}

/* ---------- Cards grid (home overview) ---------- */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
  margin: 1.5rem 0;
}
.cards-grid .card {
  display: flex;
  flex-direction: column;
}
.cards-grid .card h3 { margin-top: 0; }
.cards-grid .card p { color: var(--color-muted); flex: 1; }
.cards-grid .card a.btn { align-self: flex-start; margin-top: 0.5em; }

/* ---------- Math (KaTeX overrides) ---------- */
.katex-display {
  margin: 1.25em 0 !important;
  overflow-x: auto;
  overflow-y: hidden;
}

/* ---------- Misc ---------- */
.muted { color: var(--color-muted); }
.center { text-align: center; }
.mt-0 { margin-top: 0 !important; }
.mb-0 { margin-bottom: 0 !important; }
.mb-2 { margin-bottom: 1.5rem !important; }
.small { font-size: 0.88rem; }
.divider {
  height: 1px;
  background: var(--color-border);
  margin: 2.5em 0;
  border: none;
}
.kbd {
  display: inline-block;
  padding: 0.1em 0.45em;
  font-family: inherit;
  font-size: 0.85em;
  font-weight: 600;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-bottom-width: 2px;
  border-radius: 4px;
}

/* ---------- Cue badges (Sign / Meter / Curb / Aggregation) ---------- */
.cue-tag {
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
  margin-left: 0.55em;
  padding: 0.18em 0.65em;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-radius: 999px;
  line-height: 1.4;
  white-space: nowrap;
}
.cue-tag::before {
  content: "";
  display: inline-block;
  width: 0.5em;
  height: 0.5em;
  border-radius: 999px;
  margin-right: 0.45em;
  background: currentColor;
  opacity: 0.85;
}
.cue-sign        { background: #dbeafe; color: #1d4ed8; }
.cue-meter       { background: #fef3c7; color: #92400e; }
.cue-curb        { background: #dcfce7; color: #166534; }
.cue-aggregation { background: #ede9fe; color: #6d28d9; }
.cue-all         { background: #f3f4f6; color: #374151; }

/* legend row above sections */
.cue-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.25rem 0 1.5rem;
}

/* ---------- Lightbox slideshow controls ---------- */
.lightbox {
  flex-direction: column;
}
.lightbox-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.lightbox-stage img { pointer-events: auto; }

.lightbox-prev,
.lightbox-next {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.12);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  font-size: 1.5rem;
  cursor: pointer;
  user-select: none;
  pointer-events: auto;
  transition: background 0.15s ease, transform 0.05s ease;
}
.lightbox-prev:hover,
.lightbox-next:hover { background: rgba(255, 255, 255, 0.25); }
.lightbox-prev { left: 1.25rem; }
.lightbox-next { right: 1.25rem; }
.lightbox-prev[disabled],
.lightbox-next[disabled],
.lightbox-prev[hidden],
.lightbox-next[hidden] { display: none !important; }

.lightbox-counter {
  position: absolute;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  color: white;
  background: rgba(0, 0, 0, 0.5);
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
.lightbox-caption {
  position: absolute;
  bottom: 3.5rem;
  left: 50%;
  transform: translateX(-50%);
  max-width: min(900px, calc(100% - 2rem));
  color: white;
  background: rgba(0, 0, 0, 0.5);
  padding: 0.45rem 0.9rem;
  border-radius: 6px;
  font-size: 0.9rem;
  text-align: center;
  pointer-events: none;
}
.lightbox-caption:empty { display: none; }

@media (max-width: 600px) {
  .lightbox-prev, .lightbox-next { width: 40px; height: 40px; font-size: 1.2rem; }
  .lightbox-prev { left: 0.5rem; }
  .lightbox-next { right: 0.5rem; }
  .lightbox-caption { bottom: 3rem; font-size: 0.82rem; padding: 0.35rem 0.7rem; }
}
