:root {
  --bg: #f7fbfa;
  --surface: #ffffff;
  --surface-soft: #eef8f5;
  --text: #0b211b;
  --muted: #59756d;
  --border: #d9e9e4;
  --brand: #0b8b7d;
  --brand-2: #19b8a4;
  --blue: #3f9fff;
  --blue-bg: #eaf5ff;
  --violet: #9a62e8;
  --violet-bg: #f4edff;
  --orange: #ef6f2f;
  --orange-bg: #fff1e9;
  --yellow: #d7aa20;
  --yellow-bg: #fff8da;
  --green: #20ad68;
  --green-bg: #e7f8ef;
  --shadow: rgba(13, 50, 40, .11);
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body[data-theme="dark"] {
  --bg: #081512;
  --surface: #10221d;
  --surface-soft: #153129;
  --text: #eef8f5;
  --muted: #8fb0a6;
  --border: #263d36;
  --brand: #35d1bd;
  --brand-2: #18ad9b;
  --blue-bg: #13283b;
  --violet-bg: #271e36;
  --orange-bg: #342117;
  --yellow-bg: #302a14;
  --green-bg: #153326;
  --shadow: rgba(0, 0, 0, .34);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; }
body { overflow: hidden; background: var(--bg); color: var(--text); transition: background .25s ease, color .25s ease; }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 38%, transparent); outline-offset: 3px; }

.ambient { position: fixed; pointer-events: none; border-radius: 50%; filter: blur(4px); }
.ambient-a { width: 44vw; height: 44vw; right: -22vw; top: -28vw; background: radial-gradient(circle, color-mix(in srgb, var(--brand) 17%, transparent), transparent 70%); }
.ambient-b { width: 34vw; height: 34vw; left: -20vw; bottom: -22vw; background: radial-gradient(circle, color-mix(in srgb, var(--blue) 12%, transparent), transparent 72%); }

.topbar { position: fixed; inset: 0 0 auto; z-index: 30; height: 72px; padding: 0 clamp(22px, 4vw, 62px); display: grid; grid-template-columns: 178px 1fr 112px; align-items: center; gap: 22px; border-bottom: 1px solid color-mix(in srgb, var(--border) 82%, transparent); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(18px); }
.brand { display: inline-flex; align-items: center; gap: 9px; color: var(--text); text-decoration: none; font-weight: 800; letter-spacing: -.02em; }
.brand img { width: 31px; height: 31px; object-fit: contain; }
.chapter-tabs { justify-self: center; display: inline-grid; grid-template-columns: repeat(3, auto); gap: 6px; padding: 5px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); }
.chapter-tab { padding: 8px 13px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); cursor: pointer; font-size: .82rem; font-weight: 720; }
.chapter-tab span { color: var(--brand); margin-right: 5px; }
.chapter-tab.active { background: var(--surface-soft); color: var(--text); box-shadow: 0 2px 8px var(--shadow); }
.top-actions { justify-self: end; display: flex; gap: 7px; }
.icon-button { width: 42px; height: 42px; border: 1px solid var(--border); border-radius: 13px; background: var(--surface); color: var(--text); cursor: pointer; font-size: 1.15rem; }
.icon-button:hover { color: var(--brand); border-color: var(--brand); transform: translateY(-1px); }

.deck { position: fixed; inset: 72px 0 72px; }
.chapter { position: absolute; inset: 0; padding: clamp(28px, 4.5vh, 56px) clamp(28px, 5vw, 76px); overflow: auto; opacity: 0; visibility: hidden; transform: translateX(34px); transition: opacity .34s ease, transform .42s cubic-bezier(.2,.8,.2,1), visibility 0s .42s; }
.chapter.active { opacity: 1; visibility: visible; transform: translateX(0); transition-delay: 0s; }
.chapter.exiting { transform: translateX(-34px); }
.eyebrow { color: var(--brand); font-size: .76rem; font-weight: 850; letter-spacing: .14em; }

.intro-layout { min-height: 100%; display: grid; grid-template-columns: minmax(0, .98fr) minmax(500px, 1.02fr); align-items: center; gap: clamp(42px, 7vw, 110px); }
.kicker { margin: 30px 0 15px; color: var(--brand); font-size: clamp(1rem, 1.35vw, 1.25rem); font-weight: 760; }
h1 { margin: 0; max-width: 850px; font-size: clamp(3rem, 5.8vw, 6.2rem); line-height: .94; letter-spacing: -.072em; }
h1 em { color: var(--brand); font-style: normal; }
.lead { max-width: 760px; margin: 27px 0; color: var(--muted); font-size: clamp(1.05rem, 1.45vw, 1.28rem); line-height: 1.6; }
.creator-callout { max-width: 700px; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px; padding: 15px 17px; border: 1px solid var(--border); border-radius: 18px; background: var(--surface); box-shadow: 0 16px 38px var(--shadow); }
.creator-callout .spark { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 13px; background: var(--surface-soft); color: var(--brand); font-size: 1.35rem; }
.creator-callout small, .creator-callout strong { display: block; }
.creator-callout small { color: var(--muted); font-size: .76rem; margin-bottom: 3px; }
.creator-callout code { color: var(--brand); }
.creator-callout a { color: var(--brand); font-size: .84rem; text-underline-offset: 4px; }

.concept-lab { padding: 18px; border: 1px solid var(--border); border-radius: 30px; background: color-mix(in srgb, var(--surface) 92%, transparent); box-shadow: 0 30px 80px var(--shadow); }
.concept-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 5px; border-radius: 14px; background: var(--surface-soft); }
.concept-switch button { padding: 10px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-weight: 780; cursor: pointer; }
.concept-switch button.active { background: var(--surface); color: var(--brand); box-shadow: 0 5px 15px var(--shadow); }
.concept-card { min-height: 350px; padding: clamp(25px, 3vw, 42px); }
.concept-icon { width: 54px; height: 54px; display: grid; place-items: center; border-radius: 17px; background: var(--surface-soft); color: var(--brand); font-size: 1.7rem; }
.concept-card h2 { margin: 24px 0 10px; font-size: clamp(2rem, 3vw, 3rem); letter-spacing: -.05em; }
.concept-card > p { color: var(--muted); font-size: 1.04rem; line-height: 1.65; }
.concept-points { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; margin-top: 27px; }
.concept-points div { min-height: 96px; padding: 14px; border: 1px solid var(--border); border-radius: 15px; background: var(--surface-soft); }
.concept-points span { display: block; color: var(--brand); font-size: .72rem; font-weight: 850; margin-bottom: 9px; }
.concept-points strong { font-size: .9rem; line-height: 1.35; }
.equation { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; padding: 16px; border-top: 1px solid var(--border); color: var(--muted); font-size: .8rem; }
.equation span, .equation strong { padding: 6px 9px; border-radius: 8px; background: var(--surface-soft); }
.equation b { color: var(--brand); }
.equation strong { background: var(--brand); color: #fff; }

.section-head { display: flex; align-items: end; justify-content: space-between; gap: 28px; margin-bottom: 14px; }
.section-head.compact { margin-bottom: 12px; }
.section-head h2 { margin: 6px 0 5px; font-size: clamp(2rem, 3.45vw, 3.65rem); line-height: 1; letter-spacing: -.06em; }
.section-head p { margin: 0; color: var(--muted); font-size: 1rem; }
.primary-button { display: inline-flex; align-items: center; gap: 9px; white-space: nowrap; padding: 12px 17px; border: 0; border-radius: 13px; background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; font-weight: 800; cursor: pointer; box-shadow: 0 14px 30px color-mix(in srgb, var(--brand) 20%, transparent); }
.primary-button:hover { transform: translateY(-2px); }
.primary-button:disabled { opacity: .64; cursor: wait; transform: none; }

.diagram-shell { display: grid; grid-template-columns: minmax(650px, 1.6fr) minmax(280px, .65fr); gap: clamp(20px, 3vw, 44px); align-items: stretch; margin-top: 18px; }
.flowchart { position: relative; display: flex; flex-direction: column; align-items: center; min-height: 452px; padding: 2px 24px 8px; }
.flow-node { position: relative; z-index: 2; min-width: 250px; padding: 8px 16px; border: 2px solid currentColor; background: var(--surface); color: var(--text); cursor: pointer; text-align: center; box-shadow: 0 10px 22px transparent; transition: .25s ease; }
.flow-node small { display: block; color: currentColor; font-size: .64rem; font-weight: 900; letter-spacing: .09em; margin-bottom: 3px; }
.flow-node strong, .flow-node span { display: block; }
.flow-node strong { font-size: .9rem; }
.flow-node span { margin-top: 2px; color: var(--muted); font-size: .7rem; }
.flow-node.pill { border-radius: 999px; }
.flow-node.violet, .flow-node.yellow, .flow-node.double { border-radius: 4px; }
.flow-node.orange { border-radius: 3px; }
.flow-node.blue { border-color: var(--blue); background: var(--blue-bg); }
.flow-node.violet { border-color: var(--violet); background: var(--violet-bg); }
.flow-node.orange { border-color: var(--orange); background: var(--orange-bg); }
.flow-node.yellow { border-color: var(--yellow); background: var(--yellow-bg); }
.flow-node.green { border-color: var(--green); background: var(--green-bg); }
.flow-node.double { border-color: var(--blue); background: var(--blue-bg); box-shadow: inset 6px 0 0 var(--blue-bg), inset 8px 0 0 var(--blue), inset -6px 0 0 var(--blue-bg), inset -8px 0 0 var(--blue); }
.flow-node:hover, .flow-node.active { transform: translateY(-3px) scale(1.02); box-shadow: 0 14px 30px color-mix(in srgb, currentColor 18%, transparent); }
.flow-node.active::after { content: ""; position: absolute; inset: -8px; border: 2px solid currentColor; border-radius: inherit; opacity: .22; animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.035); opacity: .08; } }
.flow-arrow { height: 16px; display: grid; place-items: center; color: var(--muted); font-size: .92rem; }
.task-row { width: 100%; display: grid; grid-template-columns: repeat(3, minmax(160px, 1fr)); gap: 24px; }
.task-row .flow-node { width: 100%; min-width: 0; min-height: 56px; }
.branch-lines, .merge-lines { position: relative; width: 72%; height: 20px; display: grid; grid-template-columns: repeat(3, 1fr); }
.branch-lines::before, .merge-lines::after { content: ""; position: absolute; left: 16.66%; right: 16.66%; height: 1px; background: var(--border); }
.branch-lines::before { top: 0; }
.merge-lines::after { bottom: 0; }
.branch-lines i, .merge-lines i { justify-self: center; width: 1px; height: 100%; background: var(--border); }
.detail-panel, .build-panel { min-height: 452px; padding: clamp(20px, 2.5vw, 29px); border: 1px solid var(--border); border-radius: 24px; background: linear-gradient(145deg, var(--surface), color-mix(in srgb, var(--surface-soft) 70%, var(--surface))); box-shadow: 0 24px 60px var(--shadow); }
.detail-index { color: var(--brand); font-size: .72rem; font-weight: 900; letter-spacing: .12em; }
.detail-panel h3, .build-panel h3 { margin: 15px 0 8px; font-size: clamp(1.65rem, 2.25vw, 2.35rem); line-height: 1.05; letter-spacing: -.05em; }
.detail-panel > p, .build-panel > p { color: var(--muted); line-height: 1.65; }
.detail-list { display: grid; gap: 7px; margin-top: 17px; }
.detail-list div { padding: 10px 12px; border: 1px solid var(--border); border-radius: 13px; background: var(--surface); }
.detail-list span { display: block; color: var(--muted); font-size: .72rem; margin-bottom: 5px; }
.detail-list strong { font-size: .9rem; }
.tip { margin-top: 14px; padding: 11px 13px; border-left: 3px solid var(--brand); border-radius: 0 12px 12px 0; background: var(--surface-soft); color: var(--muted); font-size: .8rem; line-height: 1.45; }

.example-layout { display: grid; grid-template-columns: minmax(720px, 1.65fr) minmax(300px, .68fr); gap: clamp(20px, 3vw, 42px); margin-top: 18px; }
.example-flow { min-height: 482px; padding-top: 0; }
.example-flow > .flow-node:first-child { min-width: 340px; }
.example-tasks .flow-node { min-height: 61px; }
.example-flow .flow-arrow { height: 15px; }
.build-panel { min-height: 482px; }
.file-tree { margin-top: 16px; padding: 13px 15px; border: 1px solid var(--border); border-radius: 15px; background: var(--surface); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .73rem; line-height: 1.65; }
.file-tree b { color: var(--brand); }
.prompt-fragment { margin-top: 12px; padding: 12px 14px; border-radius: 14px; background: #0f211c; color: #dcebe6; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .72rem; line-height: 1.45; white-space: pre-line; }
.prompt-fragment span { color: #49d8c3; }

.controls { position: fixed; inset: auto 0 0; z-index: 30; height: 72px; padding: 0 clamp(22px, 4vw, 62px); display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; border-top: 1px solid color-mix(in srgb, var(--border) 82%, transparent); background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(18px); }
.chapter-label { display: flex; align-items: center; gap: 11px; }
.chapter-label span { color: var(--brand); font-weight: 900; }
.chapter-label strong { font-size: .88rem; }
.keyboard-help { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: .74rem; }
kbd { min-width: 25px; padding: 4px 6px; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 7px; background: var(--surface); color: var(--text); text-align: center; }
.nav-buttons { justify-self: end; display: flex; align-items: center; gap: 9px; }
.nav-buttons button { width: 38px; height: 38px; border: 1px solid var(--border); border-radius: 11px; background: var(--surface); color: var(--text); cursor: pointer; }
.nav-buttons button:hover:not(:disabled) { color: var(--brand); border-color: var(--brand); }
.nav-buttons button:disabled { opacity: .34; cursor: default; }
.nav-buttons span { width: 48px; text-align: center; color: var(--muted); font-size: .78rem; }

@media (min-width: 1101px) {
  .diagram-shell > .flowchart,
  .example-layout > .flowchart {
    margin-top: clamp(44px, 4.6vh, 72px);
  }
}

@media (max-width: 1100px) {
  .chapter-tabs .chapter-tab { font-size: 0; }
  .chapter-tabs .chapter-tab span { font-size: .8rem; margin: 0; }
  .intro-layout { grid-template-columns: 1fr; }
  .intro-copy { max-width: 900px; }
  .concept-lab { display: none; }
  .diagram-shell, .example-layout { grid-template-columns: 1fr; }
  .detail-panel, .build-panel { min-height: 0; }
}

@media (max-width: 720px) {
  .topbar { height: 62px; grid-template-columns: auto 1fr auto; padding: 0 15px; gap: 12px; }
  .brand span, .keyboard-help { display: none; }
  .chapter-tabs { justify-self: center; }
  .chapter-tab { padding: 7px 10px; }
  .deck { inset: 62px 0 62px; }
  .chapter { padding: 24px 16px; }
  .controls { height: 62px; padding: 0 15px; grid-template-columns: 1fr auto; }
  .chapter-label strong { display: none; }
  .nav-buttons { grid-column: 2; }
  h1 { font-size: clamp(2.8rem, 13vw, 4.8rem); }
  .creator-callout { grid-template-columns: auto 1fr; }
  .creator-callout a { grid-column: 2; }
  .section-head { display: grid; align-items: start; }
  .section-head h2 { font-size: 2.55rem; }
  .flowchart { min-width: 680px; align-items: center; }
  .diagram-shell, .example-layout { overflow-x: auto; }
  .detail-panel, .build-panel { min-width: 320px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
