/* ==========================================================================
   RISC-V Book — 공통 스타일
   모든 장(chapter)과 첫 화면이 이 파일 하나를 공유한다.
   색은 반드시 아래 토큰(var(--...))으로만 쓴다. 그래야 다크 모드가 저절로 맞는다.
   ========================================================================== */
@import url("https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/variable/pretendardvariable-dynamic-subset.min.css");
@import url("https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600;700&display=swap");

:root {
  --bg: #f5f6fb;
  --bg-elev: #ffffff;
  --surface: #eceff7;
  --surface-2: #e0e5f1;
  --border: #d3d9e8;
  --text: #121729;
  --text-dim: #525c76;
  --text-faint: #8790a8;
  /* RISC-V 로고의 남색과 금색에서 가져온 두 강조색 */
  --accent: #2c3aa8;
  --accent-soft: rgba(44, 58, 168, 0.10);
  --accent-2: #b97800;
  --accent-2-soft: rgba(242, 169, 0, 0.16);
  --ok: #1d8f4e;
  --ok-soft: rgba(29, 143, 78, 0.12);
  --warn: #c76a00;
  --warn-soft: rgba(199, 106, 0, 0.12);
  --bad: #cf3a3a;
  --bad-soft: rgba(207, 58, 58, 0.11);
  --violet: #7a3fc4;
  --violet-soft: rgba(122, 63, 196, 0.12);
  --teal: #0b8a99;
  --teal-soft: rgba(11, 138, 153, 0.12);
  --grid: rgba(18, 23, 41, 0.08);
  --canvas-bg: #ffffff;
  --on-accent: #ffffff;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 6px 20px rgba(16, 24, 40, 0.06);
  --radius: 14px;
  --radius-small: 8px;
  --font: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --content-width: 860px;
  --nav-height: 58px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a0d18;
    --bg-elev: #111627;
    --surface: #171d33;
    --surface-2: #1f2742;
    --border: #28304d;
    --text: #e5e9f6;
    --text-dim: #9ba5c2;
    --text-faint: #69728f;
    --accent: #8d9cff;
    --accent-soft: rgba(141, 156, 255, 0.15);
    --accent-2: #ffc23d;
    --accent-2-soft: rgba(255, 194, 61, 0.14);
    --ok: #3fcf7f;
    --ok-soft: rgba(63, 207, 127, 0.14);
    --warn: #ffa63d;
    --warn-soft: rgba(255, 166, 61, 0.14);
    --bad: #ff6b6b;
    --bad-soft: rgba(255, 107, 107, 0.14);
    --violet: #b48cff;
    --violet-soft: rgba(180, 140, 255, 0.15);
    --teal: #38d3e3;
    --teal-soft: rgba(56, 211, 227, 0.13);
    --grid: rgba(229, 233, 246, 0.08);
    --canvas-bg: #0e1323;
    --on-accent: #0a0d18;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 28px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0a0d18;
  --bg-elev: #111627;
  --surface: #171d33;
  --surface-2: #1f2742;
  --border: #28304d;
  --text: #e5e9f6;
  --text-dim: #9ba5c2;
  --text-faint: #69728f;
  --accent: #8d9cff;
  --accent-soft: rgba(141, 156, 255, 0.15);
  --accent-2: #ffc23d;
  --accent-2-soft: rgba(255, 194, 61, 0.14);
  --ok: #3fcf7f;
  --ok-soft: rgba(63, 207, 127, 0.14);
  --warn: #ffa63d;
  --warn-soft: rgba(255, 166, 61, 0.14);
  --bad: #ff6b6b;
  --bad-soft: rgba(255, 107, 107, 0.14);
  --violet: #b48cff;
  --violet-soft: rgba(180, 140, 255, 0.15);
  --teal: #38d3e3;
  --teal-soft: rgba(56, 211, 227, 0.13);
  --grid: rgba(229, 233, 246, 0.08);
  --canvas-bg: #0e1323;
  --on-accent: #0a0d18;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 28px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--nav-height) + 16px); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.78;
  word-break: keep-all;
  overflow-wrap: break-word;
  -webkit-font-smoothing: antialiased;
  /* Pretendard 의 문맥 대체 글리프가 "0x10" 의 x 를 곱셈 기호(×)로 바꾸므로 끈다 */
  font-feature-settings: "calt" 0;
  font-variant-ligatures: no-contextual;
}
img, svg, canvas, video { max-width: 100%; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, kbd { font-family: var(--mono); font-size: 0.86em; background: var(--surface); padding: 0.1em 0.42em; border-radius: 5px; }
kbd { border: 1px solid var(--border); border-bottom-width: 2px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 48px 0; }
::selection { background: var(--accent-soft); }
.mono { font-family: var(--mono); }

/* ------------------------------------------------------------------ 상단 바 */
.book-topbar {
  position: sticky; top: 0; z-index: 50;
  height: var(--nav-height);
  display: flex; align-items: center; gap: 10px;
  padding: 0 16px;
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.book-logo { display: flex; align-items: center; gap: 10px; font-weight: 800; color: var(--text); letter-spacing: -0.02em; font-size: 18px; white-space: nowrap; }
.book-logo:hover { text-decoration: none; }
.book-logo svg { width: 28px; height: 28px; flex: none; }
.book-logo small { font-weight: 500; color: var(--text-dim); font-size: 13px; }
.book-topbar .spacer { flex: 1; }
.topbar-chapter { font-size: 14px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.topbar-button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg-elev); color: var(--text);
  font: inherit; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.topbar-button:hover { border-color: var(--accent); text-decoration: none; }
.topbar-button.icon-only { width: 36px; padding: 0; }
.topbar-button svg { width: 18px; height: 18px; }
.reading-progress { position: absolute; left: 0; bottom: -1px; height: 2px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); width: 0; }
@media (max-width: 640px) { .book-logo small, .topbar-chapter { display: none; } .topbar-button .label { display: none; } }

/* ------------------------------------------------------------------ 목차 서랍 */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.38); z-index: 60; opacity: 0; pointer-events: none; transition: opacity 0.2s; }
.drawer {
  position: fixed; top: 0; left: 0; bottom: 0; width: min(350px, 88vw); z-index: 61;
  background: var(--bg-elev); border-right: 1px solid var(--border);
  transform: translateX(-102%); transition: transform 0.25s ease;
  overflow-y: auto; padding: 18px 12px 40px;
}
body.drawer-open .drawer { transform: none; }
body.drawer-open .drawer-backdrop { opacity: 1; pointer-events: auto; }
.drawer h4 { margin: 18px 10px 6px; font-size: 11.5px; letter-spacing: 0.12em; color: var(--text-faint); text-transform: uppercase; }
.drawer-list { list-style: none; margin: 0; padding: 0; }
.drawer-list a { display: flex; gap: 10px; align-items: baseline; padding: 7px 10px; border-radius: 9px; color: var(--text); font-size: 15px; line-height: 1.45; }
.drawer-list a:hover { background: var(--surface); text-decoration: none; }
.drawer-list a.current { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.drawer-list .number { font-family: var(--mono); font-size: 12px; color: var(--text-faint); min-width: 20px; }
.drawer-list a.is-done .number::after { content: " ✓"; color: var(--ok); }

/* ------------------------------------------------------------------ 본문 레이아웃 */
.page-layout { display: grid; grid-template-columns: minmax(0, 1fr); max-width: 1220px; margin: 0 auto; }
@media (min-width: 1180px) { .page-layout { grid-template-columns: minmax(0, 1fr) 240px; gap: 24px; } }
.page-toc { display: none; }
@media (min-width: 1180px) {
  .page-toc { display: block; position: sticky; top: calc(var(--nav-height) + 24px); align-self: start; max-height: calc(100vh - var(--nav-height) - 48px); overflow-y: auto; padding: 4px 16px 24px 0; font-size: 13.5px; }
  .page-toc h5 { margin: 0 0 8px; font-size: 11.5px; letter-spacing: 0.12em; color: var(--text-faint); text-transform: uppercase; }
  .page-toc a { display: block; padding: 4px 10px; border-left: 2px solid var(--border); color: var(--text-dim); line-height: 1.45; }
  .page-toc a:hover { color: var(--text); text-decoration: none; }
  .page-toc a.active { border-left-color: var(--accent); color: var(--accent); font-weight: 600; }
}

.chapter { width: 100%; max-width: var(--content-width); margin: 0 auto; padding: 32px 20px 80px; min-width: 0; }
@media (max-width: 520px) { .chapter { padding: 20px 16px 64px; } body { font-size: 16px; } }
.chapter h2 { font-size: 27px; line-height: 1.35; letter-spacing: -0.025em; margin: 64px 0 14px; }
.chapter h3 { font-size: 20px; line-height: 1.4; letter-spacing: -0.015em; margin: 40px 0 10px; }
.chapter h4 { font-size: 17px; margin: 28px 0 8px; }
.chapter p { margin: 0 0 16px; }
.chapter ul, .chapter ol { padding-left: 1.4em; margin: 0 0 18px; }
.chapter li { margin: 4px 0; }
.chapter section { position: relative; }

.chapter-hero { padding: 24px 0 8px; }
.eyebrow { font-family: var(--mono); font-size: 13px; letter-spacing: 0.12em; color: var(--accent); font-weight: 700; text-transform: uppercase; }
.chapter-hero h1 { font-size: clamp(30px, 5vw, 44px); line-height: 1.2; letter-spacing: -0.035em; margin: 8px 0 16px; }
.lead { font-size: 18.5px; color: var(--text-dim); }
.lead strong { color: var(--text); }
.objectives { list-style: none; padding: 16px 20px !important; margin: 22px 0 0 !important; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-elev); }
.objectives::before { content: "이 장에서 배우는 것"; display: block; font-size: 12.5px; font-weight: 700; letter-spacing: 0.08em; color: var(--text-faint); margin-bottom: 6px; }
.objectives li { position: relative; padding-left: 26px; }
.objectives li::before { content: "✓"; position: absolute; left: 2px; color: var(--ok); font-weight: 800; }
.spec-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }

.term { font-weight: 700; color: var(--text); background: linear-gradient(transparent 62%, var(--accent-2-soft) 62%); }
.english { color: var(--text-faint); font-size: 0.86em; margin-left: 3px; }

/* 규격 문서로 가는 작은 링크 칩 */
.spec-link {
  display: inline-flex; align-items: center; gap: 6px; font-size: 13px; line-height: 1.3;
  padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--bg-elev); color: var(--text-dim); font-family: var(--mono);
}
.spec-link::before { content: "§"; color: var(--accent-2); font-weight: 800; }
.spec-link:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }

.pill { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--border); color: var(--text-dim); background: var(--bg-elev); white-space: nowrap; }
.pill.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.pill.gold { background: var(--accent-2-soft); color: var(--accent-2); border-color: transparent; }
.pill.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }

/* ------------------------------------------------------------------ 그림 */
figure { margin: 26px 0; }
.diagram { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.diagram svg { display: block; width: 100%; height: auto; margin: 0 auto; }
.diagram .scroll-x { overflow-x: auto; }
.diagram .scroll-x > svg { min-width: 640px; }
figcaption { font-size: 14.5px; color: var(--text-dim); margin-top: 12px; line-height: 1.6; }
figcaption b { color: var(--text); }
.figure-row { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }

/* SVG 안에서 쓰는 색 클래스. 테마가 바뀌면 함께 바뀐다. */
svg text { font-family: var(--font); font-feature-settings: "calt" 0; }
.t { fill: var(--text); font-size: 14px; }
.t-dim { fill: var(--text-dim); font-size: 13px; }
.t-faint { fill: var(--text-faint); font-size: 12px; }
.t-mono { fill: var(--text); font-family: var(--mono); font-size: 13px; }
.t-accent { fill: var(--accent); font-size: 14px; font-weight: 700; }
.t-gold { fill: var(--accent-2); font-size: 14px; font-weight: 700; }
.t-ok { fill: var(--ok); font-weight: 700; }
.t-warn { fill: var(--warn); font-weight: 700; }
.t-bad { fill: var(--bad); font-weight: 700; }
.t-violet { fill: var(--violet); font-weight: 700; }
.t-teal { fill: var(--teal); font-weight: 700; }
.t-on-accent { fill: var(--on-accent); font-weight: 700; }
.t-bold { font-weight: 700; }
.f-bg { fill: var(--bg); }
.f-elev { fill: var(--bg-elev); stroke: var(--border); stroke-width: 1.2; }
.f-surface { fill: var(--surface); stroke: var(--border); stroke-width: 1; }
.f-surface-2 { fill: var(--surface-2); }
.f-accent { fill: var(--accent); }
.f-accent-soft { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 1.2; }
.f-gold { fill: var(--accent-2); }
.f-gold-soft { fill: var(--accent-2-soft); stroke: var(--accent-2); stroke-width: 1.2; }
.f-ok-soft { fill: var(--ok-soft); stroke: var(--ok); stroke-width: 1.2; }
.f-warn-soft { fill: var(--warn-soft); stroke: var(--warn); stroke-width: 1.2; }
.f-bad-soft { fill: var(--bad-soft); stroke: var(--bad); stroke-width: 1.2; }
.f-violet-soft { fill: var(--violet-soft); stroke: var(--violet); stroke-width: 1.2; }
.f-teal-soft { fill: var(--teal-soft); stroke: var(--teal); stroke-width: 1.2; }
.s-line { stroke: var(--text-faint); stroke-width: 1.6; fill: none; }
.s-accent { stroke: var(--accent); stroke-width: 2; fill: none; }
.s-gold { stroke: var(--accent-2); stroke-width: 2; fill: none; }
.s-ok { stroke: var(--ok); stroke-width: 2; fill: none; }
.s-bad { stroke: var(--bad); stroke-width: 2; fill: none; }
.s-dashed { stroke-dasharray: 5 4; }

/* 움직이는 그림: 데이터가 선을 따라 흐르는 느낌을 준다 */
.flow-dash { stroke-dasharray: 7 7; animation: flow-dash 1.1s linear infinite; }
@keyframes flow-dash { to { stroke-dashoffset: -14; } }
.pulse { animation: pulse 1.8s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }
.blink-highlight { animation: blink-highlight 1.6s ease-in-out infinite; }
@keyframes blink-highlight { 0%, 100% { fill-opacity: 1; } 50% { fill-opacity: 0.35; } }
.reveal { opacity: 0; transform: translateY(14px); transition: opacity 0.6s ease, transform 0.6s ease; }
.reveal.is-visible { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) {
  .flow-dash, .pulse, .blink-highlight { animation: none; }
  .reveal { opacity: 1; transform: none; transition: none; }
  html { scroll-behavior: auto; }
}

/* ------------------------------------------------------------------ 표 */
.table-wrap { overflow-x: auto; margin: 22px 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-elev); }
table { border-collapse: collapse; width: 100%; font-size: 15px; line-height: 1.55; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--surface); font-size: 13.5px; color: var(--text-dim); font-weight: 700; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
td code { white-space: nowrap; }
td.number, th.number { text-align: right; font-family: var(--mono); }
table.instruction-table td:first-child { font-family: var(--mono); font-weight: 700; color: var(--accent); white-space: nowrap; }
table.compact td, table.compact th { padding: 6px 10px; font-size: 14px; }

/* ------------------------------------------------------------------ 알림 상자 */
.callout { border-radius: var(--radius); padding: 16px 20px 6px; margin: 24px 0; border: 1px solid var(--border); border-left-width: 4px; background: var(--bg-elev); }
.callout > strong:first-child { display: block; margin-bottom: 4px; font-size: 15.5px; }
.callout > strong:first-child::before { margin-right: 6px; }
.callout p { font-size: 15.5px; }
.callout.tip { border-left-color: var(--ok); }
.callout.tip > strong:first-child::before { content: "💡"; }
.callout.warn { border-left-color: var(--warn); }
.callout.warn > strong:first-child::before { content: "⚠️"; }
.callout.deep { border-left-color: var(--violet); }
.callout.deep > strong:first-child::before { content: "🔬"; }
.callout.history { border-left-color: var(--accent-2); }
.callout.history > strong:first-child::before { content: "📜"; }
/* 규격 원문을 짧게 인용하고 출처 링크를 붙이는 상자 */
.callout.spec { border-left-color: var(--accent); background: linear-gradient(90deg, var(--accent-soft), var(--bg-elev) 60%); }
.callout.spec > strong:first-child::before { content: "📘"; }
.callout.spec blockquote { margin: 0 0 12px; padding: 0; font-style: italic; color: var(--text-dim); font-size: 15px; }

/* ------------------------------------------------------------------ 코드 */
.codebox {
  font-family: var(--mono); font-size: 14px; line-height: 1.7;
  background: var(--canvas-bg); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; margin: 22px 0; overflow-x: auto; white-space: pre; tab-size: 8;
}
.codebox[data-title]::before { content: attr(data-title); display: block; font-size: 12px; color: var(--text-faint); letter-spacing: 0.06em; margin-bottom: 8px; font-family: var(--font); font-weight: 700; }
.codebox .keyword { color: var(--accent); font-weight: 700; }
.codebox .register { color: var(--teal); }
.codebox .number { color: var(--accent-2); }
.codebox .comment { color: var(--text-faint); font-style: italic; }
.codebox .label { color: var(--violet); font-weight: 700; }
.codebox .directive { color: var(--warn); }
.codebox .highlight { background: var(--accent-2-soft); border-radius: 4px; }

/* ------------------------------------------------------------------ 비트 필드 (명령어 인코딩 그림) */
.bitfield { display: flex; width: 100%; font-family: var(--mono); font-size: 13px; margin: 18px 0 6px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); }
.bitfield .field { display: flex; flex-direction: column; justify-content: space-between; text-align: center; border-right: 1px solid var(--border); min-width: 0; }
.bitfield .field:last-child { border-right: 0; }
.bitfield .field .range { font-size: 10.5px; color: var(--text-faint); padding: 3px 4px 0; display: flex; justify-content: space-between; }
.bitfield .field .name { font-weight: 700; padding: 6px 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bitfield .field .value { font-size: 12px; padding: 0 4px 6px; color: var(--text-dim); word-break: break-all; }
.bitfield .field.opcode { background: var(--accent-soft); }
.bitfield .field.register { background: var(--teal-soft); }
.bitfield .field.immediate { background: var(--accent-2-soft); }
.bitfield .field.function { background: var(--violet-soft); }
.bitfield .field.plain { background: var(--surface); }

/* ------------------------------------------------------------------ 시뮬레이터 상자 */
.sim { border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-elev); box-shadow: var(--shadow); margin: 30px 0; overflow: hidden; }
.sim-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.sim-head h3 { margin: 0 !important; font-size: 17px !important; }
.sim-tag { font-family: var(--mono); font-size: 11px; font-weight: 700; letter-spacing: 0.1em; padding: 3px 8px; border-radius: 6px; background: var(--accent); color: var(--on-accent); }
.sim-tag.animation { background: var(--accent-2); color: #1b1300; }
.sim-view { background: var(--canvas-bg); position: relative; }
.sim-view canvas { display: block; width: 100%; }
.sim-pad { padding: 18px; }
.sim-controls { display: flex; flex-wrap: wrap; gap: 14px 22px; padding: 14px 18px; border-top: 1px solid var(--border); align-items: flex-end; }
.control { display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; color: var(--text-dim); min-width: 0; }
.control > span:first-child { font-weight: 600; }
.control output { font-family: var(--mono); color: var(--accent); font-weight: 700; margin-left: 4px; }
.control input[type="range"] { width: 220px; max-width: 100%; accent-color: var(--accent); }
.control input[type="text"], .control input[type="number"], .control select, .control textarea {
  font: inherit; font-family: var(--mono); font-size: 14px; color: var(--text);
  background: var(--canvas-bg); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; min-width: 0;
}
.control textarea { width: 100%; min-height: 160px; resize: vertical; line-height: 1.55; }
.control input:focus, .control select:focus, .control textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.control.wide { flex: 1 1 100%; }
.segmented { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 3px; background: var(--surface); border-radius: 10px; }
.segmented button { font: inherit; font-size: 13.5px; border: 0; background: transparent; color: var(--text-dim); padding: 6px 11px; border-radius: 8px; cursor: pointer; }
.segmented button:hover { color: var(--text); }
.segmented button.on { background: var(--bg-elev); color: var(--accent); font-weight: 700; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; }
.button { font: inherit; font-size: 14px; padding: 7px 14px; border-radius: 9px; border: 1px solid var(--border); background: var(--bg-elev); color: var(--text); cursor: pointer; }
.button:hover { border-color: var(--accent); }
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 700; }
.button.primary:hover { filter: brightness(1.08); }
.button:disabled { opacity: 0.45; cursor: not-allowed; }
.checkbox { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-size: 14px; color: var(--text); }
.checkbox input { accent-color: var(--accent); width: 16px; height: 16px; }
.sim-readout { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 1px; background: var(--border); border-top: 1px solid var(--border); }
.stat { background: var(--bg-elev); padding: 10px 16px; display: flex; flex-direction: column; min-width: 0; }
.stat .key { font-size: 12px; color: var(--text-faint); font-weight: 600; }
.stat .value { font-family: var(--mono); font-size: 18px; font-weight: 700; color: var(--text); overflow-wrap: anywhere; }
.sim-note { padding: 12px 18px; border-top: 1px solid var(--border); font-size: 14.5px; color: var(--text-dim); background: var(--surface); line-height: 1.65; }
.sim-note::before { content: "해볼 것 · "; font-weight: 800; color: var(--accent); }
.sim-note.plain::before { content: none; }
.step-description { padding: 12px 18px; border-top: 1px solid var(--border); font-size: 15px; min-height: 64px; line-height: 1.65; }
.log-box { font-family: var(--mono); font-size: 13px; line-height: 1.6; max-height: 220px; overflow-y: auto; padding: 10px 14px; background: var(--canvas-bg); border-top: 1px solid var(--border); white-space: pre-wrap; }

/* 레지스터·메모리 칸 같은 반복 셀 */
.cell-grid { display: grid; gap: 6px; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); }
.cell { border: 1px solid var(--border); border-radius: 8px; padding: 6px 9px; background: var(--bg-elev); font-family: var(--mono); font-size: 13px; transition: background 0.3s, border-color 0.3s; min-width: 0; }
.cell .cell-name { font-size: 11px; color: var(--text-faint); display: flex; justify-content: space-between; gap: 6px; }
.cell .cell-value { font-weight: 700; overflow-wrap: anywhere; }
.cell.changed { background: var(--accent-2-soft); border-color: var(--accent-2); }
.cell.active { background: var(--accent-soft); border-color: var(--accent); }
.cell.zero { opacity: 0.6; }

/* 비트 하나하나를 눌러서 바꾸는 상자 */
.bit-row { display: flex; flex-wrap: wrap; gap: 3px; justify-content: center; }
.bit { width: 26px; height: 32px; display: inline-flex; align-items: center; justify-content: center; border-radius: 6px; font-family: var(--mono); font-weight: 700; font-size: 14px; border: 1px solid var(--border); background: var(--surface); color: var(--text-dim); cursor: pointer; user-select: none; transition: background 0.2s; }
.bit.on { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.bit.gap { margin-left: 8px; }

/* ------------------------------------------------------------------ 핵심 정리와 퀴즈 */
.keypoints { margin-top: 64px; padding: 6px 24px 10px; border-radius: var(--radius); background: linear-gradient(135deg, var(--accent-soft), var(--accent-2-soft)); border: 1px solid var(--border); }
.keypoints h2 { margin-top: 22px !important; }
.keypoints li { margin: 8px 0; }
.quiz { display: grid; gap: 14px; }
.quiz-question { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; background: var(--bg-elev); }
.quiz-question > p { font-weight: 700; margin-bottom: 10px; }
.quiz-question > p::before { content: "Q" counter(quiz) ". "; color: var(--accent); }
.quiz { counter-reset: quiz; }
.quiz-question { counter-increment: quiz; }
.options { display: grid; gap: 7px; }
.option { font: inherit; font-size: 15px; text-align: left; padding: 9px 13px; border-radius: 9px; border: 1px solid var(--border); background: var(--bg); color: var(--text); cursor: pointer; line-height: 1.5; }
.option:hover:not(:disabled) { border-color: var(--accent); }
.option.correct { background: var(--ok-soft); border-color: var(--ok); }
.option.wrong { background: var(--bad-soft); border-color: var(--bad); }
.option:disabled { cursor: default; }
.quiz-explanation { display: none; margin-top: 10px; font-size: 14.5px; color: var(--text-dim); padding: 10px 12px; border-radius: 8px; background: var(--surface); }
.quiz-question.answered .quiz-explanation { display: block; }
.quiz-score { margin-top: 14px; font-weight: 700; color: var(--accent); }

.references { font-size: 14.5px; color: var(--text-dim); }
.references li { margin: 6px 0; }

/* ------------------------------------------------------------------ 이전·다음 장 */
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 60px; }
.pager a { display: block; padding: 14px 18px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-elev); color: var(--text); }
.pager a:hover { border-color: var(--accent); text-decoration: none; }
.pager small { display: block; color: var(--text-faint); font-size: 12.5px; }
.pager .next { text-align: right; grid-column: 2; }
.book-footer { text-align: center; color: var(--text-faint); font-size: 13px; padding: 30px 16px 40px; border-top: 1px solid var(--border); margin-top: 40px; }
.book-footer a { color: var(--text-dim); }

/* ------------------------------------------------------------------ 첫 화면 */
.home-hero { border-bottom: 1px solid var(--border); background: radial-gradient(1200px 500px at 85% -10%, var(--accent-soft), transparent 60%), radial-gradient(800px 400px at 0% 110%, var(--accent-2-soft), transparent 60%); }
.home-hero .inner { max-width: 1180px; margin: 0 auto; padding: 56px 20px 48px; display: grid; gap: 36px; align-items: center; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 960px) { .home-hero .inner { grid-template-columns: 1.05fr 1fr; } }
.home-hero h1 { font-size: clamp(36px, 6vw, 58px); line-height: 1.12; letter-spacing: -0.04em; margin: 10px 0 18px; }
.gradient-text { background: linear-gradient(90deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.home-hero p { color: var(--text-dim); font-size: 18px; max-width: 600px; }
.call-to-action { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 22px; }
.call-to-action a { padding: 11px 20px; border-radius: 12px; font-weight: 700; font-size: 16px; }
.call-to-action .primary { background: var(--accent); color: var(--on-accent); }
.call-to-action .ghost { border: 1px solid var(--border); background: var(--bg-elev); color: var(--text); }
.call-to-action a:hover { text-decoration: none; filter: brightness(1.06); }
.hero-badges { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 18px; }
.hero-badges span { font-size: 13px; padding: 4px 11px; border-radius: 999px; border: 1px solid var(--border); color: var(--text-dim); background: var(--bg-elev); }
.hero-visual { border: 1px solid var(--border); border-radius: 18px; background: var(--canvas-bg); box-shadow: var(--shadow); overflow: hidden; position: relative; }
.hero-visual canvas { display: block; width: 100%; }
.hero-visual .hint { position: absolute; left: 14px; bottom: 10px; font-size: 12px; color: var(--text-faint); pointer-events: none; }
.home-section { max-width: 1180px; margin: 0 auto; padding: 56px 20px 8px; }
.home-section h2 { font-size: 28px; letter-spacing: -0.03em; margin: 0 0 6px; }
.home-section .subtitle { color: var(--text-dim); margin: 0 0 22px; max-width: 760px; }
.part-title { font-size: 13px; letter-spacing: 0.1em; font-weight: 800; color: var(--text-faint); margin: 30px 0 10px; text-transform: uppercase; }
.chapter-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.chapter-card { display: flex; flex-direction: column; padding: 16px 18px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--bg-elev); color: var(--text); transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s; position: relative; }
.chapter-card:hover { transform: translateY(-2px); border-color: var(--accent); box-shadow: var(--shadow); text-decoration: none; }
.chapter-card .number { font-family: var(--mono); font-size: 12px; color: var(--accent); font-weight: 700; letter-spacing: 0.08em; }
.chapter-card h3 { margin: 4px 0 6px; font-size: 17.5px; line-height: 1.35; }
.chapter-card p { margin: 0 0 10px; color: var(--text-dim); font-size: 14px; line-height: 1.55; flex: 1; }
.chapter-card .tags { display: flex; flex-wrap: wrap; gap: 5px; }
.chapter-card .tags span { font-family: var(--mono); font-size: 11px; padding: 1px 7px; border-radius: 5px; background: var(--surface); color: var(--text-dim); }
.chapter-card .tags span.simulator { background: var(--accent-soft); color: var(--accent); }
.chapter-card.is-done .number::after { content: "  ✓ 다 읽음"; color: var(--ok); }
.stat-strip { display: grid; gap: 1px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.stat-strip div { background: var(--bg-elev); padding: 18px 20px; }
.stat-strip b { display: block; font-family: var(--mono); font-size: 24px; letter-spacing: -0.02em; color: var(--text); }
.stat-strip span { color: var(--text-dim); font-size: 14px; }
.path-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }
.path-card { padding: 18px 20px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--bg-elev); }
.path-card h3 { margin: 0 0 6px; font-size: 17px; }
.path-card p { margin: 0 0 10px; color: var(--text-dim); font-size: 14.5px; }
.path-card .steps { display: flex; flex-wrap: wrap; gap: 6px; }
.path-card .steps a { font-family: var(--mono); font-size: 12px; padding: 3px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.path-card .steps a:hover { text-decoration: none; filter: brightness(1.1); }
