/* ==========================================================================
   SF90SR.wiki — Technical Reference & Systems Encyclopedia Stylesheet
   Zero external dependencies · Responsive 3-column Wiki Architecture
   ========================================================================== */

:root {
  --bg-page: #f8f9fa;
  --bg-surface: #ffffff;
  --bg-subtle: #f1f3f5;
  --bg-elevated: #ffffff;
  --bg-header: #ffffff;
  --bg-banner: #fef2f2;
  --bg-info: #f0f6fc;
  --bg-warn: #fffbeb;
  --bg-code: #f3f4f6;
  --bg-hover: #eaecf0;
  --bg-active: #e8eef7;

  --text-primary: #1f2328;
  --text-secondary: #4b5563;
  --text-muted: #6b7280;
  --text-inverse: #ffffff;

  --link: #0b57d0;
  --link-visited: #5b21b6;
  --link-hover: #0842a0;

  --accent: #b91c1c;
  --accent-strong: #991b1b;
  --accent-soft: rgba(185, 28, 28, 0.1);
  --accent-gold: #b45309;
  --accent-emerald: #047857;

  --border: #d0d7de;
  --border-subtle: #e5e7eb;
  --border-strong: #9ca3af;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 4px 14px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, 0.14);

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-serif: Georgia, "Liberation Serif", "Times New Roman", serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;

  --fs-base: 15px;
  --header-h: 58px;
}

html[data-theme="dark"] {
  --bg-page: #0d1117;
  --bg-surface: #161b22;
  --bg-subtle: #1c2128;
  --bg-elevated: #21262d;
  --bg-header: #161b22;
  --bg-banner: rgba(185, 28, 28, 0.14);
  --bg-info: rgba(56, 139, 253, 0.12);
  --bg-warn: rgba(210, 153, 34, 0.14);
  --bg-code: #21262d;
  --bg-hover: #292e36;
  --bg-active: #1f2d42;

  --text-primary: #e6edf3;
  --text-secondary: #b1bac4;
  --text-muted: #8b949e;
  --text-inverse: #0d1117;

  --link: #58a6ff;
  --link-visited: #bc8cff;
  --link-hover: #79c0ff;

  --accent: #ef4444;
  --accent-strong: #dc2626;
  --accent-soft: rgba(239, 68, 68, 0.15);
  --accent-gold: #f59e0b;
  --accent-emerald: #34d399;

  --border: #30363d;
  --border-subtle: #21262d;
  --border-strong: #484f58;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 14px 36px rgba(0, 0, 0, 0.65);
}

html[data-theme="contrast"] {
  --bg-page: #000000;
  --bg-surface: #0a0a0a;
  --bg-subtle: #141414;
  --bg-elevated: #171717;
  --bg-header: #000000;
  --bg-banner: #1e0a0a;
  --bg-info: #08182e;
  --bg-warn: #241b00;
  --bg-code: #1f1f1f;
  --bg-hover: #262626;
  --bg-active: #1e293b;

  --text-primary: #ffffff;
  --text-secondary: #e5e5e5;
  --text-muted: #bdbdbd;
  --text-inverse: #000000;

  --link: #7dd3fc;
  --link-visited: #e9d5ff;
  --link-hover: #bae6fd;

  --accent: #fb7185;
  --accent-strong: #f43f5e;
  --accent-soft: rgba(251, 113, 133, 0.22);
  --accent-gold: #fbbf24;
  --accent-emerald: #6ee7b7;

  --border: #525252;
  --border-subtle: #333333;
  --border-strong: #737373;
}

html[data-font="small"] { --fs-base: 13.5px; }
html[data-font="normal"] { --fs-base: 15px; }
html[data-font="large"] { --fs-base: 17px; }

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

html {
  scroll-behavior: smooth;
  font-size: var(--fs-base);
}

body {
  margin: 0;
  background-color: var(--bg-page);
  color: var(--text-primary);
  font-family: var(--font-sans);
  line-height: 1.62;
  -webkit-font-smoothing: antialiased;
}

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

a:hover {
  color: var(--link-hover);
  text-decoration: underline;
}

a:visited {
  color: var(--link-visited);
}

.btn, button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
}

button, .btn {
  cursor: pointer;
}

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

code {
  background: var(--bg-code);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.1em 0.36em;
  font-size: 0.88em;
}

kbd {
  background: var(--bg-subtle);
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: var(--radius-sm);
  padding: 0.08em 0.4em;
  font-size: 0.82em;
  color: var(--text-secondary);
}

pre {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.9rem 1rem;
  overflow-x: auto;
  font-size: 0.86rem;
  line-height: 1.5;
}

/* Skip to content */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 4px;
  z-index: 9999;
  padding: 0.5rem 0.9rem;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
}

.skip-link:focus {
  left: 8px;
}

/* Top Utility Ticker */
.utility-strip {
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.78rem;
  color: var(--text-secondary);
  padding: 0.28rem 1rem;
}

.utility-strip-inner {
  max-width: 1580px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem 1.25rem;
}

.utility-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: center;
}

.status-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-emerald);
  margin-right: 0.35rem;
}

/* Main Sticky Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.header-inner {
  max-width: 1580px;
  margin: 0 auto;
  padding: 0.55rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex-wrap: wrap;
}

.menu-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--text-primary);
}

.menu-toggle-btn:hover {
  background: var(--bg-hover);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  color: var(--text-primary) !important;
  text-decoration: none !important;
  flex-shrink: 0;
}

.brand-title {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand-name {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 1.18rem;
  letter-spacing: -0.01em;
}

.brand-name span {
  color: var(--accent);
}

.brand-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

/* Header Search */
.header-search {
  position: relative;
  flex: 1 1 280px;
  max-width: 480px;
}

.search-form {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  overflow: hidden;
}

.search-form:focus-within {
  border-color: var(--link);
  box-shadow: 0 0 0 2px rgba(11, 87, 208, 0.15);
}

.search-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  padding: 0.42rem 0.7rem;
  color: var(--text-primary);
  font-size: 0.9rem;
  outline: none;
}

.search-submit-btn {
  border: none;
  border-left: 1px solid var(--border);
  background: var(--bg-subtle);
  color: var(--text-primary);
  padding: 0 0.85rem;
  font-size: 0.84rem;
  font-weight: 600;
}

.search-submit-btn:hover {
  background: var(--bg-hover);
}

.search-results-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 250;
  max-height: 410px;
  overflow-y: auto;
  display: none;
}

.search-results-dropdown.open {
  display: block;
}

.search-result-item {
  display: block;
  padding: 0.6rem 0.85rem;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary) !important;
  text-decoration: none !important;
}

.search-result-item:hover {
  background: var(--bg-hover);
}

.search-result-title {
  font-weight: 600;
  font-size: 0.92rem;
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}

.search-result-cat {
  font-size: 0.72rem;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 0.08rem 0.4rem;
  border-radius: var(--radius-sm);
}

.search-result-desc {
  font-size: 0.79rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

/* Header Action Buttons */
.header-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
  margin-left: auto;
}

.ui-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.36rem 0.68rem;
  font-size: 0.82rem;
  font-weight: 500;
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  text-decoration: none !important;
  transition: background 0.12s ease, border-color 0.12s ease;
}

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

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

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

.ui-btn.active {
  background: var(--bg-active);
  border-color: var(--link);
  color: var(--link);
}

.ui-btn-sm {
  padding: 0.22rem 0.5rem;
  font-size: 0.76rem;
}

/* Primary Namespace Bar */
.namespace-bar {
  background: var(--bg-subtle);
  border-top: 1px solid var(--border-subtle);
  overflow-x: auto;
}

.namespace-bar-inner {
  max-width: 1580px;
  margin: 0 auto;
  padding: 0 1rem;
  display: flex;
  align-items: center;
  gap: 0.15rem;
  white-space: nowrap;
}

.ns-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.42rem 0.72rem;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary) !important;
  border-bottom: 2px solid transparent;
  text-decoration: none !important;
}

.ns-link:hover {
  color: var(--text-primary) !important;
  background: var(--bg-hover);
}

.ns-link.active {
  color: var(--accent) !important;
  border-bottom-color: var(--accent);
  font-weight: 600;
}

/* 3-Column Wiki Layout */
.wiki-shell {
  max-width: 1580px;
  margin: 0 auto;
  padding: 1rem;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr) 248px;
  gap: 1.15rem;
  align-items: start;
}

.wiki-shell.no-right-rail {
  grid-template-columns: 248px minmax(0, 1fr);
}

/* Left Sidebar */
.sidebar-left {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.85rem;
  position: sticky;
  top: calc(var(--header-h) + 46px);
  max-height: calc(100vh - 115px);
  overflow-y: auto;
  box-shadow: var(--shadow-sm);
}

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

.sidebar-group:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.sidebar-heading {
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 700;
  margin: 0 0 0.45rem 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sidebar-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.sidebar-list li {
  margin: 0.14rem 0;
}

.sidebar-list a {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.28rem 0.45rem;
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  color: var(--text-primary);
  text-decoration: none !important;
}

.sidebar-list a:hover {
  background: var(--bg-hover);
  color: var(--link);
}

.sidebar-list a.current {
  background: var(--bg-active);
  color: var(--link);
  font-weight: 600;
}

.count-pill {
  font-size: 0.72rem;
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 0.04rem 0.42rem;
}

.stats-mini-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}

.stat-chip {
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.45rem;
  font-size: 0.74rem;
}

.stat-chip strong {
  display: block;
  font-size: 0.92rem;
  color: var(--text-primary);
}

/* Main Content Card */
.content-surface {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.35rem 1.75rem 2rem;
  box-shadow: var(--shadow-sm);
  min-width: 0;
}

/* Breadcrumbs & Article Toolbar */
.breadcrumb-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.79rem;
  color: var(--text-muted);
  margin-bottom: 0.65rem;
}

.breadcrumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}

.rev-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.14rem 0.58rem;
  font-size: 0.74rem;
  color: var(--text-secondary);
}

.rev-badge.verified {
  border-color: rgba(4, 120, 87, 0.35);
  color: var(--accent-emerald);
}

.article-tabs-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-end;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
  gap: 0.5rem;
}

.wiki-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.wiki-tab {
  padding: 0.42rem 0.75rem;
  font-size: 0.83rem;
  font-weight: 500;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  color: var(--text-secondary) !important;
  background: transparent;
  text-decoration: none !important;
  margin-bottom: -1px;
}

.wiki-tab:hover {
  background: var(--bg-subtle);
}

.wiki-tab.active {
  background: var(--bg-surface);
  color: var(--text-primary) !important;
  border-color: var(--border);
  border-bottom-color: var(--bg-surface);
  font-weight: 600;
}

.article-tool-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding-bottom: 0.4rem;
}

/* Headings */
.article-title {
  font-family: var(--font-serif);
  font-size: 1.95rem;
  line-height: 1.22;
  margin: 0 0 0.25rem 0;
  padding-bottom: 0.45rem;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

.article-subtitle {
  font-size: 0.83rem;
  color: var(--text-muted);
  margin: 0 0 1rem 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1rem;
}

article h2, .section-h2 {
  font-family: var(--font-serif);
  font-size: 1.38rem;
  font-weight: 600;
  margin: 1.65rem 0 0.65rem 0;
  padding-bottom: 0.28rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

article h3 {
  font-size: 1.08rem;
  font-weight: 600;
  margin: 1.15rem 0 0.45rem 0;
  color: var(--text-primary);
}

.edit-sec-link {
  font-family: var(--font-sans);
  font-size: 0.74rem;
  font-weight: 500;
  color: var(--text-muted);
}

/* Callout / Hatnote Banners */
.hatnote {
  font-style: italic;
  font-size: 0.88rem;
  color: var(--text-secondary);
  padding: 0.35rem 0 0.35rem 1rem;
  border-left: 3px solid var(--border);
  margin: 0 0 0.9rem 0;
}

.notice-box {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.75rem 0.95rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  border-left-width: 4px;
  background: var(--bg-info);
  margin: 0.9rem 0 1.15rem;
  font-size: 0.88rem;
}

.notice-box.warn {
  background: var(--bg-warn);
  border-left-color: var(--accent-gold);
}

.notice-box.alert {
  background: var(--bg-banner);
  border-left-color: var(--accent);
}

.notice-box.info {
  border-left-color: var(--link);
}

/* Wikipedia-style Infobox */
.infobox {
  float: right;
  width: 318px;
  margin: 0.2rem 0 1.15rem 1.35rem;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.infobox-header {
  background: var(--accent);
  color: #ffffff;
  font-weight: 700;
  font-size: 0.95rem;
  text-align: center;
  padding: 0.55rem 0.7rem;
}

.infobox-sub {
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  text-align: center;
  font-size: 0.76rem;
  color: var(--text-muted);
  padding: 0.3rem 0.6rem;
}

.infobox-diagram {
  background: var(--bg-surface);
  padding: 0.65rem;
  border-bottom: 1px solid var(--border);
  text-align: center;
}

.infobox-caption {
  font-size: 0.74rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
}

.infobox-section-th {
  background: var(--bg-hover);
  color: var(--text-primary);
  font-weight: 700;
  text-align: left;
  padding: 0.34rem 0.6rem;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.infobox table {
  width: 100%;
  border-collapse: collapse;
}

.infobox th, .infobox td {
  padding: 0.36rem 0.6rem;
  vertical-align: top;
  border-bottom: 1px solid var(--border-subtle);
}

.infobox tbody th {
  width: 42%;
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
}

/* Data Tables */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  margin: 0.9rem 0 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.wiki-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
  background: var(--bg-surface);
}

.wiki-table th, .wiki-table td {
  padding: 0.52rem 0.7rem;
  border-bottom: 1px solid var(--border-subtle);
  border-right: 1px solid var(--border-subtle);
  text-align: left;
  vertical-align: top;
}

.wiki-table th:last-child, .wiki-table td:last-child {
  border-right: none;
}

.wiki-table thead th {
  background: var(--bg-subtle);
  font-weight: 600;
  color: var(--text-primary);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.wiki-table tbody tr:hover {
  background: var(--bg-hover);
}

.wiki-table th[data-sort] {
  cursor: pointer;
  user-select: none;
}

.wiki-table th[data-sort]::after {
  content: " ↕";
  font-size: 0.75em;
  color: var(--text-muted);
}

.wiki-table th[data-sort-dir="asc"]::after {
  content: " ↑";
  color: var(--accent);
}

.wiki-table th[data-sort-dir="desc"]::after {
  content: " ↓";
  color: var(--accent);
}

/* Right TOC & Inspector Rail */
.sidebar-right {
  position: sticky;
  top: calc(var(--header-h) + 46px);
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  max-height: calc(100vh - 115px);
  overflow-y: auto;
}

.rail-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.85rem;
  box-shadow: var(--shadow-sm);
  font-size: 0.82rem;
}

.rail-card h3 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 0 0 0.55rem 0;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--border-subtle);
}

.toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.toc-list li {
  margin: 0.16rem 0;
}

.toc-list a {
  display: block;
  padding: 0.2rem 0.4rem;
  border-left: 2px solid transparent;
  color: var(--text-secondary);
  text-decoration: none !important;
  font-size: 0.81rem;
}

.toc-list a:hover {
  color: var(--link);
  background: var(--bg-subtle);
}

.toc-list a.active {
  border-left-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.toc-sub {
  padding-left: 0.85rem;
}

/* Interactive Cards, Grids & Portal Widgets */
.portal-hero {
  background: linear-gradient(135deg, var(--bg-subtle) 0%, var(--bg-surface) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.25rem 1.35rem;
  margin-bottom: 1.25rem;
}

.portal-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin: 1rem 0;
}

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

.portal-grid-4 {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
  margin: 1rem 0;
}

.card-box {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.95rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.card-box.tinted {
  background: var(--bg-subtle);
}

.card-box h3, .card-box h4 {
  margin: 0;
  font-size: 0.98rem;
}

.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.12rem 0.46rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  color: var(--text-secondary);
}

.badge.red {
  background: var(--accent-soft);
  border-color: rgba(185, 28, 28, 0.35);
  color: var(--accent);
}

.badge.green {
  background: rgba(4, 120, 87, 0.12);
  border-color: rgba(4, 120, 87, 0.35);
  color: var(--accent-emerald);
}

.badge.gold {
  background: rgba(180, 83, 9, 0.12);
  border-color: rgba(180, 83, 9, 0.35);
  color: var(--accent-gold);
}

/* Interactive Tabs Component */
.tab-panel-group {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  margin: 1rem 0 1.25rem;
  overflow: hidden;
}

.tab-btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
  padding: 0.45rem 0.6rem 0;
}

.tab-btn {
  border: 1px solid transparent;
  border-bottom: none;
  background: transparent;
  color: var(--text-secondary);
  padding: 0.42rem 0.85rem;
  font-size: 0.84rem;
  font-weight: 600;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  margin-bottom: -1px;
}

.tab-btn:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.tab-btn.active {
  background: var(--bg-surface);
  color: var(--accent);
  border-color: var(--border);
  border-bottom-color: var(--bg-surface);
}

.tab-pane {
  display: none;
  padding: 1rem 1.15rem;
}

.tab-pane.active {
  display: block;
}

/* Accordions & Details */
details.wiki-accordion {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin: 0.55rem 0;
  background: var(--bg-surface);
}

details.wiki-accordion summary {
  padding: 0.62rem 0.9rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--bg-subtle);
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

details.wiki-accordion summary::after {
  content: "+";
  font-weight: 700;
  color: var(--text-muted);
}

details.wiki-accordion[open] summary::after {
  content: "−";
}

details.wiki-accordion .accordion-body {
  padding: 0.8rem 0.95rem;
  border-top: 1px solid var(--border-subtle);
}

/* Figures & Diagrams */
.diagram-figure {
  margin: 1.15rem 0;
  padding: 0.9rem;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.diagram-figure svg {
  width: 100%;
  height: auto;
  display: block;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
}

.diagram-figure figcaption {
  margin-top: 0.55rem;
  font-size: 0.81rem;
  color: var(--text-secondary);
}

/* Citations & References */
.cite-ref {
  font-size: 0.74em;
  vertical-align: super;
  margin-left: 1px;
}

.references-list {
  font-size: 0.84rem;
  color: var(--text-secondary);
  padding-left: 1.45rem;
  column-count: 2;
  column-gap: 2rem;
}

.references-list li {
  margin-bottom: 0.45rem;
  break-inside: avoid;
}

.references-list li:target {
  background: var(--bg-warn);
  padding: 0.15rem 0.35rem;
  border-radius: var(--radius-sm);
}

/* Category Pills Footer on Articles */
.catlinks-box {
  margin-top: 1.75rem;
  padding: 0.7rem 0.9rem;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
}

.cat-pill {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.15rem 0.62rem;
  font-size: 0.78rem;
  color: var(--link);
}

/* Interactive Form Controls / Calculators */
.form-row {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 0.75rem;
}

.form-row label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.form-input, .form-select, .form-textarea {
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 0.44rem 0.65rem;
  font-size: 0.88rem;
}

.filter-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0.75rem 0;
}

.filter-pill {
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 0.25rem 0.72rem;
  font-size: 0.8rem;
  font-weight: 500;
}

.filter-pill:hover {
  background: var(--bg-hover);
}

.filter-pill.active {
  background: var(--accent);
  border-color: var(--accent-strong);
  color: #ffffff;
}

/* Modal & Toast */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.56);
  z-index: 500;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-backdrop.open {
  display: flex;
}

.modal-dialog {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 680px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  padding: 0.85rem 1.15rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  margin: 0;
  font-size: 1.05rem;
}

.modal-body {
  padding: 1rem 1.15rem;
  overflow-y: auto;
  font-size: 0.9rem;
}

.modal-footer {
  padding: 0.75rem 1.15rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.toast-banner {
  position: fixed;
  bottom: 18px;
  right: 18px;
  z-index: 600;
  background: var(--text-primary);
  color: var(--text-inverse);
  padding: 0.65rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.84rem;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast-banner.show {
  opacity: 1;
  transform: translateY(0);
}

/* Footer */
.site-footer {
  margin-top: 2rem;
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
  padding: 1.75rem 1rem 2rem;
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.footer-inner {
  max-width: 1580px;
  margin: 0 auto;
}

.footer-cols {
  display: grid;
  grid-template-columns: 1.4fr repeat(3, 1fr);
  gap: 1.25rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
}

.footer-cols h4 {
  margin: 0 0 0.5rem 0;
  font-size: 0.85rem;
  color: var(--text-primary);
}

.footer-cols ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.footer-cols li {
  margin: 0.25rem 0;
}

.footer-bottom {
  padding-top: 1rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
}

/* Responsive Breakpoints */
@media (max-width: 1220px) {
  .wiki-shell {
    grid-template-columns: 224px minmax(0, 1fr);
  }
  .sidebar-right {
    display: none;
  }
}

@media (max-width: 920px) {
  .wiki-shell, .wiki-shell.no-right-rail {
    grid-template-columns: minmax(0, 1fr);
  }
  .sidebar-left {
    display: none;
    position: fixed;
    top: calc(var(--header-h) + 8px);
    left: 10px;
    right: 10px;
    z-index: 300;
    max-height: 75vh;
  }
  .sidebar-left.drawer-open {
    display: block;
  }
  .infobox {
    float: none;
    width: 100%;
    margin: 0 0 1.15rem 0;
  }
  .portal-grid-2, .portal-grid-3, .portal-grid-4, .footer-cols {
    grid-template-columns: 1fr;
  }
  .references-list {
    column-count: 1;
  }
}

@media print {
  .utility-strip, .site-header, .sidebar-left, .sidebar-right, .article-tool-btns, .modal-backdrop {
    display: none !important;
  }
  .wiki-shell {
    display: block;
    padding: 0;
  }
  .content-surface {
    border: none;
    box-shadow: none;
    padding: 0;
  }
}
