/**
 * chem_chapter.css
 * Guided Chapter Reader Styling & 4-Theme Accessible Chemistry Chips
 * Part of [OAW-Chem] platform styles (<= 220 lines)
 */

.chem-chapter-reader-pane {
  width: 100%; flex: 1; min-height: 0; height: 100%;
  overflow-y: auto; overflow-x: hidden; box-sizing: border-box;
  background: var(--bg-canvas); color: var(--ink-primary);
}
.chem-chapter-article {
  max-width: 780px; margin: 0 auto; padding: 20px 24px 64px;
  box-sizing: border-box;
}

/* Chapter Switcher Strip (Wrap >= 700px; Swipe <= 699px) */
.chem-chapter-switcher-strip {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  padding: 4px 0 12px; margin-bottom: 14px;
  border-bottom: 1px solid var(--border-grid);
}
.chem-chapter-switcher-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-elevated); border: 1px solid var(--border-grid);
  color: var(--ink-secondary); font-family: var(--font-sans);
  font-size: 11.5px; font-weight: 600; padding: 5px 10px;
  border-radius: 999px; cursor: pointer; transition: all 0.15s ease;
  white-space: nowrap;
}
.chem-chapter-switcher-btn .ch-idx {
  font-family: var(--font-mono); font-weight: 700; color: var(--accent-link);
}
.chem-chapter-switcher-btn:hover {
  border-color: var(--accent-link); color: var(--accent-link);
  background: var(--sig-bg);
}
.chem-chapter-switcher-btn.is-active {
  background: var(--sig-bg); border-color: var(--accent-link);
  color: var(--accent-link); font-weight: 700;
  box-shadow: inset 0 -2px 0 var(--accent-link);
}

.chem-chapter-header {
  margin-bottom: 22px; border-bottom: 1px solid var(--border-grid);
}
.chem-chapter-kicker {
  display: flex; align-items: center; gap: 10px; font-size: 11px;
  font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  margin-bottom: 8px;
}
.chem-chapter-badge {
  background: var(--sig-bg); color: var(--accent-link);
  border: 1px solid color-mix(in oklab, var(--accent-link) 35%, transparent);
  padding: 2px 8px; border-radius: 4px;
}
.chem-chapter-track { color: var(--ink-muted); }

.chem-chapter-title {
  font-family: var(--font-serif); font-size: 26px; font-weight: 700;
  line-height: 1.25; margin: 8px 0 16px; color: var(--ink-primary);
}

.chem-chapter-jump-nav {
  display: flex; flex-wrap: wrap; gap: 8px; padding-bottom: 16px;
}
.chem-jump-pill {
  background: var(--bg-elevated); border: 1px solid var(--border-grid);
  color: var(--ink-secondary); font-family: var(--font-sans);
  font-size: 12px; font-weight: 600; padding: 5px 12px;
  border-radius: 999px; cursor: pointer; transition: all 0.15s ease;
  text-align: left; max-width: 100%;
}
.chem-jump-pill:hover {
  border-color: var(--accent-link); color: var(--accent-link);
  background: var(--sig-bg);
}

.chem-chapter-h2 {
  font-family: var(--font-sans); font-size: 19px; font-weight: 700;
  margin: 32px 0 12px; padding-top: 14px;
  border-top: 1px solid var(--border-grid);
  color: var(--ink-primary); scroll-margin-top: 24px;
}
.chem-chapter-h3 {
  font-family: var(--font-sans); font-size: 15.5px; font-weight: 600;
  margin: 22px 0 8px; color: var(--ink-primary); scroll-margin-top: 24px;
}

.chem-chapter-p {
  font-family: var(--font-sans); font-size: 15px; line-height: 1.72;
  color: var(--ink-secondary); margin: 0 0 14px;
}
.chem-chapter-list {
  padding-left: 22px; margin: 0 0 16px; color: var(--ink-secondary);
  font-family: var(--font-sans); font-size: 14.5px; line-height: 1.68;
}
.chem-chapter-list li { margin-bottom: 7px; }
.chem-chapter-list li:last-child { margin-bottom: 0; }
.chem-chapter-article sub,
.chem-chapter-article sup {
  font-size: 0.74em; line-height: 0;
}

/* Callout Blocks (>) */
.chem-chapter-callout {
  border-left: 3px solid var(--accent-link); background: var(--sig-bg);
  border-radius: 0 6px 6px 0; padding: 11px 14px; margin: 16px 0;
  font-size: 13.5px; line-height: 1.62; color: var(--ink-primary);
}
.chem-chapter-callout p { margin: 0; }

/* Markdown Booktabs Tables */
.table-scroll-wrapper {
  width: 100%; max-width: 100%; overflow-x: auto; margin: 16px 0 20px;
  border: 1px solid var(--border-grid); border-radius: 6px;
  background: var(--bg-canvas);
}
.chem-chapter-table.booktabs {
  width: 100%; border-collapse: collapse; font-size: 13px; line-height: 1.48;
  background: var(--bg-canvas); text-align: left;
}
.chem-chapter-table.booktabs th {
  padding: 9px 11px; font-weight: 700; color: var(--ink-primary);
  border-bottom: 2px solid var(--border-grid); background: var(--bg-recessed);
  white-space: normal; font-family: var(--font-sans); vertical-align: bottom;
}
.chem-chapter-table.booktabs td {
  padding: 8px 11px; border-bottom: 1px solid var(--border-hairline);
  color: var(--ink-secondary); vertical-align: top;
  white-space: normal; overflow-wrap: break-word;
}
.chem-chapter-table.booktabs td code { white-space: nowrap; }
.chem-chapter-table.booktabs tbody tr:nth-child(even) {
  background: var(--bg-elevated);
}
.chem-chapter-table.booktabs tbody tr:hover {
  background: var(--sig-bg);
}

.chem-chapter-math-block {
  background: var(--bg-recessed); border: 1px solid var(--border-grid);
  border-radius: 6px; padding: 12px 16px; margin: 16px 0; max-width: 100%;
  overflow-x: auto; text-align: center; font-family: var(--font-mono);
  font-size: 13.5px; line-height: 1.55; color: var(--ink-primary);
}

/* Interactive Chips (WCAG AA >= 4.5:1 across all 4 themes) */
.chem-chapter-chip {
  display: inline-flex; align-items: center; gap: 4px; max-width: 100%;
  background: var(--tint-indigo-bg);
  border: 1px solid color-mix(in oklab, var(--trace-rf) 35%, transparent);
  color: var(--trace-rf); font-family: var(--font-sans); font-size: 12.5px;
  font-weight: 600; padding: 1px 8px; border-radius: 12px; cursor: pointer;
  vertical-align: middle; line-height: 1.4; white-space: nowrap;
  text-align: left; transition: transform 0.15s ease, background 0.15s ease;
}
.chem-chip-icon { display: inline-flex; align-items: center; flex-shrink: 0; }
.chem-chip-label { min-width: 0; overflow-wrap: break-word; }
.chem-chapter-chip:hover {
  background: color-mix(in oklab, var(--tint-indigo-bg) 70%, var(--trace-rf) 18%);
  transform: translateY(-1px);
}
.chem-chapter-chip.chem-chip-mol {
  background: var(--tint-violet-bg); white-space: normal;
  border-color: color-mix(in oklab, var(--trace-carrier) 35%, transparent);
  color: var(--trace-carrier);
}
.chem-chapter-chip.chem-chip-mol:hover { background: color-mix(in oklab, var(--tint-violet-bg) 70%, var(--trace-carrier) 18%); }
.chem-chapter-chip.chem-chip-prim {
  background: var(--tint-amber-bg); white-space: normal;
  border-color: color-mix(in oklab, var(--trace-demod) 35%, transparent);
  color: color-mix(in oklab, var(--trace-demod) 78%, var(--ink-primary));
}
.chem-chapter-chip.chem-chip-prim:hover { background: color-mix(in oklab, var(--tint-amber-bg) 70%, var(--trace-demod) 18%); }
.chem-chapter-chip.chem-chip-stoich {
  background: var(--bg-elevated); white-space: normal;
  border-color: var(--border-grid);
  color: var(--ink-secondary);
}
.chem-chapter-chip.chem-chip-stoich:hover { background: var(--sig-bg); border-color: var(--accent-link); color: var(--accent-link); }

.chem-inline-code {
  font-family: var(--font-mono); font-size: 0.88em; background: var(--bg-recessed);
  border: 1px solid var(--border-grid); padding: 1px 5px; border-radius: 3px; color: var(--ink-primary);
}
.chem-chapter-anchor-link { color: var(--accent-link); text-decoration: none; font-weight: 600; }
.chem-chapter-anchor-link:hover, .chem-chapter-ext-link:hover { text-decoration: underline; }
.chem-chapter-ext-link { color: var(--accent-link); text-decoration: none; display: inline-flex; align-items: center; gap: 3px; }
.chem-chapter-loading, .chem-chapter-error { text-align: center; padding: 50px 20px; color: var(--ink-secondary); }
.chem-chapter-retry-btn {
  margin-top: 10px; padding: 6px 14px; border: 1px solid var(--border-grid);
  background: var(--bg-elevated); color: var(--ink-primary);
  border-radius: var(--radius-ui, 8px); cursor: pointer; font-weight: 600;
}

/* Embedded ~~~chem-visual Interactive Makeup Galleries */
.chem-chapter-visual-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px; margin: 16px 0 22px; min-width: 0;
}
.chem-vis-card {
  display: flex; flex-direction: column; gap: 8px; min-width: 0;
  background: var(--bg-elevated); border: 1px solid var(--border-grid);
  border-radius: 12px; padding: 12px 14px; box-sizing: border-box;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
}
.chem-vis-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; min-width: 0;
}
.chem-vis-title-wrap { min-width: 0; flex: 1; }
.chem-vis-formula {
  font-family: var(--font-mono); font-size: 0.95rem; font-weight: 700; color: var(--accent-link);
}
.chem-vis-title { font-size: 0.84rem; font-weight: 700; color: var(--ink-primary); margin-top: 1px; }
.chem-vis-caption { font-size: 0.72rem; color: var(--ink-muted); margin-top: 2px; line-height: 1.35; }
.chem-vis-tree-btn {
  appearance: none; flex-shrink: 0; font-family: var(--font-sans); font-size: 0.68rem; font-weight: 700;
  padding: 4px 8px; border-radius: 6px; border: 1px solid var(--border-grid);
  background: var(--bg-canvas); color: var(--accent-link); cursor: pointer; white-space: nowrap;
}
.chem-vis-tree-btn:hover { background: var(--sig-bg); border-color: var(--accent-link); }
.chem-vis-svg-stage {
  display: flex; align-items: center; justify-content: center; width: 100%; min-height: 112px;
  background: var(--bg-canvas); border: 1px solid var(--border-hairline, var(--border-grid));
  border-radius: 8px; padding: 6px; box-sizing: border-box; overflow: hidden;
}
.chem-vis-svg-stage svg { max-width: 100%; max-height: 140px; height: auto; display: block; }
.chem-vis-stats-row {
  display: flex; flex-wrap: wrap; gap: 6px 10px; font-size: 0.70rem; color: var(--ink-secondary);
  padding: 4px 8px; background: var(--bg-recessed); border-radius: 6px;
}
.chem-vis-stats-row b { color: var(--ink-primary); font-weight: 700; }
.chem-vis-summary { font-size: 0.74rem; line-height: 1.48; color: var(--ink-secondary); margin: 0; }
.chem-vis-alloy-card { padding: 10px 12px; gap: 6px; }
.chem-vis-alloy-inner { position: relative; min-width: 0; padding: 2px 0; }
.chem-vis-alloy-card .chem-co-reactant-nubs {
  position: static; transform: none; justify-content: flex-start; margin-bottom: 6px; flex-wrap: wrap;
}
.chem-vis-alloy-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding-top: 6px; border-top: 1px dashed var(--border-grid); min-width: 0;
}

@media (max-width: 699px) {
  .chem-chapter-article { padding: 16px 14px 56px; }
  .chem-chapter-title { font-size: 22px; }
  .chem-chapter-visual-grid { grid-template-columns: 1fr; }
  .chem-chapter-switcher-strip {
    flex-wrap: nowrap; overflow-x: auto; scroll-snap-type: inline proximity;
    scrollbar-width: none; padding: 4px 0 10px;
  }
  .chem-chapter-switcher-btn { flex: none; scroll-snap-align: start; min-height: 36px; }
  @supports not (scrollbar-width: none) {
    .chem-chapter-switcher-strip { scrollbar-width: auto; }
    .chem-chapter-switcher-strip::-webkit-scrollbar { display: none; }
  }
}

@media (forced-colors: active) {
  .chem-chapter-switcher-btn.is-active { border: 2px solid Highlight; outline: 2px solid Highlight; }
  .chem-chapter-chip { border: 1px solid ButtonText; }
}

