:root {
  color-scheme: light dark;
  --page: light-dark(#f4f7f5, #0b1114);
  --panel: light-dark(#ffffff, #121b20);
  --panel-soft: light-dark(#edf3f0, #18262b);
  --ink: light-dark(#17292d, #edf6f3);
  --muted: light-dark(#5a7075, #a9bdba);
  --line: light-dark(#cedbd7, #34484b);
  --brand: light-dark(#087866, #73dcc6);
  --brand-ink: light-dark(#ffffff, #07110f);
  --blue: light-dark(#315fa5, #87b2ff);
  --blue-soft: light-dark(#e9f0fb, #182741);
  --violet: light-dark(#7554a5, #c8aff0);
  --violet-soft: light-dark(#f1ecf8, #291f39);
  --amber: light-dark(#97651b, #e9be6f);
  --amber-soft: light-dark(#fbf2df, #302615);
  --coral: light-dark(#a65436, #f1a489);
  --coral-soft: light-dark(#faeee9, #342018);
  --radius: 16px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--page);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP", Meiryo, sans-serif;
  line-height: 1.75;
}
button, a { font: inherit; }
a { color: inherit; }
.skip-link { position: fixed; top: 8px; left: 8px; z-index: 100; padding: 8px 12px; color: var(--brand-ink); background: var(--brand); border-radius: 8px; transform: translateY(-150%); }
.skip-link:focus { transform: none; }
.site-header { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--panel) 96%, transparent); border-bottom: 1px solid var(--line); backdrop-filter: blur(12px); }
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 24px; max-width: 1180px; min-height: 68px; margin: 0 auto; padding: 10px 24px; }
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 600; white-space: nowrap; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; color: var(--brand-ink); background: var(--brand); border-radius: 9px; font: 600 12px/1 ui-monospace, Consolas, monospace; }
.course-nav { display: flex; align-items: center; gap: 6px; overflow-x: auto; padding: 2px; }
.course-nav a { padding: 7px 9px; color: var(--muted); border-radius: 7px; text-decoration: none; font-size: 12px; white-space: nowrap; }
.course-nav a:hover, .course-nav a:focus-visible { color: var(--ink); background: var(--panel-soft); }
.course-nav a[aria-current="page"] { color: var(--brand-ink); background: var(--brand); }

main { overflow: hidden; }
.lesson-hero { padding: clamp(54px, 8vw, 96px) 24px; background: linear-gradient(color-mix(in srgb, var(--brand) 6%, transparent) 1px, transparent 1px), linear-gradient(90deg, color-mix(in srgb, var(--brand) 6%, transparent) 1px, transparent 1px), var(--panel); background-size: 30px 30px, 30px 30px, auto; }
.hero-inner { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(300px, .75fr); align-items: center; gap: clamp(32px, 7vw, 80px); max-width: 1120px; margin: 0 auto; }
.eyebrow { margin: 0 0 9px; color: var(--brand); font: 600 12px/1.4 ui-monospace, Consolas, monospace; letter-spacing: .1em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1 { max-width: 760px; margin-bottom: 18px; font-size: clamp(40px, 6vw, 68px); line-height: 1.15; letter-spacing: -.045em; font-weight: 600; }
.lead { max-width: 740px; margin-bottom: 0; color: var(--muted); font-size: clamp(16px, 2vw, 20px); }
.hero-answer { padding: 24px; background: var(--panel); border: 1px solid var(--line); border-top: 5px solid var(--brand); border-radius: var(--radius); box-shadow: 0 15px 40px light-dark(rgba(24, 54, 49, .11), rgba(0, 0, 0, .3)); }
.hero-answer small { display: block; margin-bottom: 10px; color: var(--brand); font-weight: 600; letter-spacing: .08em; }
.hero-answer strong { display: block; margin-bottom: 8px; font-size: 21px; line-height: 1.45; }
.hero-answer p { margin-bottom: 0; color: var(--muted); font-size: 14px; }

.section { padding: clamp(52px, 7vw, 82px) 24px; border-top: 1px solid var(--line); }
.section:nth-of-type(odd) { background: var(--panel); }
.section-inner { max-width: 1120px; margin: 0 auto; }
.section-head { max-width: 760px; margin-bottom: 28px; }
.section-head h2 { margin-bottom: 8px; font-size: clamp(29px, 4vw, 44px); line-height: 1.25; letter-spacing: -.03em; font-weight: 600; }
.section-head p { margin-bottom: 0; color: var(--muted); }
.one-line { padding: 18px 20px; color: var(--muted); background: var(--panel-soft); border-left: 4px solid var(--brand); border-radius: 0 10px 10px 0; }
.one-line strong { color: var(--ink); }

.flow { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); align-items: stretch; gap: 22px; }
.flow-step { position: relative; display: grid; align-content: center; min-height: 116px; padding: 18px; background: var(--panel-soft); border: 1px solid var(--line); border-top: 4px solid var(--step-color, var(--brand)); border-radius: 10px; }
.flow-step:nth-child(1) { --step-color: var(--coral); }
.flow-step:nth-child(2) { --step-color: var(--amber); }
.flow-step:nth-child(3) { --step-color: var(--blue); }
.flow-step:nth-child(4) { --step-color: var(--brand); }
.flow-step:not(:last-child)::after { content: "→"; position: absolute; top: 42%; right: -18px; z-index: 2; width: 14px; color: var(--brand); background: var(--panel); text-align: center; }
.flow-step b { display: block; margin-bottom: 4px; font-weight: 600; }
.flow-step span { color: var(--muted); font-size: 13px; }

.role-grid, .example-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.role-card, .example-card { min-width: 0; padding: 22px; background: var(--panel); border: 1px solid var(--line); border-radius: 11px; }
.role-card { border-top: 5px solid var(--card-color, var(--brand)); }
.role-card:nth-child(1) { --card-color: var(--coral); }
.role-card:nth-child(2) { --card-color: var(--blue); }
.role-card:nth-child(3) { --card-color: var(--brand); }
.card-label { display: block; margin-bottom: 12px; color: var(--card-color, var(--brand)); font: 600 11px/1.2 ui-monospace, Consolas, monospace; letter-spacing: .08em; }
.role-card h3, .example-card h3 { margin-bottom: 7px; font-size: 19px; font-weight: 600; }
.role-card p, .example-card p { margin-bottom: 0; color: var(--muted); font-size: 14px; }
.example-card ul { margin: 12px 0 0; padding-left: 20px; color: var(--muted); font-size: 13px; }

.steps { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; counter-reset: lesson-step; }
.steps li { display: grid; grid-template-columns: auto 1fr; gap: 14px; align-items: start; padding: 16px 18px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; counter-increment: lesson-step; }
.steps li::before { content: counter(lesson-step, decimal-leading-zero); display: grid; place-items: center; width: 34px; height: 34px; color: var(--brand-ink); background: var(--brand); border-radius: 8px; font: 600 11px/1 ui-monospace, Consolas, monospace; }
.steps strong { display: block; margin-bottom: 3px; font-weight: 600; }
.steps span { display: block; color: var(--muted); font-size: 14px; }

.compare { width: 100%; border-collapse: separate; border-spacing: 0; overflow: hidden; background: var(--panel); border: 1px solid var(--line); border-radius: 11px; }
.compare th, .compare td { padding: 13px 15px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.compare th { color: var(--brand); background: var(--panel-soft); font-size: 13px; }
.compare td { color: var(--muted); font-size: 14px; }
.compare tr:last-child td { border-bottom: 0; }

.misconception { display: grid; grid-template-columns: auto 1fr; gap: 14px; padding: 18px 20px; background: var(--amber-soft); border-radius: 10px; }
.misconception b { color: var(--amber); white-space: nowrap; }
.misconception p { margin-bottom: 0; color: var(--muted); }
.check-list { display: grid; gap: 10px; }
.check-list details { padding: 15px 18px; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; }
.check-list summary { cursor: pointer; font-weight: 600; }
.check-list p { margin: 10px 0 0; color: var(--muted); }

.chapter-nav { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 26px; }
.chapter-nav a { padding: 7px 11px; color: var(--muted); background: var(--panel-soft); border: 1px solid var(--line); border-radius: 999px; text-decoration: none; font-size: 12px; }
.chapter-nav a:hover, .chapter-nav a:focus-visible { color: var(--ink); border-color: var(--brand); }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.detail-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.detail-card { min-width: 0; padding: 22px; background: var(--panel); border: 1px solid var(--line); border-radius: 11px; }
.detail-card h3 { margin-bottom: 8px; font-size: 19px; font-weight: 600; }
.detail-card p { margin-bottom: 0; color: var(--muted); font-size: 14px; }
.detail-card p + p { margin-top: 10px; }
.detail-card ul { margin: 12px 0 0; padding-left: 20px; color: var(--muted); font-size: 14px; }
.detail-card code, .demo-output code { padding: 2px 5px; background: var(--panel-soft); border-radius: 4px; font-family: ui-monospace, Consolas, monospace; }
.callout { padding: 20px 22px; background: var(--blue-soft); border-left: 4px solid var(--blue); border-radius: 0 11px 11px 0; }
.callout.amber { background: var(--amber-soft); border-left-color: var(--amber); }
.callout h3 { margin-bottom: 7px; font-size: 18px; }
.callout p { margin-bottom: 0; color: var(--muted); }
.callout p + p { margin-top: 8px; }
.spec-list { display: grid; gap: 0; margin: 0; }
.spec-list > div { display: grid; grid-template-columns: minmax(130px, .45fr) 1fr; gap: 20px; padding: 15px 0; border-bottom: 1px solid var(--line); }
.spec-list > div:last-child { border-bottom: 0; }
.spec-list dt { color: var(--ink); font-weight: 600; }
.spec-list dd { margin: 0; color: var(--muted); }
.path-list { display: grid; gap: 9px; margin: 0; padding: 0; list-style: none; }
.path-list li { position: relative; padding: 14px 16px 14px 44px; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; color: var(--muted); }
.path-list li::before { content: attr(data-step); position: absolute; top: 14px; left: 14px; color: var(--brand); font: 600 12px/1.75 ui-monospace, Consolas, monospace; }
.path-list strong { color: var(--ink); }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.metric { padding: 18px; background: var(--panel-soft); border: 1px solid var(--line); border-radius: 9px; }
.metric b { display: block; margin-bottom: 4px; font-size: 16px; }
.metric span { display: block; color: var(--muted); font-size: 13px; }
.mini-demo { display: grid; grid-template-columns: minmax(250px, .75fr) minmax(0, 1.25fr); gap: 24px; padding: clamp(20px, 4vw, 32px); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 16px 35px light-dark(rgba(24, 54, 49, .08), rgba(0, 0, 0, .22)); }
.demo-controls { display: grid; align-content: start; gap: 14px; }
.demo-controls label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.demo-controls input[type="range"] { width: 100%; accent-color: var(--brand); }
.demo-controls select, .demo-controls input[type="number"] { width: 100%; min-height: 42px; padding: 7px 10px; color: var(--ink); background: var(--panel-soft); border: 1px solid var(--line); border-radius: 7px; }
.demo-button { min-height: 42px; padding: 8px 14px; color: var(--brand-ink); background: var(--brand); border: 0; border-radius: 7px; cursor: pointer; font-weight: 600; }
.demo-button.secondary { color: var(--ink); background: var(--panel-soft); border: 1px solid var(--line); }
.demo-output { min-width: 0; padding: 20px; background: var(--panel-soft); border-radius: 10px; }
.demo-output h3 { margin-bottom: 10px; font-size: 18px; }
.demo-output p { color: var(--muted); }
.demo-output p:last-child { margin-bottom: 0; }
.bit-row { display: grid; grid-template-columns: repeat(8, minmax(24px, 1fr)); gap: 6px; margin: 14px 0; }
.bit-cell { display: grid; place-items: center; min-height: 42px; color: var(--muted); background: var(--panel); border: 1px solid var(--line); border-radius: 6px; font: 600 13px/1 ui-monospace, Consolas, monospace; }
.bit-cell.is-on { color: var(--brand-ink); background: var(--brand); border-color: var(--brand); }
.memory-cells, .block-cells { display: grid; grid-template-columns: repeat(8, minmax(38px, 1fr)); gap: 7px; margin: 12px 0; }
.memory-cell, .block-cell { display: grid; place-items: center; min-height: 50px; padding: 4px; color: var(--muted); background: var(--panel); border: 1px solid var(--line); border-radius: 6px; font: 12px/1.2 ui-monospace, Consolas, monospace; }
button.memory-cell { cursor: pointer; }
.memory-cell.is-selected, .block-cell.is-used { color: var(--brand-ink); background: var(--brand); border-color: var(--brand); }
.block-cell.is-slack { color: var(--ink); background: var(--amber-soft); border-color: var(--amber); }
.demo-status { min-height: 44px; padding: 10px 12px; color: var(--muted); background: var(--panel); border: 1px solid var(--line); border-radius: 7px; }
.pixel-preview { display: grid; place-items: center; min-height: 190px; margin-bottom: 16px; color: #fff; background: rgb(36, 142, 210); border: 12px solid light-dark(#18313a, #05090b); border-radius: 10px; box-shadow: inset 0 0 0 1px rgba(255,255,255,.18); font: 600 15px/1.4 ui-monospace, Consolas, monospace; text-shadow: 0 1px 4px rgba(0,0,0,.75); }
.tag-list { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 12px; }
.tag-list span { padding: 5px 8px; color: var(--muted); background: var(--panel-soft); border-radius: 5px; font-size: 12px; }
.note { color: var(--muted); font-size: 13px; }
.lane-grid { display: grid; grid-template-columns: repeat(8, minmax(62px, 1fr)); gap: 7px; margin: 14px 0; }
.lane { display: grid; gap: 5px; min-height: 104px; padding: 10px 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 7px; text-align: center; transition: border-color .2s, background .2s, transform .2s; }
.lane small { color: var(--muted); font: 11px/1.2 ui-monospace, Consolas, monospace; }
.lane code { font-size: 12px; }
.lane output { color: var(--muted); font: 600 18px/1.2 ui-monospace, Consolas, monospace; }
.lane.is-read { border-color: var(--blue); background: var(--blue-soft); }
.lane.is-compute { border-color: var(--amber); background: var(--amber-soft); transform: translateY(-3px); }
.lane.is-done { color: var(--brand-ink); background: var(--brand); border-color: var(--brand); }
.lane.is-done small, .lane.is-done output { color: inherit; }
.embedded-demo { margin: 22px 0 0; padding: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.embedded-demo iframe { display: block; width: 100%; height: min(72vw, 760px); min-height: 560px; background: #fff; border: 0; border-radius: 8px; }
.embedded-demo figcaption { margin-top: 10px; color: var(--muted); font-size: 13px; }
.display-layer { position: relative; padding-top: 34px; }
.display-layer::before { content: attr(data-layer); position: absolute; top: 0; left: 0; color: var(--brand); font: 600 11px/1 ui-monospace, Consolas, monospace; letter-spacing: .08em; }

.lesson-pager { padding: 30px 24px; color: var(--brand-ink); background: var(--brand); }
.pager-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; max-width: 1120px; margin: 0 auto; }
.pager-link { display: inline-flex; align-items: center; min-height: 44px; padding: 9px 14px; color: var(--ink); background: var(--panel); border-radius: 8px; text-decoration: none; font-weight: 600; }
.pager-center { text-align: center; }
.pager-center small { display: block; opacity: .8; }
.site-footer { padding: 24px; color: var(--muted); background: var(--panel); border-top: 1px solid var(--line); text-align: center; font-size: 12px; }

.term { display: inline; margin: 0; padding: 0; color: inherit; background: transparent; border: 0; border-bottom: 1px dotted currentColor; border-radius: 0; cursor: help; font: inherit; line-height: inherit; text-align: inherit; }
.term-tooltip { position: fixed; z-index: 1000; display: none; width: min(320px, calc(100vw - 24px)); padding: 11px 13px; color: var(--brand-ink); background: light-dark(#173b36, #d9f6ee); border: 1px solid color-mix(in srgb, var(--brand) 55%, transparent); border-radius: 8px; box-shadow: 0 12px 30px rgba(0, 0, 0, .25); font-size: 13px; line-height: 1.55; }
.term-tooltip.is-visible { display: block; }

@media (max-width: 900px) {
  .header-inner { align-items: flex-start; flex-direction: column; gap: 8px; }
  .course-nav { width: 100%; padding-bottom: 4px; }
  .hero-inner { grid-template-columns: 1fr; }
  .hero-answer { max-width: 680px; }
  .flow { grid-template-columns: repeat(2, minmax(0, 1fr)); row-gap: 28px; }
  .flow-step:nth-child(2)::after { content: none; }
  .role-grid, .example-grid { grid-template-columns: 1fr; }
  .detail-grid.three { grid-template-columns: 1fr; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .mini-demo { grid-template-columns: 1fr; }
  .lane-grid { grid-template-columns: repeat(4, minmax(62px, 1fr)); }
}

@media (max-width: 600px) {
  .header-inner { padding-inline: 16px; }
  .brand span:last-child { display: none; }
  .lesson-hero, .section { padding-inline: 18px; }
  h1 { font-size: clamp(38px, 13vw, 54px); }
  .flow { grid-template-columns: 1fr; gap: 10px; }
  .flow-step:not(:last-child)::after { content: "↓"; top: auto; right: 18px; bottom: -15px; }
  .compare { display: block; overflow-x: auto; }
  .misconception { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .metric-grid { grid-template-columns: 1fr; }
  .spec-list > div { grid-template-columns: 1fr; gap: 4px; }
  .memory-cells, .block-cells { grid-template-columns: repeat(4, minmax(38px, 1fr)); }
  .lane-grid { grid-template-columns: repeat(2, minmax(62px, 1fr)); }
  .embedded-demo iframe { height: 440px; min-height: 440px; }
  .pager-inner { align-items: stretch; flex-direction: column; }
  .pager-center { order: -1; }
  .pager-link { justify-content: center; }
}

@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
