/* ============================================================
   ML Visual Academy — shared/theme.css
   デザイントークン + 共通コンポーネント CSS（全ページ共通）
   章ページ・index.html はこのファイルのクラスのみを使用する。
   ============================================================ */

:root {
  /* --- カラートークン (SPEC §3) --- */
  --bg: #faf6ee;
  --card: #fffdf8;
  --ink: #2b2620;
  --ink-soft: #5a5245;
  --line: #e4dccb;
  --accent: #b0793a;
  --accent-soft: #f3e7d4;
  --ok: #3e7d4f;
  --ok-soft: #e1efe3;
  --ng: #b04a3a;
  --ng-soft: #f5e2de;
  --code-bg: #2d2a24;
  --code-ink: #f0ead9;

  /* --- レイアウト・その他トークン --- */
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 2px 10px rgba(43, 38, 32, 0.08);
  --shadow-lg: 0 10px 28px rgba(43, 38, 32, 0.16);
  --container-w: 960px;
  --font: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic UI",
    "Yu Gothic", Meiryo, sans-serif;
  --font-mono: Consolas, "SFMono-Regular", Menlo, "Courier New", monospace;
}

/* --- 章別アクセントカラー上書き (SPEC §3) --- */
body[data-chapter="ch01"] { --accent: #b0793a; --accent-soft: #f3e7d4; }
body[data-chapter="ch02"] { --accent: #8a6d3b; --accent-soft: #efe8d8; }
body[data-chapter="ch03"] { --accent: #3a6ea5; --accent-soft: #dce8f2; }
body[data-chapter="ch04"] { --accent: #a5533a; --accent-soft: #f3ded4; }
body[data-chapter="ch05"] { --accent: #6a5aa5; --accent-soft: #e5e0f2; }
body[data-chapter="ch06"] { --accent: #2f7d6d; --accent-soft: #d9ece8; }
body[data-chapter="ch07"] { --accent: #a5387a; --accent-soft: #f2dcea; }
body[data-chapter="ch08"] { --accent: #7d6a2f; --accent-soft: #ece6d3; }
body[data-chapter="ch09"] { --accent: #3a8aa5; --accent-soft: #d9edf2; }
body[data-chapter="ch10"] { --accent: #5a7d2f; --accent-soft: #e3ecd3; }
body[data-chapter="ch11"] { --accent: #7d3aa5; --accent-soft: #e6d9f2; }
body[data-chapter="ch12"] { --accent: #a5722f; --accent-soft: #f2e6d3; }
body[data-chapter="boss"] { --accent: #8f2f2f; --accent-soft: #f0d9d9; }

/* ============================================================
   リセット & ベース
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 18px;
  line-height: 1.8;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { color: var(--ink); line-height: 1.4; margin: 0 0 0.6em; }
h1 { font-size: clamp(26px, 4vw, 38px); }
h2 { font-size: clamp(22px, 3vw, 28px); }
h3 { font-size: clamp(19px, 2.4vw, 23px); }
p { margin: 0 0 1em; }
a { color: var(--accent); }
ul, ol { padding-left: 1.4em; }
img, svg { max-width: 100%; display: block; }

main {
  max-width: var(--container-w);
  margin: 0 auto;
  padding: 24px 20px 64px;
}

button {
  font-family: inherit;
  font-size: 16px;
  cursor: pointer;
}

/* タップ領域確保 */
button, a.chapter-nav-btn, .quiz-choice {
  min-height: 44px;
}

/* ============================================================
   .mla-header — 上部バー（サイト名 / 章タイトル / XPバー）
   ============================================================ */
.mla-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.mla-header-inner {
  max-width: var(--container-w);
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 20px;
}

.mla-brand {
  font-weight: 700;
  font-size: 17px;
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
}
.mla-brand:hover { text-decoration: underline; }

.mla-chapter-title {
  font-size: 16px;
  color: var(--ink-soft);
  font-weight: 600;
  flex: 1 1 auto;
  min-width: 120px;
}

.mla-header-status {
  flex: 0 0 auto;
  min-width: 200px;
}

/* ============================================================
   .xp-bar — XPバー（ヘッダー内 & index.html ステータスカードで再利用）
   ============================================================ */
.xp-bar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.xp-bar-track {
  position: relative;
  width: 160px;
  height: 12px;
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
  flex: 1 1 auto;
}

.xp-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent) 0%, #e8c98a 100%);
  transition: width 0.5s ease;
}

.xp-bar-label {
  font-size: 14px;
  color: var(--ink-soft);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}

.mla-level-badge {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  padding: 2px 9px;
  border-radius: 999px;
}

/* レベルアップ時のパルス */
@keyframes xp-pulse {
  0% { box-shadow: 0 0 0 0 rgba(176, 121, 58, 0.55); }
  70% { box-shadow: 0 0 0 14px rgba(176, 121, 58, 0); }
  100% { box-shadow: 0 0 0 0 rgba(176, 121, 58, 0); }
}
.xp-bar.level-up-pulse .xp-bar-track {
  animation: xp-pulse 0.9s ease-out 2;
}

/* 大きめ表示（index.html ステータスカード用） */
.xp-bar.xp-bar-lg .xp-bar-track { width: 100%; height: 18px; }
.xp-bar.xp-bar-lg .xp-bar-label { font-size: 16px; }

/* ============================================================
   .level-band — Lv1〜4 の帯見出し（深さが増すほど濃い配色）
   ============================================================ */
.level-band {
  position: relative;
  margin: 36px 0;
  padding: 22px 24px 22px 30px;
  border-radius: var(--radius);
  border-left: 6px solid var(--accent);
  background: var(--card);
  box-shadow: var(--shadow);
}

.level-band::before {
  content: "Lv" attr(data-level);
  position: absolute;
  top: -12px;
  left: 20px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  padding: 3px 12px;
  border-radius: 999px;
  box-shadow: var(--shadow);
}

.level-band h2, .level-band h3 { margin-top: 0; }

.level-band[data-level="1"] {
  background: color-mix(in srgb, var(--accent-soft) 45%, var(--card));
  border-left-color: color-mix(in srgb, var(--accent) 45%, var(--card));
}
.level-band[data-level="2"] {
  background: color-mix(in srgb, var(--accent-soft) 75%, var(--card));
  border-left-color: color-mix(in srgb, var(--accent) 65%, var(--card));
}
.level-band[data-level="3"] {
  background: var(--accent-soft);
  border-left-color: var(--accent);
  border-left-width: 8px;
}
.level-band[data-level="4"] {
  background: color-mix(in srgb, var(--accent) 16%, var(--card));
  border-left-color: var(--accent);
  border-left-width: 10px;
}

/* ============================================================
   .lab — インタラクティブ実験ラボ枠
   ============================================================ */
.lab {
  margin: 22px 0;
  padding: 20px;
  background: var(--card);
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
}

.lab-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 17px;
  color: var(--accent);
  margin-bottom: 12px;
}
.lab-title::before { content: "🧪"; }

.lab-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  margin: 14px 0;
}

.lab-controls label {
  font-size: 16px;
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  gap: 8px;
}

.lab input[type="range"] { accent-color: var(--accent); }
.lab input[type="range"],
.lab select {
  min-height: 32px;
}

.lab button,
.lab .lab-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-weight: 600;
  min-height: 44px;
}
.lab button:hover, .lab .lab-btn:hover { filter: brightness(1.08); }
.lab button:active, .lab .lab-btn:active { filter: brightness(0.95); }

.lab-task-list {
  margin-top: 14px;
  padding: 12px 16px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  font-size: 16px;
}
.lab-task-list li { margin-bottom: 6px; }
.lab-task-list li.done { color: var(--ok); text-decoration: line-through; }

/* ============================================================
   .quiz-box — クイズ
   ============================================================ */
.quiz-box {
  margin: 20px 0;
  padding: 22px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.quiz-progress {
  font-size: 15px;
  color: var(--ink-soft);
  font-weight: 600;
  margin-bottom: 10px;
}

.quiz-q-text {
  font-size: 19px;
  font-weight: 700;
  margin-bottom: 16px;
}

.quiz-choices {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.quiz-choice {
  text-align: left;
  padding: 12px 16px;
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.5;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.quiz-choice:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.quiz-choice:disabled { cursor: default; }

.quiz-choice.correct {
  border-color: var(--ok);
  background: var(--ok-soft);
  color: var(--ok);
  font-weight: 700;
}
.quiz-choice.incorrect {
  border-color: var(--ng);
  background: var(--ng-soft);
  color: var(--ng);
  font-weight: 700;
}
.quiz-choice.reveal-correct {
  border-color: var(--ok);
  box-shadow: inset 0 0 0 2px var(--ok-soft);
}

.quiz-explain {
  margin-top: 16px;
  padding: 14px 16px;
  background: var(--accent-soft);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm);
  font-size: 16px;
}

.quiz-next-btn, .quiz-retry-btn {
  margin-top: 18px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px 22px;
  font-weight: 700;
  font-size: 16px;
}
.quiz-next-btn:hover, .quiz-retry-btn:hover { filter: brightness(1.08); }

.quiz-summary h3 { color: var(--accent); }
.quiz-summary .quiz-score-line { font-size: 18px; margin-bottom: 8px; }
.quiz-summary .quiz-xp-line { color: var(--ink-soft); }
.quiz-summary .quiz-done-tag {
  display: inline-block;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 10px;
  border-radius: 999px;
  margin-bottom: 10px;
}

/* ============================================================
   .code-block — コードブロック（ダーク地・シンタックスハイライト）
   ============================================================ */
.code-block {
  background: var(--code-bg);
  color: var(--code-ink);
  border-radius: var(--radius);
  padding: 18px 20px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 15px;
  line-height: 1.7;
  margin: 16px 0;
}
.code-block code { white-space: pre; }

.tok-kw   { color: #7fb0e8; font-weight: 700; }
.tok-str  { color: #c9e08a; }
.tok-com  { color: #8a8577; font-style: italic; }
.tok-num  { color: #e8b26a; }

.code-note {
  font-size: 14px;
  color: var(--ink-soft);
  margin: -8px 0 14px;
}

.sim-btn {
  background: var(--ink);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-weight: 600;
  margin: 4px 0 14px;
}
.sim-btn:hover { filter: brightness(1.2); }

.sim-output {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-size: 15px;
  margin-bottom: 16px;
}

/* ============================================================
   .note / .warn — 補足・つまずき注意
   ============================================================ */
.note, .warn {
  margin: 18px 0;
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  font-size: 16px;
  border-left: 5px solid;
}

.note {
  background: var(--accent-soft);
  border-left-color: var(--accent);
}
.note::before { content: "💡 "; }

.warn {
  background: var(--ng-soft);
  border-left-color: var(--ng);
  color: #7a3324;
}
.warn::before { content: "⚠️ "; }

/* ============================================================
   .formula — 数式カード
   ============================================================ */
.formula {
  margin: 18px 0;
  padding: 20px 24px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.formula-expr {
  font-size: 22px;
  font-family: var(--font-mono);
  color: var(--ink);
  text-align: center;
  margin-bottom: 12px;
  overflow-x: auto;
}

.formula-read {
  font-size: 16px;
  color: var(--ink-soft);
}
.formula-read::before { content: "読み下し: "; font-weight: 700; color: var(--ink); }

/* ============================================================
   .chapter-nav — 前後章ナビ
   ============================================================ */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 56px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

.chapter-nav-btn {
  display: inline-flex;
  align-items: center;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  background: var(--card);
  border: 2px solid var(--accent);
  color: var(--accent);
  text-decoration: none;
  font-weight: 700;
  font-size: 16px;
}
.chapter-nav-btn:hover { background: var(--accent-soft); }

.chapter-nav-home {
  background: var(--accent);
  color: #fff;
}
.chapter-nav-home:hover { filter: brightness(1.08); }

/* ============================================================
   .badge-chip — バッジ表示
   ============================================================ */
.badge-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 14px;
  font-weight: 700;
  margin: 4px 6px 4px 0;
}
.badge-chip::before { content: "🏅"; }

/* ============================================================
   トースト（右下スライドイン）
   ============================================================ */
.mla-toast-stack {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(340px, calc(100vw - 32px));
}

.mla-toast {
  background: var(--ink);
  color: #fff;
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: 15px;
  font-weight: 600;
  transform: translateX(120%);
  opacity: 0;
  transition: transform 0.35s ease, opacity 0.35s ease;
}
.mla-toast.show { transform: translateX(0); opacity: 1; }

.mla-toast-xp { background: var(--accent); }
.mla-toast-badge { background: #4a3f6b; }
.mla-toast-levelup {
  background: linear-gradient(90deg, var(--accent), #e8b26a);
  font-size: 16px;
}

/* ============================================================
   汎用レイアウトヘルパー
   ============================================================ */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  align-items: start;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  text-decoration: none;
}
.btn:hover { filter: brightness(1.08); }
.btn.btn-outline {
  background: transparent;
  border: 2px solid var(--accent);
  color: var(--accent);
}

/* ============================================================
   レスポンシブ (360px〜1400px, 900px以下で2カラム→縦積み)
   ============================================================ */
@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
  .mla-header-inner { flex-direction: column; align-items: stretch; }
  .mla-header-status { min-width: 0; }
  .xp-bar-track { width: auto; }
  .chapter-nav { flex-direction: column; align-items: stretch; }
  .chapter-nav-btn { justify-content: center; }
}

@media (max-width: 480px) {
  body { font-size: 18px; }
  main { padding: 16px 14px 48px; }
  .lab, .quiz-box, .formula, .card { padding: 16px; }
  .level-band { padding: 18px 16px 18px 20px; }
  .mla-toast-stack { left: 12px; right: 12px; max-width: none; }
}
