:root {
  --bg: #f3efe6;
  --card: #fffdf8;
  --ink: #1a1916;
  --muted: #5c574e;
  --line: #ddd6c6;
  --accent: #1c4d3c;
  --accent-soft: #d7efe4;
  --warn: #7a3e00;
  --warn-soft: #ffe8c8;
  --bad: #8a1f11;
  --bad-soft: #fde8e6;
  --ok: #145c38;
  --ok-soft: #d8f3e8;
  --focus: #0b5fff;
  --shadow: 0 1px 0 rgba(26, 25, 22, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121411;
    --card: #1c1f1b;
    --ink: #f0eee6;
    --muted: #a8a49a;
    --line: #2e332c;
    --accent: #8fd6b5;
    --accent-soft: #1a3328;
    --warn: #f0c36a;
    --warn-soft: #3a2e12;
    --bad: #f0a090;
    --bad-soft: #3a1c18;
    --ok: #8fd6b5;
    --ok-soft: #1a3a2c;
    --focus: #7eb6ff;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html {
  font-size: 17px;
  overflow-x: clip;
  background: var(--bg);
  scroll-padding-top: 5.5rem;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  overflow-x: clip;
  max-width: 100%;
  overflow-wrap: break-word;
}

img, svg, video, canvas { max-width: 100%; height: auto; }

pre, textarea, code {
  max-width: 100%;
  overflow-x: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

a {
  color: var(--focus);
  overflow-wrap: anywhere;
}

button, input, textarea, select {
  font: inherit;
  color: inherit;
}

button, select, input:not([type="hidden"]):not([type="checkbox"]), textarea {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 12px;
  min-height: 44px;
  min-width: 44px;
  padding: 0.7rem 0.9rem;
  text-align: left;
  cursor: pointer;
  scroll-margin-top: 5.5rem;
}

input[type="number"],
input[type="search"],
input[type="text"],
textarea {
  width: 100%;
  cursor: text;
}

input[type="checkbox"] {
  appearance: auto;
  width: 22px;
  height: 22px;
  min-width: 22px;
  min-height: 22px;
  margin: 0.15rem 0 0;
  flex: 0 0 22px;
  accent-color: var(--accent);
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.sticky-bar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  max-width: 45rem;
  margin: 0 auto;
}

.progress {
  padding: 0;
  min-width: 0;
}

.progress-copy {
  display: flex;
  justify-content: space-between;
  gap: 0.4rem;
  font-size: 0.72rem;
  color: var(--muted);
}

.progress-kicker {
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.progress-track {
  height: 6px;
  margin-top: 0.2rem;
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
}

.sticky-tools {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto auto;
  gap: 0.35rem;
  align-items: center;
  padding: 0.35rem 0.75rem;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem;
}

#chapter-nav-toggle {
  white-space: nowrap;
  width: auto;
  min-width: 44px;
  padding: 0.55rem 0.8rem;
  text-align: center;
  overflow-wrap: normal;
}

.mini-radar { display: block; width: 36px; height: 36px; overflow: hidden; }
.mini-radar svg { width: 36px; height: 36px; }

.review-chip { min-width: 0; }

.review-chip button {
  min-height: 44px;
  padding: 0.35rem 0.6rem;
  text-align: center;
  white-space: nowrap;
}

.review-chip [data-testid="review-count"] {
  display: inline-block;
  margin-left: 0.25rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.search-wrap { min-width: 0; }
.search-wrap input { width: 100%; }

.search-results,
#chapter-nav {
  padding: 0.4rem 1rem 0.8rem;
  max-height: 70vh;
  overflow: auto;
  background: var(--bg);
}

.search-result,
.chapter-nav-link {
  display: flex;
  align-items: center;
  min-height: 44px;
  width: 100%;
  margin: 0.25rem 0;
  text-decoration: none;
  color: inherit;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.65rem 0.8rem;
}

.nav-group { margin: 0.7rem 0 0.3rem; color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; }

.hero, .app {
  max-width: 45rem;
  margin: 0 auto;
  padding: 1.1rem 1rem 0;
}

.hero { padding-top: 1.25rem; padding-bottom: 0.4rem; }

.kicker {
  margin: 0 0 0.35rem;
  font-size: 0.78rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

h1, h2, h3, h4 {
  line-height: 1.25;
  font-weight: 700;
  letter-spacing: -0.02em;
}

h1 { margin: 0 0 0.55rem; font-size: 1.85rem; }
h2 { margin: 0 0 0.45rem; font-size: 1.35rem; }
h3 { margin: 0 0 0.4rem; font-size: 1.08rem; }

.lede, .kid, .grown, .who, .detail p, .quiz p, .card p, .recap li {
  margin: 0 0 0.7rem;
}

.lede { font-size: 1.05rem; }

#start-btn, .primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 48px;
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
  font-weight: 650;
  text-align: center;
}

@media (prefers-color-scheme: dark) {
  #start-btn, .primary { color: #121411; }
}

.chapter, .widget {
  scroll-margin-top: 5.5rem;
}

.chapter {
  margin: 1.15rem 0 1.6rem;
  padding-bottom: 0.2rem;
}

.chapter-head, .card, .widget, .quiz, .x-post, .glossary-item, .recap, .template, .failure-card, .exam-box {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem;
  margin: 0.75rem 0;
  box-shadow: var(--shadow);
}

.badge {
  display: inline-block;
  margin: 0 0 0.45rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 650;
}

.stack { display: flex; flex-direction: column; gap: 0.55rem; }
.row { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.row > button, .row > a { flex: 1 1 calc(50% - 0.5rem); min-width: 44px; }
.row.presets > button { flex: 1 1 100%; text-align: center; }
.muted { color: var(--muted); }
.sources { margin: 0.2rem 0 0; color: var(--muted); font-size: 0.9rem; }
.hidden { display: none; }
[hidden] { display: none !important; }

.pipeline-step[aria-pressed="true"],
.board-option[aria-pressed="true"],
.bot-node[aria-pressed="true"],
.pr-scenario[aria-pressed="true"],
.x-filter[aria-pressed="true"],
.budget-model[aria-pressed="true"],
.level-step[data-complete]:not([data-complete="0"]) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.step-index {
  display: block;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.15rem;
}

.detail {
  margin-top: 0.65rem;
  padding: 0.85rem;
  border: 1px dashed var(--line);
  border-radius: 12px;
}

.pr-state { font-size: 1.15rem; font-weight: 700; margin: 0 0 0.35rem; }
[data-testid="pr-lab"] > .kid { margin-bottom: 0.4rem; }
[data-testid="pr-lab"] .chips { margin: 0.25rem 0 0.45rem; }
[data-testid="pr-lab"] .detail { margin-top: 0.4rem; padding: 0.65rem; }
[data-testid="pr-fix-option"] { line-height: 1.3; }

.quiz-feedback[data-state="correct"],
.pr-fix-feedback[data-state="correct"] {
  background: var(--ok-soft);
  color: var(--ok);
  border-radius: 10px;
  padding: 0.7rem 0.8rem;
}

.quiz-feedback[data-state="wrong"],
.pr-fix-feedback[data-state="wrong"] {
  background: var(--bad-soft);
  color: var(--bad);
  border-radius: 10px;
  padding: 0.7rem 0.8rem;
}

.check-row, .role-row, .gate-row {
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
  min-height: 44px;
  min-width: 44px;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--line);
}

.check-row:last-child, .role-row:last-child, .gate-row:last-child { border-bottom: 0; }

.check-why, .how { display: block; color: var(--muted); font-size: 0.92rem; margin-top: 0.15rem; }

.x-post blockquote {
  margin: 0 0 0.65rem;
  padding: 0 0 0 0.75rem;
  border-left: 3px solid var(--accent);
}

.glossary-filter, .field {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  padding: 0.65rem 0.8rem;
  margin: 0.4rem 0 0.75rem;
}

.org, .level-path { display: flex; flex-direction: column; gap: 0.45rem; }

.footnote { color: var(--muted); font-size: 0.9rem; margin: 1.5rem 0 2.2rem; }

.field-label { display: block; margin: 0.45rem 0 0.2rem; font-weight: 650; }
.stat { display: flex; justify-content: space-between; gap: 0.5rem; padding: 0.35rem 0; }
.stat strong { font-variant-numeric: tabular-nums; }

.compare { display: grid; gap: 0.6rem; }
.compare-col { border: 1px solid var(--line); border-radius: 12px; padding: 0.8rem; }
.problem { display: none; color: var(--bad); }
.compare-col.open .problem { display: block; }

.anatomy { display: grid; grid-template-columns: 1fr 1fr; gap: 0.45rem; }
.anatomy button { min-height: 56px; }

.table-wrap { max-width: 100%; overflow-x: auto; }
table { width: 100%; table-layout: fixed; border-collapse: collapse; font-size: 0.92rem; }
th, td { border-bottom: 1px solid var(--line); padding: 0.55rem 0.4rem; text-align: left; vertical-align: top; }

.recap { background: var(--accent-soft); }
.recap ol { margin: 0; padding-left: 1.2rem; }

.chapter-done[aria-pressed="true"] {
  background: var(--ok-soft);
  border-color: var(--ok);
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(18, 20, 17, 0.55);
  display: flex;
  align-items: flex-end;
  padding: 1rem;
}

.sheet-card {
  width: 100%;
  max-height: 85vh;
  overflow: auto;
  background: var(--card);
  border-radius: 16px 16px 12px 12px;
  padding: 1rem;
}

.meter-row { display: grid; grid-template-columns: 72px 1fr 48px; gap: 0.4rem; align-items: center; margin: 0.35rem 0; }
.meter-bar { height: 12px; background: var(--line); border-radius: 999px; overflow: hidden; }
.meter-fill { height: 100%; background: var(--accent); width: 0; }

.failure-row[data-caught="true"] { background: var(--ok-soft); }
.failure-row[data-caught="false"] { background: var(--bad-soft); }
.failure-row { border-radius: 10px; padding: 0.55rem 0.65rem; margin: 0.35rem 0; }

.timeline { display: flex; gap: 4px; margin: 0.5rem 0; }
.timeline i {
  flex: 1;
  height: 8px;
  border-radius: 99px;
  background: var(--line);
}
.timeline i.on { background: var(--accent); }

.template pre, .team-spec, #team-spec {
  background: var(--bg);
  border-radius: 10px;
  padding: 0.75rem;
  min-height: 160px;
  max-height: 280px;
  overflow: auto;
}

.phase { margin: 1rem 0 0.4rem; font-weight: 700; }

.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.5rem 0; }
.chips button { flex: 1 1 calc(50% - 0.4rem); text-align: center; }

[data-testid="pr-sim-next"][aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
}

.outcome-title { font-size: 1.25rem; margin: 0.4rem 0; }
.exam-score { font-size: 1.2rem; font-weight: 700; margin: 0 0 0.6rem; }

.status-dot {
  display: inline-block;
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 99px;
  background: var(--muted);
  margin-right: 0.35rem;
}
[data-status="success"] .status-dot, [data-status="merged"] .status-dot { background: var(--ok); }
[data-status="failure"] .status-dot { background: var(--bad); }
[data-status="neutral"] .status-dot { background: var(--warn); }
[data-status="blocked"] .status-dot { background: var(--bad); }

.cert {
  border: 2px solid var(--accent);
  border-radius: 12px;
  padding: 1rem;
  background: var(--card);
}

@media (min-width: 720px) {
  h1 { font-size: 2.1rem; }
  .hero, .app, .sticky-tools, .search-results, #chapter-nav { padding-left: 1.25rem; padding-right: 1.25rem; }
  .compare { grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: no-preference) {
  .progress-fill, .meter-fill { transition: width 180ms ease; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
