:root {
  --ink: #1f2430;
  --ink-soft: #5b6473;
  --line: #e4e7ee;
  --bg: #f7f8fb;
  --card: #ffffff;
  --accent: #185FA5;
  --gold: #d4a017;
  --silver: #9aa3ad;
  --bronze: #b07a4b;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: -apple-system, "Segoe UI", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  line-height: 1.6;
}
.topbar {
  background: var(--card); border-bottom: 1px solid var(--line);
  padding: 12px 22px; position: sticky; top: 0; z-index: 5;
}
.brand h1 { font-size: 18px; margin: 0; }
.topsub { font-size: 12.5px; color: var(--ink-soft); }
.app { max-width: 1280px; margin: 0 auto; padding: 20px 22px 60px; }
.muted { color: var(--ink-soft); }
.lead { font-size: 14px; margin: 4px 0 18px; }
.loading, .error { padding: 40px; text-align: center; color: var(--ink-soft); }
.error { color: #b3261e; }

/* ブラウズ */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.comp-card {
  text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px; cursor: pointer; font: inherit; transition: border-color .15s, transform .05s;
}
.comp-card:hover { border-color: #c3ccdb; }
.comp-card:active { transform: scale(.995); }
.comp-name { font-size: 15px; font-weight: 600; margin-bottom: 2px; }
.comp-en { font-size: 11.5px; margin-bottom: 8px; }
.flow-en { font-size: 12px; margin: -1px 0 2px; }
.comp-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12px; }
.comp-sub { font-size: 12px; margin-top: 8px; }
.badge { font-size: 11.5px; padding: 2px 9px; border-radius: 999px; background: #eef1f6; color: #41495a; }
.badge.bt-tabular { background: #e6f1fb; color: #185FA5; }
.badge.bt-timeseries { background: #efeafe; color: #5a47b8; }

/* フロー */
.flow-head { display: flex; align-items: flex-start; gap: 14px; margin-bottom: 14px; }
.back {
  font: inherit; font-size: 13px; background: var(--card); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 12px; cursor: pointer; white-space: nowrap;
}
.back:hover { border-color: #c3ccdb; }
.flow-title h2 { font-size: 18px; margin: 0 0 2px; }
.flow-meta { font-size: 12.5px; }

.picker { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 6px 0 12px; }
.picker-label { font-size: 12px; margin-right: 2px; }
.chip {
  font: inherit; font-size: 12px; padding: 3px 10px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
}
.chip:hover { border-color: #c3ccdb; }
.chip.on { background: #eaf1fb; border-color: var(--accent); color: var(--accent); font-weight: 600; }
.chip.medal-gold { border-color: var(--gold); }
.chip.medal-silver { border-color: var(--silver); }
.chip.medal-bronze { border-color: var(--bronze); }

.legend { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--ink-soft); margin: 6px 0 12px; }
.legend-row { display: flex; align-items: center; gap: 6px 14px; flex-wrap: wrap; }
.lg-key { font-weight: 700; color: var(--ink); margin-right: 4px; }
.lg { display: inline-block; vertical-align: -1px; margin-right: 4px; }
.lg-many { width: 18px; height: 11px; border-radius: 2px; background: #3B6D11; }
.lg-mid  { width: 18px; height: 11px; border-radius: 2px; background: #97C459; }
.lg-few  { width: 18px; height: 11px; border-radius: 2px; background: #D85A30; }
.lg-none { width: 18px; height: 11px; border-radius: 2px; background: #b4b9c0; }
.lg-flow { width: 20px; height: 9px; border-radius: 2px; background: #b7c0cc; }
.lg-hero { width: 20px; height: 3px; border-radius: 2px; background: #185FA5; }
.badge-key { display: inline-block; padding: 1px 6px; border-radius: 4px; font-size: 11px; font-weight: 600; color: #41495a; margin-right: 3px; border: 1px solid; background: #fff; }
.bk-gold { border-color: #d4a017; }
.bk-silver { border-color: #9aa3ad; }
.bk-bronze { border-color: #b07a4b; }
.bk-none { border-color: #d7dce5; }
.bk-active { background: #eaf1fb; border-color: #185FA5; color: #185FA5; }

.flow-scroll { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px 4px; }
.flow-scroll svg { display: block; }

.detail {
  font-size: 13px; margin-top: 12px; padding: 12px 14px; background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; line-height: 1.8;
}
.detail-head { color: var(--ink); font-weight: 600; }
.code-link { display: inline-block; margin-left: 8px; font-size: 12.5px; font-weight: 600; color: #185FA5; text-decoration: none; padding: 2px 10px; border: 1px solid #bcd8f5; border-radius: 999px; background: #eaf1fb; }
.code-link:hover { background: #d8e8fb; }

/* 解法ツアー（学習ページ） */
.learn-btn { font: inherit; font-size: 12px; font-weight: 600; color: #185FA5; background: #eaf1fb; border: 1px solid #bcd8f5; border-radius: 999px; padding: 2px 12px; cursor: pointer; margin-left: 8px; }
.learn-btn:hover { background: #d8e8fb; }
.learn-note { font-size: 13px; margin: 6px 0 18px; line-height: 1.8; white-space: pre-line; }
.learn-phase { font-size: 15px; margin: 24px 0 10px; padding-bottom: 4px; border-bottom: 2px solid var(--line); color: var(--ink); }
.learn-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin-bottom: 12px; }
.learn-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.learn-stage { font-size: 15px; font-weight: 600; }
.learn-choice { font-size: 12.5px; font-weight: 600; color: #0F6E56; background: #e1f5ee; border-radius: 999px; padding: 2px 10px; }
.learn-dist { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 12px; margin-bottom: 10px; }
.dist-chip { font-size: 11.5px; padding: 1px 8px; border-radius: 999px; background: #f1f3f7; color: #5b6473; border: 1px solid var(--line); }
.dist-chip.on { background: #fff7e6; color: #8a5a00; border-color: #f0d9a8; font-weight: 600; }
.learn-code { background: #1f2430; color: #e8eaf0; font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 12px; line-height: 1.55; padding: 12px 14px; border-radius: 8px; overflow-x: auto; white-space: pre; margin: 0 0 10px; }
.learn-reason { font-size: 13.5px; line-height: 1.9; white-space: pre-wrap; }
.est-badge { display: inline-block; font-size: 11px; font-weight: 700; color: #8a5a00; background: #fef0d0; border: 1px solid #f0d9a8; border-radius: 4px; padding: 0 6px; margin-right: 8px; vertical-align: 1px; }

/* データ実習（EDA＋before→after） */
.data-btn { background: #fff7e6; border-color: #f0d9a8; }
.eda-intro { background: #eef4fb; border: 1px solid #cfe0f3; border-radius: 12px; padding: 14px 16px; margin: 4px 0 16px; }
.eda-intro-h { font-size: 13px; font-weight: 700; color: #185FA5; margin-bottom: 6px; }
.eda-intro-body { font-size: 13.5px; line-height: 1.95; white-space: pre-line; }
.eda-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; margin: 8px 0 16px; }
.eda-card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.eda-label { font-size: 12px; color: var(--ink-soft); margin-bottom: 4px; }
.eda-val { font-size: 15px; font-weight: 600; }
.table-wrap { overflow-x: auto; max-width: 100%; -webkit-overflow-scrolling: touch; }
.data-table { border-collapse: collapse; font-size: 11.5px; font-family: ui-monospace, Consolas, monospace; }
.data-table th, .data-table td { border: 1px solid var(--line); padding: 2px 8px; text-align: left; white-space: nowrap; }
.data-table th { background: #f1f3f7; font-weight: 600; color: #41495a; }
.demo-title { font-size: 13px; font-weight: 600; margin: 2px 0 8px; }
.demo-ba { display: flex; align-items: center; gap: 10px; overflow-x: auto; padding-bottom: 4px; }
.demo-cap { font-size: 11px; margin-bottom: 3px; }
.demo-arrow { font-size: 20px; color: var(--accent); font-weight: 700; }
.demo-added { font-size: 12px; margin-top: 8px; color: #0F6E56; }
.demo-note { font-size: 12.5px; margin-top: 6px; line-height: 1.8; white-space: pre-wrap; }
.demo-toggle { margin-top: 10px; }
.toggle-btn { font: inherit; font-size: 12px; background: #f1f3f7; border: 1px solid var(--line); border-radius: 8px; padding: 4px 12px; cursor: pointer; }
.toggle-btn:hover { background: #e7eaf0; }
.toggle-panel { margin-top: 8px; }
.tg-reason .toggle-btn { background: #fef0d0; border-color: #f0d9a8; color: #8a5a00; }
.tg-reason .toggle-btn:hover { background: #fce6b8; }
.tg-data .toggle-btn { background: #eaf1fb; border-color: #bcd8f5; color: #185FA5; }
.tg-glossary .toggle-btn { background: #e8f3ee; border-color: #b9ddca; color: #0F6E56; }
.tg-glossary .toggle-btn:hover { background: #d8ece1; }
.glossary { font-size: 13px; line-height: 1.85; background: #f4f9f6; border: 1px solid #d8ebe1; border-radius: 8px; padding: 10px 13px; }
.gl-sec { margin: 0 0 7px; }
.gl-sec:last-child { margin-bottom: 0; }
.gl-h { display: block; font-size: 11.5px; font-weight: 700; color: #0F6E56; margin-bottom: 1px; }

/* スマホ: before→after を縦積みにして、各表は横スクロールで全体を見られるように */
@media (max-width: 640px) {
  .demo-ba { flex-direction: column; align-items: stretch; overflow-x: visible; }
  .demo-side { min-width: 0; width: 100%; }
  .demo-side .table-wrap { width: 100%; }
  .demo-arrow { align-self: center; transform: rotate(90deg); margin: 2px 0; }
}
