:root {
  --bg: #ffffff;
  --bg-soft: #f8fafc;
  --bg-muted: #f1f5f9;
  --bg-active: #eef0f4;
  --border: #e5e7eb;
  --border-subtle: #eef0f4;
  --ink: #0f1115;
  --ink-2: #334155;
  --muted: #64748b;
  --brand: #446bf5;
  --brand-soft: #eff6ff;
  --brand-border: #dbeafe;
  --pali: #b91c1c;
  --end-bg: #fde68a;
  --end-fg: #78350f;
  --shared-bg: #fefce8;
  --shared-border: #d4a72c;
  --callout-bg: #f8fafc;
  --callout-border: #cbd5e1;
  --badge-bg: #ffffff;
  --badge-border: #e2e8f0;
  --shadow-pop: 0 14px 38px rgba(15, 17, 21, 0.14);
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

html[data-theme="dark"] {
  --bg: #0f1218;
  --bg-soft: #151922;
  --bg-muted: #1b212d;
  --bg-active: #232a38;
  --border: #262e3d;
  --border-subtle: #1e2532;
  --ink: #f1f5f9;
  --ink-2: #cbd5e1;
  --muted: #94a3b8;
  --brand: #6d8cff;
  --brand-soft: rgba(109, 140, 255, 0.14);
  --brand-border: rgba(109, 140, 255, 0.3);
  --pali: #fca5a5;
  --end-bg: rgba(250, 204, 21, 0.24);
  --end-fg: #fde047;
  --shared-bg: rgba(250, 204, 21, 0.08);
  --shared-border: #ca8a04;
  --callout-bg: #151922;
  --callout-border: #334155;
  --badge-bg: #161c27;
  --badge-border: #2d3748;
  --shadow-pop: 0 18px 44px rgba(0, 0, 0, 0.55);
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: 76px;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15.5px;
  line-height: 1.68;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--brand);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ==================== Top Header (56px, docs style) ==================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 60;
  height: 58px;
  background: var(--bg);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-shrink: 0;
  min-width: 0;
}

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

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--ink);
  text-decoration: none !important;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.brand-logo {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: var(--brand);
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
}

.brand-slash {
  color: var(--border);
  font-size: 16px;
}

.brand-sub {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Center Search */
.search-shell {
  position: relative;
  flex: 1 1 380px;
  max-width: 440px;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 10px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: border-color 0.14s, background 0.14s, box-shadow 0.14s;
}

.search-box:focus-within {
  background: var(--bg);
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

.search-icon {
  color: var(--muted);
  flex-shrink: 0;
}

#globalSearch {
  flex: 1 1 auto;
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 13.5px;
  outline: none;
}

#globalSearch::placeholder {
  color: var(--muted);
}

#globalSearch::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}

.velthuis-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--muted);
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}

.velthuis-pill input {
  margin: 0;
  accent-color: var(--brand);
}

.clear-x {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px;
}

.search-results-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 74vh;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-pop);
  padding: 10px;
  z-index: 80;
}

.sr-group {
  margin-bottom: 10px;
}

.sr-group:last-child {
  margin-bottom: 0;
}

.sr-group-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  padding: 2px 8px 5px;
}

.sr-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 7px 9px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--ink);
  text-decoration: none !important;
  cursor: pointer;
  font: inherit;
}

.sr-item:hover {
  background: var(--bg-soft);
}

.sr-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13.5px;
  font-weight: 600;
}

.sr-sub {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 2px;
  line-height: 1.45;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}

.top-nav-link {
  color: var(--ink-2);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none !important;
}

.top-nav-link:hover,
.top-nav-link.active {
  color: var(--ink);
  font-weight: 600;
}

.top-nav-ext {
  color: var(--brand);
}

.icon-btn {
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
}

.icon-btn:hover {
  background: var(--bg-soft);
  color: var(--ink);
}

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

/* ==================== 3-Column Docs Shell ==================== */
.docs-shell {
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr) 232px;
  min-height: calc(100vh - 58px);
}

/* Left Sidebar */
.left-sidebar {
  position: sticky;
  top: 58px;
  height: calc(100vh - 58px);
  overflow-y: auto;
  border-right: 1px solid var(--border-subtle);
  padding: 18px 14px 40px;
  background: var(--bg);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sb-home-link {
  display: block;
  padding: 7px 10px;
  border-radius: 7px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none !important;
}

.sb-home-link:hover {
  background: var(--bg-soft);
}

.sb-home-link.active {
  background: var(--bg-active);
}

.sb-section-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 16px 10px 6px;
}

.sb-group-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s;
}

.sb-group-toggle:hover {
  background: var(--bg-soft);
}

.sb-label-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 10px 6px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-align: left;
  cursor: pointer;
}

.sb-label-btn:hover {
  color: var(--ink);
}

.chev {
  color: var(--muted);
  transition: transform 0.16s ease;
  flex-shrink: 0;
}

.sb-group.collapsed .chev {
  transform: rotate(-90deg);
}

.sb-group-items {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 2px 0 4px 10px;
  padding-left: 8px;
  border-left: 1px solid var(--border-subtle);
}

.sb-group.collapsed .sb-group-items {
  display: none;
}

.sb-item-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 9px;
  border-radius: 7px;
  color: var(--ink-2);
  font-size: 13.5px;
  line-height: 1.4;
  text-decoration: none !important;
}

.sb-item-link:hover {
  background: var(--bg-soft);
  color: var(--ink);
}

.sb-item-link.active {
  background: var(--bg-active);
  color: var(--ink);
  font-weight: 600;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  background: var(--badge-bg);
  border: 1px solid var(--badge-border);
  white-space: nowrap;
  flex-shrink: 0;
}

.pill-blue {
  color: var(--brand);
  background: var(--brand-soft);
  border-color: var(--brand-border);
  font-weight: 600;
}

/* Center Content */
.docs-main {
  min-width: 0;
  padding: 28px 44px 72px;
}

.docs-article {
  max-width: 780px;
  margin: 0 auto;
}

.breadcrumb-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 10px;
}

.breadcrumb-row a {
  color: var(--muted);
}

.breadcrumb-row .crumb-current {
  color: var(--brand);
  font-weight: 500;
}

.docs-article h1 {
  margin: 0 0 10px;
  font-size: 28px;
  line-height: 1.25;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.lead {
  margin: 0 0 24px;
  font-size: 16px;
  line-height: 1.65;
  color: var(--muted);
}

.docs-article h2 {
  margin: 34px 0 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 20px;
  line-height: 1.35;
  letter-spacing: -0.015em;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 10px;
}

.docs-article h3 {
  margin: 24px 0 10px;
  font-size: 16.5px;
  line-height: 1.4;
  color: var(--ink);
}

.docs-article p {
  margin: 0 0 14px;
  color: var(--ink-2);
}

.docs-article ul,
.docs-article ol {
  margin: 0 0 16px;
  padding-left: 22px;
  color: var(--ink-2);
}

.docs-article li {
  margin-bottom: 7px;
}

.docs-article ul li::marker {
  color: var(--brand);
}

/* Home Topic Grid */
.topic-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin: 14px 0 8px;
}

.topic-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px 18px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  text-decoration: none !important;
  color: var(--ink);
  transition: border-color 0.14s, box-shadow 0.14s, transform 0.12s;
}

.topic-card:hover {
  border-color: var(--brand);
  box-shadow: 0 4px 16px rgba(68, 107, 245, 0.08);
  transform: translateY(-1px);
}

.topic-card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.35;
}

.topic-card-desc {
  font-size: 13.5px;
  color: var(--muted);
  line-height: 1.5;
}

/* Pali Monospace & Suffix Highlighting (Exact pali.catusacca.net signature!) */
.pali-mono {
  font-family: var(--font-mono);
  color: var(--pali);
  font-size: 0.94em;
  font-weight: 500;
}

.pali-word {
  display: inline-flex;
  align-items: baseline;
  white-space: nowrap;
}

.end-hl {
  display: inline-block;
  font-family: var(--font-mono);
  background: var(--end-bg);
  color: var(--end-fg);
  border-radius: 4px;
  padding: 0 4px;
  margin: 0 1px;
  font-weight: 700;
  line-height: 1.45;
  white-space: nowrap;
}

/* Clean Rounded Tables */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin: 14px 0 22px;
  background: var(--bg);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14.5px;
}

thead th {
  background: var(--bg-muted);
  color: var(--ink);
  font-size: 13.5px;
  font-weight: 600;
  text-align: left;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border-subtle);
  border-right: 1px solid var(--border-subtle);
  vertical-align: top;
  color: var(--ink-2);
}

tbody td:last-child,
thead th:last-child {
  border-right: none;
}

tbody tr:last-child td {
  border-bottom: none;
}

.decl-table tbody td {
  vertical-align: middle;
  white-space: nowrap;
}

.decl-table td.case-col {
  background: var(--bg-soft);
  font-weight: 600;
  color: var(--ink);
  width: 24%;
  white-space: nowrap;
}

.case-sub {
  display: block;
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
  margin-top: 2px;
  white-space: nowrap;
}

.decl-table td.shared-cell {
  background: var(--shared-bg);
  border-left: 2.5px solid var(--shared-border) !important;
  vertical-align: middle;
}

.decl-subnote {
  display: block;
  margin-top: 6px;
  font-size: 12.5px;
  color: var(--muted);
}

.multiline-cell {
  white-space: pre-line;
}

.alpha-toc-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
  margin-top: 4px;
}

.alpha-btn {
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--ink-2);
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.alpha-btn:hover {
  border-color: var(--brand);
  color: var(--brand);
  background: var(--brand-soft);
}

.right-toc.is-hidden {
  visibility: hidden;
  pointer-events: none;
}

/* Callout */
.callout {
  background: var(--callout-bg);
  border: 1px solid var(--border);
  border-left: 3px solid var(--brand);
  border-radius: 8px;
  padding: 12px 15px;
  margin: 14px 0 18px;
  font-size: 14px;
  color: var(--ink-2);
}

.callout-warn {
  border-left-color: var(--shared-border);
  background: var(--shared-bg);
}

/* Analyzer & Filter Controls */
.filter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 12px 0 14px;
}

.doc-input {
  height: 40px;
  min-width: 260px;
  flex: 1 1 280px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-soft);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  outline: none;
}

.doc-input:focus {
  background: var(--bg);
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

.seg-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.seg-btn {
  padding: 5px 11px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg);
  color: var(--ink-2);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.seg-btn:hover {
  background: var(--bg-soft);
}

.seg-btn.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #ffffff;
  font-weight: 600;
}

.dia-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 10px;
}

.dia-btn {
  min-width: 30px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 13.5px;
  cursor: pointer;
}

.dia-btn:hover {
  border-color: var(--brand);
  color: var(--brand);
  background: var(--brand-soft);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 8px 0 14px;
}

.chip-btn {
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--ink-2);
  font-family: var(--font-mono);
  font-size: 12.5px;
  cursor: pointer;
}

.chip-btn:hover {
  border-color: var(--brand);
  color: var(--brand);
  background: var(--brand-soft);
}

.analyzer-result {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  background: var(--bg-soft);
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
}

/* Passage Cards inside Readings */
.passage-block {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  margin-bottom: 16px;
  background: var(--bg);
}

.passage-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.passage-pali {
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.7;
  color: var(--ink);
  background: var(--bg-soft);
  border-left: 3px solid var(--brand);
  border-radius: 0 8px 8px 0;
  padding: 10px 14px;
  white-space: pre-line;
  margin: 8px 0;
}

.passage-details summary {
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--brand);
  margin-top: 8px;
  user-select: none;
}

/* Mini Diagrams */
.mini-diagram-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 14px 0 20px;
}

.mini-diagram {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  background: var(--bg-soft);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.mini-diagram-cap {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 10px;
}

.dg-svg {
  display: block;
  width: 100%;
  max-width: 570px;
  min-width: 440px;
  height: auto;
}

.dg-svg-box {
  fill: var(--bg);
  stroke: var(--border);
  stroke-width: 1.5;
}

.dg-svg-box-accent {
  stroke: var(--brand);
  stroke-width: 1.6;
}

.dg-svg-word {
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  fill: var(--ink);
}

.dg-svg-sub {
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 500;
  fill: var(--brand);
}

.dg-svg-note {
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 500;
  fill: var(--muted);
}

.dg-svg-line {
  fill: none;
  stroke: var(--ink-2);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.dg-svg-head {
  fill: var(--ink-2);
}

/* Prev / Next Page Footer */
.page-pager {
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px solid var(--border-subtle);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.pager-link {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  text-decoration: none !important;
  color: var(--ink);
}

.pager-link:hover {
  border-color: var(--brand);
}

.pager-link.is-next {
  text-align: right;
}

.pager-dir {
  font-size: 11.5px;
  color: var(--muted);
}

.pager-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--brand);
}

/* Right TOC ("TRÊN TRANG NÀY") */
.right-toc {
  position: sticky;
  top: 58px;
  height: calc(100vh - 58px);
  overflow-y: auto;
  padding: 24px 18px 40px 10px;
}

.right-toc-title {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 10px;
}

.page-toc-nav {
  display: flex;
  flex-direction: column;
  border-left: 1.5px solid var(--border-subtle);
}

.page-toc-link {
  display: block;
  padding: 4px 0 4px 12px;
  margin-left: -1.5px;
  border-left: 2px solid transparent;
  font-size: 13px;
  line-height: 1.45;
  color: var(--muted);
  text-decoration: none !important;
}

.page-toc-link.depth-3 {
  padding-left: 22px;
  font-size: 12.5px;
}

.page-toc-link:hover {
  color: var(--ink);
}

.page-toc-link.active {
  color: var(--brand);
  border-left-color: var(--brand);
  font-weight: 600;
}

.vocab-click-word {
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
  text-align: left;
  font: inherit;
}

.vocab-click-word:hover {
  text-decoration: underline;
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 9px 16px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 500;
  z-index: 120;
  box-shadow: var(--shadow-pop);
}

/* Mobile / Tablet sticky "Trên trang này" collapsible bar */
.mobile-toc-bar {
  display: none;
}

/* ==================== Responsive ==================== */
@media (max-width: 1160px) {
  html {
    scroll-padding-top: 112px;
  }
  .docs-shell {
    grid-template-columns: 256px minmax(0, 1fr);
  }
  .right-toc {
    display: none;
  }
  .mobile-toc-bar:not([hidden]) {
    display: block;
    position: sticky;
    top: 58px;
    z-index: 45;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
  }
  .mobile-toc-trigger {
    width: 100%;
    height: 40px;
    padding: 0 14px;
    border: none;
    background: transparent;
    color: var(--ink);
    font: inherit;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    cursor: pointer;
    text-align: left;
  }
  .mobile-toc-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    overflow: hidden;
  }
  .mobile-toc-label {
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--muted);
    white-space: nowrap;
    flex-shrink: 0;
  }
  .mobile-toc-current {
    font-size: 13px;
    font-weight: 600;
    color: var(--brand);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .mobile-toc-chev {
    color: var(--muted);
    flex-shrink: 0;
    transition: transform 0.18s ease;
  }
  .mobile-toc-bar.open .mobile-toc-chev {
    transform: rotate(180deg);
  }
  .mobile-toc-dropdown {
    position: absolute;
    left: 0;
    right: 0;
    top: 40px;
    max-height: 60vh;
    overflow-y: auto;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-pop);
    padding: 10px 16px 14px;
  }
  .mobile-toc-dropdown .page-toc-link {
    padding: 6px 0 6px 12px;
    font-size: 13.5px;
    border-left: 2px solid var(--border-subtle);
    margin-left: 0;
  }
  .mobile-toc-dropdown .page-toc-link.active {
    border-left-color: var(--brand);
  }
  .mobile-toc-dropdown .alpha-toc-grid {
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
  }
  .brand-sub,
  .brand-slash {
    display: none;
  }
}

@media (max-width: 820px) {
  .topbar {
    padding: 0 12px;
    gap: 8px;
  }
  .topbar-right {
    gap: 8px;
  }
  .search-shell {
    flex: 1 1 0;
    min-width: 0;
    max-width: none;
  }
  .velthuis-pill {
    display: none;
  }
  .docs-shell {
    grid-template-columns: 1fr;
  }
  .mobile-menu-btn {
    display: inline-flex;
  }
  .left-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    height: 100vh;
    width: 286px;
    z-index: 100;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
  }
  .left-sidebar.open {
    transform: translateX(0);
  }
  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 17, 21, 0.45);
    z-index: 90;
  }
  .docs-main {
    padding: 20px 14px 56px;
  }
  .table-wrap table.decl-table {
    min-width: 440px;
    font-size: 13.5px;
  }
  .table-wrap thead th,
  .table-wrap tbody td {
    padding: 9px 11px;
  }
  .doc-input {
    min-width: 0;
    flex: 1 1 180px;
  }
  .topic-grid,
  .page-pager {
    grid-template-columns: 1fr;
  }
  .top-nav-link {
    display: none;
  }
}

/* Mobile stacked card view for all prose/reference tables (eliminates narrow squeezed columns on phones like Pixel 3) */
@media (max-width: 680px) {
  .table-wrap.is-card-wrap,
  .table-wrap:has(table:not(.decl-table)) {
    overflow-x: visible;
    border: none;
    border-radius: 0;
    background: transparent;
    margin: 12px 0 18px;
  }
  table:not(.decl-table),
  table:not(.decl-table) tbody {
    display: block;
    width: 100%;
    min-width: 0 !important;
  }
  table:not(.decl-table) thead {
    display: none;
  }
  table:not(.decl-table) tbody tr {
    display: block;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg);
    padding: 12px 14px;
    margin-bottom: 10px;
  }
  table:not(.decl-table) tbody tr:last-child {
    margin-bottom: 0;
  }
  table:not(.decl-table) tbody td {
    display: block;
    width: 100% !important;
    border: none !important;
    padding: 6px 0;
    font-size: 14px;
    line-height: 1.55;
    overflow-wrap: break-word;
  }
  table:not(.decl-table) tbody td:first-child {
    padding-top: 0;
    padding-bottom: 8px;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--border-subtle) !important;
    font-size: 14.5px;
    color: var(--ink);
  }
  table:not(.decl-table) tbody td:last-child {
    padding-bottom: 0;
  }
  table:not(.decl-table) tbody td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 2px;
  }
  table:not(.decl-table) tbody td:first-child[data-label]::before {
    font-size: 10.5px;
    margin-bottom: 3px;
  }
  table:not(.decl-table) tbody td[colspan] {
    border-bottom: none !important;
    text-align: center;
  }
}

@media (max-width: 480px) {
  .brand-name {
    display: none;
  }
}
