/* ── PaperView Reader v2 ──
   Depends on: ../shared/tokens.css, ../shared/layout.css
   ══════════════════════════════════════════════════════════════ */

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── PAPER-SPECIFIC HEADER OVERRIDES ── */
.header-logo a:hover {
  color: var(--accent-hover);
}

.header-paper-id,
.header-paper-title,
.header-paper-cit {
  font-size: 11px;
  color: var(--text-2);
  white-space: nowrap;
  flex-shrink: 0;
}

.header-paper-title {
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex-shrink: 1;
}


/* Paper-plane InspireHEP search button inside header search bar */
.search-wrap .search-go {
  position: absolute;
  right: 1px;
  top: 1px;
  bottom: 1px;
  width: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-left: 1px solid var(--border);
  border-radius: 0 5px 5px 0;
  background: var(--bg);
  color: var(--text-3);
  cursor: default;
  z-index: 5;
  transition: background 0.15s, color 0.15s;
  padding: 0;
}

.search-wrap:has(input:not(:placeholder-shown)) .search-go {
  cursor: pointer;
}

.search-wrap:has(input:not(:placeholder-shown)) .search-go:hover {
  background: rgba(0, 86, 179, 0.06);
  color: var(--accent);
}

/* Extra right padding so text doesn't overlap the Go button */
.search-wrap input {
  padding-right: 36px;
}

.zoom-display {
  font-size: 10px;
  font-weight: 400;
  color: var(--text-3);
  min-width: 28px;
  text-align: center;
}

.paper-subheader .header-btn {
  color: var(--text-3);
  font-weight: 400;
}

.header-btn a,
a.header-btn {
  color: inherit;
  text-decoration: none;
}

a.header-btn.header-roadmap-btn {
  color: var(--text-3);
}

/* ═══════════════════════════════════════════════════════════
   MAIN LAYOUT
   ═══════════════════════════════════════════════════════════ */
.main {
  display: flex;
  flex: 1;
  overflow: hidden;
  gap: 0;
}

/* ═══════════════════════════════════════════════════════════
   SIDEBAR (left, collapsible, ~320px)
   ═══════════════════════════════════════════════════════════ */
.sidebar {
  width: 390px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--bg);
  overflow-y: auto;
  overflow-x: hidden;
  transition: width 0.3s ease, opacity 0.3s ease;
}

.sidebar.hidden {
  width: 0;
  opacity: 0;
  border-right: none;
}

/* Stacked sidebar sections */
.sb-section {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

/* Resources section fills remaining space */
.sb-section.sb-section-flex {
  flex: 0 0 auto;
  flex-shrink: 0;
  overflow: visible;
}

/* Section header */
.sb-section-head {
  display: flex;
  align-items: center;
  height: 34px;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
  user-select: none;
}

.sb-section-head span {
  font-size: 10px;
  color: var(--text-3);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.pv-claims-head-pager {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  letter-spacing: 0;
  text-transform: none;
}

.sb-close-btn {
  height: 24px;
  width: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 400;
  color: var(--text-3);
  background: none;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  line-height: 1;
  margin-left: auto;
}

.sb-close-btn:hover {
  background: var(--bg-3);
  color: var(--text);
}

#btn-toggle-sidebar {
  display: none;
}

#btn-toggle-sidebar.visible {
  display: flex;
}

/* Section content area */
.sb-section-content {
  flex: 0 0 auto;
  overflow: visible;
  display: flex;
  flex-direction: column;
  min-height: auto;
}

/* Sidebar footer */
.sidebar-footer {
  flex-shrink: 0;
  padding: 12px;
  border-top: 1px solid var(--border);
  background: var(--bg-2);
  position: sticky;
  bottom: 0;
  z-index: 2;
}

.paper-summary {
  font-size: 11px;
}

.paper-title {
  font-weight: 600;
  color: var(--text);
  line-height: 1.35;
  margin-bottom: 4px;
}

.paper-meta {
  font-size: 10px;
  color: var(--text-3);
  line-height: 1.3;
  margin-bottom: 4px;
}

.paper-stats {
  font-size: 10px;
  color: var(--text-3);
}


/* ── OUTLINE / SPINE ── */
.outline-empty {
  padding: 16px 12px;
  text-align: center;
  font-size: 11px;
  color: var(--text-3);
  font-style: italic;
}
.outline-loading {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 12px;
  font-size: 11px;
  color: var(--text-3);
}
.outline-spinner {
  width: 14px; height: 14px;
  border: 2px solid var(--border, #e5e7eb);
  border-top-color: var(--blue, #2563eb);
  border-radius: 50%;
  animation: outline-spin 0.8s linear infinite;
}
@keyframes outline-spin {
  to { transform: rotate(360deg); }
}

.spine-list {
  display: flex;
  flex-direction: column;
  padding: 6px 0;
}

.spine-node {
  display: flex;
  align-items: flex-start;
  gap: 0;
  padding: 6px 12px 6px 42px;
  cursor: pointer;
  transition: background 0.15s;
}

.spine-node:hover {
  background: var(--bg-2);
}

.spine-node.active {
  background: rgba(232, 240, 254, 0.5);
}

/* Vertical minimap SVG strip */
.spine-svg {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
  z-index: 10;
  overflow: visible;
}

.spine-content {
  flex: 1;
  min-width: 0;
}

.spine-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  margin-bottom: 3px;
}

.spine-label {
  font-family: var(--font);
  font-size: 12px;
  font-weight: 560;
  color: var(--text);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.spine-node.active .spine-label {
  color: var(--accent);
}

.spine-type {
  font-family: var(--font);
  font-size: 8.5px;
  font-weight: 650;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  line-height: 1;
  white-space: nowrap;
}

.spine-sub {
  font-family: var(--font);
  font-size: 10.5px;
  color: var(--text-2);
  line-height: 1.32;
  margin-top: 3px;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
  overflow: hidden;
}

.spine-section {
  font-size: 8.5px;
  color: var(--text-3);
  font-family: var(--mono);
  flex-shrink: 0;
  margin-left: auto;
}

/* Rigor legend row inside outline */
.spine-legend-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 6px 12px 4px;
}

/* Branch indent handled by SVG minimap node positions */

/* ── CONCEPTS / FINGERPRINT ──
   Base .fp-chip/.fp-grid/.fp-bar styles are in shared/concepts.css.
   Page-specific overrides below. */

/* Match search/roadmap chip style — color set by JS via taxonomy */
.fp-grid .fp-chip {
  padding: 2px 7px;
  font-weight: 500;
  text-decoration: none;
  border: none;
  color: #fff;
}


/* Foundational banner in concept detail */
.cd-foundational-banner {
  font-size: 10px;
  font-weight: 600;
  color: var(--green);
  background: var(--green-bg);
  padding: 4px 8px;
  border-radius: 4px;
  margin-bottom: 6px;
  letter-spacing: -0.1px;
}

/* Concept detail card inside fingerprint section */
.fp-concept-detail {
  padding: 8px 12px;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg);
  display: none;
}

/* ── CONCEPT DETAIL (related papers for selected concept) ── */
.cd-empty {
  padding: 20px 12px;
  text-align: center;
  font-size: 12px;
  color: var(--text-3);
}

.cd-header {
  padding: 10px 12px 6px;
  border-bottom: 1px solid var(--border-subtle);
}

.cd-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}

.cd-desc {
  font-size: 11px;
  color: var(--text-2);
  line-height: 1.45;
  margin-top: 3px;
}

.cd-parents {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.cd-parent-chip {
  font-size: 9px;
  padding: 1px 6px;
  border-radius: 3px;
  background: var(--bg-3);
  color: var(--text-2);
  cursor: pointer;
}

.cd-parent-chip:hover {
  background: var(--accent-bg);
  color: var(--accent);
}

.cd-kw-line {
  font-size: 10px;
  color: var(--text-2);
  line-height: 1.5;
  margin-top: 6px;
}

.cd-kw-label {
  font-weight: 600;
  color: var(--text-3);
  text-transform: lowercase;
}

.cd-kw-link {
  color: var(--accent);
  cursor: pointer;
}
.cd-kw-link:hover {
  text-decoration: underline;
}

.cd-kw-more {
  color: var(--text-3);
}

/* Keyword detail panel (expands below concept detail) */
.fp-keyword-detail {
  padding: 8px 12px;
  border-top: 1px solid var(--bg-3);
  margin-top: 4px;
  cursor: pointer;
}

.kd-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

.kd-desc {
  font-size: 10px;
  color: var(--text-2);
  line-height: 1.45;
  margin-top: 3px;
}

.cd-keyword-of {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-3);
  margin-top: 4px;
}

.cd-keyword-concept {
  font-size: 12px;
  font-weight: 500;
  color: var(--accent);
  cursor: pointer;
  margin-top: 2px;
}
.cd-keyword-concept:hover {
  text-decoration: underline;
}

.cd-map-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  color: var(--text-3);
  text-decoration: none;
  cursor: pointer;
  margin-top: 6px;
  padding: 2px 0;
}

.cd-map-link:hover {
  color: var(--text-2);
}

/* Paper petal lists (foundational/review/recent) */
.cd-petal-section {
  padding: 0 12px;
}

.cd-petal-label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 0 4px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.cd-petal-label .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.cd-paper {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 5px 0;
  cursor: pointer;
  border-bottom: 1px solid var(--border-subtle);
}

.cd-paper:last-child {
  border-bottom: none;
}

.cd-paper:hover {
  background: var(--bg-2);
  margin: 0 -12px;
  padding: 5px 12px;
}

.cd-paper-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 6px;
}

.cd-paper-info {
  flex: 1;
  min-width: 0;
}

.cd-paper-title {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  line-height: 1.35;
}

.cd-paper:hover .cd-paper-title {
  color: var(--accent);
}

.cd-paper-meta {
  font-size: 10px;
  color: var(--text-3);
  margin-top: 1px;
}

.cd-paper-meta .cites {
  color: var(--accent);
  font-weight: 500;
}

.cd-paper-meta .cd-relevance {
  color: var(--text-2);
  font-style: italic;
}

/* Role tags on references */
.res-type-tag {
  font-size: 8px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  padding: 1px 5px;
  border-radius: 3px;
  flex-shrink: 0;
  align-self: flex-start;
  margin-top: 5px;
}

.res-type-tag.type-builds-on { color: var(--green); background: var(--green-bg); }
.res-type-tag.type-extends { color: var(--blue); background: var(--blue-bg); }
.res-type-tag.type-cites { color: var(--text-3); background: var(--bg-3); }

/* Type legend at bottom of resources */
.res-type-legend {
  display: flex;
  gap: 12px;
  padding: 8px 12px;
  margin-top: auto;
}

/* Rigor dot colors for references */
.cd-paper-dot.rigor-proven { background: var(--green); }
.cd-paper-dot.rigor-derived { background: var(--orange); }
.cd-paper-dot.rigor-argued { background: var(--blue); }
.cd-paper-dot.rigor-conj { background: var(--red); }

/* Legend bar for rigor levels */
.cd-legend {
  display: flex;
  gap: 12px;
  padding: 8px 12px 12px;
  border-top: 1px solid var(--border-subtle);
}

.cd-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 9px;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.cd-legend-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════════════
   RESIZE HANDLE
   ═══════════════════════════════════════════════════════════ */
.resize-handle {
  width: 1px;
  cursor: col-resize;
  background: var(--border);
  flex-shrink: 0;
  transition: background 0.15s, width 0.15s;
}

.resize-handle:hover,
.resize-handle:active {
  background: var(--accent);
  width: 2px;
}

.resize-handle.hidden {
  display: none;
}

/* ═══════════════════════════════════════════════════════════
   PAPER PANE (main content)
   ═══════════════════════════════════════════════════════════ */
.paper-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* Paper subheader */
.paper-subheader {
  display: flex;
  align-items: center;
  height: 34px;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
  flex-shrink: 0;
  gap: 2px;
  justify-content: space-between;
  z-index: 10;
}

.paper-subheader-left {
  display: flex;
  align-items: center;
  gap: 2px;
}

.paper-subheader-right {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: auto;
}

.paper-subheader-right a.header-btn {
  font-size: 10px;
  font-weight: 400;
  padding: 0 4px;
  color: var(--text-3);
}

.paper-btn {
  height: 24px;
  width: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--text-2);
  background: none;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}

.paper-btn:hover {
  background: var(--bg-3);
  color: var(--text);
}

.paper-btn.hidden {
  display: none;
}

.subheader-title {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-left: 4px;
}

/* Old floating TOC dropdown removed — TOC now lives in sidebar */

.toc-item {
  width: 100%;
  border: none;
  background: none;
  text-align: left;
  padding: 8px 10px;
  font-size: 12px;
  color: var(--text-2);
  cursor: pointer;
  border-bottom: 1px solid var(--border-subtle);
}

.toc-item:hover {
  background: var(--bg-2);
}

.toc-item.active {
  color: var(--accent);
  font-weight: 600;
}

.toc-item.toc-h3 {
  padding-left: 26px;
}

.toc-item.toc-h4,
.toc-item.toc-h5,
.toc-item.toc-h6 {
  padding-left: 38px;
  font-size: 11px;
}

/* TOC section in sidebar */
#toc-section #toc-list {
  overflow-y: auto;
}

/* TOC button icon swaps between hamburger and KG graph via JS */

/* ── Important references in sidebar ── */
/* Resources panel reuses .search-result-item / .sr-* from layout.css */
.ref-row { border-bottom: 1px solid var(--border-subtle); }
.ref-row .sr-cit { text-align: right; }
.ref-tag-wrap {
  display: flex;
  gap: 3px;
  justify-content: flex-end;
  flex-wrap: wrap;
  margin-top: 3px;
}
.ref-tag-role {
  font-size: 8px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  padding: 2px 5px;
  border-radius: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.ref-tag-key {
  color: var(--accent, #4a7fd4);
  background: rgba(74, 127, 212, 0.08);
}
.ref-tag-foundational {
  color: var(--green, #28a745);
  background: rgba(40, 167, 69, 0.08);
}
.ref-tag-review {
  color: #6f42c1;
  background: rgba(111, 66, 193, 0.08);
}
.ref-tag-similar {
  color: #c2660a;
  background: rgba(194, 102, 10, 0.08);
}
.similar-divider {
  height: 1px;
  background: var(--border-subtle);
  margin: -1px 0 0 0;
}
/* Hide divider when no real references follow */
#chunky-similar-injected:last-child .similar-divider,
#chunky-similar-injected:has(+ .cd-empty:last-child) .similar-divider {
  display: none;
}

#loading-overlay {
  position: absolute;
  top: 34px;
  right: 0;
  bottom: 0;
  left: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.78);
  z-index: 55;
}

#loading-overlay .spinner {
  width: 30px;
  height: 30px;
  border: 3px solid #e5e7eb;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: pv-spin 0.7s linear infinite;
}

@keyframes pv-spin {
  to { transform: rotate(360deg); }
}

/* PDF iframe */
#pdf-iframe {
  flex: 1;
  border: none;
  background: #eee;
  visibility: hidden;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

#pdf-iframe.pg-ready {
  visibility: visible;
}

#pdf-fallback {
  flex: 1;
  display: none;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px;
  color: var(--text-2);
  font-size: 13px;
}

#pdf-fallback a {
  color: var(--accent);
}

/* ═══════════════════════════════════════════════════════════
   RSVP SPEED READER
   ═══════════════════════════════════════════════════════════ */
.rsvp-overlay {
  position: absolute;
  top: 34px;
  left: 0;
  right: 0;
  height: 160px;
  background: var(--bg);
  z-index: 50;
  display: none;
  flex-direction: column;
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.rsvp-overlay.active {
  display: flex;
}

.rsvp-overlay.active ~ #pdf-iframe {
  margin-top: 160px;
}

#rsvp-word-container {
  position: relative;
  flex: 1;
  max-width: clamp(280px, 80%, 860px);
  margin-left: 40px;
  font-family: var(--mono);
  font-size: 34px;
  letter-spacing: 1px;
  user-select: none;
  overflow: hidden;
}
#rsvp-word-container::before,
#rsvp-word-container::after {
  content: '';
  position: absolute;
  width: 12px;
  height: 12px;
  border-color: #e0e0e0;
  border-style: solid;
  pointer-events: none;
  z-index: 1;
}
#rsvp-word-container::before {
  top: 8px;
  left: 0;
  border-width: 1px 0 0 1px;
}
#rsvp-word-container::after {
  top: 8px;
  right: 0;
  border-width: 1px 1px 0 0;
}
.rsvp-corner {
  position: absolute;
  width: 12px;
  height: 12px;
  border-color: #e0e0e0;
  border-style: solid;
  pointer-events: none;
  z-index: 1;
}
.rsvp-corner-bl {
  bottom: 8px;
  left: 0;
  border-width: 0 0 1px 1px;
}
.rsvp-corner-br {
  bottom: 8px;
  right: 0;
  border-width: 0 1px 1px 0;
}

#rsvp-context {
  position: absolute;
  top: 4px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  font-family: var(--sans, system-ui, sans-serif);
  color: var(--text-3);
  letter-spacing: 0.5px;
  text-transform: uppercase;
  pointer-events: none;
}

#rsvp-focus-line {
  position: absolute;
  top: 12.5%;
  bottom: 12.5%;
  left: 50%;
  width: 1px;
  background: #e0e0e0;
  pointer-events: none;
}

#rsvp-word {
  position: absolute;
  white-space: nowrap;
}

#rsvp-equation {
  display: none;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  max-width: 90%;
  max-height: 80%;
  overflow: hidden;
}

#rsvp-equation.active {
  display: block;
}

#rsvp-pre, #rsvp-post {
  color: var(--text);
}

#rsvp-pivot {
  color: #d32f2f;
  font-weight: 700;
}

#rsvp-controls {
  height: 36px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  background: var(--bg-2);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-2);
}

#rsvp-controls button {
  background: none;
  border: none;
  padding: 2px 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.4;
  border-radius: 4px;
  transition: all 0.15s;
}

#rsvp-controls button:hover {
  background: var(--bg-3);
  color: var(--text);
}

#rsvp-controls-inner {
  display: flex;
  align-items: center;
  gap: 8px;
  width: clamp(280px, 80%, 860px);
  margin-left: 32px;
  padding-left: 8px;
}
#rsvp-close {
  color: var(--text-3);
  margin-left: auto;
}
#rsvp-close:hover {
  color: var(--text);
  background: var(--bg-3);
}

#rsvp-progress-wrap {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  cursor: pointer;
  position: relative;
}

#rsvp-progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  width: 0%;
  transition: width 0.1s;
}

#rsvp-position {
  font-size: 10px;
  color: var(--text-3);
  min-width: 60px;
  text-align: right;
}

#rsvp-wpm-display {
  font-size: 11px;
  color: var(--text-2);
  min-width: 52px;
  text-align: center;
}

/* RSVP mobile */
@media (max-width: 600px) {
  .rsvp-overlay {
    height: 120px;
  }
  .rsvp-overlay.active ~ #pdf-iframe {
    margin-top: 120px;
  }
  #rsvp-word-container {
    margin-left: 12px;
    font-size: 22px;
    letter-spacing: 0;
  }
  #rsvp-controls-inner {
    margin-left: 8px;
    gap: 2px;
    padding-left: 4px;
  }
  #rsvp-controls button {
    min-height: 44px;
    min-width: 36px;
    padding: 0 6px;
  }
  #rsvp-controls button:active {
    opacity: 0.6;
  }
  #rsvp-progress-wrap {
    height: 20px;
    padding: 7px 0;
    box-sizing: border-box;
  }
  #rsvp-progress-bar {
    height: 6px;
  }
  #rsvp-position { min-width: 44px; font-size: 11px; }
  #rsvp-wpm-display { min-width: 44px; font-size: 11px; }
}

/* ═══════════════════════════════════════════════════════════
   KG PANEL (right, optional)
   ═══════════════════════════════════════════════════════════ */
.kg-panel {
  width: 420px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
  background: var(--bg);
  overflow: hidden;
  transition: width 0.3s ease;
}

.kg-panel.hidden {
  width: 0;
  border-left: none;
}

.kg-header {
  display: flex;
  align-items: center;
  height: 34px;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
  flex-shrink: 0;
  justify-content: space-between;
}

.kg-header span {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.kg-btn {
  height: 24px;
  width: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: var(--text-2);
  background: none;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
  line-height: 1;
}

.kg-btn:hover {
  background: var(--bg-3);
  color: var(--text);
}

.kg-header-controls {
  display: flex;
  gap: 4px;
  align-items: center;
}


/* ── SVG Tree Nodes ── */
.node-bg {
  fill: transparent;
  stroke: none;
  cursor: pointer;
}

.node-underline {
  stroke: var(--text-3);
  stroke-width: 1;
  transition: stroke-width 0.12s;
}

.node-group:hover .node-underline {
  stroke-width: 2;
}

.node-group.selected .node-underline {
  stroke-width: 2.5;
}

.node-card-inner {
  font-family: var(--font);
  font-size: 13px;
  font-weight: 400;
  color: var(--text);
  padding: 5px 9px;
  display: flex;
  align-items: center;
  height: 100%;
  overflow: hidden;
  line-height: 1.35;
  cursor: pointer;
  user-select: none;
}

.node-label-text {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.collapse-icon {
  fill: var(--text-2);
  cursor: pointer;
  transition: fill 0.15s;
}
.collapse-icon:hover { fill: var(--accent); }

/* ── SVG Edges ── */
.tree-link {
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: square;
  transition: stroke-width 0.15s;
}

.cross-ref-path {
  fill: none;
  stroke-width: 1;
  stroke-dasharray: 4, 5;
  opacity: 0.35;
  stroke-linecap: square;
}

/* ── Edge tooltip ── */
#edge-tooltip {
  position: absolute;
  top: 8px;
  right: 8px;
  left: auto;
  padding: 6px 10px;
  background: rgba(33, 37, 41, 0.92);
  color: #fff;
  font-size: 11px;
  border-radius: 4px;
  pointer-events: none;
  max-width: 280px;
  line-height: 1.4;
  z-index: 50;
  display: none;
}

/* ── KG Minimap ── */
#kg-minimap {
  position: absolute;
  top: 16px;
  left: 16px;
  width: 50%;
  background: none;
  border: none;
  border-radius: 6px;
  z-index: 80;
  cursor: pointer;
  overflow: visible;
}
#kg-minimap.hidden { display: none; }
#kg-minimap canvas {
  width: 100%;
  height: 100%;
  display: block;
}
#minimap-tooltip {
  position: absolute;
  background: rgba(30, 30, 30, 0.88);
  color: #f0f0f0;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 4px;
  white-space: nowrap;
  display: none;
  z-index: 90;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Detail panel (collapses when empty) ── */
#detail {
  flex-shrink: 0;
  max-height: 290px;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-top: 1px solid var(--border);
  transition: max-height 0.2s ease;
  overflow: hidden;
}

#detail.detail-empty {
  max-height: 0;
  border-top: none;
  overflow: hidden;
}

#detail.detail-empty #detail-title-row,
#detail.detail-empty #detail-body {
  display: none;
}

#detail-title-row {
  display: flex;
  align-items: flex-start;
  padding: 6px 8px 0 20px;
  flex-shrink: 0;
}

#detail h2 {
  font-size: 15px;
  font-weight: 600;
  color: var(--accent);
  line-height: 1.3;
  margin: 0;
  flex: 1;
}

#detail-close {
  background: none;
  border: none;
  color: var(--text-3);
  font-size: 14px;
  cursor: pointer;
  line-height: 1;
  padding: 0 0 0 8px;
  flex-shrink: 0;
}
#detail-close:hover { color: var(--text); }

#detail-body {
  overflow-y: auto;
  flex: 1;
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-2);
}

.detail-section-hdr {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  padding: 2px 20px 1px;
}

#detail .description {
  padding: 1px 20px 8px;
}

.detail-rigor-tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 2px;
  font-size: 10px;
  font-weight: 600;
  color: #fff;
  margin-right: 4px;
  vertical-align: middle;
  cursor: pointer;
  position: relative;
}

.rigor-tooltip {
  position: fixed;
  background: #333;
  color: #fff;
  padding: 5px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 400;
  max-width: 280px;
  line-height: 1.4;
  pointer-events: none;
  z-index: 1000;
  white-space: normal;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.detail-connections {
  padding: 0 20px 16px;
}
.detail-connections:empty { display: none; }
.detail-conn-heading {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  padding-top: 4px;
  margin-bottom: 2px;
}
.detail-conn-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
}
.detail-conn-node {
  color: var(--text);
  cursor: pointer;
}
.detail-conn-node:hover { text-decoration: underline; }

#tree-group {
  will-change: transform;
}

/* ═══════════════════════════════════════════════════════════
   MOBILE BOTTOM SHEET (for sidebar on small screens)
   ═══════════════════════════════════════════════════════════ */
.mobile-sheet-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 199;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.mobile-sheet-backdrop.visible {
  display: block;
  opacity: 1;
}

/* Floating action button to open sidebar on mobile */
.mobile-sidebar-fab {
  display: none;
  position: fixed;
  bottom: 20px;
  right: 16px;
  z-index: 150;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, box-shadow 0.15s;
}

.mobile-sidebar-fab:active {
  transform: scale(0.92);
}

.mobile-sidebar-fab svg {
  width: 20px;
  height: 20px;
}

/* ═══════════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 1000px) {
  .kg-panel {
    display: none !important;
  }
}

@media (max-width: 768px) {
  .sidebar {
    position: absolute;
    left: 0;
    top: 44px;
    height: calc(100% - 44px);
    z-index: 100;
    box-shadow: 1px 0 8px rgba(0, 0, 0, 0.1);
  }

  .sidebar.hidden {
    opacity: 0;
    visibility: hidden;
  }

  .resize-handle {
    display: none !important;
  }

  .paper-btn {
    display: flex !important;
  }

  .search-wrap {
    flex: 0 1 200px;
  }

  /* Increase touch targets on tablet */
  .header-btn {
    min-height: 36px;
    min-width: 36px;
    padding: 0 10px;
  }

  .sb-close-btn {
    min-height: 44px;
    min-width: 44px;
  }
}

@media (max-width: 600px) {
  /* ── Bottom sheet sidebar ── */
  .sidebar {
    position: fixed !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    top: auto !important;
    width: 100% !important;
    height: 55vh !important;
    max-height: 55vh;
    z-index: 200;
    border-right: none;
    border-top: 1px solid var(--border);
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.12);
    transform: translateY(0);
    transition: transform 0.3s ease, opacity 0.3s ease, visibility 0.3s;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    visibility: visible;
  }

  .sidebar.hidden {
    transform: translateY(100%) !important;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
  }

  /* Drag handle at top of bottom sheet */
  .sidebar::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 8px auto 4px;
    flex-shrink: 0;
  }

  .resize-handle {
    display: none !important;
  }

  /* Show the FAB */
  .mobile-sidebar-fab {
    display: flex;
  }

  /* Hide FAB when sheet is open */
  .sidebar:not(.hidden) ~ .mobile-sidebar-fab,
  .mobile-sheet-backdrop.visible ~ .mobile-sidebar-fab {
    display: none;
  }

  /* ── Header: compact single row ── */
  .header {
    height: 48px;
    padding: 0 8px;
    gap: 6px;
    flex-wrap: nowrap;
    overflow: hidden;
  }

  .header-logo {
    font-size: 13px;
    flex-shrink: 0;
  }

  .header-right {
    gap: 0;
    flex-shrink: 0;
  }

  /* Hide paper title/ID on mobile — not enough room */
  .header-paper-id,
  .header-paper-title,
  .header-paper-cit {
    display: none;
  }

  .search-wrap {
    flex: 1 1 auto;
    min-width: 0;
    max-width: none;
  }

  .search-wrap.search-short {
    flex: 1 1 auto;
    max-width: none;
  }

  .search-wrap input {
    height: 44px;
    font-size: 16px; /* prevents iOS zoom on focus */
    border-radius: 6px;
  }

  /* ── Touch-friendly buttons ── */
  .header-btn {
    min-height: 44px;
    min-width: 44px;
    padding: 0 8px;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  a.header-btn.header-roadmap-btn {
    min-height: 44px;
    min-width: 44px;
  }

  /* ── Paper subheader: streamlined ── */
  .paper-subheader {
    height: 44px;
    padding: 0 6px;
    gap: 0;
  }

  .paper-subheader .header-btn {
    min-height: 44px;
    min-width: 44px;
    padding: 0 8px;
  }

  /* Show paper ID instead of full title on mobile */
  .subheader-title {
    display: block;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 11px;
    color: var(--text-3);
    padding: 0 6px;
  }

  /* Hide less-essential subheader actions on mobile */
  #btn-notebook {
    display: none;
  }

  .zoom-display {
    display: none;
  }

  #btn-zoom-out-hdr,
  #btn-zoom-in-hdr {
    display: none;
  }

  /* Keep speed reader accessible on mobile */
  #btn-speed-reader {
    min-height: 44px;
    min-width: 44px;
  }

  .paper-subheader-right {
    margin-left: 0;
    gap: 0;
  }

  /* PDF link and download stay visible */
  #pdf-link-hdr {
    min-height: 44px;
    min-width: 44px;
    font-size: 11px;
  }

  /* ── Sidebar sections: bigger touch targets ── */
  .sb-section-head {
    height: 44px;
    padding: 0 16px;
  }

  .sb-section-head span {
    font-size: 12px;
  }

  .sb-close-btn {
    min-height: 44px;
    min-width: 44px;
  }

  .spine-node {
    padding: 10px 16px 10px 42px;
    min-height: 44px;
  }

  .toc-item {
    padding: 12px 16px;
    min-height: 44px;
    font-size: 14px;
  }

  .toc-item.toc-h3 {
    padding-left: 32px;
  }

  .toc-item.toc-h4,
  .toc-item.toc-h5,
  .toc-item.toc-h6 {
    padding-left: 44px;
    font-size: 13px;
  }

  /* Concept chips: bigger tap targets */
  .fp-grid .fp-chip {
    padding: 10px 12px;
    font-size: 13px;
    min-height: 44px;
  }

  /* Search results: bigger tap targets */
  .search-dropdown .search-result-item {
    padding: 10px 12px;
    min-height: 44px;
  }

  /* Touch feedback: active states for tappable elements */
  .header-btn:active,
  .spine-node:active,
  .toc-item:active,
  .fp-chip:active,
  .download-item:active,
  .search-result-item:active {
    opacity: 0.7;
    transition: opacity 0.05s;
  }

  /* Prevent iOS tap highlight flashing */
  * {
    -webkit-tap-highlight-color: transparent;
  }

  /* Loading overlay: match mobile subheader height */
  #loading-overlay {
    top: 44px;
  }

  /* Search dropdown: fit within mobile viewport */
  .search-dropdown {
    max-height: calc(100vh - 96px);
  }
}

/* Landscape on small phones: shrink bottom sheet, tighten header */
@media (max-width: 800px) and (orientation: landscape) {
  .sidebar {
    height: 45vh !important;
    max-height: 45vh;
  }
  .header {
    height: 40px;
  }
  .paper-subheader {
    height: 36px;
  }
  .rsvp-overlay {
    height: 100px;
  }
  .rsvp-overlay.active ~ #pdf-iframe {
    margin-top: 100px;
  }
  #rsvp-word-container {
    font-size: 20px;
  }
}

/* ═══════════════════════════════════════════════════════════
   DOWNLOAD DROPDOWN
   ═══════════════════════════════════════════════════════════ */
.paper-subheader {
  position: relative;
}

.download-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  min-width: 160px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0 0 0 4px;
  z-index: 5;
}

.download-dropdown.show {
  display: block;
}

.download-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  font-size: 11px;
  font-family: var(--font-sans, system-ui, sans-serif);
  color: var(--text-2);
  text-decoration: none;
}

.download-item + .download-item {
  border-top: 1px solid var(--border-subtle);
}

.download-item:hover {
  background: var(--bg-2);
  color: var(--text);
}

@media (max-width: 600px) {
  .download-dropdown {
    min-width: 180px;
    right: 0;
    left: auto;
  }
  .download-item {
    padding: 10px 14px;
    font-size: 13px;
    min-height: 44px;
  }
}

.download-item-label {
  font-weight: 500;
  flex: 1;
}

.download-item-ext {
  font-size: 10px;
  color: var(--text-3);
  font-family: var(--mono);
  margin-left: auto;
}

/* ═══════════════════════════════════════════════════════════
   CONCEPT SEARCH/FILTER
   ═══════════════════════════════════════════════════════════ */
.concepts-filter-wrap {
  padding: 6px 12px 2px;
}

.concepts-filter-input {
  width: 100%;
  height: 26px;
  padding: 0 8px;
  font-size: 11px;
  font-family: var(--font);
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  outline: none;
}

.concepts-filter-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(0, 86, 179, 0.08);
}

.concepts-filter-input::placeholder {
  color: var(--text-3);
}

@media (max-width: 600px) {
  .concepts-filter-input {
    min-height: 44px;
    font-size: 16px; /* prevent iOS auto-zoom on focus */
    padding: 0 12px;
  }
  .chunky-filter-item {
    min-height: 44px;
    padding: 0;
  }
  .chunky-filter-clear {
    min-height: 44px;
    font-size: 13px;
    padding: 0 12px;
  }
  .chunky-related-grid {
    grid-template-columns: 1fr;
  }
}

/* ═══════════════════════════════════════════════════════════
   UTILITY CLASSES
   ═══════════════════════════════════════════════════════════ */
.hidden {
  display: none !important;
}

/* Toast notifications */
.pg-toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  padding: 14px 24px;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.5;
  max-width: 520px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
  animation: pgToastIn 0.3s ease-out, pgToastOut 0.3s ease-in forwards;
  animation-delay: 0s, 6s;
  pointer-events: auto;
  cursor: pointer;
}

.pg-toast-warning {
  background: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
}

.pg-toast-error {
  background: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
}

.pg-toast-success {
  background: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

@keyframes pgToastIn {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(-12px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

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

/* ── Chunky semantic layer styles ── */


/* Inspector panel: type bars */
.chunky-type-bars { display: flex; flex-direction: column; gap: 5px; padding: 8px 0 6px; }
.chunky-bar-row { display: flex; align-items: center; gap: 6px; font-size: 11px; }
.chunky-bar-label { flex: 0 0 130px; text-overflow: ellipsis; overflow: hidden; white-space: nowrap; color: var(--text-2, #6b7280); }
.chunky-bar-track { flex: 1; height: 6px; background: var(--bg-2, #f3f4f6); border-radius: 3px; overflow: hidden; }
.chunky-bar-fill { height: 100%; border-radius: 3px; transition: width 0.3s ease; }
.chunky-bar-count { flex: 0 0 22px; text-align: right; color: var(--text-3, #9ca3af); font-size: 10px; }

/* Variant chips */
.chunky-variants { display: flex; flex-wrap: wrap; gap: 4px; padding: 4px 0 6px; }
.chunky-variant-chip {
  display: inline-block; padding: 2px 7px; border-radius: 10px; font-size: 11px;
  border: 1px solid; cursor: pointer; white-space: nowrap;
  transition: opacity 0.15s;
}
.chunky-variant-chip:hover { opacity: 0.75; }

/* Meta row */
.chunky-meta-row { display: flex; flex-wrap: wrap; gap: 8px; padding: 4px 0 2px; font-size: 10px; color: var(--text-3, #9ca3af); }
.chunky-meta-item.chunky-ambiguity { font-weight: 500; }

/* Chunky lay summary line (below concept chips) */
#chunky-lay-line {
  margin: 6px 0 2px;
  padding: 6px 8px;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--text-2, #6b7280);
  background: var(--bg-2, #f9fafb);
  border-left: 2px solid var(--accent, #6366f1);
  border-radius: 0 4px 4px 0;
}

/* Empty / loading states */
.chunky-empty, .chunky-loading { padding: 10px 0; font-size: 12px; color: var(--text-3, #9ca3af); }

/* Related papers grid */
.chunky-related-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 4px 0; }
.chunky-related-card {
  display: flex; flex-direction: column; gap: 2px; padding: 6px 8px;
  border: 1px solid var(--border, #e5e7eb); border-radius: 6px;
  text-decoration: none; color: inherit;
  transition: border-color 0.15s, background 0.15s;
}
.chunky-related-card:hover { border-color: var(--text-3, #9ca3af); background: var(--bg-2, #f9fafb); }
.chunky-related-type { font-size: 9px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.chunky-related-title { font-size: 11px; line-height: 1.4; color: var(--text, #111); }
.chunky-related-year { font-size: 10px; color: var(--text-3, #9ca3af); }

/* Facet filter */
.chunky-filter-list { display: flex; flex-direction: column; gap: 3px; padding: 4px 0; }
.chunky-filter-item { display: flex; align-items: center; gap: 6px; font-size: 12px; cursor: pointer; padding: 2px 0; }
.chunky-filter-item:hover { color: var(--text, #111); }
.chunky-filter-cb { flex-shrink: 0; cursor: pointer; }
.chunky-filter-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.chunky-filter-type { flex: 1; color: var(--text-2, #6b7280); }
.chunky-filter-count { color: var(--text-3, #9ca3af); font-size: 10px; }
.chunky-filter-clear { margin-top: 6px; padding: 3px 8px; font-size: 11px; cursor: pointer; background: none; border: 1px solid var(--border, #e5e7eb); border-radius: 4px; color: var(--text-2, #6b7280); }
.chunky-filter-clear:hover { border-color: var(--text-3, #9ca3af); }
.chunky-filter-empty { padding: 8px 0; font-size: 12px; color: var(--text-3, #9ca3af); }

/* Overlay toggle button */
.chunky-overlay-btn { font-size: 10px; padding: 2px 6px; opacity: 0.6; margin-left: auto; }
.chunky-overlay-btn:hover { opacity: 1; }
.chunky-overlay-btn.chunky-overlay-active { opacity: 1; background: var(--text-2, #6b7280); color: #fff; border-radius: 3px; }

/* ── Theoria Claim Sidecar ── */
.theoria-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px 4px;
  flex-wrap: wrap;
}
.theoria-role {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 3px;
}
.theoria-status {
  font-size: 10px;
  font-weight: 600;
}
.theoria-conf {
  font-size: 10px;
  opacity: 0.7;
}
.theoria-conf::before { content: '·'; margin-right: 4px; }
.theoria-claim {
  font-size: 12px;
  line-height: 1.55;
  color: var(--text, #111);
  padding: 4px 12px 8px;
  margin: 0;
}
.theoria-what {
  font-size: 11px;
  line-height: 1.4;
  color: var(--text-3, #9ca3af);
  padding: 0 12px 8px;
  margin: 0;
  font-style: italic;
}

/* ── Notebook View (Mathematica style) ── */
#notebook-panel {
  position: absolute;
  top: 35px; /* below paper-subheader (34px + 1px border) */
  left: 0;
  right: 0;
  bottom: 0;
  overflow-y: auto;
  background: #ffffff;
  font-family: "Times New Roman", Times, serif;
  padding: 12px 0 80px;
  z-index: 5;
}

.nb-empty {
  padding: 32px 40px;
  font-size: 13px;
  color: #999;
  font-family: "Courier New", Courier, monospace;
}

/* ── Variables dropdown ── */
.nb-variables-dropdown {
  position: relative;
  margin: 4px 48px 8px 28px;
  border-bottom: 1px solid #f0f0f0;
  padding-bottom: 8px;
}
.nb-variables-header {
  font-family: "Courier New", Courier, monospace;
  font-size: 11px;
  color: #888;
  padding: 4px 0;
  user-select: none;
}
.nb-variables-header:hover {
  color: #555;
}
.nb-variables-table {
  position: relative;
  padding: 0;
}
.nb-var-cols {
  display: flex;
  gap: 20px;
}
.nb-var-col {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}
.nb-var-row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  margin: 0;
  padding: 0 8px 0 0;
  font-size: 10px;
  line-height: 1;
  height: 16px;
  border-bottom: 1px solid #f5f5f5;
  overflow: hidden;
}
.nb-var-row:last-child {
  border-bottom: none;
}
.nb-var-wolfram {
  font-family: "Courier New", Courier, monospace;
  color: #333;
  flex: 0 0 40%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
}
.nb-var-latex {
  flex: 0 0 25%;
  overflow: hidden;
  text-align: left;
}
.nb-var-latex .katex-display {
  margin: 0;
  text-align: left !important;
}
.nb-var-latex .katex {
  font-size: 0.95em;
  text-align: left !important;
}
.nb-var-name {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 10px;
  color: #999;
  font-style: italic;
  text-align: left;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Cell group: wraps description + equation + wolfram input */
.nb-cell-group {
  position: relative;
  margin: 0 48px 0 28px;
  border-bottom: 1px solid #f0f0f0;
  padding-bottom: 6px;
  margin-bottom: 6px;
  overflow: hidden;
}
.nb-cell-group.nb-cell-nowolfram {
  opacity: 0.45;
}

/* Individual cell */
.nb-cell {
  position: relative;
  display: flex;
  align-items: flex-start;
  min-height: 22px;
}

/* Text cells: Title, Section, Subtitle */
.nb-cell-text {
  padding-left: 0;
  padding-right: 0;
}

.nb-style-title .nb-content {
  font-size: 24px;
  font-weight: bold;
  text-align: center;
  width: 100%;
  padding: 16px 0 4px;
  color: #000;
}

.nb-style-subtitle .nb-content {
  font-size: 14px;
  text-align: center;
  color: #555;
  width: 100%;
  padding: 2px 0 12px;
}

.nb-style-section .nb-content {
  font-size: 16px;
  font-weight: bold;
  color: #000;
  width: 100%;
  padding: 20px 0 4px;
  border-bottom: 1px solid #ddd;
  margin-bottom: 4px;
}

.nb-style-text .nb-content {
  font-size: 14px;
  color: #222;
  line-height: 1.5;
}

/* Content column — sits after the io-label, stacks math/actions/var-table vertically */
.nb-cell-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* Input cells */
.nb-cell-input {
  background: #fff;
  padding-left: 0;
}

.nb-cell-input .nb-content {
  font-family: "Courier New", Courier, monospace;
  font-size: 12px;
  color: #333;
  line-height: 1.4;
  word-break: break-all;
  flex: 1;
  padding: 1px 0;
}

/* Preamble / setup cell */
.nb-cell-preamble {
  background: #fafaf8;
  border-bottom: 1px solid #efefeb;
  margin-bottom: 8px;
}
.nb-preamble-content {
  color: #666 !important;
  font-size: 11.5px !important;
  white-space: pre;
}

/* Description line above the equation */
.nb-cell-desc {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 11px;
  color: #777;
  font-style: italic;
  padding: 6px 0 2px 0;
  line-height: 1.3;
}

/* Display equation row: Copy nb ... equation ... (label) */
.nb-cell-display-eq {
  display: flex;
  align-items: center;
  background: #fff;
  padding: 2px 0 2px 0;
}
.nb-copy-nb {
  font-family: "Courier New", Courier, monospace;
  font-size: 10px;
  color: #bbb;
  cursor: pointer;
  padding: 0;
  border: none;
  background: none;
  outline: none;
  box-shadow: none;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
  white-space: nowrap;
  margin-right: 12px;
  flex-shrink: 0;
  min-width: 48px;
  text-align: left;
}
.nb-copy-nb:hover {
  color: #555;
}
.nb-cell-group:hover .nb-copy-nb {
  opacity: 1;
}

/* Touch devices: always show notebook copy buttons */
@media (hover: none) and (pointer: coarse) {
  .nb-copy-nb {
    opacity: 0.6 !important;
    font-size: 12px;
    padding: 4px 0;
  }
}
@media (hover: none) and (pointer: coarse) and (max-width: 430px) {
  .nb-copy-nb {
    opacity: 0.4 !important;
    font-size: 10px;
  }
}

.nb-cell-display-eq .nb-math-content {
  flex: 1;
  padding: 2px 0;
  min-width: 0;
  overflow: hidden;
}
.nb-eq-label {
  font-family: "Courier New", Courier, monospace;
  font-size: 11px;
  color: #888;
  flex-shrink: 0;
  text-align: right;
  padding-left: 12px;
  padding-right: 8px;
  user-select: none;
}

/* KaTeX display math sizing */
.nb-math-content .katex-display {
  margin: 0;
  text-align: left;
}
.nb-math-content .katex {
  font-size: 0.95em;
}

.nb-latex-fallback {
  font-family: "Courier New", Courier, monospace;
  font-size: 11px;
  color: #555;
  white-space: pre-wrap;
  word-break: break-all;
}

/* In[n]:= / Out[n]= labels */
.nb-io-label {
  font-family: "Courier New", Courier, monospace;
  font-size: 11px;
  white-space: nowrap;
  padding-right: 8px;
  padding-top: 3px;
  min-width: 64px;
  text-align: right;
  user-select: none;
  flex-shrink: 0;
}

.nb-in-label  { color: #a0522d; } /* Sienna — matches Mathematica input label color */
.nb-out-label { color: #00008b; } /* Dark blue — matches Mathematica output label */

/* Inline In[n]:= label (not a separate column — same left as description) */
.nb-in-label-inline {
  color: #a0522d;
  font-family: "Courier New", Courier, monospace;
  font-size: 12px;
  font-weight: normal;
  white-space: nowrap;
}

/* Right-side cell bracket */
.nb-bracket {
  position: absolute;
  right: -18px;
  top: 2px;
  bottom: 2px;
  width: 4px;
  border-top: 1px solid #bbb;
  border-right: 1px solid #bbb;
  border-bottom: 1px solid #bbb;
  cursor: default;
}

/* Group bracket spanning input+output */
.nb-bracket-group {
  position: absolute;
  right: -24px;
  top: 2px;
  bottom: 2px;
  width: 4px;
  border-top: 1px solid #999;
  border-right: 1px solid #999;
  border-bottom: 1px solid #999;
}

/* Cell actions (copy buttons) — shown on hover */
.nb-cell-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 0 2px 0; /* align with content */
  opacity: 0;
  transition: opacity 0.15s;
}

.nb-cell-output:hover .nb-cell-actions,
.nb-cell-group:hover .nb-cell-actions {
  opacity: 1;
}

/* Touch devices: always show cell action buttons */
@media (hover: none) and (pointer: coarse) {
  .nb-cell-actions {
    opacity: 0.7 !important;
  }
}
@media (hover: none) and (pointer: coarse) and (max-width: 430px) {
  .nb-cell-actions {
    opacity: 0.45 !important;
    font-size: 0.85em;
  }
}

.nb-eq-num {
  font-family: "Courier New", Courier, monospace;
  font-size: 10px;
  color: #999;
  margin-right: 4px;
}
.nb-eq-num-prominent {
  font-family: "Times New Roman", Times, serif;
  font-size: 13px;
  font-weight: bold;
  color: #444;
  margin-right: 10px;
  letter-spacing: 0.02em;
}

/* Display math cell (no In/Out labels — equation SymPy couldn't convert) */
.nb-cell-display {
  padding-left: 0;
  padding-right: 0;
  position: relative;
  display: block;
}

.nb-display-math {
  overflow-x: auto;
  padding: 6px 0;
}

.nb-display-math .katex-display {
  margin: 0;
  text-align: center;
}

.nb-display-eqnum {
  position: absolute;
  right: 32px;
  top: 50%;
  transform: translateY(-50%);
  font-family: "Times New Roman", Times, serif;
  font-size: 12px;
  color: #555;
}

.nb-loading-msg {
  font-family: "Courier New", Courier, monospace;
  padding: 60px 40px 32px;
}

.nb-copy-btn {
  font-size: 10px;
  font-family: "Courier New", Courier, monospace;
  color: #888;
  background: none;
  border: none;
  outline: none;
  padding: 0;
  cursor: pointer;
  transition: color 0.1s;
}
.nb-copy-btn:hover {
  color: #333;
}

#btn-notebook.active,
#btn-speed-reader.active,
#btn-sentence-highlights.active {
  color: var(--accent, #6366f1);
}

#btn-notebook.disabled,
#btn-sentence-highlights.disabled {
  opacity: 0.35;
  pointer-events: none;
}

/* ── Equation type badge + description ───────────────────────────────────── */
.nb-cell-meta {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 3px 0 4px 0;
  flex-wrap: wrap;
}
.nb-eq-type-badge {
  font-family: "Courier New", Courier, monospace;
  font-size: 10px;
  color: #fff;
  background: #6a5acd;
  border-radius: 3px;
  padding: 1px 6px;
  white-space: nowrap;
  letter-spacing: 0.01em;
}
.nb-eq-desc {
  font-size: 11px;
  color: #777;
  font-family: "Times New Roman", Times, serif;
  font-style: italic;
}

/* ── Variable table ──────────────────────────────────────────────────────── */
.nb-var-details {
  margin: 4px 0 2px 0;
}
.nb-var-summary {
  font-size: 10px;
  font-family: "Courier New", Courier, monospace;
  color: #999;
  cursor: pointer;
  user-select: none;
  padding: 2px 0;
}
.nb-var-summary:hover { color: #555; }
.nb-var-table {
  border-collapse: collapse;
  font-size: 10.5px;
  font-family: "Courier New", Courier, monospace;
  margin-top: 4px;
  width: 100%;
  max-width: 680px;
}
.nb-var-table th {
  font-weight: 600;
  color: #888;
  border-bottom: 1px solid #e8e8e8;
  padding: 2px 8px 2px 0;
  text-align: left;
}
.nb-var-table td {
  padding: 2px 8px 2px 0;
  color: #444;
  border-bottom: 1px solid #f2f2f2;
  vertical-align: top;
}
.nb-var-sym {
  font-weight: bold;
  color: #333 !important;
}
.nb-var-label {
  color: #666 !important;
  font-style: italic;
}

/* ── Variable index (top of notebook) ───────────────────────────────────── */
.nb-var-index {
  margin: 0 28px 12px 40px;
  border-bottom: 1px solid #f0f0f0;
  padding-bottom: 12px;
}

/* ── Equations not covered footer ───────────────────────────────────────── */
.nb-uncovered-note {
  margin: 16px 28px 0 40px;
  font-size: 10.5px;
  font-family: "Courier New", Courier, monospace;
  color: #aaa;
}

/* ── Notebook footer row (note + refresh on same line) ─────────────────── */
.nb-footer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 48px 0 28px;
}
.nb-footer-row .nb-uncovered-note,
.nb-footer-stats {
  font-family: "Courier New", Courier, monospace;
  font-size: 11px;
  color: #aaa;
  margin: 0;
  padding: 0;
}
.nb-toolbar {
  text-align: right;
}
.nb-footer-row .nb-toolbar {
  padding: 0;
}
.nb-toolbar-btn {
  font-family: "Courier New", Courier, monospace;
  font-size: 11px;
  color: #aaa;
  background: none;
  border: 1px solid #e0e0e0;
  border-radius: 3px;
  padding: 3px 10px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.nb-toolbar-btn:hover:not(:disabled) {
  color: #555;
  border-color: #bbb;
}
.nb-toolbar-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

/* .nb download button inherits download-item styles but needs button reset */
button.download-item {
  width: 100%;
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
}
