/* ==========================================================================
   SIGGRAPH Font Family Definitions (Local woff2 + Google Fonts fallback)
   ACM SIGGRAPH / acmart standard (from fairmeta.cls):
     - Body Text: Linux Libertine (Libertinus Serif)
     - Titles & Headings: Linux Biolinum (Libertinus Sans)
     - Monospace / Code: Inconsolata
   ========================================================================== */

@font-face {
  font-family: 'Libertinus Serif';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: local('Libertinus Serif'), local('Linux Libertine'), local('Linux Libertine O'),
       url('../fonts/LibertinusSerif-Regular.woff2') format('woff2');
}

@font-face {
  font-family: 'Libertinus Serif';
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: local('Libertinus Serif Italic'), local('Linux Libertine Italic'),
       url('../fonts/LibertinusSerif-Italic.woff2') format('woff2');
}

@font-face {
  font-family: 'Libertinus Serif';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: local('Libertinus Serif Bold'), local('Linux Libertine Bold'),
       url('../fonts/LibertinusSerif-Bold.woff2') format('woff2');
}

@font-face {
  font-family: 'Libertinus Sans';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: local('Libertinus Sans'), local('Linux Biolinum'), local('Linux Biolinum O'),
       url('../fonts/LibertinusSans-Regular.woff2') format('woff2');
}

@font-face {
  font-family: 'Libertinus Sans';
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: local('Libertinus Sans Italic'), local('Linux Biolinum Italic'),
       url('../fonts/LibertinusSans-Italic.woff2') format('woff2');
}

@font-face {
  font-family: 'Libertinus Sans';
  font-style: normal;
  font-weight: 600 800;
  font-display: swap;
  src: local('Libertinus Sans Bold'), local('Linux Biolinum Bold'),
       url('../fonts/LibertinusSans-Bold.woff2') format('woff2');
}

@font-face {
  font-family: 'Inconsolata';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: local('Inconsolata'),
       url('../fonts/Inconsolata-Regular.woff2') format('woff2');
}

@import url('https://fonts.googleapis.com/css2?family=Inconsolata:wght@400;500;600;700&family=Libertinus+Sans:ital,wght@0,400;0,700;1,400&family=Libertinus+Serif:ital,wght@0,400;0,700;1,400;1,700&display=swap');

:root {
  /* SIGGRAPH Font Trinity (as defined in fairmeta.cls) */
  --font-serif: 'Libertinus Serif', 'Linux Libertine', 'Linux Libertine O', 'LinLibertine', Georgia, 'Times New Roman', serif;
  --font-sans: 'Libertinus Sans', 'Linux Biolinum', 'Linux Biolinum O', 'LinBiolinum', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: 'Inconsolata', 'Liberation Mono', Menlo, Monaco, Consolas, 'Courier New', monospace;

  /* Authentic MIT Palette */
  --mit-red: #750014;
  --mit-red-dark: #56000e;
  --mit-red-soft: rgba(117, 0, 20, 0.06);
  --mit-red-glow: rgba(117, 0, 20, 0.16);
  --ink-primary: #212326;
  --ink-secondary: #3b424d;
  --ink-muted: #6b7280;
  
  --bg-page: #FFFFFF;
  --bg-box: #F2F4F8;
  --bg-box-subtle: #F8FAFC;
  --bg-surface: #FFFFFF;
  --bg-surface-elevated: #F8FAFC;
  --border-color: #D1D5DB;
  --border-line: #D1D5DB;
  --border-subtle: #E5E7EB;

  --collab-blue: #1d4ed8;
  --collab-blue-bg: #eff6ff;

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-full: 9999px;
  --nav-height: 60px;
  --sidebar-width: 250px;
  --sidebar-gap: 2.25rem;
  --content-max: 1080px;
  /* sidebar column + gap + 1080px content column + 1.25rem side padding */
  --sidebar-layout-max: calc(var(--sidebar-width) + var(--sidebar-gap) + var(--content-max) + 2.5rem);
}

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

html {
  font-size: 16.5px;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--nav-height) + 15px);
  max-width: 100vw;
  overflow-x: clip;
}

body {
  font-family: var(--font-serif);
  background-color: var(--bg-page);
  color: var(--ink-primary);
  line-height: 1.72;
  margin: 0;
  padding: 0;
  padding-top: var(--nav-height);
  -webkit-font-smoothing: antialiased;
  max-width: 100vw;
  overflow-x: clip;
  position: relative;
}

.tab-label-short {
  display: none;
}
.tab-label-full {
  display: inline;
}

.gallery-domain-section,
.gallery-subsection-block {
  scroll-margin-top: calc(var(--nav-height) + 14px);
}

/* All headings across the website strictly follow ACM SIGGRAPH standard:
   Linux Biolinum (Libertinus Sans) for \sffamily titles and section headings */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-sans);
  font-weight: 700;
  letter-spacing: -0.01em;
}

code, pre, kbd, samp, tt {
  font-family: var(--font-mono);
}

/* Reading Progress Bar */
#reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  background: var(--mit-red);
  width: 0%;
  z-index: 1500;
  transition: width 0.1s ease-out;
}

/* ==========================================================================
   Fixed Top Navigation Bar (Always visible on scroll)
   ========================================================================== */
.top-nav-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  box-sizing: border-box;
  height: var(--nav-height);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1.5px solid var(--border-subtle);
  z-index: 1000;
  font-family: var(--font-sans);
}

.nav-inner {
  max-width: 1540px;
  width: 100%;
  margin: 0 auto;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
  padding: 0 2.25rem;
}

.nav-brand {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.brand-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  text-decoration: none;
  color: inherit;
  transition: opacity 0.15s ease;
}

.brand-link:hover {
  opacity: 0.88;
}

/* MIT brand: the standard logo is for digital use above 30 px tall, with clear
   space equal to the width of its M (brand.mit.edu/logos-marks/mit-logo). */
.mit-brand-logo {
  height: 32px;
  width: auto;
  display: block;
  flex-shrink: 0;
  margin-right: 1.1rem;
}

.csail-brand-logo {
  height: 22px;
  width: auto;
  display: block;
  flex-shrink: 0;
  object-fit: contain;
}

.brand-divider {
  width: 1px;
  height: 22px;
  background: var(--border-line);
  flex-shrink: 0;
  margin: 0 0.55rem;
}

.brand-text-lockup {
  display: flex;
  flex-direction: column;
  justify-content: center;
  line-height: 1.22;
}

.brand-lab-badge {
  font-family: var(--font-sans);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--mit-red);
  text-transform: uppercase;
  white-space: nowrap;
}

.brand-site-title {
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--ink-primary);
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.view-switcher {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--bg-box);
  padding: 4px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  flex-shrink: 0;
  margin: 0 auto;
}

.btn-icon-svg {
  display: inline-block;
  vertical-align: -2px;
  flex-shrink: 0;
  stroke: currentColor;
}

.view-tab-btn {
  background: transparent;
  border: none;
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-secondary);
  padding: 0.38rem 0.85rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  white-space: nowrap;
}

.view-tab-btn:hover {
  color: var(--mit-red);
}

.view-tab-btn.active {
  background: var(--mit-red);
  color: #FFFFFF !important;
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(117, 0, 20, 0.25);
}

.view-tab-btn .badge-count {
  background: rgba(0, 0, 0, 0.08);
  color: var(--ink-secondary);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.1rem 0.42rem;
  border-radius: var(--radius-full);
  margin-left: 0.15rem;
}

.view-tab-btn.active .badge-count {
  background: rgba(255, 255, 255, 0.28);
  color: #FFFFFF;
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex-shrink: 0;
}

.btn-nav-github {
  background: var(--bg-page);
  border: 1px solid var(--border-line);
  color: var(--ink-primary);
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.38rem 0.85rem;
  border-radius: var(--radius-full);
  text-decoration: none;
  transition: all 0.15s ease;
  white-space: nowrap;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.btn-nav-github:hover {
  border-color: var(--ink-primary);
  background: var(--bg-box);
  text-decoration: none;
}

/* Reads / Views Counter Badges */
.nav-reads-badge {
  background: var(--bg-page);
  border: 1px solid var(--border-line);
  color: var(--ink-secondary);
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.38rem 0.8rem;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  white-space: nowrap;
  flex-shrink: 0;
  transition: all 0.2s ease;
  user-select: none;
}

.nav-reads-badge:hover {
  border-color: var(--mit-red);
  color: var(--ink-primary);
  background: var(--bg-box);
}

.reads-num {
  font-family: var(--font-mono, monospace);
  font-weight: 700;
  color: var(--ink-primary);
  letter-spacing: -0.01em;
}

.footer-stats-strip {
  margin-top: 0.85rem;
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  font-family: var(--font-sans);
  font-size: 0.82rem;
  color: var(--ink-secondary);
  background: var(--bg-box);
  padding: 0.4rem 0.95rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-subtle);
}

@media (max-width: 600px) {
  .nav-reads-badge .reads-label {
    display: none;
  }
}

.btn-nav-download {
  background: var(--bg-page);
  border: 1.5px solid var(--mit-red);
  color: var(--mit-red);
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 700;
  padding: 0.38rem 0.95rem;
  border-radius: var(--radius-full);
  text-decoration: none;
  transition: all 0.15s ease;
  white-space: nowrap;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.btn-nav-download:hover {
  background: var(--mit-red);
  color: #fff;
}

/* ==========================================================================
   Page Main Container (Responsive & Centered)
   ========================================================================== */
.page-body {
  max-width: calc(var(--sidebar-layout-max) + 3rem);
  margin: 0 auto;
  padding: 2.5rem 1.5rem 5rem;
}

/* ==========================================================================
   Academic Header Block
   ========================================================================== */
.academic-header {
  max-width: 1080px;
  margin: 0 auto 2.5rem;
  text-align: center;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 2rem;
}

.header-pre-tag {
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--mit-red);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.85rem;
}

.main-paper-title {
  font-family: var(--font-sans);
  font-size: clamp(1.85rem, 3.6vw, 2.55rem);
  font-weight: 700;
  line-height: 1.22;
  color: var(--mit-red);
  margin-bottom: 1.15rem;
  letter-spacing: -0.01em;
  max-width: 1000px;
  margin-left: auto;
  margin-right: auto;
}

.authors-row {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.35rem 0.9rem;
  font-family: var(--font-sans);
  font-size: 1.08rem;
  font-weight: 600;
  color: var(--ink-primary);
  margin-bottom: 0.5rem;
}

.author-item {
  display: inline-flex;
  align-items: baseline;
  white-space: nowrap;
}

.author-item sup {
  font-size: 0.72rem;
  color: var(--mit-red);
  margin-left: 2px;
  font-weight: 700;
}

.affiliation-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  font-family: var(--font-sans);
  font-size: 0.98rem;
  color: var(--ink-secondary);
  margin-bottom: 1.5rem;
}

.affil-divider {
  display: none;
}

.status-badge {
  color: var(--mit-red);
  font-weight: 600;
}

.action-pills-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.65rem;
  margin-bottom: 1.75rem;
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font-sans);
  font-size: 0.86rem;
  font-weight: 600;
  padding: 0.45rem 1.1rem;
  background: var(--bg-box);
  border: 1px solid var(--border-line);
  color: var(--ink-primary);
  border-radius: var(--radius-full);
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s ease;
}

.pill-btn:hover {
  background: var(--mit-red);
  color: #fff !important;
  border-color: var(--mit-red);
}

.pill-btn.primary {
  background: var(--mit-red);
  color: #fff !important;
  border-color: var(--mit-red);
}

.pill-btn.primary:hover {
  background: var(--mit-red-dark);
}

.pill-btn.github-btn {
  background: #24292e;
  border-color: #24292e;
  color: #ffffff !important;
}

.pill-btn.github-btn:hover {
  background: #000000;
  border-color: #000000;
  color: #ffffff !important;
  transform: translateY(-1px);
}

[data-theme="dark"] .pill-btn.github-btn {
  background: #21262d;
  border-color: #30363d;
  color: #f0f6fc !important;
}

[data-theme="dark"] .pill-btn.github-btn:hover {
  background: #30363d;
  border-color: #8b949e;
}

.pill-btn.disabled {
  opacity: 0.65;
  cursor: default;
  border-style: dashed;
  color: var(--ink-muted) !important;
  background: var(--bg-box-subtle);
}

.pill-btn.disabled:hover {
  background: var(--bg-box-subtle);
  border-color: var(--border-color);
  transform: none;
  box-shadow: none;
}

/* ==========================================================================
   Core Mission & Empirical Framework Section (3 Pillars)
   ========================================================================== */
.core-mission-container {
  max-width: 1080px;
  width: 100%;
  box-sizing: border-box;
  margin: 1.25rem auto 1.5rem;
  background: var(--bg-box-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1.15rem 1.35rem 1.25rem;
  text-align: left;
}

.core-mission-header {
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 0.65rem;
  margin-bottom: 0.85rem;
}

.mission-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.mission-title-left {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.mission-badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--mit-red);
  background: var(--mit-red-soft);
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

.mission-title {
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--ink-primary);
  letter-spacing: -0.01em;
  margin: 0;
  white-space: nowrap;
}

.mission-live-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 600;
  color: #065F46;
  background: #ECFDF5;
  border: 1px solid #A7F3D0;
  padding: 0.15rem 0.55rem;
  border-radius: 9999px;
  white-space: nowrap;
  letter-spacing: 0.02em;
}

.live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: #10B981;
  box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  animation: pulse-green 2s infinite;
  display: inline-block;
  flex-shrink: 0;
}

@keyframes pulse-green {
  0% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  }
  70% {
    transform: scale(1);
    box-shadow: 0 0 0 5px rgba(16, 185, 129, 0);
  }
  100% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
  }
}

.mission-header-desc {
  font-family: var(--font-sans);
  font-size: 0.81rem;
  color: var(--ink-secondary);
  margin: 0.35rem 0 0;
  line-height: 1.45;
}

.mission-pillars-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
}

.mission-pillar-card {
  background: #FFFFFF;
  border: 1px solid var(--border-subtle);
  border-top: 3px solid var(--mit-red);
  border-radius: var(--radius-sm);
  padding: 0.8rem 0.9rem;
  display: flex;
  flex-direction: column;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.mission-pillar-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.05);
}

.pillar-header {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.2rem;
}

.pillar-num {
  font-family: var(--font-mono);
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--mit-red);
  line-height: 1;
}

.pillar-header h4 {
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--ink-primary);
  margin: 0;
}

.pillar-tagline {
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 0.4rem;
  line-height: 1.3;
}

.mission-pillar-card p {
  font-family: var(--font-serif);
  font-size: 0.86rem;
  color: var(--ink-secondary);
  line-height: 1.56;
  margin: 0;
  text-align: left;
  hyphens: auto;
}

.pillar-caveat-note {
  margin-top: 0.65rem;
  padding: 0.45rem 0.6rem;
  background: var(--bg-box-subtle);
  border-left: 2.5px solid #d97706;
  border-radius: var(--radius-sm);
  font-family: var(--font-serif);
  font-size: 0.8rem;
  line-height: 1.45;
  color: var(--ink-secondary);
}

.pillar-caveat-note strong {
  font-family: var(--font-sans);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #b45309;
  display: block;
  margin-bottom: 0.15rem;
}

[data-theme="dark"] .pillar-caveat-note {
  background: rgba(217, 119, 6, 0.08);
  border-left-color: #f59e0b;
}

[data-theme="dark"] .pillar-caveat-note strong {
  color: #fbbf24;
}

@media (max-width: 860px) {
  .mission-title-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.45rem;
  }
  .mission-pillars-grid {
    grid-template-columns: 1fr;
    gap: 0.85rem;
  }
  .ranking-rules-grid {
    grid-template-columns: 1fr;
    gap: 0.85rem;
  }
}

.collab-title {
  font-weight: 700;
  color: var(--collab-blue);
  margin-bottom: 0.3rem;
}

/* ==========================================================================
   View Panels Switching
   ========================================================================== */
.view-panel {
  display: none;
  animation: fadeIn 0.2s ease;
}

.view-panel.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ==========================================================================
   VIEW 1: HTML FULL PAPER READER
   Two-column layout that mirrors the Case Archive exactly: a sticky
   directory sidebar on the left and the header + article on the right.
   Both views share --sidebar-width / --sidebar-gap and the same 1200px
   collapse breakpoint so the sidebars line up when switching tabs.
   ========================================================================== */
.html-reader-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  grid-template-areas:
    "toc header"
    "toc article";
  column-gap: var(--sidebar-gap);
  align-items: start;
  max-width: var(--sidebar-layout-max);
  margin: 0 auto;
  padding: 0 1.25rem;
}

.html-reader-layout > .academic-header {
  grid-area: header;
  max-width: none;
  margin: 0 0 2.5rem;
  min-width: 0;
}

/* reading measure stays at the original 860px, centred under the 1080px header */
.paper-article {
  grid-area: article;
  min-width: 0;
  width: 100%;
  max-width: 860px;
  justify-self: center;
}

/* Sidebar box: same look as .gallery-toc-sidebar */
.toc-pane {
  grid-area: toc;
  align-self: start;
  position: sticky;
  top: calc(var(--nav-height) + 1.5rem);
  max-height: calc(100vh - var(--nav-height) - 3rem);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--bg-box-subtle);
  border: 1px solid var(--border-subtle);
  border-left: 3px solid var(--mit-red);
  border-radius: var(--radius-md);
  padding: 1.15rem 0.95rem;
  font-family: var(--font-sans);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.03);
  z-index: 80;
}

.toc-pane::-webkit-scrollbar {
  width: 4px;
}
.toc-pane::-webkit-scrollbar-thumb {
  background: var(--border-line);
  border-radius: 2px;
}

.toc-links {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

/* Section links: same scale and states as .sidebar-domain-head / .sidebar-sub-link */
.toc-links a {
  display: block;
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--ink-secondary);
  text-decoration: none;
  padding: 0.25rem 0.4rem;
  border-left: 2px solid transparent;
  border-radius: var(--radius-sm);
  line-height: 1.35;
  transition: all 0.15s ease;
}

.toc-links a:hover {
  color: var(--mit-red);
  background: #ffffff;
}

.toc-links a.active {
  color: var(--mit-red);
  background: #ffffff;
  font-weight: 700;
  border-left-color: var(--mit-red);
}

/* Subsections: shown for the section being read, like the archive's sub-lists */
.toc-sub-list {
  display: none;
  list-style: none;
  flex-direction: column;
  gap: 0.1rem;
  margin: 0.15rem 0 0.4rem 0.55rem;
  padding-left: 0.45rem;
  border-left: 1px solid var(--border-subtle);
}

.toc-section.expanded > .toc-sub-list {
  display: flex;
}

.toc-links .toc-sub-link {
  font-size: 0.74rem;
  padding: 0.16rem 0.4rem;
  line-height: 1.3;
}

.toc-links .toc-sub-link.active {
  font-weight: 600;
}

@media (max-width: 1200px) {
  .html-reader-layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "header"
      "toc"
      "article";
    max-width: calc(var(--content-max) + 2rem);
    padding: 0 1rem;
  }

  .toc-pane {
    position: static;
    max-height: none;
    overflow: visible;
    margin-bottom: 2rem;
  }


  .toc-pane .toc-links {
    display: block;
    columns: 240px 3;
    column-gap: 1.25rem;
  }

  .toc-pane .toc-links li {
    break-inside: avoid;
    margin-bottom: 0.15rem;
  }

  /* compact in-flow version: sections only, subsections live in the drawer */
  .toc-pane .toc-sub-list,
  .toc-pane .toc-section.expanded > .toc-sub-list {
    display: none;
  }
}

/* ==========================================================================
   LaTeX Content Typography & Formatting
   ========================================================================== */
.latex-content-body {
  font-size: 1.05rem;
  line-height: 1.74;
  color: var(--ink-primary);
  text-align: justify;
  text-justify: inter-word;
}

.latex-content-body p {
  margin-bottom: 1.25rem;
  text-indent: 1.5em;
  font-family: var(--font-serif);
  font-size: 1.05rem;
  line-height: 1.74;
}

/* First paragraph following any heading, or explicitly non-indented */
.latex-content-body h1 + p,
.latex-content-body h2 + p,
.latex-content-body h3 + p,
.latex-content-body h4 + p,
.latex-content-body p.no-indent,
.latex-content-body p:has(> strong:first-child) {
  text-indent: 0;
}

.latex-content-body h1,
.latex-content-body h2,
.latex-content-body h3,
.latex-content-body h4 {
  text-indent: 0;
  text-align: left;
  letter-spacing: -0.015em;
}

/* Major Section Heading (e.g., Executive summary, 1 Introduction) */
.latex-content-body h1 {
  font-family: var(--font-sans);
  font-size: 1.55rem;
  font-weight: 700;
  color: var(--ink-primary);
  margin: 3.5rem 0 1.25rem;
  padding-bottom: 0.45rem;
  border-bottom: 1px solid var(--border-line);
}

.latex-content-body h1.unnumbered {
  color: var(--mit-red);
}

.latex-content-body .header-section-number {
  color: var(--mit-red);
  font-weight: 700;
  margin-right: 0.5rem;
}

/* Subsections (e.g., 1.1 Related work) */
.latex-content-body h2 {
  font-family: var(--font-sans);
  font-size: 1.28rem;
  font-weight: 700;
  color: var(--ink-primary);
  margin: 2.5rem 0 0.85rem;
  border-bottom: none;
  padding-bottom: 0;
}

/* Sub-subsections / Card Titles */
.latex-content-body h3 {
  font-family: var(--font-sans);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--mit-red);
  margin: 2rem 0 0.75rem;
}

/* Paragraph Sub-headings (e.g., The agentic tool layer.) */
.latex-content-body h4 {
  font-family: var(--font-sans);
  font-size: 1.08rem;
  font-weight: 700;
  color: var(--ink-primary);
  margin: 1.75rem 0 0.5rem;
  text-indent: 0;
}

/* ==========================================================================
   Executive Summary & Keybox Callout Cards
   ========================================================================== */
.keybox {
  background: var(--bg-box-subtle);
  border-left: 4px solid var(--mit-red);
  border-top: 1px solid var(--border-subtle);
  border-right: 1px solid var(--border-subtle);
  border-bottom: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 1.35rem 1.6rem;
  margin: 2rem 0 2.25rem;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.03);
}

[data-theme="dark"] .keybox {
  background: #181c22;
  border-color: #2b323c;
  border-left-color: var(--mit-red);
  box-shadow: none;
}

.keybox .keybox-title,
.keybox > p:first-child,
.keybox h3 {
  font-family: var(--font-sans);
  font-size: 1.22rem;
  font-weight: 700;
  color: var(--mit-red);
  text-indent: 0 !important;
  margin: 0 0 0.85rem 0;
  letter-spacing: -0.01em;
  line-height: 1.35;
}

.keybox ul {
  margin: 0;
  padding-left: 1.3rem;
}

.keybox li {
  margin-bottom: 0.75rem;
  line-height: 1.68;
  font-size: 0.98rem;
  color: var(--ink-primary);
}

.keybox li:last-child {
  margin-bottom: 0;
}

.keybox li p {
  text-indent: 0 !important;
  margin-bottom: 0;
}

.latex-content-body blockquote {
  border-left: 3.5px solid var(--mit-red);
  background: var(--bg-box-subtle);
  padding: 0.9rem 1.4rem;
  margin: 1.5rem 0;
  font-style: italic;
  color: var(--ink-secondary);
}

.latex-content-body code {
  font-family: var(--font-mono);
  background: var(--bg-box);
  padding: 0.15rem 0.35rem;
  border-radius: 3px;
  font-size: 0.9em;
}

.latex-content-body pre {
  background: #212326;
  color: #f8fafc;
  padding: 1.2rem;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.86rem;
  margin: 1.5rem 0;
}

.latex-content-body pre code {
  background: transparent;
  color: inherit;
  padding: 0;
}

/* ==========================================================================
   LaTeX Content Tables (Enhanced Academic Table Cards)
   ========================================================================== */
.academic-table-card {
  width: 100%;
  margin: 2.25rem 0;
  border: 1px solid var(--border-line);
  border-radius: var(--radius-md);
  background: #ffffff;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  scroll-margin-top: calc(var(--nav-height) + 1.5rem);
}

.academic-table-card .table-caption {
  padding: 0.95rem 1.25rem;
  background: var(--bg-box-subtle);
  border-bottom: 1px solid var(--border-subtle);
  font-family: var(--font-sans);
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--ink-secondary);
  text-align: left;
}

.academic-table-card .table-caption strong {
  color: var(--ink-primary);
  font-weight: 700;
}

.academic-table-card .table-scroll-container {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.academic-table-card table.academic-table,
.latex-content-body table.academic-table {
  width: 100% !important;
  min-width: 660px;
  display: table !important;
  margin: 0 !important;
  border: none !important;
  border-collapse: collapse !important;
  font-family: var(--font-sans);
  font-size: 0.85rem;
}

.academic-table-card th {
  background: var(--bg-box);
  border-top: none !important;
  border-bottom: 1.5px solid var(--ink-primary) !important;
  padding: 0.75rem 0.85rem;
  font-weight: 700;
  color: var(--ink-primary);
  text-align: left;
  vertical-align: bottom;
  white-space: normal;
}

.academic-table-card td {
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--ink-primary);
  line-height: 1.5;
  vertical-align: top;
}

.academic-table-card tbody tr:last-child td {
  border-bottom: none;
}

.academic-table-card tbody tr:hover {
  background: rgba(0, 0, 0, 0.015);
}

.academic-table-card .table-card-note {
  padding: 0.85rem 1.25rem;
  background: var(--bg-box-subtle);
  border-top: 1px solid var(--border-subtle);
  font-family: var(--font-sans);
  font-size: 0.82rem;
  line-height: 1.55;
  color: var(--ink-secondary);
}

.academic-table-card .table-card-note p {
  margin: 0;
  text-indent: 0 !important;
  font-family: var(--font-sans) !important;
  font-size: 0.82rem !important;
  line-height: 1.55 !important;
}

.latex-content-body table,
.latex-content-body table[style] {
  width: 100% !important;
  max-width: 100% !important;
  border-collapse: collapse;
  font-size: 0.88rem;
  font-family: var(--font-sans);
}

.latex-content-body th {
  background: var(--bg-box);
  border-top: 1.5px solid var(--ink-primary);
  border-bottom: 1px solid var(--ink-primary);
  padding: 0.6rem 0.8rem;
  text-align: left;
  font-weight: 700;
}

.latex-content-body td {
  border-bottom: 1px solid var(--border-subtle);
  padding: 0.55rem 0.8rem;
  vertical-align: top;
}

/* ==========================================================================
   Academic Figures & Subfigures (Matching PDF Figure Layout)
   ========================================================================== */
.academic-figure {
  margin: 2.5rem auto;
  max-width: 860px;
  width: 100%;
  text-align: center;
}

.academic-figure .figure-img-wrap {
  background: #FFFFFF;
  padding: 0.5rem;
  border: 1px solid var(--border-line);
  border-radius: var(--radius-sm);
  display: inline-block;
  max-width: 100%;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.04);
}

.academic-figure img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto;
  border-radius: var(--radius-sm);
}

.figure-subfigures-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  margin-bottom: 0.75rem;
  justify-content: center;
}

.subfigure {
  background: #FFFFFF;
  border: 1px solid var(--border-line);
  border-radius: var(--radius-sm);
  padding: 0.5rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  text-align: center;
}

.subfigure img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: var(--radius-sm);
}

.subcaption {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-secondary);
  margin-top: 0.45rem;
}

.academic-figure figcaption {
  font-family: var(--font-serif);
  font-size: 0.92rem;
  line-height: 1.58;
  color: var(--ink-secondary);
  margin: 0.85rem auto 0;
  max-width: 820px;
  text-align: justify;
  text-justify: inter-word;
  padding: 0 0.5rem;
}

.academic-figure figcaption strong {
  font-family: var(--font-sans);
  color: var(--ink-primary);
  font-weight: 700;
}

/* ==========================================================================
   Gallery Case Figures (Matching LaTeX Figures 3, 4, 6, 8)
   ========================================================================== */
.figure-gallery-figure {
  width: 100%;
  margin: 2.5rem 0;
  border: 1px solid var(--border-line);
  border-radius: var(--radius-md);
  background: #ffffff;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  padding: 0;
}

.gallery-tiles-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.15rem;
  background: var(--bg-box-subtle);
  border-bottom: 1px solid var(--border-subtle);
}

.gallery-tiles-tag {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--mit-red);
}

.gallery-tiles-count {
  font-size: 0.78rem;
  color: var(--ink-secondary);
  font-weight: 600;
}

.figure-gallery-figure .gallery-tiles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 0.65rem;
  padding: 0.9rem;
  background: var(--bg-box);
  max-height: 520px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 600px) {
  .figure-gallery-figure .gallery-tiles-grid {
    grid-template-columns: repeat(auto-fill, minmax(105px, 1fr));
    gap: 0.45rem;
    padding: 0.6rem;
    max-height: 440px;
  }
}

.gallery-tile-card {
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.gallery-tile-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  border-color: var(--mit-red);
}

.gallery-tile-thumb-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #111;
  overflow: hidden;
}

.gallery-tile-thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.gallery-tile-gid {
  position: absolute;
  top: 4px;
  left: 4px;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
}

.gallery-tile-meta {
  padding: 0.4rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.gallery-tile-author {
  font-size: 0.70rem;
  font-weight: 600;
  color: var(--ink-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gallery-tile-title {
  font-size: 0.66rem;
  color: var(--ink-secondary);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.figure-gallery-figure figcaption {
  padding: 0.85rem 1.15rem;
  background: #ffffff;
  border-top: 1px solid var(--border-subtle);
  font-size: 0.85rem;
  line-height: 1.55;
  color: var(--ink-secondary);
}

.figure-gallery-figure figcaption strong {
  color: var(--ink-primary);
  font-weight: 700;
}

.gallery-figure-actions {
  padding: 0.6rem 1.15rem 0.9rem;
  background: #ffffff;
  border-top: 1px dashed var(--border-subtle);
  display: flex;
  justify-content: flex-end;
}

/* In-Paper Case Archive Preview Cards */
.gallery-callout-panel {
  background: var(--bg-box);
  border: 1.5px dashed var(--border-line);
  border-radius: var(--radius-md);
  padding: 1.4rem 1.6rem;
  margin: 2.2rem auto;
  max-width: 860px;
  text-align: left;
}

.gallery-callout-panel .callout-tag {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--mit-red);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.35rem;
}

.gallery-callout-panel h4 {
  font-family: var(--font-sans);
  font-size: 1.12rem;
  font-weight: 700;
  color: var(--ink-primary);
  margin-bottom: 0.4rem;
}

.gallery-callout-panel p {
  font-family: var(--font-serif);
  font-size: 0.95rem;
  color: var(--ink-secondary);
  margin-bottom: 0.9rem;
  line-height: 1.6;
}

.btn-callout-switch {
  background: var(--mit-red);
  color: #FFFFFF;
  border: none;
  border-radius: var(--radius-full);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.45rem 1.1rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-callout-switch:hover {
  background: var(--mit-red-dark);
  transform: translateY(-1px);
  box-shadow: 0 3px 10px rgba(117, 0, 20, 0.2);
}

/* ==========================================================================
   VIEW 2: STATISTICS DASHBOARD STYLES
   ========================================================================== */
.stats-container {
  max-width: 1080px;
  margin: 0 auto;
  width: 100%;
}

.panel-section-title {
  font-family: var(--font-sans);
  font-size: 1.55rem;
  font-weight: 700;
  color: var(--mit-red);
  margin-bottom: 0.5rem;
}

.panel-section-desc {
  font-family: var(--font-serif);
  font-size: 1rem;
  color: var(--ink-secondary);
  margin-bottom: 2rem;
  line-height: 1.65;
}

.stat-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.25rem;
  margin-bottom: 2.75rem;
}

.stat-card {
  background: var(--bg-box-subtle);
  border: 1px solid var(--border-subtle);
  border-top: 3.5px solid var(--mit-red);
  border-radius: var(--radius-sm);
  padding: 1.35rem 1.5rem;
  transition: transform 0.15s ease;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.05);
}

.stat-val {
  font-family: var(--font-sans);
  font-size: 2.25rem;
  font-weight: 700;
  color: var(--mit-red);
  line-height: 1.1;
  margin-bottom: 0.4rem;
}

.stat-desc {
  font-family: var(--font-sans);
  font-size: 0.88rem;
  color: var(--ink-secondary);
  font-weight: 600;
}

.subsection-title {
  font-family: var(--font-sans);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--ink-primary);
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 0.35rem;
}

.academic-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 2.5rem;
  font-family: var(--font-sans);
  font-size: 0.88rem;
  background: #fff;
  border: 1px solid var(--border-subtle);
}

.academic-table th {
  background: var(--bg-box);
  border-top: 2px solid var(--ink-primary);
  border-bottom: 1.5px solid var(--ink-primary);
  padding: 0.75rem 0.85rem;
  text-align: left;
  font-weight: 700;
}

.academic-table td {
  padding: 0.75rem 0.85rem;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}

.academic-table tbody tr:hover {
  background: var(--bg-box-subtle);
}

.top-val {
  font-weight: 700;
  color: var(--mit-red);
}

.table-container {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
  margin-bottom: 2rem;
}

.table-container .academic-table {
  margin-bottom: 0;
  border: none;
}

.benchmark-table {
  min-width: 980px;
  font-size: 0.85rem;
}

.benchmark-table th {
  white-space: nowrap;
  font-size: 0.80rem;
  letter-spacing: 0.03em;
  background: var(--bg-box);
  color: var(--ink-primary);
  padding: 0.8rem 0.9rem;
}

.benchmark-table td {
  line-height: 1.5;
  font-size: 0.83rem;
  vertical-align: top;
  padding: 0.8rem 0.9rem;
}

.benchmark-table td:nth-child(1) {
  min-width: 140px;
  font-weight: 600;
  color: var(--ink-primary);
}

.benchmark-table td:nth-child(2) {
  min-width: 250px;
  color: var(--ink-secondary);
}

.benchmark-table td:nth-child(3) {
  min-width: 230px;
  color: var(--ink-primary);
}

.benchmark-table td:nth-child(4) {
  min-width: 190px;
  color: var(--ink-secondary);
}

.benchmark-table td:nth-child(5) {
  min-width: 120px;
  font-size: 0.80rem;
  color: var(--ink-secondary);
}

.benchmark-table td:nth-child(6) {
  min-width: 90px;
  white-space: nowrap;
}

.academic-link {
  color: var(--mit-red);
  text-decoration: underline;
  font-weight: 600;
  transition: color 0.15s ease;
}

.academic-link:hover {
  color: #5a0010;
}

.badge-tier {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
}

.badge-tier.tier-1 {
  background: #dcfce7;
  color: #15803d;
}

.badge-tier.tier-2 {
  background: #fef3c7;
  color: #b45309;
}

.tier-matrix-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.25rem;
  margin-top: 1.25rem;
}

.tier-card {
  background: #fff;
  border: 1px solid var(--border-line);
  border-radius: var(--radius-sm);
  padding: 1.25rem;
  font-family: var(--font-sans);
}

.tier-card.t1 { border-top: 3.5px solid #16a34a; }
.tier-card.t2 { border-top: 3.5px solid #d97706; }
.tier-card.t3 { border-top: 3.5px solid #2563eb; }
.tier-card.t4 { border-top: 3.5px solid #dc2626; }

.tier-badge {
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.4rem;
}

.tier-card.t1 .tier-badge { color: #15803d; }
.tier-card.t2 .tier-badge { color: #b45309; }
.tier-card.t3 .tier-badge { color: #2563eb; }
.tier-card.t4 .tier-badge { color: #dc2626; }

.tier-card h4 {
  font-size: 0.98rem;
  font-weight: 700;
  margin-bottom: 0.45rem;
}

.tier-card p {
  font-family: var(--font-serif);
  font-size: 0.88rem;
  color: var(--ink-secondary);
  line-height: 1.55;
}

/* ==========================================================================
   VIEW 3: VISUAL GALLERY STYLES
   ========================================================================== */
.gallery-page-layout {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: var(--sidebar-gap);
  max-width: var(--sidebar-layout-max);
  margin: 0 auto;
  padding: 0 1.25rem;
}

.gallery-toc-sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  position: sticky;
  top: calc(var(--nav-height) + 1.5rem);
  max-height: calc(100vh - var(--nav-height) - 3rem);
  overflow-y: auto;
  background: var(--bg-box-subtle);
  border: 1px solid var(--border-subtle);
  border-left: 3px solid var(--mit-red);
  border-radius: var(--radius-md);
  padding: 1.15rem 0.95rem;
  font-family: var(--font-sans);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.03);
  z-index: 80;
}

.gallery-toc-sidebar::-webkit-scrollbar {
  width: 4px;
}
.gallery-toc-sidebar::-webkit-scrollbar-thumb {
  background: var(--border-line);
  border-radius: 2px;
}

.sidebar-header {
  margin-bottom: 0.85rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-subtle);
}

.sidebar-overview-link {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink-secondary);
  text-decoration: none;
  padding: 0.35rem 0.55rem;
  margin-bottom: 0.75rem;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  transition: all 0.15s ease;
}

.sidebar-overview-link:hover {
  color: var(--mit-red);
  border-color: var(--mit-red);
  background: #ffffff;
}

.sidebar-overview-link svg {
  flex-shrink: 0;
}

.sidebar-tag {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--mit-red);
  margin-bottom: 0.15rem;
}

.sidebar-title {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--ink-primary);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.sidebar-domain-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.sidebar-domain-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--ink-primary);
  text-decoration: none;
  padding: 0.25rem 0.4rem;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
}

.sidebar-domain-head:hover,
.sidebar-domain-head.active {
  color: var(--mit-red);
  background: #ffffff;
}

.sidebar-domain-count {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ink-muted);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  padding: 0.05rem 0.35rem;
  border-radius: var(--radius-full);
}

.sidebar-sub-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding-left: 0.5rem;
  border-left: 1px solid var(--border-subtle);
  margin-left: 0.35rem;
}

.sidebar-sub-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.76rem;
  color: var(--ink-secondary);
  text-decoration: none;
  padding: 0.18rem 0.4rem;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
  line-height: 1.3;
}

.sidebar-sub-link:hover {
  color: var(--mit-red);
  background: #ffffff;
  padding-left: 0.6rem;
}

.sidebar-sub-link.active {
  color: var(--mit-red);
  background: #ffffff;
  font-weight: 600;
  border-left: 2px solid var(--mit-red);
  padding-left: 0.5rem;
}

.sub-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 170px;
}

.sub-cnt {
  font-size: 0.7rem;
  color: var(--ink-muted);
  margin-left: 0.25rem;
}

.gallery-container {
  flex: 1;
  min-width: 0;
  max-width: 1080px;
}

.gallery-domain-section {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 2px solid var(--border-subtle);
}

.gallery-domain-section:first-of-type {
  margin-top: 1.5rem;
  border-top: none;
  padding-top: 0;
}

.gallery-domain-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 0.4rem;
}

.domain-header-left {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.domain-label-badge {
  display: inline-block;
  font-family: var(--font-sans);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: var(--mit-red);
  color: #fff;
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
}

.gallery-domain-title {
  font-family: var(--font-serif);
  font-size: 1.65rem;
  font-weight: 700;
  color: var(--ink-primary);
  margin: 0;
}

.domain-count-badge {
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--mit-red);
  background: var(--mit-red-soft);
  border: 1px solid var(--mit-red-glow);
  padding: 0.2rem 0.65rem;
  border-radius: var(--radius-full);
}

.domain-header-desc {
  font-family: var(--font-serif);
  font-size: 0.95rem;
  color: var(--ink-secondary);
  margin-bottom: 1.5rem;
  line-height: 1.5;
}

.gallery-subsection-block {
  margin-top: 2rem;
}

.gallery-subsection-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  padding-bottom: 0.45rem;
  border-bottom: 1px solid var(--border-subtle);
}

.gallery-subsection-title {
  font-family: var(--font-sans);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--ink-primary);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.gallery-subsection-title::before {
  content: "§";
  color: var(--mit-red);
  font-weight: 400;
  font-size: 1.1rem;
}

.gallery-subsection-badge {
  font-family: var(--font-sans);
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--ink-secondary);
  background: var(--bg-box-subtle);
  border: 1px solid var(--border-subtle);
  padding: 0.12rem 0.55rem;
  border-radius: var(--radius-full);
}

@media (max-width: 1200px) {
  .gallery-page-layout {
    flex-direction: column;
    gap: 1.5rem;
    max-width: calc(var(--content-max) + 2rem);
    padding: 0 1rem;
  }
  .gallery-toc-sidebar {
    position: static;
    width: 100%;
    max-height: none;
  }
  .sidebar-nav {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 1.25rem;
  }
  .sidebar-domain-group {
    flex: 1;
    min-width: 240px;
  }
}

.gallery-controls-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 2rem;
  padding: 1rem 1.25rem;
  background: var(--bg-box);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
}

.filter-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.gallery-controls-card {
  background: var(--bg-box-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1.15rem 1.35rem;
  margin-bottom: 2rem;
}

.filter-row {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex-wrap: wrap;
}

.filter-label {
  font-family: var(--font-sans);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-secondary);
  min-width: 140px;
  flex-shrink: 0;
}

.filter-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
}

.filter-pill {
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.3rem 0.75rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-line);
  background: #fff;
  color: var(--ink-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.filter-pill:hover {
  border-color: var(--ink-primary);
  color: var(--ink-primary);
}

.filter-pill.active {
  background: var(--mit-red);
  color: #fff;
  border-color: var(--mit-red);
}

.filter-pill.rank-pill.pill-r1.active {
  background: var(--mit-red);
  border-color: var(--mit-red);
  color: #fff;
}

.filter-pill.rank-pill.pill-r2.active {
  background: #1D4ED8;
  border-color: #1D4ED8;
  color: #fff;
}

.filter-pill.rank-pill.pill-r3.active {
  background: #475569;
  border-color: #475569;
  color: #fff;
}

.rank-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
}

.dot-r1 { background-color: var(--mit-red); }
.dot-r2 { background-color: #1D4ED8; }
.dot-r3 { background-color: #64748B; }

.filter-pill.active .rank-dot {
  background-color: #ffffff;
}

.gallery-search-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
  flex-wrap: wrap;
  margin-top: 1rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border-subtle);
}

.search-input-wrap {
  flex: 1;
  max-width: 480px;
}

.search-input-wrap input {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  padding: 0.45rem 1rem;
  border: 1px solid var(--border-line);
  border-radius: var(--radius-full);
  width: 100%;
  outline: none;
  background: #fff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.search-input-wrap input[type="search"] {
  -webkit-appearance: none;
  appearance: none;
}

.search-input-wrap input:focus {
  border-color: var(--mit-red);
  box-shadow: 0 0 0 2px var(--mit-red-glow);
}

.filter-status-text {
  font-family: var(--font-sans);
  font-size: 0.82rem;
  color: var(--ink-secondary);
}

.gallery-sort-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-sans);
  font-size: 0.85rem;
}

.gallery-sort-label {
  color: var(--ink-secondary);
  font-weight: 600;
}

.gallery-sort-select {
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-line);
  background: #ffffff;
  color: var(--ink-primary);
  font-family: var(--font-sans);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.gallery-sort-select:focus {
  border-color: var(--mit-red);
  box-shadow: 0 0 0 2px var(--mit-red-glow);
}

.tile-subcat-sep {
  color: var(--ink-muted);
  margin: 0 0.15rem;
}

.tile-subcat-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--ink-secondary);
  max-width: 130px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}

/* ==========================================================================
   Evidence Ranking & Reproducibility Protocol Cards
   ========================================================================== */
.ranking-protocol-section {
  max-width: 1080px;
  width: 100%;
  box-sizing: border-box;
  margin: 0 auto 2rem;
  background: var(--bg-box-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1.25rem 1.45rem 1.35rem;
}

.ranking-protocol-header {
  margin-bottom: 1.25rem;
}

.ranking-protocol-desc {
  font-family: var(--font-serif);
  font-size: 0.95rem;
  color: var(--ink-secondary);
  line-height: 1.55;
  margin-top: 0.25rem;
}

.ranking-rules-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  align-items: stretch;
  margin-top: 1rem;
}

.ranking-tier-card {
  background: #FFFFFF;
  border: 1px solid var(--border-line);
  border-radius: var(--radius-sm);
  padding: 1.35rem 1.3rem 1.15rem;
  display: flex;
  flex-direction: column;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.03);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  position: relative;
  overflow: hidden;
  cursor: pointer;
}

.ranking-tier-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
}

.ranking-tier-card.tier-1 {
  border-top: 4px solid var(--mit-red);
}
.ranking-tier-card.tier-1:hover {
  border-color: var(--mit-red);
}

.ranking-tier-card.tier-2 {
  border-top: 4px solid #1D4ED8;
}
.ranking-tier-card.tier-2:hover {
  border-color: #1D4ED8;
}

.ranking-tier-card.tier-3 {
  border-top: 4px solid #64748B;
}
.ranking-tier-card.tier-3:hover {
  border-color: #64748B;
}

.tier-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
}

.tier-pill-badge {
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
}

.tier-pill-badge.pill-t1 {
  background: var(--mit-red);
  color: #FFFFFF;
}

.tier-pill-badge.pill-t2 {
  background: #1D4ED8;
  color: #FFFFFF;
}

.tier-pill-badge.pill-t3 {
  background: #64748B;
  color: #FFFFFF;
}

.tier-tag-pill {
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 600;
  color: #4b5563;
  background: var(--bg-box);
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-subtle);
}

.tier-card-title {
  font-family: var(--font-sans);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink-primary);
  margin-bottom: 0.55rem;
  letter-spacing: -0.01em;
}

.tier-card-desc {
  font-family: var(--font-serif);
  font-size: 0.88rem;
  color: var(--ink-secondary);
  line-height: 1.55;
  margin-bottom: 1.15rem;
  flex-grow: 1;
}

.tier-criteria-list {
  list-style: none;
  padding: 0;
  margin: 0;
  border-top: 1px solid var(--border-subtle);
  padding-top: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-family: var(--font-sans);
  font-size: 0.8rem;
  color: var(--ink-secondary);
}

.tier-criteria-list li {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.check-icon {
  color: #16A34A;
  font-weight: 800;
}

.cross-icon {
  color: #94A3B8;
  font-weight: 700;
}

.gallery-tiles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.gallery-tile {
  background: #fff;
  border: 1px solid var(--border-line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.gallery-tile:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
}

.tile-img-wrap {
  position: relative;
  width: 100%;
  height: 135px;
  background: var(--bg-box);
  cursor: pointer;
  overflow: hidden;
}

.tile-img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.2s ease;
}

.tile-img-wrap:hover img {
  transform: scale(1.05);
}

.tile-badges-overlay {
  position: absolute;
  top: 6px;
  left: 6px;
  right: 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
  z-index: 2;
}

.tile-badge-id {
  background: rgba(33, 35, 38, 0.88);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.15rem 0.45rem;
  border-radius: 3px;
  backdrop-filter: blur(4px);
  user-select: none;
  -webkit-user-select: none;
}

.tile-badge-rank {
  font-family: var(--font-sans);
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.15rem 0.45rem;
  border-radius: 3px;
  backdrop-filter: blur(4px);
  user-select: none;
  -webkit-user-select: none;
}

.tile-badge-rank.rank-1 {
  background: var(--mit-red);
  color: #FFFFFF;
  box-shadow: 0 1px 4px rgba(117, 0, 20, 0.4);
}

.tile-badge-rank.rank-2 {
  background: #1D4ED8;
  color: #FFFFFF;
  box-shadow: 0 1px 4px rgba(29, 78, 216, 0.4);
}

.tile-badge-rank.rank-3 {
  background: rgba(51, 65, 85, 0.9);
  color: #F8FAFC;
}

.tile-badge-video {
  position: absolute;
  bottom: 6px;
  right: 6px;
  background: rgba(15, 23, 42, 0.85);
  color: #FFFFFF;
  font-family: var(--font-sans);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 0.12rem 0.42rem;
  border-radius: 3px;
  backdrop-filter: blur(4px);
  pointer-events: none;
  z-index: 2;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

.tile-meta {
  padding: 0.75rem 0.85rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  font-family: var(--font-sans);
}

.tile-author {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--mit-red);
  margin-bottom: 0.25rem;
  overflow-wrap: anywhere;
}

.tile-author-link {
  color: var(--mit-red);
  text-decoration: none;
  transition: color 0.15s ease;
}

.tile-author-link:hover {
  text-decoration: underline;
  color: #a31f34;
}

/* Long names with a handle wrap as text; "· X ↗" stays together. */
.tile-platform {
  font-weight: 400;
  color: var(--ink-muted);
  white-space: nowrap;
}

.tile-desc {
  font-family: var(--font-serif);
  font-size: 0.84rem;
  color: var(--ink-secondary);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tile-desc-link {
  color: inherit;
  text-decoration: none;
  display: block;
}

.tile-desc-link:hover {
  color: var(--mit-red);
  text-decoration: underline;
}

.tile-footer {
  margin-top: auto;
  padding-top: 0.65rem;
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

.tile-action-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  width: 100%;
}

.tile-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.22rem 0.55rem;
  border-radius: 4px;
  text-decoration: none;
  transition: all 0.15s ease;
  font-family: var(--font-sans);
}

.tile-btn svg {
  flex-shrink: 0;
}

.tile-btn.btn-code {
  background: #FFF;
  color: var(--mit-red);
  border: 1.2px solid var(--mit-red);
}

.tile-btn.btn-code:hover {
  background: var(--mit-red);
  color: #FFF;
  text-decoration: none;
}

.tile-btn.btn-interactive {
  background: #EFF6FF;
  color: #1D4ED8;
  border: 1.2px solid #1D4ED8;
}

.tile-btn.btn-interactive:hover {
  background: #1D4ED8;
  color: #FFF;
  text-decoration: none;
}

.tile-btn.btn-post {
  background: var(--bg-box);
  color: var(--ink-secondary);
  border: 1px solid var(--border-line);
}

.tile-btn.btn-post:hover {
  background: var(--ink-primary);
  color: #FFF;
  border-color: var(--ink-primary);
  text-decoration: none;
}

/* Tier Card Clickable Footer */
.tier-card-footer {
  margin-top: auto;
  padding-top: 0.85rem;
  border-top: 1px dashed var(--border-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.tier-count-tag {
  font-family: var(--font-sans);
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ink-primary);
}

.tier-click-hint {
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--mit-red);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* Table 7 Evidence Rank Badges */
.badge-rank {
  display: inline-block;
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
  white-space: nowrap;
}

.badge-rank.rank-1 {
  background: #FEE2E2;
  color: #991B1B;
  border: 1px solid #FECACA;
}

.badge-rank.rank-2 {
  background: #EFF6FF;
  color: #1E40AF;
  border: 1px solid #BFDBFE;
}

.badge-rank.rank-3 {
  background: #F1F5F9;
  color: #475569;
  border: 1px solid #E2E8F0;
}

.post-interactive-link {
  color: #1D4ED8;
  font-weight: 600;
  text-decoration: underline;
}

.modal-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

.btn-lightbox-code {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 1.25rem;
  background: #1e293b;
  color: #fff;
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 600;
  border-radius: 6px;
  text-decoration: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  transition: all 0.15s ease;
}

.btn-lightbox-code:hover {
  background: #0f172a;
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  text-decoration: none;
}

.btn-lightbox-source {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 1.25rem;
  background: var(--mit-red);
  color: #fff;
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 600;
  border-radius: 6px;
  text-decoration: none;
  box-shadow: 0 2px 8px rgba(117, 0, 20, 0.25);
  transition: all 0.15s ease;
}

.btn-lightbox-source:hover {
  background: #90162a;
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(117, 0, 20, 0.35);
  text-decoration: none;
}

.btn-lightbox-source.btn-interactive {
  background: #1D4ED8;
  box-shadow: 0 2px 8px rgba(29, 78, 216, 0.25);
}

.btn-lightbox-source.btn-interactive:hover {
  background: #1e40af;
  box-shadow: 0 4px 12px rgba(29, 78, 216, 0.35);
}

[data-theme="dark"] .tile-source-btn {
  background: #202226;
  border-color: #32353c;
  color: #a8b0bd;
}

[data-theme="dark"] .tile-source-btn:hover {
  background: var(--mit-red);
  border-color: var(--mit-red);
  color: #fff;
}

/* ==========================================================================
   VIEW 4: PDF READER STYLES
   ========================================================================== */
.pdf-container {
  max-width: 1000px;
  margin: 0 auto;
}

.pdf-download-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  background: var(--bg-box);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 1rem 1.4rem;
  margin-bottom: 1.5rem;
  font-family: var(--font-sans);
}

.btn-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 1.15rem;
  border-radius: var(--radius-full);
  text-decoration: none;
  font-weight: 700;
  font-size: 0.86rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-pill-primary {
  background: var(--mit-red);
  color: #fff;
  border: 1px solid var(--mit-red);
}

.btn-pill-primary:hover {
  background: var(--mit-red-dark);
}

.pdf-frame-wrapper {
  width: 100%;
  height: 85vh;
  border: 1px solid var(--border-line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.06);
}

.pdf-iframe {
  width: 100%;
  height: 100%;
  border: none;
}

/* ==========================================================================
   Numbered Academic References & In-Text Citations
   ========================================================================== */
#references {
  margin-top: 3.5rem;
  padding-top: 1.5rem;
  border-top: 2px solid var(--ink-primary);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-family: var(--font-sans);
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink-primary);
}

.ref-count-badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ink-muted);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  padding: 0.15rem 0.55rem;
  border-radius: 9999px;
  vertical-align: middle;
}

.references.csl-bib-body {
  margin-top: 1.25rem;
  margin-bottom: 3.5rem;
}

.csl-entry {
  position: relative;
  text-align: left;
  overflow-wrap: anywhere;
  padding-left: 3.6rem;
  margin-bottom: 0.95rem;
  font-family: var(--font-serif);
  font-size: 0.88rem;
  line-height: 1.55;
  color: var(--ink-primary);
  scroll-margin-top: 5rem;
  border-radius: var(--radius-sm);
  transition: background-color 0.3s ease, padding 0.2s ease;
}

.csl-entry.ref-highlight {
  background-color: #FEF3C7;
  box-shadow: inset 3px 0 0 var(--mit-red);
  padding-top: 0.4rem;
  padding-bottom: 0.4rem;
  padding-right: 0.6rem;
}

.csl-entry.ref-highlight .csl-num {
  top: 0.4rem;
}

.csl-entry.ref-pulse {
  animation: refPulse 1.6s ease-out;
}

@keyframes refPulse {
  0% {
    background-color: #FDE68A;
    box-shadow: inset 3px 0 0 var(--mit-red), 0 0 0 5px rgba(117, 0, 20, 0.18);
  }
  100% {
    background-color: #FEF3C7;
    box-shadow: inset 3px 0 0 var(--mit-red), 0 0 0 0 rgba(117, 0, 20, 0);
  }
}

.ref-backlink {
  display: inline-block;
  margin-left: 0.5rem;
  font-family: var(--font-sans);
  font-size: 0.74rem;
  font-weight: 700;
  line-height: 1.5;
  color: var(--mit-red);
  background: #FFFFFF;
  border: 1px solid rgba(117, 0, 20, 0.3);
  border-radius: var(--radius-full);
  padding: 0 0.55rem;
  cursor: pointer;
  vertical-align: baseline;
}

.ref-backlink:hover,
.ref-backlink:focus-visible {
  background: var(--mit-red);
  color: #FFFFFF;
}

.citation-link.cite-return-flash {
  animation: citeFlash 1.8s ease-out;
  border-radius: 2px;
}

@keyframes citeFlash {
  0%, 40% { background-color: #FDE68A; }
  100% { background-color: transparent; }
}

.csl-num {
  position: absolute;
  left: 0;
  top: 0;
  width: 3rem;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--mit-red);
  user-select: all;
  letter-spacing: -0.02em;
  line-height: 1.55;
}

.citation-link,
.academic-ref-link {
  color: var(--mit-red);
  text-decoration: none;
  border-bottom: 1px dotted rgba(163, 31, 52, 0.45);
  transition: all 0.15s ease;
  cursor: pointer;
  font-weight: 500;
}

.citation-link:hover,
.academic-ref-link:hover {
  color: #7A0019;
  border-bottom: 1px solid #7A0019;
  background: var(--mit-red-soft);
  border-radius: 2px;
}

/* Post index table (Table 7 / Appendix C) */
.post-index-table {
  width: 100%;
  font-size: 0.82rem;
  line-height: 1.45;
  border-collapse: collapse;
}

.post-index-table th {
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.6rem 0.65rem;
  background: var(--bg-box);
  border-top: 2px solid var(--ink-primary);
  border-bottom: 1.5px solid var(--ink-primary);
  text-align: left;
}

.post-index-table td {
  padding: 0.5rem 0.65rem;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: top;
}

.post-index-table tbody tr:hover {
  background: var(--bg-box-subtle);
}

.post-index-table .post-gid {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--mit-red);
}

.post-index-table .post-type {
  font-family: var(--font-mono);
  text-align: center;
}

.badge-type {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 0.72rem;
  font-weight: 700;
  text-align: center;
}

.type-c { background: #eef2ff; color: #3730a3; border: 1px solid #c7d2fe; }
.type-f { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.type-s { background: #fefce8; color: #854d0e; border: 1px solid #fef08a; }
.type-r { background: #f8fafc; color: #475569; border: 1px solid #e2e8f0; }

.post-index-table .post-link {
  color: var(--ink-primary);
  text-decoration: none;
}

.post-index-table .post-link:hover {
  color: var(--mit-red);
  text-decoration: underline;
}

.post-index-table .post-platform-link {
  color: var(--ink-secondary);
  text-decoration: none;
}

.post-index-table .post-platform-link:hover {
  color: var(--mit-red);
  text-decoration: underline;
}

.post-index-table .post-code-link {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  padding: 2px 7px;
  background: var(--bg-box);
  border: 1px solid var(--border-line);
  border-radius: 3px;
  color: var(--mit-red);
  text-decoration: none;
  font-weight: 600;
  transition: all 0.15s ease;
}

.post-index-table .post-code-link:hover {
  background: var(--mit-red);
  color: #fff;
  border-color: var(--mit-red);
}

.text-muted {
  color: var(--ink-muted);
}

/* ==========================================================================
   BibTeX Citation Block
   ========================================================================== */
.citation-section {
  max-width: 900px;
  margin: 4rem auto 2.5rem;
}

.bibtex-box {
  background: var(--bg-box-subtle);
  border: 1px solid var(--border-line);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.bibtex-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-box);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0.6rem 1.25rem;
  font-family: var(--font-sans);
}

.bibtex-label {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-secondary);
}

.btn-copy {
  background: #fff;
  border: 1px solid var(--border-line);
  border-radius: var(--radius-sm);
  padding: 0.25rem 0.65rem;
  font-family: var(--font-sans);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-copy:hover {
  background: var(--mit-red);
  color: #fff;
  border-color: var(--mit-red);
}

.bibtex-code {
  padding: 1.25rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--ink-primary);
  overflow-x: auto;
  white-space: pre;
}

/* ==========================================================================
   Academic Footer
   ========================================================================== */
.academic-footer {
  max-width: 900px;
  margin: 3rem auto 0;
  border-top: 1px solid var(--border-subtle);
  padding-top: 2rem;
  text-align: center;
  font-family: var(--font-sans);
  font-size: 0.88rem;
  color: var(--ink-secondary);
}

.academic-footer a {
  color: var(--mit-red);
  text-decoration: none;
}

.academic-footer a:hover {
  text-decoration: underline;
}

/* ==========================================================================
   Modal Lightbox & Toast
   ========================================================================== */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(17, 24, 39, 0.88);
  backdrop-filter: blur(6px);
  z-index: 2000;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.modal.active {
  display: flex;
}

.modal-close {
  position: absolute;
  top: 1.5rem;
  right: 1.5rem;
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: #fff;
  font-size: 2rem;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}

.modal-close:hover {
  background: rgba(255, 255, 255, 0.4);
}

.modal-inner {
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.modal-inner img {
  max-width: 100%;
  max-height: 80vh;
  object-fit: contain;
  border-radius: var(--radius-sm);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

.modal-caption {
  color: #f8fafc;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  margin-top: 1rem;
  text-align: center;
  max-width: 800px;
}

#toast {
  visibility: hidden;
  min-width: 250px;
  background-color: var(--ink-primary);
  color: #fff;
  text-align: center;
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  position: fixed;
  z-index: 3000;
  left: 50%;
  bottom: 30px;
  transform: translateX(-50%);
  font-family: var(--font-sans);
  font-size: 0.88rem;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
  opacity: 0;
  transition: opacity 0.3s, visibility 0.3s;
}

#toast.show {
  visibility: visible;
  opacity: 1;
}

/* ==========================================================================
   Responsive Breakpoints & Zoom Scaling
   ========================================================================== */
@media (max-width: 1380px) {
  .nav-inner {
    padding: 0 1.5rem;
    gap: 1.25rem;
  }
  .view-tab-btn {
    padding: 0.35rem 0.65rem;
    font-size: 0.8rem;
  }
  .tab-hint-extra {
    display: none;
  }
}

@media (max-width: 1100px) {
  .nav-inner {
    gap: 0.85rem;
    padding: 0 1.25rem;
  }
  .brand-lab-badge {
    display: none;
  }
  .brand-site-title {
    font-size: 0.82rem;
  }
  .btn-nav-github span {
    display: none;
  }
  .btn-nav-github {
    padding: 0.38rem 0.6rem;
  }
}

@media (max-width: 900px) {
  .csail-brand-logo, .brand-divider {
    display: none;
  }
  .view-switcher {
    gap: 0.2rem;
    padding: 3px;
  }
  .view-tab-btn {
    padding: 0.32rem 0.55rem;
    font-size: 0.76rem;
  }
  .btn-nav-download span {
    display: none;
  }
  .btn-nav-download {
    padding: 0.38rem 0.6rem;
  }
}

@media (max-width: 768px) {
  :root {
    --nav-height: 52px;
  }

  html {
    font-size: 14.5px;
    max-width: 100vw;
    overflow-x: clip;
  }

  body {
    max-width: 100vw;
    overflow-x: clip;
    padding-top: 52px;
  }

  .tab-label-short {
    display: inline;
  }
  .tab-label-full {
    display: none;
  }

  .top-nav-bar {
    height: 52px;
    width: 100%;
    overflow: hidden;
    padding: 0;
  }

  .nav-inner {
    padding: 0 0.5rem;
    gap: 0.35rem;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    justify-content: space-between;
  }

  .nav-brand {
    flex-shrink: 0;
  }

  .brand-site-title,
  .csail-brand-logo,
  .brand-divider,
  .brand-text-lockup {
    display: none !important;
  }

  .mit-brand-logo {
    height: 30px;
    width: auto;
    display: block;
    flex-shrink: 0;
    margin-right: 0;
  }

  .view-switcher {
    flex: 1;
    min-width: 0;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 2px 3px;
    gap: 0.2rem;
    justify-content: center;
    border-radius: var(--radius-sm);
  }
  .view-switcher::-webkit-scrollbar {
    display: none;
  }

  .view-tab-btn {
    flex-shrink: 0;
    padding: 0.28rem 0.45rem;
    font-size: 0.74rem;
    gap: 0.25rem;
    border-radius: 4px;
  }

  .view-tab-btn .btn-icon-svg {
    width: 12px;
    height: 12px;
  }

  .view-tab-btn .badge-count {
    font-size: 0.65rem;
    padding: 0.05rem 0.32rem;
    margin-left: 0.1rem;
  }

  .nav-right {
    gap: 0.35rem;
    flex-shrink: 0;
  }

  .nav-btn-text {
    display: none !important;
  }

  .btn-nav-github,
  .btn-nav-download {
    padding: 0.35rem 0.5rem;
    font-size: 0.75rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .page-body {
    padding: 1rem 0.6rem 3.5rem;
    width: 100%;
    max-width: 100vw;
    box-sizing: border-box;
    overflow-x: hidden;
  }

  .academic-header {
    margin-bottom: 1.5rem;
    padding-bottom: 1.25rem;
  }

  .header-pre-tag {
    font-size: 0.72rem;
    letter-spacing: 0.05em;
  }

  .main-paper-title {
    font-size: 1.45rem;
    line-height: 1.25;
  }

  .affiliation-row {
    font-size: 0.82rem;
    gap: 0.35rem;
  }

  .action-pills-row {
    gap: 0.45rem;
    margin-bottom: 1.25rem;
  }

  .pill-btn {
    padding: 0.35rem 0.75rem;
    font-size: 0.78rem;
  }

  .core-mission-container {
    padding: 1rem;
  }

  .mission-pillars-grid {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  .mission-pillar-card {
    flex-direction: column;
    gap: 0.4rem;
    padding: 0.75rem;
  }

  .gallery-page-layout {
    flex-direction: column;
    gap: 1rem;
    padding: 0;
    width: 100%;
    box-sizing: border-box;
  }

  .gallery-container {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  .gallery-toc-sidebar,
  .toc-pane {
    position: static;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    padding: 0.85rem;
    max-height: none;
    border-left: 1px solid var(--border-subtle);
    border-top: 3px solid var(--mit-red);
  }

  .html-reader-layout {
    padding: 0;
  }

  .toc-pane .toc-links {
    columns: 1;
  }

  .toc-pane .toc-links a {
    font-size: 0.84rem;
    padding: 0.4rem 0.5rem;
  }

  /* archive directory on phones: domains only, full list in the drawer */
  .gallery-toc-sidebar .sidebar-sub-list {
    display: none;
  }

  .sidebar-nav {
    flex-direction: column;
    gap: 0.75rem;
  }

  .sidebar-domain-group {
    min-width: 0;
    width: 100%;
  }

  .sidebar-sub-link {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .ranking-rules-grid {
    grid-template-columns: 1fr;
    gap: 0.85rem;
  }

  .ranking-tier-card {
    padding: 1rem;
  }

  .stat-summary-grid {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  .gallery-controls-bar {
    flex-direction: column;
    align-items: stretch;
    padding: 0.75rem;
    gap: 0.75rem;
  }

  .gallery-search-wrap {
    flex-direction: column;
    align-items: stretch;
    gap: 0.65rem;
  }

  .search-input-wrap {
    max-width: 100%;
    width: 100%;
  }

  .filter-pills {
    flex-wrap: wrap;
    gap: 0.35rem;
  }

  .filter-pill {
    padding: 0.25rem 0.6rem;
    font-size: 0.74rem;
  }

  .gallery-tiles-grid {
    grid-template-columns: repeat(auto-fill, minmax(145px, 1fr));
    gap: 0.65rem;
  }

  .gallery-domain-header {
    padding: 0.75rem 0.85rem;
    font-size: 1.05rem;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
  }

  .gallery-subsection-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
  }

  .gallery-subsection-title {
    font-size: 1.02rem;
  }

  .gallery-domain-section,
  .gallery-subsection-block {
    scroll-margin-top: calc(52px + 10px);
  }

  .pdf-frame-wrapper {
    height: 70vh;
  }
}

/* ==========================================================================
   Interaction states shared by the paper, archive and case viewer
   ========================================================================== */
html.modal-open {
  overflow: hidden;
}

.academic-figure:not(.figure-gallery-figure) img.zoomable {
  cursor: zoom-in;
}

.tile-img-wrap:focus-visible,
.ranking-tier-card:focus-visible,
.gallery-tile-card:focus-visible,
img.zoomable:focus-visible,
.citation-link:focus-visible,
.toc-links a:focus-visible,
.sidebar-sub-link:focus-visible,
.sidebar-domain-head:focus-visible {
  outline: 2px solid var(--mit-red);
  outline-offset: 2px;
}

.gallery-tile.tile-flash {
  animation: tileFlash 2s ease-out;
}

@keyframes tileFlash {
  0%, 35% { box-shadow: 0 0 0 3px var(--mit-red), 0 8px 24px rgba(117, 0, 20, 0.18); }
  100% { box-shadow: 0 0 0 0 rgba(117, 0, 20, 0); }
}

.gallery-empty-state {
  margin: 1.5rem 0 0;
  padding: 2rem 1rem;
  text-align: center;
  font-family: var(--font-sans);
  color: var(--ink-secondary);
  background: var(--bg-box-subtle);
  border: 1px dashed var(--border-line);
  border-radius: var(--radius-md);
}

.gallery-empty-state p {
  margin-bottom: 0.75rem;
}

.gallery-empty-state[hidden] {
  display: none;
}

/* ==========================================================================
   Tablet / phone contents drawer (paper TOC and archive directory)
   ========================================================================== */
.contents-fab {
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 1500;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 44px;
  padding: 0.55rem 1.05rem;
  border: none;
  border-radius: var(--radius-full);
  background: var(--mit-red);
  color: #FFFFFF;
  font-family: var(--font-sans);
  font-size: 0.86rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  box-shadow: 0 6px 20px rgba(117, 0, 20, 0.3);
  cursor: pointer;
}

.contents-fab:hover,
.contents-fab:focus-visible {
  background: var(--mit-red-dark);
}

.contents-fab[hidden],
.contents-drawer[hidden] {
  display: none;
}

.contents-drawer {
  position: fixed;
  inset: 0;
  z-index: 1900;
}

.contents-drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(17, 24, 39, 0.45);
}

.contents-drawer-sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: min(80vh, 680px);
  display: flex;
  flex-direction: column;
  background: var(--bg-page);
  border-top: 3px solid var(--mit-red);
  border-radius: 14px 14px 0 0;
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.18);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  animation: drawerUp 0.2s ease;
}

@media (min-width: 769px) {
  .contents-drawer-sheet {
    left: auto;
    top: 0;
    width: 380px;
    max-height: none;
    border-top: none;
    border-left: 3px solid var(--mit-red);
    border-radius: 0;
    animation: drawerIn 0.2s ease;
  }
}

@keyframes drawerUp {
  from { transform: translateY(28px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

@keyframes drawerIn {
  from { transform: translateX(28px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.contents-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.95rem 1.1rem 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
  font-family: var(--font-sans);
}

.contents-drawer-close {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border-line);
  border-radius: var(--radius-full);
  background: var(--bg-box-subtle);
  color: var(--ink-primary);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}

.contents-drawer-body {
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 0.75rem 1rem 1.25rem;
  font-family: var(--font-sans);
}

.contents-drawer-body .toc-links {
  display: flex;
  flex-direction: column;
  columns: auto;
  gap: 0.1rem;
}

.contents-drawer-body .toc-links a {
  font-size: 0.9rem;
  padding: 0.5rem 0.6rem;
}

.contents-drawer-body .toc-links .toc-sub-link {
  font-size: 0.84rem;
  padding: 0.42rem 0.6rem;
}

.contents-drawer-body .sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.contents-drawer-body .sidebar-sub-list {
  display: flex;
}

.contents-drawer-body .sidebar-domain-head,
.contents-drawer-body .sidebar-sub-link,
.contents-drawer-body .sidebar-overview-link {
  min-height: 40px;
  font-size: 0.9rem;
}

.contents-drawer-body .sidebar-sub-link .sub-name {
  max-width: none;
}

/* ==========================================================================
   Case viewer (lightbox): readable text on the dark overlay, fits short screens
   ========================================================================== */
.modal {
  overflow-y: auto;
  overscroll-behavior: contain;
}

.modal-inner {
  margin: auto;
  max-height: none;
}

.modal-media {
  max-width: 100%;
  max-height: min(68vh, calc(100vh - 240px));
  border-radius: 6px;
  object-fit: contain;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

@supports (height: 100dvh) {
  .modal-media {
    max-height: min(68vh, calc(100dvh - 240px));
  }
}

.modal-caption-sub {
  font-size: 0.88rem;
  color: #CBD5E1;
  margin-top: 0.2rem;
}

.modal-caption-subsection {
  color: #FCA5A5;
  font-weight: 600;
}

.modal-meta {
  margin-top: 0.35rem;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  color: #CBD5E1;
  text-align: center;
}

.modal-meta strong {
  color: #F1F5F9;
}

.modal-textonly {
  max-width: 520px;
  padding: 2.5rem 1.5rem;
  border: 1px dashed rgba(255, 255, 255, 0.35);
  border-radius: 8px;
  color: #E2E8F0;
  font-family: var(--font-sans);
  text-align: center;
}

.modal-textonly[hidden] {
  display: none;
}

/* ==========================================================================
   Tables
   ========================================================================== */
.latex-content-body td[colspan] {
  background: var(--bg-box-subtle);
  font-family: var(--font-sans);
  font-size: 0.86rem;
}

.latex-content-body td[colspan] > strong:first-child {
  color: var(--mit-red);
}

.benchmark-table {
  min-width: 900px;
}

.benchmark-table td:nth-child(1) { min-width: 130px; }
.benchmark-table td:nth-child(2) { min-width: 170px; }
.benchmark-table td:nth-child(3) { min-width: 210px; }
.benchmark-table td:nth-child(4) { min-width: 150px; }
.benchmark-table td:nth-child(5) { min-width: 110px; }
.benchmark-table td:nth-child(6) {
  min-width: 80px;
  white-space: normal;
}

.table-scroll-hint {
  display: none;
  margin: 0 0 0.35rem;
  font-family: var(--font-sans);
  font-size: 0.78rem;
  color: var(--ink-muted);
}

.bibtex-code {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* ==========================================================================
   Archive: ranking cards reflect the active rank filter; badges keep one line
   ========================================================================== */
.ranking-tier-card.active {
  border-color: var(--mit-red);
  box-shadow: 0 0 0 2px var(--mit-red), 0 6px 18px rgba(117, 0, 20, 0.12);
}

.tier-card-header {
  flex-wrap: wrap;
}

.tier-pill-badge,
.tier-tag-pill,
.sidebar-domain-count {
  white-space: nowrap;
}

/* Category sits on its own line under the author, so a wrapped line never
   starts with a dangling separator. */
.tile-subcat-wrap {
  display: block;
  margin-top: 0.1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tile-subcat-wrap .tile-subcat-sep {
  display: none;
}

.tile-subcat-wrap .tile-subcat-badge {
  max-width: 100%;
}

.pill-btn {
  line-height: 1.2;
}

@media (max-width: 1200px) {
  .gallery-toc-sidebar .sidebar-nav {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1.25rem;
  }

  .table-scroll-hint {
    display: block;
  }
}

/* ==========================================================================
   Top navigation between tablet and small laptop widths
   ========================================================================== */
@media (max-width: 1000px) and (min-width: 769px) {
  .brand-text-lockup {
    display: none;
  }
}

@media (max-width: 768px) {
  /* center the tabs when they fit, start-align (fully reachable) when they don't */
  .view-switcher {
    justify-content: flex-start;
  }
  .view-switcher > :first-child {
    margin-left: auto;
  }
  .view-switcher > :last-child {
    margin-right: auto;
  }

  .view-tab-btn {
    min-height: 34px;
  }

  .btn-nav-github {
    min-width: 36px;
    min-height: 36px;
  }

  .pill-btn {
    min-height: 38px;
  }

  .filter-pill {
    min-height: 32px;
  }

  .tile-btn {
    min-height: 32px;
    display: inline-flex;
    align-items: center;
  }

  .stat-summary-grid {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  }

  /* smallest labels stay legible */
  .tile-badge-video,
  .tile-badge-rank,
  .tile-badge-id,
  .view-tab-btn .badge-count,
  .gallery-tile-gid,
  .gallery-tile-title,
  .sidebar-tag,
  .domain-label-badge {
    font-size: 11px;
  }
}

@media (max-width: 600px) {
  /* a lone dash looks like a minus button once the "Reads" label is hidden */
  .nav-reads-badge:not([data-reads-state="ready"]) {
    display: none;
  }

  /* justified narrow columns open wide gaps between words */
  .latex-content-body,
  .latex-content-body p {
    text-align: left;
    hyphens: auto;
  }
}

/* Vector figures: the frame takes the width the figure has in the PDF (set inline
   by the build) and the drawing fills it */
.academic-figure .figure-img-wrap--vector {
  display: block;
  margin: 0 auto;
}

.figure-img-wrap--vector img {
  width: 100%;
  height: auto;
}

@media (max-width: 1200px) {
  .gallery-container {
    max-width: none;
    width: 100%;
  }
}

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

/* Ranking cards: share row heights across the three cards so titles, descriptions
   and checklists line up even when one card's header badges wrap */
@media (min-width: 861px) {
  @supports (grid-template-rows: subgrid) {
    .ranking-rules-grid {
      grid-template-rows: repeat(4, auto);
      row-gap: 0;
    }

    .ranking-tier-card {
      display: grid;
      grid-row: span 4;
      grid-template-rows: subgrid;
    }

    .tier-card-header {
      align-self: start;
    }
  }
}

/* Category panels inside the paper's case-gallery figures */
.gallery-cat-heading {
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--ink-primary, #1a1a1a);
  margin: 1.4rem 0 0.6rem;
  padding: 0 1.15rem;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem;
}
.gallery-cat-heading:first-of-type { margin-top: 0.4rem; }
.gallery-cat-count {
  font-weight: 400;
  font-size: 0.85rem;
  color: var(--ink-secondary);
}
.figure-gallery-figure .gallery-tiles-grid {
  grid-template-columns: repeat(6, minmax(0, 1fr));
  max-height: none;
  overflow: visible;
}
@media (max-width: 900px) {
  .figure-gallery-figure .gallery-tiles-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 520px) {
  .figure-gallery-figure .gallery-tiles-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
