:root {
  /* Dark theme — navy-toned to complement digitalfire's clean aesthetic */
  --bg: #181c24;
  --bg-header: #1a1e28;
  --bg-card: #1f2330;
  --bg-hover: #272c3a;
  --bg-input: #14171f;
  --border: #2c3244;
  --border-focus: #4dabf7;
  --text: #e9ecef;
  --text-dim: #8d99ae;
  --text-muted: #55606e;
  --accent: #4dabf7;
  --accent-hover: #74c0fc;
  --accent-glow: rgba(77, 171, 247, 0.15);
  --material: #e8a838;
  --glossary: #4ecdc4;
  --article: #9b7cf7;
  --picture: #f77c7c;
  --recipe: #f7a84a;
  --hazard: #ff6b6b;
  --test: #6bcfff;
  --oxide: #a8e86b;
  --video: #ff8fd4;
  --trouble: #ffb347;
  --mineral: #88d8b0;
  --project: #b8b0ff;
  --schedule: #f9c74f;
  --temperature: #f94144;
  --property: #90be6d;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 2px 8px rgba(0,0,0,0.35);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);
  --mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* Light theme — matching digitalfire.com (Bootstrap 4 palette + #007bff) */
[data-theme="light"] {
  --bg: #ffffff;
  --bg-header: #f8f9fa;
  --bg-card: #ffffff;
  --bg-hover: #e9ecef;
  --bg-input: #ffffff;
  --border: #dee2e6;
  --border-focus: #007bff;
  --text: #212529;
  --text-dim: #495057;
  --text-muted: #6c757d;
  --accent: #007bff;
  --accent-hover: #0056b3;
  --accent-glow: rgba(0, 123, 255, 0.12);
  --material: #b05c08;
  --glossary: #0e7a75;
  --article: #5a3dbf;
  --picture: #b92020;
  --recipe: #b86e08;
  --hazard: #cc2020;
  --test: #0c7bc4;
  --oxide: #3d8f15;
  --video: #b83e8e;
  --trouble: #a86e15;
  --mineral: #1c8a56;
  --project: #5040c0;
  --schedule: #9c7a08;
  --temperature: #bf2020;
  --property: #2c6e2e;
  --shadow: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.10);
}

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

html { font-size: 15px; }

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Loading screen */
#loading-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: opacity 0.5s;
}
#loading-screen.hidden {
  opacity: 0;
  pointer-events: none;
}
.loading-title {
  font-size: 1.6rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  letter-spacing: 0.03em;
}
.loading-sub {
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-bottom: 2rem;
}
.loading-bar {
  width: 240px;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.loading-bar-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.3s ease;
}
.loading-status {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 1rem;
  font-family: var(--mono);
}

/* Header */
header {
  border-bottom: 1px solid var(--border);
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  position: sticky;
  top: 0;
  background: var(--bg-header, var(--bg));
  z-index: 100;
}
.logo {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
  color: var(--text);
}
.logo span {
  color: var(--accent);
}

/* Search */
.search-wrap {
  flex: 1;
  max-width: 640px;
  position: relative;
}
.search-wrap input {
  width: 100%;
  padding: 0.6rem 5.8rem 0.6rem 2.4rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.95rem;
  font-family: var(--sans);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.search-wrap input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.search-wrap input::placeholder {
  color: var(--text-muted);
}
.search-icon {
  position: absolute;
  left: 0.8rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 0.9rem;
  pointer-events: none;
}
/* Search mode toggle button */
.search-mode-btn {
  position: absolute;
  right: 0.45rem;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  font-size: 0.71rem;
  font-family: var(--mono);
  padding: 0.17rem 0.42rem;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
  line-height: 1.4;
}
.search-mode-btn:hover { color: var(--text); border-color: var(--text-dim); }
.search-mode-btn.mode-fuzzy { border-color: var(--trouble); color: var(--trouble); }
.search-mode-btn.mode-deep  { border-color: var(--accent);  color: var(--accent);  }
/* Explanation hint shown below search bar when a non-normal mode is active */
.search-mode-hint {
  position: absolute;
  top: calc(100% + 3px);
  left: 0;
  font-size: 0.71rem;
  color: var(--text-muted);
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
/* Deep mode: divider + related badge in result list */
.deep-divider {
  padding: 0.4rem 0.75rem;
  font-size: 0.71rem;
  font-family: var(--mono);
  color: var(--accent);
  border-top: 1px solid var(--border);
  border-bottom: 1px dashed var(--border);
  background: var(--accent-glow);
  letter-spacing: 0.03em;
}
.rc-related-badge {
  font-size: 0.63rem;
  font-family: var(--mono);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 3px;
  padding: 0 0.28rem;
  opacity: 0.7;
  margin-left: auto;
  flex-shrink: 0;
}

/* Stats */
.header-stats {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: var(--mono);
  white-space: nowrap;
}

/* Theme toggle */
.theme-toggle {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: all 0.15s;
  flex-shrink: 0;
}
.theme-toggle:hover {
  background: var(--bg-hover);
  color: var(--text);
  border-color: var(--accent);
}

/* Main layout */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem 2rem;
}

/* Category tabs */
.category-tabs {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.75rem;
}
.cat-tab {
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.8rem;
  cursor: pointer;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-dim);
  font-family: var(--sans);
  transition: all 0.15s;
  white-space: nowrap;
}
.cat-tab:hover {
  background: var(--bg-hover);
  color: var(--text);
}
.cat-tab.active {
  background: var(--accent-glow);
  border-color: var(--accent);
  color: var(--accent);
}
.cat-tab .cat-count {
  font-size: 0.7rem;
  opacity: 0.7;
  margin-left: 0.3rem;
}

/* Results list */
.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}
.results-count {
  font-size: 0.85rem;
  color: var(--text-dim);
}
.results-time {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: var(--mono);
}

.result-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 0.6rem;
  cursor: pointer;
  transition: all 0.15s;
}
.result-card:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
  box-shadow: var(--shadow);
}
.result-card .rc-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.3rem;
}
.result-card .rc-cat {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0.15rem 0.45rem;
  border-radius: 3px;
  font-weight: 600;
  white-space: nowrap;
}
.result-card .rc-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}
.result-card .rc-snippet {
  font-size: 0.85rem;
  color: var(--text-dim);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Category badge colors — solid dark bg, white text, works in both themes */
.rc-cat.material    { background: #8c5e06; color: #fff; }
.rc-cat.glossary    { background: #0d726e; color: #fff; }
.rc-cat.article     { background: #4d2fa0; color: #fff; }
.rc-cat.picture     { background: #9e1e1e; color: #fff; }
.rc-cat.recipe      { background: #9a6002; color: #fff; }
.rc-cat.hazard      { background: #a81414; color: #fff; }
.rc-cat.test        { background: #0d6daa; color: #fff; }
.rc-cat.oxide       { background: #3d820d; color: #fff; }
.rc-cat.video       { background: #8e2e72; color: #fff; }
.rc-cat.trouble     { background: #8a5200; color: #fff; }
.rc-cat.mineral     { background: #0d6e3d; color: #fff; }
.rc-cat.project     { background: #3d2ea0; color: #fff; }
.rc-cat.schedule    { background: #7a5e00; color: #fff; }
.rc-cat.temperature { background: #921010; color: #fff; }
.rc-cat.property    { background: #2c6e2e; color: #fff; }

/* Detail view (panel slides in from right) */
.detail-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: none;
  opacity: 0;
  transition: opacity 0.2s;
}
.detail-overlay.visible {
  display: block;
  opacity: 1;
}

.detail-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: min(720px, 85vw);
  height: 100vh;
  background: var(--bg);
  border-left: 1px solid var(--border);
  z-index: 201;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.detail-panel.open {
  transform: translateX(0);
}
.detail-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 1rem;
  position: sticky;
  top: 0;
  background: var(--bg-header, var(--bg));
  z-index: 1;
}
.detail-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: all 0.15s;
}
.detail-close:hover {
  background: var(--bg-hover);
  color: var(--text);
}
.detail-title {
  font-size: 1.2rem;
  font-weight: 600;
  flex: 1;
}
.detail-body {
  padding: 1.5rem;
  flex: 1;
}
.detail-section {
  margin-bottom: 1.5rem;
}
.detail-section h3 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--border);
}
.detail-section .body-text {
  font-size: 0.9rem;
  line-height: 1.7;
  color: var(--text-dim);
  word-wrap: break-word;
  max-height: 400px;
  overflow-y: auto;
}
.detail-section .body-text p {
  margin: 0 0 0.6em 0;
}
.detail-section .body-text .content-h2 {
  font-size: 1.1rem;
  color: var(--text);
  margin: 1.2em 0 0.4em 0;
  font-weight: 600;
}
.detail-section .body-text .content-h3 {
  font-size: 1rem;
  color: var(--text);
  margin: 1em 0 0.3em 0;
  font-weight: 600;
}
.detail-section .body-text h4, .detail-section .body-text h5 {
  font-size: 0.95rem;
  color: var(--text);
  margin: 0.8em 0 0.3em 0;
  font-weight: 600;
}
.detail-section .body-text hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1em 0;
}
.detail-section .body-text .content-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.5em 0;
  font-size: 0.85rem;
}
.detail-section .body-text .content-table th,
.detail-section .body-text .content-table td {
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--border);
  text-align: left;
}
.detail-section .body-text .content-table th {
  background: var(--bg-hover);
  color: var(--text);
  font-weight: 600;
}
.internal-link {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dotted var(--accent);
  cursor: pointer;
}
.internal-link:hover {
  color: var(--accent-hover);
  border-bottom-style: solid;
}
.ext-link {
  color: var(--text-dim);
  text-decoration: none;
  border-bottom: 1px dotted var(--text-muted);
  word-break: break-all;
}
.ext-link:hover {
  color: var(--accent);
}
.dead-link {
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.85em;
}
.detail-section .body-text.expanded {
  max-height: none;
}
.expand-btn {
  display: inline-block;
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--accent);
  cursor: pointer;
  border: none;
  background: none;
  font-family: var(--sans);
}
.expand-btn:hover {
  text-decoration: underline;
}

/* Oxide table */
.oxide-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  font-family: var(--mono);
}
.oxide-table th {
  text-align: left;
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.oxide-table td {
  padding: 0.3rem 0.6rem;
  border-bottom: 1px solid rgba(42,46,61,0.5);
  color: var(--text-dim);
}
.oxide-table tr:hover td {
  background: var(--bg-hover);
}
.oxide-bar {
  display: inline-block;
  height: 4px;
  background: var(--accent);
  border-radius: 2px;
  margin-left: 0.5rem;
  vertical-align: middle;
}

/* Related items */
.related-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.related-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-dim);
  transition: all 0.15s;
}
.related-item:hover {
  background: var(--bg-hover);
  color: var(--text);
}
.related-item .ri-cat {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  font-weight: 600;
}

/* Similar materials */
.similar-list {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.similar-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-dim);
  transition: all 0.15s;
}
.similar-item:hover {
  background: var(--bg-hover);
  color: var(--text);
}
.sim-score {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Oxide filter panel */
.filter-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem;
  margin-bottom: 1.5rem;
  display: none;
}
.filter-panel.visible { display: block; }
.filter-panel h3 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}
.filter-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}
.filter-row select, .filter-row input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  padding: 0.3rem 0.5rem;
  font-size: 0.85rem;
  font-family: var(--mono);
  outline: none;
}
.filter-row select:focus, .filter-row input:focus {
  border-color: var(--border-focus);
}
.filter-row input[type="number"] { width: 80px; }
.filter-btn {
  padding: 0.35rem 0.75rem;
  border-radius: 4px;
  border: 1px solid var(--accent);
  background: var(--accent-glow);
  color: var(--accent);
  font-size: 0.8rem;
  cursor: pointer;
  font-family: var(--sans);
  transition: all 0.15s;
}
.filter-btn:hover {
  background: var(--accent);
  color: white;
}

/* Home view */
#home-view {
  display: none;
}
#home-view.visible {
  display: block;
}
.home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.75rem;
  margin-top: 1rem;
}
.home-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
}
.home-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.home-card .hc-count {
  font-size: 1.8rem;
  font-weight: 700;
  font-family: var(--mono);
}
.home-card .hc-label {
  font-size: 0.8rem;
  color: var(--text-dim);
  text-transform: capitalize;
  margin-top: 0.2rem;
}

/* Recipe ingredients */
.ingredients-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.ingredients-table th {
  text-align: left;
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.75rem;
  text-transform: uppercase;
}
.ingredients-table td {
  padding: 0.3rem 0.6rem;
  border-bottom: 1px solid rgba(42,46,61,0.5);
}
.ingredients-table .pct-bar {
  display: inline-block;
  height: 4px;
  background: var(--recipe);
  border-radius: 2px;
  vertical-align: middle;
}

/* Alt names pills */
.alt-names {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}
.alt-pill {
  padding: 0.2rem 0.5rem;
  background: var(--bg-hover);
  border-radius: 4px;
  font-size: 0.8rem;
  color: var(--text-dim);
  border: 1px solid var(--border);
}

/* Image grid */
.img-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.5rem;
}
.img-grid-large {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}
.img-cell {
  display: block;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg-card);
  aspect-ratio: 1;
  transition: border-color 0.15s;
}
.img-cell:hover {
  border-color: var(--accent);
}
.img-cell img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.img-cell-large {
  display: block;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg-card);
  transition: border-color 0.15s;
}
.img-cell-large:hover {
  border-color: var(--accent);
}
.img-cell-large img {
  width: 100%;
  height: auto;
  max-height: 520px;
  object-fit: contain;
  display: block;
  background: var(--bg);
}
.img-caption {
  padding: 0.4rem 0.6rem;
  font-size: 0.8rem;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
  line-height: 1.4;
}

/* Image neighborhood — layered graph navigation */
.img-neighborhood { padding: 0; }
.img-neighborhood > .img-grid,
.img-neighborhood > .img-grid-large { margin-bottom: 0.75rem; }

.img-depth-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}
.img-depth-header > span {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}
.depth-selector {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}
.depth-label {
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-right: 0.2rem;
}
.depth-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-dim);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  padding: 0;
}
.depth-btn:hover { border-color: var(--accent); color: var(--accent); }
.depth-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Per-layer sections */
.img-layer {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}
.img-layer-label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-dim);
  margin-bottom: 0.6rem;
}
.img-layer-1 .img-layer-label { color: var(--accent); }
.img-layer-2 .img-layer-label { opacity: 0.8; }
.img-layer-3 .img-layer-label { opacity: 0.6; }

.img-neighbors { display: flex; flex-direction: column; gap: 0.75rem; }
.img-neighbor { }
.img-neighbor-title {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.4rem;
  flex-wrap: wrap;
}
.img-neighbor-title a {
  font-size: 0.8rem;
  color: var(--text);
  text-decoration: none;
  line-height: 1.3;
}
.img-neighbor-title a:hover { color: var(--accent); text-decoration: underline; }

/* Mini grid for related page thumbnails */
.img-grid-mini {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 0.35rem;
}
.img-layer-2 .img-grid-mini,
.img-layer-3 .img-grid-mini {
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  opacity: 0.85;
}

/* Responsive */
@media (max-width: 768px) {
  header { padding: 0.8rem 1rem; gap: 0.75rem; }
  .header-stats { display: none; }
  main { padding: 1rem; }
  .detail-panel { width: 100vw; }
  .home-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .filter-row { flex-direction: column; align-items: stretch; }
  html { font-size: 14px; }
}

/* Breadcrumb */
.breadcrumb {
  padding: 0.5rem 1.2rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.bc-link {
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
}
.bc-link:hover { text-decoration: underline; }
.bc-sep { color: var(--text-muted); }
.bc-current { color: var(--text-dim); }

/* Full content view */
#content-view {
  max-width: 860px;
  margin: 0 auto;
  padding: 1.5rem 1.2rem;
}
.cv-header {
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.cv-title {
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 0.3rem;
}
.cv-category {
  font-size: 0.85rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.cv-section {
  margin-bottom: 1.5rem;
}
.cv-section h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.cv-body {
  line-height: 1.7;
  font-size: 0.95rem;
}
.cv-body.expanded {
  max-height: none;
}
.cv-body:not(.expanded) {
  max-height: 600px;
  overflow: hidden;
  position: relative;
}
.cv-body:not(.expanded)::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 80px;
  background: linear-gradient(transparent, var(--bg));
}
.cv-toggle {
  margin-top: 0.5rem;
  padding: 0.3rem 0.8rem;
  font-size: 0.8rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--accent);
  cursor: pointer;
}
.cv-toggle:hover { background: var(--bg-hover); }

/* Image gallery in content view */
.cv-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  margin: 1rem 0;
}
.cv-gallery-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.2s;
}
.cv-gallery-item:hover { border-color: var(--accent); }
.cv-gallery-item img {
  width: 100%;
  display: block;
  cursor: zoom-in;
}
.cv-gallery-caption {
  padding: 0.4rem 0.6rem;
  font-size: 0.8rem;
  color: var(--text-dim);
  background: var(--bg-card);
}

/* Single hero image for picture pages */
.cv-hero-image {
  margin: 1rem 0;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.cv-hero-image img {
  max-width: 100%;
  max-height: 70vh;
  display: block;
  margin: 0 auto;
  cursor: zoom-in;
}

/* Oxide table in content view */
.cv-oxide-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.cv-oxide-table th,
.cv-oxide-table td {
  padding: 0.3rem 0.6rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.cv-oxide-table th {
  color: var(--text-dim);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.cv-bar {
  display: inline-block;
  height: 6px;
  background: var(--oxide);
  border-radius: 3px;
  min-width: 2px;
}

/* Related in content view */
.cv-related {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.cv-related-item {
  padding: 0.3rem 0.7rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 100px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: border-color 0.2s;
}
.cv-related-item:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
}

/* Alternative names pills */
.alt-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.alt-pill {
  padding: 0.2rem 0.6rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 100px;
  font-size: 0.85rem;
}

/* Properties table */
.cv-prop-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.cv-prop-table td {
  padding: 0.25rem 0.6rem;
  border-bottom: 1px solid var(--border);
}
.cv-prop-table td:first-child {
  color: var(--text-dim);
  width: 50%;
}

/* Ingredient table */
.cv-ing-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.cv-ing-table th,
.cv-ing-table td {
  padding: 0.3rem 0.6rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.cv-ing-table th {
  color: var(--text-dim);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* Lightbox */
#lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.9);
  z-index: 2000;
  justify-content: center;
  align-items: center;
  cursor: zoom-out;
}
#lightbox.visible { display: flex; }
#lightbox img {
  max-width: 95vw;
  max-height: 95vh;
  object-fit: contain;
}

/* Missing page */
.cv-missing {
  text-align: center;
  padding: 3rem;
  color: var(--text-muted);
}
.cv-missing h2 { margin-bottom: 0.5rem; }


/* =============================================
   CONTENT RENDERING IMPROVEMENTS
   ============================================= */

/* Content tables (pipe tables) */
.content-table th {
  background: var(--bg-card);
  color: var(--text-dim);
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.35rem 0.6rem;
  text-align: left;
  border-bottom: 2px solid var(--border);
}
.content-table td {
  padding: 0.3rem 0.6rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.content-table tr:last-child td { border-bottom: none; }

/* Internal links in body text */

/* Dead links (not in archive) */

/* External links */

/* Inline picture thumbnails */
.inline-pic-link {
  display: inline-block;
  margin: 0.5rem 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  transition: border-color 0.2s;
  max-width: 300px;
}
.inline-pic-link:hover {
  border-color: var(--accent);
}
.inline-thumb {
  display: block;
  width: 100%;
  height: auto;
}

/* Content headings */

/* Body text styling */

/* Home link in logo - match original site feel */
.logo {
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
}
.logo span {
  color: var(--accent);
}

/* Search input - match original site compact feel */
#search-input {
  font-size: 0.85rem;
  padding: 0.3rem 0.5rem;
}

/* Related content grid (image thumbnails) */
.related-card:hover {
  border-color: var(--accent);
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

/* CV gallery styles */

/* Hero image for picture pages */

/* Lightbox */
#lightbox {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.9);
  z-index: 9999;
  justify-content: center;
  align-items: center;
  cursor: zoom-out;
}
#lightbox.visible {
  display: flex;
}
#lightbox img {
  max-width: 95vw;
  max-height: 95vh;
  object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

/* Content page header */
.cv-category {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  font-weight: 600;
  margin-bottom: 0.25rem;
}

/* Content sections */

/* Oxide table */

/* Ingredient table */
.cv-ing-table td {
  padding: 0.25rem 0.5rem;
  border-bottom: 1px solid var(--border);
}

/* Related pills */

/* Content body */
.cv-body.expanded {
  max-height: none;
}

/* Content toggle button */

/* Missing page */
.cv-missing {
  text-align: center;
  padding: 3rem 1rem;
}
.cv-missing h2 {
  color: var(--text-dim);
  margin-bottom: 1rem;
}

/* Alternate names pills */

/* =============================================
   SIDEBAR NAVIGATION
   ============================================= */

/* Toggle button */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 0.55rem;
  left: 0.5rem;
  z-index: 100;
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 1.2rem;
  padding: 0.2rem 0.45rem;
  border-radius: 4px;
  cursor: pointer;
  line-height: 1;
}
.sidebar-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
}

@media (max-width: 768px) {
  .sidebar-toggle { display: block; }
  header .logo { margin-left: 2rem; }
}

/* Sidebar */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 240px;
  background: var(--bg);
  border-right: 1px solid var(--border);
  z-index: 200;
  overflow-y: auto;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
}
.sidebar.open {
  transform: translateX(0);
}

/* Sidebar overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.4);
  z-index: 199;
}
.sidebar-overlay.visible {
  display: block;
}

.sidebar-header {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.sidebar-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}
.sidebar-close:hover {
  color: var(--text);
}
.sidebar-logo {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  line-height: 1.2;
}
.sidebar-logo span {
  color: var(--accent);
}

.sidebar-section-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 1rem 1rem 0.35rem 1rem;
  font-weight: 600;
}

.sidenav-link {
  display: block;
  padding: 0.4rem 1rem;
  color: var(--text);
  text-decoration: none;
  font-size: 0.88rem;
  transition: background 0.15s, color 0.15s;
  border-left: 3px solid transparent;
}
.sidenav-link:hover {
  background: var(--bg-card);
  color: var(--accent);
  border-left-color: var(--accent);
}

.sidebar-footer {
  margin-top: auto;
  padding: 1rem;
  font-size: 0.7rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  line-height: 1.4;
}

/* Desktop: sidebar always visible */
@media (min-width: 769px) {
  body { padding-left: 240px; }
  .sidebar { transform: translateX(0); }
  .sidebar-overlay { display: none !important; }
  .sidebar-toggle { display: none !important; }
  header { padding-left: 1rem; }
}

/* =============================================
   BLOG FEED (Home page)
   ============================================= */

.blog-section {
  margin: 0 0 1.5rem;
}
.blog-section-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin: 0 0 0.75rem;
  color: var(--text);
  border-bottom: 2px solid var(--border);
  padding-bottom: 0.4rem;
}

.blog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.75rem;
}

.blog-card {
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  background: var(--bg-card);
  transition: border-color 0.2s, box-shadow 0.2s;
  display: flex;
  flex-direction: column;
}
.blog-card:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.blog-thumb-wrap {
  width: 100%;
  height: 160px;
  overflow: hidden;
  border-bottom: 1px solid var(--border);
}
.blog-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.blog-card-body {
  padding: 0.6rem;
  flex: 1;
  display: flex;
  flex-direction: column;
}
.blog-date {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}
.blog-card-title {
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.35;
  color: var(--text);
}
.blog-card:hover .blog-card-title {
  color: var(--accent);
}

/* =============================================
   HOME HERO
   ============================================= */

.home-hero {
  text-align: center;
  padding: 1.5rem 0 1rem;
}
.home-hero-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0 0 0.3rem;
}
.home-hero-sub {
  color: var(--text-dim);
  font-size: 0.95rem;
  max-width: 480px;
  margin: 0 auto;
  line-height: 1.5;
}
.home-hero-hint {
  color: var(--text-muted);
  font-size: 0.78rem;
  margin-top: 0.5rem;
}
.home-hero-hint kbd {
  background: var(--bg-card);
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  border: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 0.72rem;
}

/* Category grid below blog */
.home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.6rem;
  margin: 1rem 0;
}

.home-card {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem 0.5rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
}
.home-card:hover {
  border-color: var(--accent);
  background: var(--bg-card);
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.hc-count {
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1.1;
}
.hc-label {
  font-size: 0.78rem;
  margin-top: 0.25rem;
  color: var(--text-dim);
}

/* Monthly Tech-Tip signup section (matches original site feel) */
.tech-tip-section {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  margin: 1.5rem 0;
  padding: 1rem 1.25rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  border-left: 3px solid var(--accent);
}
.tech-tip-icon {
  font-size: 1.5rem;
  flex-shrink: 0;
  margin-top: 0.1rem;
}
.tech-tip-body {
  flex: 1;
}
.tech-tip-title {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 0.3rem;
  color: var(--text);
}
.tech-tip-text {
  font-size: 0.82rem;
  color: var(--text-dim);
  line-height: 1.5;
  margin-bottom: 0.4rem;
}
.tech-tip-links {
  margin-top: 0.2rem;
}
.tech-tip-link {
  display: inline-block;
  font-size: 0.8rem;
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dotted var(--accent);
  padding: 0.15rem 0;
}
.tech-tip-link:hover {
  border-bottom-style: solid;
}

/* Responsive sidebar adjustments on tablets */
@media (max-width: 1024px) and (min-width: 769px) {
  .sidebar { width: 200px; }
  body { padding-left: 200px; }
}

/* Ensure main content scrolls properly below header */
main {
  min-height: 60vh;
}

/* Fix for the header in light theme */
[data-theme="light"] header {
  border-bottom-color: rgba(0,0,0,0.08);
}

/* Site notice banner */
.site-notice {
  font-size: 0.8rem;
  color: var(--text-dim);
  padding: 0.6rem 1rem;
  margin-bottom: 0.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  line-height: 1.5;
  text-align: center;
}
.site-notice a {
  color: var(--accent);
  text-decoration: underline;
}
.site-notice a:hover {
  color: var(--accent-hover);
}

/* "View all" link below blog section */
.blog-view-all {
  display: inline-block;
  margin-top: 0.6rem;
  font-size: 0.85rem;
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dotted var(--accent);
}
.blog-view-all:hover {
  border-bottom-style: solid;
}

/* =============================================
   COMMON PROBLEMS QUICK LINKS (Home page)
   ============================================= */
.problems-section {
  margin: 0 0 1.5rem;
}
.problems-section-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin: 0 0 0.75rem;
  color: var(--text);
  border-bottom: 2px solid var(--border);
  padding-bottom: 0.4rem;
}
.problems-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 0.5rem;
}
.problem-card {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  background: var(--bg-card);
  transition: border-color 0.2s, background 0.2s;
  text-align: center;
}
.problem-card:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
}
.problem-label {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text);
  line-height: 1.3;
}
.problem-card:hover .problem-label {
  color: var(--accent);
}

/* =============================================
   RESULTS EMPTY STATE
   ============================================= */
.results-empty {
  text-align: center;
  padding: 3rem;
}
.results-empty-msg {
  color: var(--text-muted);
  font-size: 1rem;
  margin-bottom: 0.5rem;
}
.results-empty-hint {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-bottom: 0.75rem;
}
.results-empty-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
}

/* =============================================
   SCHEDULE TABLE (content view)
   ============================================= */
.cv-schedule-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.cv-schedule-table th {
  background: var(--bg-card-alt);
  font-weight: 600;
  text-align: left;
  padding: 0.4rem 0.5rem;
  border-bottom: 2px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1;
}
.cv-schedule-table td {
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.cv-schedule-table tr:hover td {
  background: var(--bg-hover);
}

/* =============================================
   IMAGE FAILED PLACEHOLDER
   ============================================= */
.img-failed {
  display: flex !important;
  align-items: center;
  justify-content: center;
  min-height: 60px;
  background: var(--bg-card-alt);
  border: 1px dashed var(--border);
  border-radius: 4px;
  font-size: 0.7rem;
  color: var(--text-dim);
  text-align: center;
  padding: 1rem 0.5rem;
  box-sizing: border-box;
}

/* =============================================
   KEYBOARD SHORTCUT HELP OVERLAY
   ============================================= */
.shortcut-help {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.6);
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
}
.shortcut-help.visible {
  display: flex;
}
.shortcut-help-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem 2rem;
  max-width: 360px;
  width: 90%;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}
.shortcut-help-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  color: var(--text);
}
.shortcut-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.35rem 0;
  font-size: 0.85rem;
  color: var(--text);
}
.shortcut-row + .shortcut-row {
  border-top: 1px solid var(--border);
}
.shortcut-key {
  display: inline-block;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1rem 0.5rem;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  min-width: 24px;
  text-align: center;
}
.shortcut-dismiss {
  margin-top: 1rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-dim);
}

/* =============================================
   RECENTLY UPDATED SECTION (home)
   ============================================= */
.recent-section {
  margin: 0 0 1.5rem;
}
.recent-section-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin: 0 0 0.75rem;
  color: var(--text);
  border-bottom: 2px solid var(--border);
  padding-bottom: 0.4rem;
}
.recent-list {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.home-section {
  margin: 2rem auto;
  max-width: 900px;
  padding: 0 1rem;
}
.home-section h3 {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.75rem;
}
.home-recent {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.5rem;
}
.recent-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0.5rem;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s;
  font-size: 0.85rem;
}
.recent-item:hover {
  background: var(--bg-hover);
}
.recent-item-cat {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  min-width: 60px;
}
.recent-item-title {
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
