:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --ink: #1f2933;
  --muted: #6b7785;
  --line: #e1e6ec;
  --brand: #2563eb;
  --brand-d: #1d4ed8;
  --ok: #16a34a;
  --ng: #dc2626;
  --warn: #d97706;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 8px 24px rgba(0,0,0,.04);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic UI", Meiryo, system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
}

.appbar {
  position: sticky; top: 0; z-index: 10;
  background: #fff; border-bottom: 1px solid var(--line);
  padding: 10px 16px;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.appbar h1 { font-size: 18px; margin: 0; white-space: nowrap; }
.tabs { display: flex; gap: 6px; margin-left: auto; }
.tab {
  border: none; background: transparent; color: var(--muted);
  padding: 8px 14px; border-radius: 999px; cursor: pointer; font-size: 14px; font-weight: 600;
}
.tab.active { background: var(--brand); color: #fff; }
.install {
  background: var(--ok); color: #fff; padding: 8px 14px; font-size: 13px;
  border-radius: 999px; white-space: nowrap;
}
.install:hover { background: #15803d; }

/* オフライン保存の進捗 */
.offline-progress { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.offline-progress .bar { flex: 1; background: #eef2f7; border-radius: 999px; height: 14px; overflow: hidden; }
.offline-progress .bar > span { display: block; height: 100%; background: var(--ok); transition: width .2s; }
.offline-progress .val { font-size: 13px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

main { max-width: 880px; margin: 0 auto; padding: 16px; }
.view { display: none; }
.view.active { display: block; }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; margin-bottom: 16px;
}
.card h2 { margin: 0 0 12px; font-size: 16px; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
label { display: flex; flex-direction: column; font-size: 13px; color: var(--muted); gap: 4px; }
select {
  padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 14px; background: #fff; color: var(--ink);
}

button, .btn {
  font-size: 14px; font-weight: 600; border-radius: 10px; cursor: pointer;
  padding: 10px 18px; border: 1px solid transparent; text-decoration: none; display: inline-block;
}
.primary { background: var(--brand); color: #fff; }
.primary:hover { background: var(--brand-d); }
.ghost { background: #fff; color: var(--ink); border-color: var(--line); }
.ghost:hover { background: #f0f3f8; }
.danger { background: #fff; color: var(--ng); border-color: #f3c5c5; }
.danger:hover { background: #fdecec; }
#btn-start { margin-top: 14px; }

.hidden { display: none !important; }

.quiz-head { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 12px 18px; }
.pill { background: var(--brand); color: #fff; padding: 4px 12px; border-radius: 999px; font-size: 13px; font-weight: 700; }
.pill.ghost { background: #eef2f7; color: var(--muted); }

.q-image-wrap {
  border: 1px solid var(--line); border-radius: 10px; background: #fff;
  padding: 8px; text-align: center; overflow: auto;
}
#q-image { max-width: 100%; height: auto; cursor: zoom-in; }

.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(64px, 1fr)); gap: 10px; margin-top: 14px; }
.choice {
  font-size: 18px; font-weight: 700; padding: 14px 0; background: #fff;
  border: 2px solid var(--line); color: var(--ink); border-radius: 12px;
}
.choice:hover:not(:disabled) { border-color: var(--brand); }
.choice.sel { border-color: var(--brand); background: #eff4ff; }
.choice.correct { border-color: var(--ok); background: #e9f8ef; color: var(--ok); }
.choice.wrong { border-color: var(--ng); background: #fdeaea; color: var(--ng); }
.choice:disabled { cursor: default; }

.feedback { margin-top: 14px; padding: 12px 14px; border-radius: 10px; font-weight: 700; }
.feedback.ok { background: #e9f8ef; color: var(--ok); }
.feedback.ng { background: #fdeaea; color: var(--ng); }

.quiz-actions { display: flex; gap: 10px; margin-top: 16px; align-items: center; }
.quiz-actions .ghost { margin-left: auto; }

.big { font-size: 22px; font-weight: 800; margin: 4px 0 14px; }
.exports { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.note { font-size: 12px; color: var(--muted); margin: 10px 0 0; }

/* バー表示 */
.bar-row { display: grid; grid-template-columns: 110px 1fr 86px; gap: 10px; align-items: center; margin: 6px 0; font-size: 14px; }
.bar { background: #eef2f7; border-radius: 999px; height: 14px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--brand); }
.bar-row .val { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.bar-row.low .bar > span { background: var(--ng); }
.bar-row.mid .bar > span { background: var(--warn); }

/* 問題一覧 */
.qlist { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.qcard { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 8px; box-shadow: var(--shadow); }
.qcard img { width: 100%; height: 90px; object-fit: cover; object-position: top; border-radius: 6px; cursor: zoom-in; border: 1px solid var(--line); }
.qcard .meta { font-size: 12px; color: var(--muted); margin-top: 6px; display: flex; justify-content: space-between; }
.qcard .acc { font-weight: 700; }
.tag { font-size: 11px; background: #eef2f7; color: var(--muted); padding: 1px 7px; border-radius: 999px; }

.weak-item { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.weak-item:last-child { border-bottom: none; }
.weak-item .acc { font-weight: 700; color: var(--ng); }

/* 成績ページ（演習後） */
.result-actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 6px 0 4px; }
h3.sub { font-size: 15px; margin: 18px 0 8px; }
.result-list { display: flex; flex-direction: column; gap: 8px; }
.result-row { display: flex; align-items: center; gap: 10px; padding: 8px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.result-row.ng { border-color: #f3c5c5; background: #fff7f7; }
.result-row img { width: 64px; height: 48px; object-fit: cover; object-position: top; border-radius: 6px; border: 1px solid var(--line); cursor: zoom-in; flex: none; }
.result-row .r-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.result-row .r-title { font-size: 13px; font-weight: 600; }
.result-row .r-ans { font-size: 12px; color: var(--muted); }
.result-row .r-mark { font-size: 20px; font-weight: 800; flex: none; width: 28px; text-align: center; }
.result-row .r-mark.ok { color: var(--ok); }
.result-row .r-mark.ng { color: var(--ng); }
.result-details { margin-top: 14px; }
.result-details > summary { cursor: pointer; color: var(--brand); font-weight: 600; font-size: 14px; }
.result-details > summary + div { margin-top: 10px; }

/* 保存した成績 */
.sess-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.sess-row:last-child { border-bottom: none; }
.sess-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.sess-date { font-size: 12px; color: var(--muted); }
.sess-cond { font-size: 13px; }
.sess-score { font-size: 13px; font-weight: 700; }
.sess-acts { display: flex; gap: 8px; }
.sess-acts button { padding: 6px 12px; font-size: 13px; }

/* プロンプトモーダル */
.prompt-box { background: #fff; border-radius: 14px; padding: 18px; width: min(720px, 94vw); max-height: 90vh; display: flex; flex-direction: column; cursor: default; }
.prompt-box h3 { margin: 0 0 6px; }
#prompt-text { width: 100%; flex: 1; min-height: 300px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; line-height: 1.5; border: 1px solid var(--line); border-radius: 10px; padding: 10px; color: var(--ink); }
.prompt-actions { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }

/* 管理ダッシュボード */
.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; }
.stat-box { background: #f7f9fc; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; }
.stat-box .k { font-size: 12px; color: var(--muted); }
.stat-box .v { font-size: 22px; font-weight: 800; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); }
.tbl th { color: var(--muted); font-weight: 700; }
.tbl td.acc-bad { color: var(--ng); font-weight: 700; }
.tbl .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
input[type=text], input[type=password] {
  padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; font-size: 14px; background: #fff; color: var(--ink);
}
.tab[href] { text-decoration: none; }

/* モーダル */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.8);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; cursor: zoom-out;
}
.modal img { max-width: 100%; max-height: 100%; background: #fff; border-radius: 8px; }

@media (max-width: 560px) {
  .appbar h1 { font-size: 16px; }
  .tabs { width: 100%; margin-left: 0; }
  .tab { flex: 1; }
}
