:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1d2330;
  --muted: #667085;
  --border: #dfe3ea;
  --accent: #2563eb;
  --accent-soft: #e8efff;
  --ok: #157f3b;
  --ok-soft: #e7f6ec;
  --ng: #b42318;
  --ng-soft: #fdecea;
  --warn: #b54708;
  --code-bg: #f3f4f6;
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  font-size: 15px;
  line-height: 1.9; /* 文章の行間(コードは別に指定) */
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
h1 { font-size: 1.5rem; margin: 0.2em 0 0.6em; }
h2 { font-size: 1.1rem; margin: 0 0 0.6em; }
code { background: var(--code-bg); padding: 0 4px; border-radius: 4px; font-size: 0.92em; }
button {
  font: inherit; cursor: pointer; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); border-radius: 8px; padding: 6px 14px;
}
button:hover { border-color: var(--accent); }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.ghost { background: transparent; color: var(--muted); }
button.link, .link { border: none; background: none; color: var(--accent); padding: 4px 8px; cursor: pointer; }
input, textarea { font: inherit; border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; background: var(--surface); color: var(--text); }
.small { font-size: 0.87rem; }
.muted { color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.badge { display: inline-block; font-size: 0.78rem; padding: 0 8px; border-radius: 99px; background: var(--code-bg); color: var(--muted); margin-left: 6px; }
.badge.final { background: #fff4e5; color: var(--warn); }
.warn { color: var(--warn); font-weight: 600; }
.okc { color: var(--ok); font-weight: 600; }

/* ヘッダー */
header.top {
  display: flex; align-items: center; gap: 16px; padding: 8px 20px; background: var(--surface);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; flex-wrap: wrap;
}
.brand { font-weight: 700; }
.teacher-tag { margin-left: 8px; font-size: 0.75rem; background: #fff4e5; color: var(--warn); padding: 1px 8px; border-radius: 99px; }
header nav { flex: 1; }
header .right { display: flex; gap: 12px; align-items: center; font-size: 0.87rem; }
.py { padding: 2px 10px; border-radius: 99px; font-size: 0.8rem; }
.py-loading { background: #fff4e5; color: var(--warn); }
.py-ready { background: var(--ok-soft); color: var(--ok); }
.py-error { background: var(--ng-soft); color: var(--ng); }

main.narrow { max-width: 760px; margin: 24px auto; padding: 0 16px; }
main.wide { max-width: 1100px; margin: 24px auto; padding: 0 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 24px; margin-bottom: 16px; }
.form { display: grid; gap: 12px; max-width: 360px; }
.form label { display: grid; gap: 4px; font-weight: 600; }
.eyebrow { color: var(--muted); font-size: 0.9rem; }

/* 回の一覧 */
.lesson-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.lesson-card { text-align: left; padding: 16px 18px; border-radius: var(--radius); display: grid; gap: 4px; }
.lesson-card.disabled { opacity: 0.7; }
.lesson-card .ln { color: var(--muted); font-size: 0.85rem; }
.lesson-card .lt { font-weight: 700; font-size: 1.05rem; }
.lesson-card .ls { font-size: 0.88rem; color: var(--muted); }
.lesson-card .lp { margin-top: 6px; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.count { margin-left: 8px; font-size: 0.85rem; color: var(--muted); }

/* 状態アイコン(色だけに依存しないよう記号も変える) */
.st { display: inline-flex; width: 22px; height: 22px; align-items: center; justify-content: center; border-radius: 50%; font-size: 0.8rem; border: 1px solid var(--border); color: var(--muted); flex: none; }
.st-graded_wrong { background: var(--ng-soft); color: var(--ng); border-color: transparent; }
.st-in_progress, .st-example_viewed { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.st-completed_self { background: var(--ok); color: #fff; border-color: transparent; }
.st-completed_after_reveal { background: var(--ok-soft); color: var(--ok); border-color: var(--ok); }

/* 導入画面 */
.situation .headline { font-size: 1.1rem; font-weight: 600; }
.situation dl { display: grid; grid-template-columns: 11em 1fr; gap: 8px 12px; margin: 0; }
.situation dt { font-weight: 700; color: var(--muted); }
.situation dd { margin: 0; }
.flow { padding-left: 1.2em; }
.flow li { margin: 6px 0; display: list-item; }

/* 問題画面 */
.situation-bar { background: var(--accent-soft); padding: 8px 20px; font-size: 0.9rem; cursor: pointer; border-bottom: 1px solid var(--border); }
.situation-full { margin-top: 6px; }
.situation-full p { margin: 2px 0; }
.layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 20px; max-width: 1200px; margin: 0 auto; padding: 20px 16px; }
.side { position: sticky; top: 64px; align-self: start; display: grid; gap: 4px; }
.side-title { font-weight: 700; font-size: 0.9rem; margin-bottom: 6px; }
.pnav { display: flex; gap: 8px; align-items: center; text-align: left; border-color: transparent; background: transparent; padding: 6px 8px; }
.pnav.active { background: var(--surface); border-color: var(--border); font-weight: 600; }
.step { color: var(--accent); font-weight: 700; font-size: 0.9rem; }
.context { color: var(--muted); margin-top: -0.4em; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 20px; margin-bottom: 14px; }
.panel:empty { display: none; }
.md p { margin: 0.6em 0; }
.md-code { line-height: 1.5; background: var(--code-bg); padding: 10px 12px; border-radius: 8px; overflow-x: auto; font-size: 0.88rem; }
.md-code code { background: none; padding: 0; }
.md-table { line-height: 1.6; border-collapse: collapse; margin: 8px 0; font-size: 0.9rem; }
.md-table th, .md-table td { border: 1px solid var(--border); padding: 4px 10px; text-align: left; vertical-align: top; }
.md-table th { background: var(--code-bg); }
.wide-table { width: 100%; }
.answer-spec { background: var(--code-bg); border-radius: 8px; padding: 8px 12px; margin: 10px 0; }
.answer-spec p, .answer-spec ul { margin: 0.2em 0; }
details { margin: 8px 0; }
summary { cursor: pointer; color: var(--accent); }
.dataset summary { color: var(--text); }
.code { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.code .CodeMirror { line-height: 1.5; height: auto; min-height: 60px; font-size: 14px; font-family: Menlo, Consolas, monospace; }
.code-fallback { line-height: 1.5; width: 100%; border: none; font-family: Menlo, Consolas, monospace; font-size: 14px; padding: 8px; resize: vertical; }
.actions { display: flex; gap: 8px; margin: 10px 0; flex-wrap: wrap; }
.output { border-top: 1px dashed var(--border); padding-top: 8px; }
.stdout, .err { line-height: 1.5; white-space: pre-wrap; font-family: Menlo, Consolas, monospace; font-size: 13px; margin: 6px 0; padding: 8px 10px; border-radius: 6px; overflow-x: auto; }
.stdout { background: var(--code-bg); }
.err { background: var(--ng-soft); color: var(--ng); }
.df-wrap { overflow-x: auto; }
.df-wrap table { line-height: 1.4; border-collapse: collapse; font-size: 13px; }
.df-wrap th, .df-wrap td { border-bottom: 1px solid var(--border); padding: 3px 10px; text-align: right; }
.fig { max-width: 100%; display: block; margin: 8px 0; }
.verdict { padding: 8px 12px; border-radius: 8px; font-weight: 700; margin-bottom: 8px; }
.verdict.ok { background: var(--ok-soft); color: var(--ok); }
.verdict.ng { background: var(--ng-soft); color: var(--ng); }
.checks { list-style: none; padding: 0; margin: 0; }
.checks li { padding: 6px 0; }
.checks .mark { display: inline-block; width: 1.5em; font-weight: 700; }
.checks .ok .mark { color: var(--ok); }
.checks .ng .mark { color: var(--ng); }
.why { margin-left: 1.5em; color: var(--ng); font-size: 0.9rem; }
.hints li { margin: 6px 0; }
.inline-form { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; }
.inline-form label { display: grid; gap: 4px; font-size: 0.9rem; }
.conclusion { border-color: var(--warn); }
.cfield { display: grid; gap: 2px; margin: 10px 0; }
.cfield > span:first-child { font-weight: 700; }
.cfield textarea { width: 100%; resize: vertical; }
.pager { display: flex; justify-content: space-between; margin: 20px 0 40px; }
.warn-list { color: var(--warn); }
.teacher { margin-top: 24px; border-color: var(--warn); }

/* 授業後の発展課題 */
.badge.adv { background: #efe9fb; color: #5b3fa0; }
.adv-sep { font-size: 0.72rem; color: #5b3fa0; margin: 0 2px 0 6px; }
.side-sep { font-size: 0.8rem; font-weight: 700; color: #5b3fa0; margin: 10px 0 2px; border-top: 1px solid var(--border); padding-top: 8px; }

/* 例題の入力ガイド(コピーではなく手で入力してもらうため、選択できないようにする) */
.guide { background: #fffaf0; border: 1px solid #f5d9a8; border-radius: 8px; padding: 10px 14px; margin: 10px 0; }
.guide h3 { margin: 0 0 4px; font-size: 1rem; }
.guide p { margin: 0 0 6px; }
.guide-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.guide-list li { display: flex; gap: 10px; align-items: flex-start; }
.guide-list .num { font-weight: 700; color: var(--warn); font-size: 1.05rem; line-height: 1.6; }
.guide-list .note { font-size: 0.87rem; color: var(--muted); }
.type-me { user-select: none; -webkit-user-select: none; font-size: 0.95rem; padding: 2px 8px; background: #fff; border: 1px dashed #e0b56a; }
.ex-done summary { color: var(--ok); }
.result { margin-top: 6px; }

/* 項目ごとの解答欄 */
.part h2 { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.pnum { color: var(--accent); }
.pstat { font-size: 0.85rem; font-weight: 700; margin-left: auto; }
.pstat.ok { color: var(--ok); }
.pstat.ng { color: var(--ng); }
.hint-box .hints { background: var(--accent-soft); border-radius: 8px; padding: 8px 12px; margin: 8px 0; }
.hint-box .hints ol { margin: 4px 0 0; padding-left: 1.4em; }
.hint-box button { margin-top: 4px; }
.problem-status { margin: 8px 0; }

/* あなたが発見した結論(5択) */
.question { border-top: 1px solid var(--border); padding: 12px 0; }
.question:first-of-type { border-top: none; }
.qhead { font-weight: 700; }
.qlabel { color: var(--warn); }
.opts { display: grid; gap: 8px; margin: 10px 0; max-width: 44em; }
.opt { display: flex; gap: 8px; align-items: flex-start; border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; cursor: pointer; }
.opt input { margin-top: 0.35em; }
.opt .onum { font-weight: 700; color: var(--muted); min-width: 1em; }
.opt.correct { border-color: var(--ok); background: var(--ok-soft); }
.opt.chosen-wrong { border-color: var(--ng); background: var(--ng-soft); }
.explain { font-size: 0.92rem; margin-top: 4px; }
.qmsg { margin-left: 8px; }

/* 読みやすさのため、文章の1行を全角40字程度までに抑える(表・コードは対象外) */
.md p, .md li, .card > p, .panel > p, .checks li, .verdict, .answer-spec, .situation-bar > *:not(.situation-full) { max-width: 40em; }
.md ul, .md ol { margin: 0.6em 0; padding-left: 1.4em; }
.md li { margin: 0.35em 0; }
.md li ul { margin: 0.2em 0; }
.context p { margin: 0.3em 0; }
.situation dd p { margin: 0 0 0.3em; }
.situation-full dl { display: grid; grid-template-columns: 6em 1fr; gap: 4px 12px; margin: 8px 0 0; max-width: 52em; }
.situation-full dt { font-weight: 700; }
.situation-full dd { margin: 0; }
.situation-full dd p { margin: 0; }

@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: static; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .situation dl { grid-template-columns: 1fr; }
}
