:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #1f2933;
  --ink-soft: #52606d;
  --line: #e1e5ea;
  --brand: #0e8a8a;
  --brand-dark: #0a6e6e;
  --brand-soft: #e3f4f4;
  --ok: #1f9d55;
  --ok-soft: #e6f6ec;
  --ng: #d64545;
  --ng-soft: #fbeaea;
  --warn: #b7791f;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 12px rgba(0,0,0,.04);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", Meiryo, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.7;
  -webkit-text-size-adjust: 100%;
}
.app-header {
  background: linear-gradient(135deg, var(--brand), var(--brand-dark));
  color: #fff;
  padding: 14px 20px;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: var(--shadow);
}
.app-header h1 { margin: 0; font-size: 1.15rem; cursor: pointer; display: inline-block; }
.header-sub { font-size: .76rem; opacity: .85; margin-top: 2px; }
.app-footer {
  text-align: center;
  color: var(--ink-soft);
  font-size: .74rem;
  padding: 24px 16px 40px;
}
#app { max-width: 760px; margin: 0 auto; padding: 18px 16px 8px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
h2.section-title { font-size: 1rem; margin: 4px 0 14px; color: var(--ink); }

/* ---- ダッシュボード ---- */
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat {
  background: var(--brand-soft);
  border-radius: 12px;
  padding: 12px 8px;
  text-align: center;
}
.stat .num { font-size: 1.5rem; font-weight: 700; color: var(--brand-dark); }
.stat .lbl { font-size: .72rem; color: var(--ink-soft); margin-top: 2px; }
.progress-line { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 14px; }
.progress-line > span { display: block; height: 100%; background: var(--brand); transition: width .3s; }
.progress-cap { font-size: .76rem; color: var(--ink-soft); margin-top: 6px; }

/* ---- メニュー ---- */
.menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mode-btn {
  display: flex; flex-direction: column; gap: 4px;
  text-align: left;
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  cursor: pointer;
  font: inherit;
  transition: border-color .15s, transform .05s;
}
.mode-btn:hover { border-color: var(--brand); }
.mode-btn:active { transform: scale(.99); }
.mode-btn .mb-title { font-weight: 700; font-size: .96rem; }
.mode-btn .mb-desc { font-size: .76rem; color: var(--ink-soft); }
.mode-btn.wide { grid-column: 1 / -1; }
.mode-btn.danger { border-color: var(--ng); color: var(--ng); }

label.field { display: block; margin-bottom: 12px; font-size: .85rem; color: var(--ink-soft); }
label.field select, label.field input {
  display: block; width: 100%; margin-top: 5px;
  padding: 9px 10px; font: inherit;
  border: 1.5px solid var(--line); border-radius: 9px; background: #fff;
}
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--brand); color: #fff; border: none;
  padding: 11px 18px; border-radius: 10px; font: inherit; font-weight: 700;
  cursor: pointer; transition: background .15s, transform .05s;
}
.btn:hover { background: var(--brand-dark); }
.btn:active { transform: scale(.98); }
.btn:disabled { background: #b8c2cc; cursor: default; }
.btn.ghost { background: transparent; color: var(--brand); border: 1.5px solid var(--brand); }
.btn.ghost:hover { background: var(--brand-soft); }
.btn.block { width: 100%; }
.btn-row { display: flex; gap: 10px; margin-top: 10px; }

/* ---- クイズ ---- */
.quiz-top { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.quiz-top .qprog { font-size: .82rem; color: var(--ink-soft); white-space: nowrap; }
.quiz-top .bar { flex: 1; height: 7px; background: var(--line); border-radius: 99px; overflow: hidden; }
.quiz-top .bar > span { display: block; height: 100%; background: var(--brand); transition: width .25s; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--brand-dark); }
.timer.warn { color: var(--ng); }

.qmeta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 4px 0 10px; }
.badge {
  font-size: .72rem; padding: 2px 9px; border-radius: 99px;
  background: var(--brand-soft); color: var(--brand-dark); font-weight: 700;
}
.badge.cat { background: #eef1f4; color: var(--ink-soft); }
.badge.multi { background: #fdf0d9; color: var(--warn); }
.badge.excl { background: var(--ng-soft); color: var(--ng); }
.stars { color: #e0a800; letter-spacing: 1px; font-size: .85rem; }

.stem { font-size: 1.04rem; white-space: pre-wrap; margin: 6px 0 14px; }
.fig { text-align: center; margin: 12px 0; }
.fig img {
  max-width: 100%; border: 1px solid var(--line); border-radius: 8px;
  cursor: zoom-in; background: #fff;
}

.choices { display: flex; flex-direction: column; gap: 9px; }
.choice {
  display: flex; align-items: flex-start; gap: 10px;
  border: 1.5px solid var(--line); border-radius: 11px;
  padding: 11px 13px; cursor: pointer; background: #fff;
  font: inherit; text-align: left; transition: border-color .12s, background .12s;
}
.choice:hover { border-color: var(--brand); }
.choice .ci {
  flex: none; width: 26px; height: 26px; border-radius: 50%;
  background: #eef1f4; color: var(--ink-soft);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .85rem;
}
.choice .ct { flex: 1; }
.choice.selected { border-color: var(--brand); background: var(--brand-soft); }
.choice.selected .ci { background: var(--brand); color: #fff; }
.choice.correct { border-color: var(--ok); background: var(--ok-soft); }
.choice.correct .ci { background: var(--ok); color: #fff; }
.choice.wrong { border-color: var(--ng); background: var(--ng-soft); }
.choice.wrong .ci { background: var(--ng); color: #fff; }
.choice.locked { cursor: default; }
.choice.locked:hover { border-color: inherit; }

.result-tag { font-weight: 700; margin: 14px 0 8px; font-size: 1.05rem; }
.result-tag.ok { color: var(--ok); }
.result-tag.ng { color: var(--ng); }
.expl {
  background: #fbfcfd; border: 1px solid var(--line); border-left: 4px solid var(--brand);
  border-radius: 8px; padding: 13px 15px; margin-top: 6px;
  white-space: pre-wrap; font-size: .92rem; color: var(--ink);
}
.expl-label { font-size: .76rem; color: var(--brand-dark); font-weight: 700; margin-bottom: 4px; }

/* ---- 結果画面 ---- */
.score-big { text-align: center; padding: 8px 0 4px; }
.score-big .pct { font-size: 3rem; font-weight: 800; color: var(--brand-dark); line-height: 1; }
.score-big .frac { color: var(--ink-soft); margin-top: 6px; }
.review-item {
  display: flex; gap: 10px; align-items: baseline;
  padding: 8px 4px; border-bottom: 1px solid var(--line); font-size: .88rem;
}
.review-item .ri-mark { font-weight: 700; flex: none; }
.review-item .ri-mark.ok { color: var(--ok); }
.review-item .ri-mark.ng { color: var(--ng); }
.review-item .ri-link { color: var(--brand-dark); cursor: pointer; text-decoration: underline; }

/* ---- 画像ズーム ---- */
.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,.82);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px;
  cursor: zoom-out;
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 6px; background:#fff; }

.empty { text-align: center; color: var(--ink-soft); padding: 24px; }

@media (max-width: 560px) {
  .stat .num { font-size: 1.25rem; }
  .menu-grid { grid-template-columns: 1fr; }
  .stem { font-size: 1rem; }
}
