:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1d2330;
  --muted: #6b7280;
  --border: #e3e6eb;
  --accent: #e95420;
  --accent-soft: #fdece5;
  --ok: #1f9d55;
  --ok-soft: #e3f6ec;
  --ng: #c53030;
  --ng-soft: #fdeaea;
  --code-bg: #eef0f3;
  --term-bg: #1e1f29;
}

/* ダークモード (<html data-theme="dark">)。ふだんは OS の設定に合わせ、目次の「ダークモード」トグルでも切り替えられる。
   CSS の @media (prefers-color-scheme) ではなく、スクリプトで data-theme を付ける (トグルの表示と見た目を必ずそろえるため) */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #14161b;
  --panel: #1b1e24;
  --text: #e6e8ec;
  --muted: #9aa1ad;
  --border: #2c3039;
  --accent-soft: #3a2219;
  --ok-soft: #173325;
  --ng: #e5484d; /* 暗い背景でも読める明るさの赤 (元の #c53030 は暗すぎる) */
  --ng-soft: #3a1c1c;
  --code-bg: #2a2e37;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", Meiryo, sans-serif;
  display: flex;
  flex-direction: column;
}

code, kbd {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 0.92em;
}
code { background: var(--code-bg); padding: 1px 5px; border-radius: 4px; }
kbd {
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0 5px;
  background: var(--panel);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.brand {
  font: inherit;
  font-weight: 700;
  font-size: 1.1rem;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}
.logo {
  font-family: ui-monospace, Consolas, monospace;
  background: var(--accent);
  color: #fff;
  padding: 2px 6px;
  border-radius: 5px;
  margin-right: 4px;
}
.progress { margin-left: auto; color: var(--muted); font-size: 0.9rem; text-align: right; }
/* 進捗のリセット: 進捗の表示のすぐ左に、目立たないボタンで置く */
.progress-reset { margin-left: auto; color: var(--muted); }
.progress-reset + .progress { margin-left: 0; }
/* ダークモードのトグル: 進捗のリセットのすぐ左 (どちらも目次のときだけ表示) */
.dark-switch { margin-left: auto; color: var(--muted); }
.dark-switch[hidden] { display: none; }
.dark-switch:not([hidden]) + .progress-reset { margin-left: 0; }
.progress-reset[hidden] { display: none; }
.progress-reset[hidden] + .progress { margin-left: auto; } /* ボタンを隠している間 (レッスンの画面) は、進捗の表示を右に寄せ直す */
.topbar .brand, .topbar .btn, .switch, .term-bar .btn { white-space: nowrap; }
.term-bar .status { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.term-bar { flex-wrap: wrap; row-gap: 4px; }
/* 目次の一番下のリセットボタンは、スマホ幅でだけ出す (上のバーに入らないため) */
.toc-foot { display: none; margin-top: 16px; align-items: center; justify-content: center; gap: 20px; flex-wrap: wrap; }
.toc-foot .dark-switch, .toc-foot .progress-reset { margin-left: 0; }
@media (max-width: 600px) {
  .topbar { gap: 10px; padding: 8px 12px; }
  .brand .name { display: none; }
  .progress { font-size: 0.78rem; }
}
/* 幅が狭いと上のバーに入りきらない (進捗の表示が縦に潰れる) ので、ダークモードと進捗のリセットは目次の一番下に出す */
@media (max-width: 900px) {
  .topbar .progress-reset, .topbar .dark-switch { display: none; }
  .topbar .progress-reset + .progress { margin-left: auto; } /* ボタンがない分、進捗の表示を右に寄せ直す */
  .toc-foot { display: flex; }
}

.layout {
  position: relative;
  flex: 1;
  min-height: 0;
  display: grid;
  /* レッスン一覧 / 本文 / ターミナル。本文を広めに取る (以前は 220px / 1fr / 1.3fr) */
  grid-template-columns: 196px minmax(320px, 1fr) minmax(420px, 1.08fr);
}

.sidebar {
  border-right: 1px solid var(--border);
  background: var(--panel);
  overflow-y: auto;
  overflow-anchor: none; /* 一覧を作り直したときに、ブラウザがスクロール位置を勝手にずらさないように */
  padding: 8px;
}
.lesson-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.lesson-item:hover { background: var(--code-bg); }
.lesson-item.active { background: var(--accent-soft); }
.lesson-item .name { font-weight: 600; font-size: 0.95rem; }
.lesson-item .name .done { color: var(--ok); margin-left: 4px; }
.lesson-item .sub { color: var(--muted); font-size: 0.8rem; margin-top: 2px; }

.lesson {
  min-width: 0;
  overflow-y: auto;
  padding: 20px 24px;
  line-height: 1.75;
}
.lesson-head { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.85rem; }
.lesson h2 { margin: 6px 0 12px; font-size: 1.35rem; }
.step-body ul, .step-body ol { padding-left: 1.3em; }
.step-body li { margin: 2px 0; }
.step-body pre {
  background: var(--term-bg);
  color: #e6e6e6;
  border-radius: 6px;
  padding: 10px 14px;
  overflow-x: auto;
  line-height: 1.5;
}
.step-body pre code { background: none; padding: 0; color: inherit; }
.step-body details { margin: 12px 0; }
.step-body .cmp { border-collapse: collapse; font-size: 0.85rem; margin: 10px 0; width: 100%; display: block; overflow-x: auto; }
.step-body .cmp th, .step-body .cmp td { border: 1px solid var(--border); padding: 4px 8px; text-align: left; white-space: nowrap; }
.step-body .cmp th { background: var(--code-bg); }
/* 上下の対応を見せる図 (文字の幅に関係なく、列でそろえる) */
.step-body .cmp.center td { text-align: center; padding: 4px 14px; }
.step-body summary { cursor: pointer; color: var(--accent); }
/* ブラウザ版だけの文 (lite/lite.css で表示する。Ubuntu 版では出さない)。
   Ubuntu 版だけの文は class="ubuntu-only" (lite/lite.css で隠す)。同じ内容を2つの版で言い分けるときは、2つ並べて書く */
.lite-only { display: none; }

.section-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.04em;
  padding: 12px 10px 4px;
}
.section-label:first-child { padding-top: 4px; }

.commands { display: flex; flex-direction: column; gap: 6px; margin: 16px 0; }
.cmd {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--term-bg);
  color: #e6e6e6;
  border-radius: 6px;
  padding: 6px 6px 6px 12px;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 0.9rem;
}
.cmd::before { content: "$"; color: #8be28b; }
.cmd .text { flex: 1; white-space: pre-wrap; word-break: break-all; }
.cmd button {
  border: 0;
  border-radius: 4px;
  background: #3b3f4d;
  color: #fff;
  font: inherit;
  font-family: system-ui, sans-serif;
  font-size: 0.78rem;
  padding: 4px 8px;
  cursor: pointer;
  white-space: nowrap;
}
.cmd button:hover { background: var(--accent); }

/* ---- コマンド解説 ---- */
.switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  user-select: none;
}
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
  position: relative;
  width: 34px;
  height: 20px;
  border-radius: 10px;
  background: var(--border);
  transition: background 0.15s;
}
.switch .knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s;
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track .knob { transform: translateX(14px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

.cmd { position: relative; }
.explain-on .cmdword {
  background: rgba(250, 204, 21, 0.28);
  border-radius: 3px;
  box-shadow: 0 0 0 2px rgba(250, 204, 21, 0.28);
  cursor: help;
}
.explain-on .cmdword:hover { background: rgba(250, 204, 21, 0.5); }
/* コマンドの吹き出し (用語の吹き出しと同じく、印の上に固定位置で出す。位置は app.js の placeTip) */
.cmd-tip {
  position: fixed;
  z-index: 200; /* 拡大した図 (z-index 100) の上にも出す */
  max-width: min(360px, calc(100vw - 16px));
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-left: 4px solid #facc15;
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  padding: 8px 12px;
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", Meiryo, sans-serif;
  font-size: 0.85rem;
  line-height: 1.6;
  white-space: normal;
  pointer-events: none;
}
.cmd-tip[hidden] { display: none; }
/* 専門用語 (水色の印) と、その吹き出し */
.explain-on .termword {
  background: rgba(56, 189, 248, 0.26);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.26);
  border-radius: 3px;
  cursor: help;
}
.explain-on .termword:hover, .explain-on .termword:focus-visible { background: rgba(56, 189, 248, 0.45); outline: none; }
.term-tip {
  position: fixed;
  z-index: 200; /* 拡大した図 (z-index 100) の上にも出す */
  max-width: min(340px, calc(100vw - 16px));
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-left: 4px solid #38bdf8;
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  padding: 8px 12px;
  font-size: 0.85rem;
  line-height: 1.6;
  pointer-events: none;
}
.term-tip[hidden] { display: none; }

/* 図 (SVG) の中の印: 文字の上に重ねる半透明の四角 (app.js の annotateDiagram)。解説がオフのときは見えない */
.sim-diagram rect.termword, .sim-diagram rect.cmdword { fill: transparent; stroke: none; pointer-events: none; }
.explain-on .sim-diagram rect.termword, .explain-on .sim-diagram rect.cmdword { pointer-events: auto; cursor: help; }
.explain-on .sim-diagram rect.termword { fill: rgba(56, 189, 248, 0.26); }
.explain-on .sim-diagram rect.termword:hover { fill: rgba(56, 189, 248, 0.45); }
.explain-on .sim-diagram rect.cmdword { fill: rgba(250, 204, 21, 0.28); }
.explain-on .sim-diagram rect.cmdword:hover { fill: rgba(250, 204, 21, 0.5); }

/* 前にクリアしたステップの印 (タイトルの横) */
.cleared-badge {
  display: inline-block;
  margin-left: 10px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--ok-soft);
  color: var(--ok);
  font-size: 0.72rem;
  font-weight: 700;
  vertical-align: middle;
}

.cmd-tip .tip-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.cmd-tip .tip-head code { font-weight: 700; }
.cmd-tip .tip-en { color: var(--muted); font-size: 0.78rem; }

.check { margin: 16px 0; }
.check-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.check-hint {
  width: 100%;
  margin-top: 10px;
  padding: 8px 12px;
  border-radius: 6px;
  background: var(--accent-soft);
  font-size: 0.9rem;
  line-height: 1.6;
}
.check-hint[hidden] { display: none; }
.hint-label { font-weight: 700; color: var(--accent); margin-right: 8px; }
.check-result.cleared-now { animation: pop 0.35s ease-out; }
@keyframes pop { from { transform: scale(0.6); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .check-result.cleared-now { animation: none; } }
.check-answer { width: 100%; margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border); }
.check-answer[hidden] { display: none; }
.answer-label { font-weight: 700; font-size: 0.85rem; color: var(--accent); }
.check-answer .commands { margin: 8px 0; }
.answer-note { font-size: 0.88rem; margin: 6px 0 0; }
.check-box {
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.check-box .label { color: var(--muted); font-size: 0.9rem; }
.check-result { font-size: 0.9rem; }
.check-result.ok { color: var(--ok); font-weight: 600; }
.check-result.ng { color: var(--ng); }
.check-box.passed { border-style: solid; border-color: var(--ok); background: var(--ok-soft); }

/* 前へ・次へ: レッスン欄の一番上に固定 (padding 分をはみ出させて、下を流れる本文を隠す) */
.step-nav {
  position: sticky;
  top: -20px; /* 固定位置はレッスン欄の padding の内側が基準になるので、その分上へ */
  z-index: 5; /* 目次 (.toc, z-index 10) より下 */
  display: flex;
  justify-content: space-between;
  margin: -20px -24px 12px;
  padding: 10px 24px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

/* ---- 確認ダイアログ ---- */
.modal {
  width: min(420px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}
.modal::backdrop { background: rgba(10, 12, 18, 0.55); }
.modal[open] { animation: modal-in 0.15s ease-out; }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
@media (prefers-reduced-motion: reduce) { .modal[open] { animation: none; } }
.modal form { padding: 20px 22px 18px; }
.modal h3 { margin: 0 0 10px; font-size: 1.1rem; }
.modal-body { font-size: 0.92rem; line-height: 1.7; }
.modal-body p { margin: 0 0 8px; }
.modal-body .muted { color: var(--muted); font-size: 0.85rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.modal .btn.danger-fill { background: var(--ng); border-color: var(--ng); color: #fff; }
.modal .btn.danger-fill:hover { filter: brightness(1.1); }

/* ---- 図解シミュレーター ---- */
.sim:empty { display: none; }
.sim {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  padding: 12px 14px;
  margin: 16px 0;
}
.sim-label { font-weight: 700; font-size: 0.9rem; margin-bottom: 8px; }
.sim-label span { font-weight: 400; color: var(--muted); font-size: 0.8rem; }
/* コマンド例 (.cmd) と同じく縦に1つずつ並べる (吹き出しが左端から出て、右のターミナルに隠れない) */
.sim-cmds { display: flex; flex-direction: column; gap: 6px; }
.sim-cmd {
  display: flex;
  align-items: center;
  width: 100%;
  text-align: left;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 0.9rem;
  color: #e6e6e6;
  background: var(--term-bg);
  border: 2px solid transparent;
  border-radius: 6px;
  padding: 6px 6px 6px 12px;
  cursor: pointer;
  white-space: pre-wrap;
  word-break: break-all;
}
.sim-cmd:hover { border-color: #555a6b; }
.sim-cmd.active { border-color: var(--accent); }
.sim-cmd .p { color: #8be28b; margin-right: 8px; flex: none; }
/* 右端の「▶ 試す」(コマンド例の「入力」「実行」ボタンと同じ見た目。行全体が押せる) */
.sim-cmd .label { flex: 1; min-width: 0; }
.sim-cmd .sim-try {
  flex: none;
  margin-left: 10px;
  border-radius: 4px;
  background: #3b3f4d;
  color: #fff;
  font-family: system-ui, sans-serif;
  font-size: 0.78rem;
  padding: 4px 8px;
  white-space: nowrap;
}
.sim-cmd:hover .sim-try { background: var(--accent); }
.sim-cmd .sim-try.tried { background: none; color: #4ade80; box-shadow: inset 0 0 0 1px #2f6b45; }
.sim-cmd:hover .sim-try.tried { background: #2f6b45; color: #fff; }
.sim-out {
  margin: 10px 0 0;
  background: var(--term-bg);
  color: #e6e6e6;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 0.8rem;
  line-height: 1.5;
  overflow-x: auto;
  white-space: pre;
}
.sim-out .p { color: #8be28b; }
.sim-hint { color: var(--muted); font-size: 0.85rem; margin: 0 0 8px; }
/* コマンドのすぐ下の注釈 (sims.js のコマンドに note を書くと出る) */
.sim-note { color: var(--muted); font-size: 0.82rem; margin: -2px 0 4px 4px; line-height: 1.5; }
.sim-diagram { margin-top: 10px; cursor: zoom-in; position: relative; }
.sim-diagram::after {
  content: "クリックで拡大";
  position: absolute;
  right: 4px;
  bottom: 2px;
  font-size: 0.7rem;
  color: var(--muted);
}
.sim-diagram svg { display: block; width: 100%; height: auto; }
.sim-diagram.zoom {
  position: fixed;
  inset: 0;
  z-index: 100;
  margin: 0;
  padding: 24px;
  background: var(--panel);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}
.sim-diagram.zoom::after { content: "クリックで戻る"; right: 16px; bottom: 12px; font-size: 0.85rem; }
.sim-diagram.zoom svg { max-width: 1200px; max-height: 100%; }
.sim-steps { counter-reset: s; list-style: none; padding: 0; margin: 8px 0 0; font-size: 0.9rem; }
.sim-steps li { counter-increment: s; display: flex; gap: 8px; margin: 6px 0; line-height: 1.6; }
/* 文は1つの span にまとめる (li が flex なので、用語の印 (.termword) が入ると文がばらばらの列に分かれてしまう) */
.sim-steps li > span { flex: 1; min-width: 0; }
.sim-steps li::before {
  content: counter(s);
  flex: none;
  width: 20px;
  height: 20px;
  margin-top: 2px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sim-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
  font-size: 0.82rem;
  color: var(--muted);
}

/* 図 (SVG) */
.sim-diagram .node rect, .sim-diagram .node ellipse { fill: var(--bg); stroke: var(--muted); stroke-width: 1.5; }
.sim-diagram .node.on rect { fill: var(--ok-soft); stroke: var(--ok); }
.sim-diagram .node.off rect { stroke-dasharray: 4 3; }
.sim-diagram .node.focus rect { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 2.5; }
.sim-diagram .node.cloud ellipse { stroke-dasharray: 5 4; }
.sim-diagram text { fill: var(--text); text-anchor: middle; font-size: 12px; font-family: inherit; }
.sim-diagram .t { font-weight: 700; font-size: 13px; }
.sim-diagram .s { fill: var(--muted); font-size: 11.5px; }
.sim-diagram .node.on .s, .sim-diagram .node.focus .s { fill: var(--text); }
.sim-diagram .note { fill: var(--muted); font-size: 10px; }
.sim-diagram .zone { fill: none; stroke: var(--border); stroke-width: 1.5; stroke-dasharray: 6 4; }
.sim-diagram .zone-t { text-anchor: start; fill: var(--muted); font-size: 11px; }
.sim-diagram .tree-line { stroke: var(--muted); stroke-width: 1.5; }
.sim-diagram .node rect.bar-bg { fill: var(--code-bg); stroke: none; }
.sim-diagram .node rect.bar-fill { fill: var(--ok); stroke: none; opacity: 0.55; }
.sim-diagram .port rect { stroke-width: 2; }
.sim-diagram .port.open rect { fill: var(--ok-soft); stroke: var(--ok); }
.sim-diagram .port.closed rect { fill: var(--bg); stroke: var(--muted); stroke-dasharray: 3 3; }
.sim-diagram .port text { font-weight: 700; font-size: 12px; }

.sim-diagram .flow line, .sim-diagram .flow path { fill: none; stroke-width: 2.5; stroke-dasharray: 7 5; animation: flow 0.9s linear infinite; }
.sim-diagram .flow.req line, .sim-diagram .flow.req path { stroke: var(--accent); }
.sim-diagram .flow.res line, .sim-diagram .flow.res path { stroke: var(--ok); }
.sim-diagram .flow.err line, .sim-diagram .flow.err path { stroke: var(--ng); }
.sim-diagram .ah.req, .sim-diagram .badge.req circle { fill: var(--accent); }
.sim-diagram .ah.res, .sim-diagram .badge.res circle { fill: var(--ok); }
.sim-diagram .ah.err, .sim-diagram .badge.err circle { fill: var(--ng); }
.sim-diagram .badge text { fill: #fff; font-size: 11px; font-weight: 700; }
.sim-diagram .lbl { text-anchor: start; font-size: 11.5px; font-weight: 600; paint-order: stroke; stroke: var(--panel); stroke-width: 4px; }
@keyframes flow { to { stroke-dashoffset: -24; } }
@media (prefers-reduced-motion: reduce) {
  .sim-diagram .flow line, .sim-diagram .flow path { animation: none; }
}

/* ---- 確認テスト ---- */
.quiz-q {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  margin: 12px 0;
  background: var(--panel);
}
.quiz-q.correct { border-color: var(--ok); }
.quiz-q .q { font-weight: 600; margin-bottom: 8px; }
.quiz-choices { display: flex; flex-direction: column; gap: 6px; }
.quiz-choices button {
  text-align: left;
  font: inherit;
  font-size: 0.92rem;
  color: inherit;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
}
.quiz-choices button:hover:not(:disabled) { border-color: var(--accent); }
.quiz-choices button.right { border-color: var(--ok); background: var(--ok-soft); }
.quiz-choices button.wrong { border-color: var(--ng); background: var(--ng-soft); }
.quiz-choices button:disabled { cursor: default; }
.quiz-feedback { margin-top: 8px; font-size: 0.9rem; }
.quiz-feedback .ok { color: var(--ok); font-weight: 600; }
.quiz-feedback .ng { color: var(--ng); font-weight: 600; }
.quiz-summary {
  border-radius: 8px;
  padding: 10px 14px;
  background: var(--code-bg);
  font-size: 0.95rem;
}
.quiz-summary.passed { background: var(--ok-soft); color: var(--ok); font-weight: 600; }

/* ---- 目次 ---- */
.toc {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  background: var(--bg);
  padding: 24px 16px 40px;
  z-index: 10;
}
.toc[hidden] { display: none; }
/* 目次を出している間は、外側をスクロールさせない (幅が狭いとき、目次の下にレッスン画面が見えてしまうため) */
.layout.toc-open { overflow: hidden; }
/* 目次の一番下の注意書き */
.toc-note { margin: 28px 0 0; text-align: center; color: var(--muted); font-size: 0.8rem; line-height: 1.6; }
.toc-inner { max-width: 960px; margin: 0 auto; }
.toc-hero {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 20px;
  margin-bottom: 20px;
}
.toc-hero h1 { font-size: 1.3rem; margin: 0 0 4px; }
.toc-hero .meta { color: var(--muted); font-size: 0.9rem; }
.toc-hero .grow { flex: 1; min-width: 220px; }
.bar { height: 8px; border-radius: 4px; background: var(--code-bg); overflow: hidden; margin-top: 8px; }
.bar > span { display: block; height: 100%; background: var(--accent); }
.toc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}
.toc-section {
  grid-column: 1 / -1;
  font-size: 1.05rem;
  margin: 12px 0 0;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--accent);
}
.toc-section:first-child { margin-top: 0; }
.toc-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}
.toc-card.complete { border-color: var(--ok); }
/* 枠のどこを押しても、そのレッスンの続きを開ける */
.toc-card { cursor: pointer; transition: border-color 0.12s, box-shadow 0.12s; }
.toc-card:hover { border-color: var(--accent); box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06); }
.toc-card h3 { margin: 0; font-size: 1.02rem; }
.toc-card h3 .num { color: var(--accent); margin-right: 6px; }
.toc-card .sum { color: var(--muted); font-size: 0.85rem; margin: 2px 0 8px; }
.toc-card .count { font-size: 0.8rem; color: var(--muted); }
.toc-steps { list-style: none; padding: 0; margin: 10px 0 0; }
.toc-steps button {
  display: flex;
  gap: 8px;
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 0.88rem;
  color: inherit;
  background: none;
  border: 0;
  border-radius: 5px;
  padding: 3px 6px;
  cursor: pointer;
}
.toc-steps button:hover { background: var(--code-bg); }
.toc-steps .mark { width: 1.1em; color: var(--muted); flex: none; }
.toc-steps .mark.on { color: var(--ok); }
.toc-steps .tag {
  margin-left: auto;
  font-size: 0.72rem;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 5px;
  flex: none;
}

.btn {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.small { font-size: 0.8rem; padding: 3px 10px; }
.btn.danger:hover:not(:disabled) { border-color: var(--ng); color: var(--ng); }

.term-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--term-bg);
}
.term-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: #16171f;
  color: #aab;
  font-size: 0.8rem;
}
.term-bar .spacer { flex: 1; }
.term-bar .btn { background: #262833; border-color: #363948; color: #ddd; }
.status::before { content: "●"; margin-right: 5px; color: #888; }
.env-notice {
  color: #fbbf77;
  border: 1px solid #7a5a2e;
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 0.75rem;
  white-space: nowrap;
}
.env-notice[hidden] { display: none; }
.status.connected::before { color: #4ade80; }
.status.error::before { color: #f87171; }
#terminal { flex: 1; min-height: 0; padding: 6px 0 0 8px; }

/* ---- 現在地マップ ---- */
.fsmap { background: #1a1b24; border-bottom: 1px solid #2c2e3b; color: #cfd3dc; font-size: 0.8rem; }
.fsmap-head { display: flex; align-items: center; gap: 10px; padding: 4px 10px; }
.fsmap-toggle {
  background: none;
  border: 0;
  color: #cfd3dc;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  padding: 2px 0;
}
.fsmap-toggle .caret { display: inline-block; transition: transform 0.15s; }
.fsmap.closed .caret { transform: rotate(-90deg); }
.fsmap-move { color: #fbbf77; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fsmap-body {
  max-height: 28vh;
  overflow-y: auto;
  padding: 2px 0 6px;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
}
.fsmap.closed .fsmap-body { display: none; }
.fsmap-empty { color: #8a90a0; padding: 4px 12px; font-family: system-ui, sans-serif; }
.fs-row { display: flex; align-items: center; gap: 5px; line-height: 1.55; white-space: nowrap; color: #9aa1b0; }
.fs-row .ic { font-size: 0.85em; }
.fs-row.path { color: #e6e8ec; }
.fs-row.here { background: rgba(233, 84, 32, 0.22); color: #fff; font-weight: 700; }
.fs-row.new { color: #86efac; }
.fs-row.gone { color: #f87171; }
.fs-row.gone .nm { text-decoration: line-through; }
.fs-row.more { color: #6b7280; font-style: italic; }
.fs-row .tag { font-family: system-ui, sans-serif; font-size: 0.72rem; font-weight: 700; margin-left: 6px; }
.fs-row .tag.here { color: #fbbf77; }
.fs-row .tag.new { color: #86efac; }
.fs-row .tag.gone { color: #f87171; }

@media (max-width: 1000px) {
  /* max-content: スクロールする箱 (レッスン一覧の帯) は auto だと高さ0まで縮められてしまうので、中身の高さを確保する */
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: max-content max-content 60vh; overflow-y: auto; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--border); display: flex; align-items: center; overflow-x: auto; overflow-y: hidden; }
  .section-label { flex: 0 0 auto; white-space: nowrap; padding: 4px 6px 4px 12px; }
  .lesson-item { flex: 0 0 auto; width: auto; white-space: nowrap; }
  .lesson-item .sub { display: none; }
  .lesson { overflow: visible; padding: 16px; }
  .step-nav { top: 0; margin: -16px -16px 12px; padding: 8px 16px; }
}
