/* CloudLab web — iOS-native path + ebook lessons */
:root {
  color-scheme: light dark;
  --bg: #f2f2f7;
  --bg-elevated: #ffffff;
  --bg-secondary: #e5e5ea;
  --text: #1c1c1e;
  --text-secondary: #3a3a3c;
  --text-tertiary: #8e8e93;
  --brand: #007aff;
  --brand-soft: rgba(0, 122, 255, 0.12);
  --on-brand: #ffffff;
  --danger: #ff3b30;
  --warn: #ff9500;
  --ok: #34c759;
  --line: rgba(60, 60, 67, 0.18);
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.08);
  --radius: 16px;
  --radius-sm: 10px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC",
    "Helvetica Neue", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --content: 38rem;
  --pad: 1.15rem;
  --icon: 40px;
  --path-line: 2px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg-elevated: #1c1c1e;
    --bg-secondary: #2c2c2e;
    --text: #f5f5f7;
    --text-secondary: #ebebf5;
    --text-tertiary: #8e8e93;
    --brand: #0a84ff;
    --brand-soft: rgba(10, 132, 255, 0.18);
    --line: rgba(84, 84, 88, 0.65);
    --shadow: 0 10px 32px rgba(0, 0, 0, 0.45);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  max-width: 100%;
}
body {
  margin: 0;
  max-width: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  overflow-wrap: anywhere;
  word-break: break-word;
}
img, svg, video, canvas, iframe {
  max-width: 100%;
  height: auto;
  display: block;
}
svg { overflow: visible; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre { font-family: var(--mono); font-size: 0.92em; }

.skip-link {
  position: absolute; left: -999px; top: 0;
  background: var(--brand); color: white; padding: 0.5rem 1rem; z-index: 99;
}
.skip-link:focus { left: 0.5rem; top: 0.5rem; }

/* Lesson top: minimal back only — not a web brand bar */
.nav-backbar {
  position: sticky; top: 0; z-index: 40;
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  border-bottom: 1px solid transparent;
}
.nav-backbar-inner {
  max-width: 52rem;
  width: 100%;
  margin: 0 auto;
  padding: 0.65rem var(--pad);
  display: flex; align-items: center; gap: 0.75rem;
  min-width: 0;
}
.back {
  color: var(--brand); font-size: 1.02rem; font-weight: 500;
  white-space: nowrap; flex: none;
}

.home, .lesson {
  max-width: 52rem;
  width: 100%;
  margin: 0 auto;
  padding: 0.5rem var(--pad) 3rem;
  min-width: 0;
}

/* iOS large title home */
.home-large-title {
  margin: 0.35rem 0 0.35rem;
  font-size: 2.125rem;
  line-height: 1.15;
  letter-spacing: -0.03em;
  font-weight: 700;
}
.home-lead {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin: 0 0 1.25rem;
  max-width: 100%;
}

/* Learning path — matches LearningPathMapView */
.path-rail {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  min-width: 0;
  padding-left: 0;
}
.path-rail::before {
  content: "";
  position: absolute;
  left: calc((var(--icon) - var(--path-line)) / 2);
  top: 0.5rem;
  bottom: 0.5rem;
  width: var(--path-line);
  background: color-mix(in srgb, var(--brand) 22%, var(--line));
  border-radius: 1px;
  pointer-events: none;
}
.stage { position: relative; width: 100%; min-width: 0; }
.stage-header {
  padding: 1.35rem 0 0.65rem;
  padding-left: calc(var(--icon) + 1rem);
  min-width: 0;
}
.stage-header h2 {
  margin: 0 0 0.25rem;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
  font-weight: 700;
  max-width: 100%;
}
.stage-summary {
  margin: 0;
  color: var(--text-tertiary);
  font-size: 0.88rem;
  max-width: 100%;
}
.path-nodes {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  width: 100%;
  min-width: 0;
}
.path-node { position: relative; width: 100%; min-width: 0; }
.node-link {
  display: flex;
  gap: 1rem;
  align-items: center;
  padding: 0.7rem 0.15rem 0.7rem 0;
  border-radius: 12px;
  color: inherit;
  text-decoration: none;
  width: 100%;
  min-width: 0;
  max-width: 100%;
}
.node-link:hover { text-decoration: none; background: transparent; }
.node-icon {
  width: var(--icon);
  height: var(--icon);
  border-radius: 999px;
  flex: none;
  display: grid;
  place-items: center;
  border: var(--path-line) solid var(--brand);
  background: var(--bg);
  color: var(--brand);
  position: relative;
  z-index: 1;
  box-shadow: 0 0 0 4px var(--bg);
}
.node-icon svg { width: 18px; height: 18px; }
.path-node.is-read .node-icon,
.path-node.is-current .node-icon {
  background: var(--brand);
  color: var(--on-brand);
}
.path-node.is-current .node-link {
  /* soft focus without widening layout */
}
.path-node.is-current .node-icon {
  box-shadow: 0 0 0 4px var(--brand-soft);
}
.node-meta {
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
  min-width: 0;
  flex: 1;
}
.node-code {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--brand);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}
.node-title {
  font-size: 1.02rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.35;
  max-width: 100%;
}
.node-chevron {
  flex: none;
  color: var(--text-tertiary);
  opacity: 0.85;
  width: 12px;
  height: 12px;
}

/* Lesson typography */
.lesson-hero { margin: 0.35rem 0 1.15rem; min-width: 0; }
.lesson-code {
  margin: 0; color: var(--brand); font-weight: 700; font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}
.lesson-hero h1 {
  margin: 0.2rem 0 0; font-size: 1.7rem; line-height: 1.25;
  letter-spacing: -0.025em; max-width: 100%;
}
.ebook {
  max-width: var(--content);
  width: 100%;
  font-size: 1.05rem;
  min-width: 0;
}
.ebook h2 {
  margin: 2rem 0 0.75rem; font-size: 1.28rem; letter-spacing: -0.02em;
  line-height: 1.35; max-width: 100%;
}
.ebook h3 { margin: 1.5rem 0 0.55rem; font-size: 1.1rem; }
.ebook h4 { margin: 1.2rem 0 0.45rem; font-size: 1.02rem; }
.ebook p, .ebook li, .ebook td, .ebook th { max-width: 100%; }
.ebook p { margin: 0.85rem 0; }
.ebook ul, .ebook ol { padding-left: 1.25rem; margin: 0.7rem 0; max-width: 100%; }
.ebook li { margin: 0.3rem 0; }
.ebook blockquote {
  margin: 1rem 0; padding: 0.55rem 0.9rem;
  border-left: 3px solid var(--brand);
  color: var(--text-secondary);
  background: var(--bg-elevated);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  max-width: 100%;
}
.ebook hr { border: 0; border-top: 1px solid var(--line); margin: 2rem 0; }
.ebook code {
  background: var(--bg-secondary); padding: 0.1em 0.35em;
  border-radius: 6px; overflow-wrap: anywhere;
}
.ebook pre.code {
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.9rem 1rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  line-height: 1.5;
  box-shadow: var(--shadow);
  max-width: 100%;
}
.ebook pre.code code {
  background: transparent;
  padding: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  max-width: 100%;
  display: block;
}

.figure-card {
  margin: 1.25rem 0;
  padding: 0.75rem;
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-width: 100%;
  min-width: 0;
}
.figure-card img {
  width: 100%;
  height: auto;
  border-radius: 10px;
  background: var(--bg-secondary);
}
.figure-card figcaption {
  margin-top: 0.55rem;
  font-size: 0.85rem;
  color: var(--text-tertiary);
  text-align: center;
  max-width: 100%;
}
.figure-card.missing { color: var(--danger); }

.callout {
  margin: 1.1rem 0;
  padding: 0.85rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  max-width: 100%;
  min-width: 0;
}
.callout-label {
  font-size: 0.75rem; font-weight: 700; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--brand); margin-bottom: 0.25rem;
}
.callout-body { max-width: 100%; }
.callout-key { border-color: color-mix(in srgb, var(--brand) 45%, var(--line)); background: var(--brand-soft); }
.callout-warn { border-color: color-mix(in srgb, var(--warn) 50%, var(--line)); }
.callout-warn .callout-label { color: var(--warn); }
.callout-tip .callout-label, .callout-plan .callout-label { color: var(--ok); }

button.glossary {
  appearance: none; border: 0; padding: 0;
  background: transparent; color: var(--brand);
  border-bottom: 1px dashed color-mix(in srgb, var(--brand) 55%, transparent);
  font: inherit; cursor: pointer;
}

.lesson-nav {
  display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem;
  margin: 2.5rem 0 1rem; max-width: var(--content); width: 100%;
}
.nav-btn {
  display: flex; flex-direction: column; gap: 0.2rem;
  padding: 0.9rem 1rem; border-radius: var(--radius-sm);
  background: var(--bg-elevated); border: 1px solid var(--line);
  color: inherit; text-decoration: none; min-height: 4.2rem;
  min-width: 0; max-width: 100%;
}
.nav-btn:hover { border-color: var(--brand); text-decoration: none; }
.nav-btn.disabled { visibility: hidden; }
.nav-btn[rel="next"] { text-align: right; align-items: flex-end; }
.nav-dir { font-size: 0.75rem; color: var(--text-tertiary); }
.nav-label { font-size: 0.92rem; font-weight: 600; max-width: 100%; }

.site-footer {
  max-width: 52rem; width: 100%; margin: 0 auto; padding: 1rem var(--pad) 2.5rem;
  color: var(--text-tertiary); font-size: 0.82rem;
}

/* Embeds */
.embed-host { margin: 1.25rem 0; min-height: 12rem; max-width: 100%; min-width: 0; }
.embed-card {
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.9rem;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  overflow-y: visible;
}
.embed-title {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  color: var(--brand); font-weight: 650; font-size: 0.98rem; margin-bottom: 0.75rem;
  min-width: 0;
}
.embed-title > span:first-child { min-width: 0; overflow-wrap: anywhere; }
.embed-count { color: var(--text-tertiary); font-weight: 500; font-size: 0.8rem; flex: none; }
.embed-canvas {
  min-height: 9rem; display: flex; flex-direction: column; justify-content: center;
  gap: 0.65rem; margin-bottom: 0.75rem; max-width: 100%; min-width: 0;
}
.embed-step-title { font-weight: 650; margin: 0; max-width: 100%; }
.embed-step-caption { margin: 0.2rem 0 0; color: var(--text-secondary); font-size: 0.9rem; max-width: 100%; }
.embed-controls {
  display: flex; gap: 0.55rem; align-items: center; margin-top: 0.75rem; flex-wrap: wrap;
}
.embed-controls button {
  appearance: none; border: 1px solid var(--line); background: var(--bg-secondary);
  color: var(--text); border-radius: 999px; padding: 0.45rem 0.85rem;
  font: inherit; font-size: 0.88rem; cursor: pointer;
}
.embed-controls button:hover { border-color: var(--brand); }
.embed-controls button:disabled { opacity: 0.4; cursor: default; }
.embed-dots { display: flex; gap: 6px; margin-left: auto; flex-wrap: wrap; }
.embed-dots button {
  width: 6px; height: 6px; padding: 0; border-radius: 999px; border: 0;
  background: var(--text-tertiary); cursor: pointer;
}
.embed-dots button.active { background: var(--brand); }
.embed-caption { color: var(--text-secondary); font-size: 0.88rem; margin: 0.35rem 0 0.75rem; max-width: 100%; }
.slider-row { margin: 0.55rem 0; max-width: 100%; }
.slider-row label {
  display: flex; justify-content: space-between; gap: 0.75rem;
  font-size: 0.9rem; margin-bottom: 0.25rem; min-width: 0;
}
.slider-row input[type="range"] { width: 100%; max-width: 100%; accent-color: var(--brand); }
.slider-readout {
  font-variant-numeric: tabular-nums; color: var(--text-secondary);
  font-size: 0.9rem; margin-top: 0.35rem; max-width: 100%;
}
.meter {
  height: 10px; border-radius: 999px; background: var(--bg-secondary); overflow: hidden; max-width: 100%;
}
.meter > span {
  display: block; height: 100%; width: 0%; background: var(--brand); border-radius: inherit;
  transition: width 0.25s ease;
}
.instance-row {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: flex-end; min-height: 3.2rem; max-width: 100%;
}
.instance-bar {
  width: 18px; border-radius: 4px; background: var(--brand);
  transition: height 0.25s ease, opacity 0.25s ease;
}
.diagram-stack, .diagram-zones, .diagram-rows, .diagram-flow, .diagram-board {
  display: flex; flex-direction: column; gap: 8px; width: 100%; max-width: 100%; min-width: 0;
}
.diagram-layer, .diagram-zone, .diagram-cell, .diagram-node-box, .diagram-bit {
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  background: var(--bg-secondary);
  border: 1px solid transparent;
  color: var(--text-tertiary);
  transition: background 0.35s ease, border-color 0.35s ease, color 0.35s ease, opacity 0.35s ease, transform 0.35s ease;
  max-width: 100%;
  min-width: 0;
  overflow-wrap: anywhere;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1.25;
  box-sizing: border-box;
}
.state-board {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1.25;
}
.diagram-layer.is-on, .diagram-zone.is-on, .diagram-cell.is-on, .diagram-node-box.is-on {
  background: var(--brand-soft);
  border-color: color-mix(in srgb, var(--brand) 55%, transparent);
  color: var(--brand);
  font-weight: 650;
}
.diagram-layer.is-dim, .diagram-zone.is-dim { opacity: 0.45; }
.diagram-layer.is-focus { transform: scale(1.02); }
.diagram-h {
  display: flex; gap: 8px; width: 100%; max-width: 100%; min-width: 0; align-items: stretch;
}
.diagram-h > * { flex: 1; min-width: 0; }
.diagram-bits {
  display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 4px; width: 100%;
}
.diagram-bit {
  text-align: center; padding: 0.35rem 0.15rem; border-radius: 6px;
  background: var(--bg-secondary); font-variant-numeric: tabular-nums;
  transition: background 0.35s ease, color 0.35s ease;
  min-width: 0;
}
.diagram-bit.is-on { background: var(--brand-soft); color: var(--brand); font-weight: 700; }
.diagram-bit .w { display: block; font-size: 0.7rem; color: var(--text-tertiary); }
.diagram-phase {
  display: grid; gap: 4px; width: 100%;
  grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
}
.diagram-phase span {
  text-align: center; font-size: 0.72rem; padding: 0.4rem 0.15rem; border-radius: 6px;
  background: var(--bg-secondary); color: var(--text-tertiary);
  transition: background 0.35s ease, color 0.35s ease;
  min-width: 0; overflow-wrap: anywhere;
}
.diagram-phase span.is-on { background: var(--brand-soft); color: var(--brand); font-weight: 650; }
.diagram-phase span.is-done { background: color-mix(in srgb, var(--brand) 12%, var(--bg-secondary)); color: var(--text-secondary); }
.region-frame {
  border: 2px solid var(--brand); border-radius: 12px; padding: 0.65rem;
  max-width: 100%; min-width: 0;
}
.region-frame .az-row { display: flex; gap: 8px; margin-top: 0.45rem; }
.region-frame .az {
  flex: 1; min-width: 0; min-height: 4.2rem; border-radius: 8px;
  display: grid; place-items: center; text-align: center; font-size: 0.82rem;
  background: var(--brand-soft); color: var(--brand);
  transition: opacity 0.35s ease, background 0.35s ease, color 0.35s ease;
  white-space: pre-line;
}
.region-frame .az.is-failed { background: rgba(255, 149, 0, 0.2); color: var(--warn); }
.region-frame .az.is-dim { opacity: 0.35; }
.failover-row {
  display: flex; align-items: center; justify-content: center; gap: 1rem;
  width: 100%; max-width: 100%;
}
.failover-node { display: flex; flex-direction: column; align-items: center; gap: 0.35rem; min-width: 0; }
.failover-orb {
  width: 54px; height: 54px; border-radius: 999px;
  display: grid; place-items: center; color: white; font-weight: 700;
  background: var(--bg-secondary); color: var(--text-secondary);
  transition: background 0.35s ease, color 0.35s ease;
}
.failover-orb.ok { background: var(--ok); color: white; }
.failover-orb.bad { background: var(--warn); color: white; }
.state-board {
  font-family: var(--mono); font-size: 0.92rem;
  padding: 0.85rem 0.9rem; border-radius: 12px;
  background: var(--bg-secondary); border: 1px solid var(--line);
  min-height: 3.2rem; max-width: 100%;
  transition: background 0.35s ease, border-color 0.35s ease;
}
.state-board.is-alert { border-color: var(--warn); color: var(--warn); }
.flow-steps {
  display: flex; flex-direction: column; gap: 6px; width: 100%; max-width: 100%;
}
.flow-step {
  display: flex; gap: 0.65rem; align-items: flex-start;
  padding: 0.45rem 0.55rem; border-radius: 10px;
  background: var(--bg-secondary); color: var(--text-tertiary);
  transition: background 0.35s ease, color 0.35s ease, opacity 0.35s ease, transform 0.35s ease;
  max-width: 100%; min-width: 0;
}
.flow-step .idx {
  flex: none; width: 1.35rem; height: 1.35rem; border-radius: 999px;
  display: grid; place-items: center; font-size: 0.72rem; font-weight: 700;
  background: var(--bg-elevated); color: var(--text-tertiary);
}
.flow-step.is-done { opacity: 0.75; color: var(--text-secondary); }
.flow-step.is-done .idx { background: color-mix(in srgb, var(--brand) 25%, var(--bg-elevated)); color: var(--brand); }
.flow-step.is-on {
  background: var(--brand-soft); color: var(--brand); font-weight: 650;
  transform: translateX(2px);
}
.flow-step.is-on .idx { background: var(--brand); color: white; }
.chart-rows { display: flex; flex-direction: column; gap: 0.55rem; max-width: 100%; }
.chart-row { display: grid; grid-template-columns: 3.2rem minmax(0, 1fr); gap: 0.55rem; align-items: center; min-width: 0; }
.chart-bar {
  display: flex; height: 1.1rem; border-radius: 6px; overflow: hidden; background: var(--bg-secondary); max-width: 100%;
}
.chart-bar .you { background: #bf5af2; height: 100%; }
.chart-bar .vendor { background: var(--brand); height: 100%; }
.latency-bars { display: flex; flex-direction: column; gap: 0.55rem; }
.latency-row { display: grid; grid-template-columns: 4.5rem minmax(0, 1fr) 3.2rem; gap: 0.45rem; align-items: center; font-size: 0.85rem; }
.latency-track { height: 0.85rem; border-radius: 6px; background: var(--bg-secondary); overflow: hidden; }
.latency-track > span { display: block; height: 100%; background: var(--brand); border-radius: inherit; transition: width 0.35s ease; }
.embed-placeholder-error { color: var(--danger); padding: 1rem; }

#glossary-dialog {
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0; background: var(--bg-elevated); color: var(--text);
  box-shadow: var(--shadow); max-width: 22rem; width: calc(100% - 2rem);
}
#glossary-dialog form { padding: 1.1rem 1.2rem 1rem; }
#glossary-dialog h2 { margin: 0 0 0.4rem; font-size: 1.05rem; }
#glossary-dialog p { margin: 0 0 1rem; color: var(--text-secondary); }
#glossary-dialog button {
  appearance: none; border: 0; background: var(--brand); color: white;
  border-radius: 999px; padding: 0.5rem 1rem; font: inherit; cursor: pointer;
}

@media (max-width: 480px) {
  .home-large-title { font-size: 1.85rem; }
  .lesson-hero h1 { font-size: 1.45rem; }
  .ebook { font-size: 1.02rem; }
  .lesson-nav { grid-template-columns: 1fr; }
  .nav-btn[rel="next"] { text-align: left; align-items: flex-start; }
  :root { --pad: 1rem; }
}

/* Faithful Swift Text(line) canvas */
.canvas-lines {
  display: flex; flex-direction: column; gap: 0.45rem;
  width: 100%; max-width: 100%; min-width: 0;
  min-height: 5.5rem; justify-content: center;
}
.canvas-line {
  font-family: var(--mono);
  font-size: 0.98rem;
  font-variant-numeric: tabular-nums;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  background: var(--bg-secondary);
  color: var(--text);
  display: flex; align-items: center; justify-content: flex-start;
  text-align: left;
  line-height: 1.35;
  max-width: 100%;
  overflow-wrap: anywhere;
  transition: background 0.35s ease, color 0.35s ease, opacity 0.35s ease, transform 0.35s ease;
}
.canvas-line.is-on {
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 650;
}
.canvas-footnote {
  font-size: 0.82rem;
  color: var(--text-tertiary);
  max-width: 100%;
  overflow-wrap: anywhere;
  padding: 0 0.15rem;
}
.cost-option {
  display: flex; gap: 0.65rem; align-items: flex-start;
  padding: 0.45rem 0.55rem; border-radius: 10px;
  max-width: 100%; min-width: 0;
  transition: background 0.25s ease;
}
.cost-option.is-pass { background: color-mix(in srgb, var(--ok) 12%, var(--bg-secondary)); }
.cost-option.is-fail { background: color-mix(in srgb, var(--warn) 14%, var(--bg-secondary)); }
.cost-option .name { flex: none; width: 5.2rem; font-weight: 650; font-size: 0.9rem; }
.cost-option .meta { min-width: 0; font-size: 0.82rem; font-family: var(--mono); }
.cost-option .verdict { font-size: 0.82rem; margin-top: 0.15rem; }

/* 0.6 reading and training controls. Keep intrinsic widths inside the viewport. */
:root { --reading-size: 18px; --brand: #0a59f7; }
:root[data-font="small"] { --reading-size: 16px; }
:root[data-font="large"] { --reading-size: 21px; }
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f2f2f7; --bg-elevated: #fff; --bg-secondary: #e5e5ea;
  --text: #1c1c1e; --text-secondary: #3a3a3c; --text-tertiary: #636366;
  --brand: #0a59f7; --brand-soft: rgba(10,89,247,.12);
  --line: rgba(60,60,67,.18); --shadow: 0 8px 28px rgba(0,0,0,.08);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #000; --bg-elevated: #1c1c1e; --bg-secondary: #2c2c2e;
  --text: #f5f5f7; --text-secondary: #ebebf5; --text-tertiary: #a1a1a6;
  --brand: #317af7; --brand-soft: rgba(49,122,247,.18);
  --line: rgba(84,84,88,.65); --shadow: 0 10px 32px rgba(0,0,0,.45);
}
.ebook { font-size: var(--reading-size); line-height: 1.8; }
.ebook h2 { font-size: 1.4em; margin: 2.3em 0 .8em; line-height: 1.4; }
.ebook h3 { font-size: 1.18em; margin: 1.8em 0 .65em; line-height: 1.5; }
.ebook h4 { font-size: 1.05em; }
.ebook [id] { scroll-margin-top: 5rem; }
.ebook pre.code code { white-space: pre; overflow-wrap: normal; word-break: normal; width: max-content; max-width: none; }
.ebook pre.code { box-shadow: none; }
.callout { border-left: 4px solid var(--brand); }
.callout-warn { border-left-color: var(--warn); }
.callout-tip { border-left-color: var(--ok); }
.figure-card figcaption { line-height: 1.6; color: var(--text-secondary); }
.table-scroll { width: 100%; max-width: 100%; overflow-x: auto; margin: 1.4rem 0; border: 1px solid var(--line); border-radius: var(--radius-sm); }
table { border-collapse: collapse; min-width: 100%; font-size: .92em; }
th, td { text-align: left; padding: .65rem .8rem; border-bottom: 1px solid var(--line); min-width: 7rem; }
th { background: var(--bg-secondary); }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; margin: 1rem 0; max-width: 100%; }
button, .button { font: inherit; cursor: pointer; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .5rem .8rem; color: var(--brand); background: var(--bg-elevated); max-width: 100%; }
button:disabled { opacity: .5; cursor: default; }
.primary { background: var(--brand); color: var(--on-brand); display: inline-block; }
.panel { padding: 1rem; margin: 1.25rem 0; border: 1px solid var(--line); background: var(--bg-elevated); border-radius: var(--radius); min-width: 0; max-width: 100%; }
.panel h2, .panel h3 { line-height: 1.4; }
.panel h2 { font-size: 1.2rem; }
.panel > :first-child { margin-top: 0; }
summary { color: var(--brand); cursor: pointer; }
details > nav a { display: block; margin-top: .65rem; }
.toc-sub { padding-left: 1rem; }
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), select, textarea {
  display: block; width: 100%; min-width: 0; max-width: 100%; font: inherit; color: var(--text);
  background: var(--bg-elevated); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .65rem; margin: .4rem 0 1rem;
}
textarea { min-height: 7rem; resize: vertical; }
label { max-width: 100%; }
input[type="checkbox"], input[type="radio"] { flex: none; width: 1.15rem; height: 1.15rem; margin: .25rem .4rem 0 0; accent-color: var(--brand); }
.check-row { display: flex; align-items: flex-start; gap: .35rem; }
.option { padding: .8rem .4rem; border-bottom: 1px solid var(--line); }
fieldset { border: 0; padding: 0; margin: 0 0 1rem; min-width: 0; width: 100%; }
legend { font-weight: 600; white-space: pre-wrap; padding: 0; max-width: 100%; }
.flash-face { display: block; width: 100%; min-height: 13rem; padding: 1.4rem; text-align: left; color: var(--text); font-size: 1.12rem; }
.preserve { white-space: pre-wrap; }
.link-list { list-style: none; padding: 0; }
.link-list li { padding: .65rem 0; border-bottom: 1px solid var(--line); }
.link-list p { margin: .25rem 0; }
.muted, .stage-progress { color: var(--text-secondary); font-size: .88rem; }
.stage-progress { margin: .2rem 0; color: var(--brand); font-variant-numeric: tabular-nums; }
.bookmarked { border-left: 3px solid var(--brand); padding-left: .65rem; }
.highlighted { background: color-mix(in srgb, var(--warn) 22%, transparent); border-radius: 4px; }
.selected-part { outline: 1px dashed var(--brand); outline-offset: 3px; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 3px; }
@media (max-width: 480px) { :root { --pad: 1rem; } }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } *, *::before, *::after { transition: none !important; } }
