/* styles.css — 技術士補 過去問トレーニング（モバイルファースト / 白・グレー・青 / ダークモード） */

:root {
  --blue: #1d4ed8;
  --blue-dark: #1e40af;
  --blue-soft: #eff6ff;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;
  --text-sub: #475569;
  --muted: #94a3b8;
  --border: #e2e8f0;
  --green: #16a34a;
  --green-soft: #dcfce7;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --amber: #d97706;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .06);
  --radius: 14px;
  --tap: 52px; /* 最小タップ領域 */
}

[data-theme="dark"] {
  --blue: #3b82f6;
  --blue-dark: #2563eb;
  --blue-soft: #1e293b;
  --bg: #0b1220;
  --surface: #111a2b;
  --surface-2: #0f1a2e;
  --text: #e7edf6;
  --text-sub: #b2c0d4;
  --muted: #6b7a90;
  --border: #243047;
  --green: #22c55e;
  --green-soft: #14361f;
  --red: #f87171;
  --red-soft: #3a1717;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; } /* author の display 指定に負けないよう明示 */

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  font-size: 17px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

body { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }

/* ---------- ヘッダ ---------- */
.appbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top));
  background: var(--blue); color: #fff;
  box-shadow: var(--shadow);
}
.appbar h1 { font-size: 18px; margin: 0; font-weight: 700; flex: 1; letter-spacing: .02em; }
.appbar .back { background: rgba(255,255,255,.16); border: none; color: #fff;
  width: 40px; height: 40px; border-radius: 10px; font-size: 20px; cursor: pointer; }
.icon-btn {
  background: rgba(255,255,255,.16); border: none; color: #fff;
  min-width: 40px; height: 40px; border-radius: 10px; font-size: 18px; cursor: pointer; padding: 0 10px;
}

/* ---------- レイアウト ---------- */
main { max-width: 640px; margin: 0 auto; padding: 16px; }
.view { animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px;
}
.section-title { font-size: 14px; color: var(--text-sub); font-weight: 700; margin: 18px 4px 8px; letter-spacing: .04em; }

/* ---------- ホーム: 統計 ---------- */
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 8px; text-align: center; box-shadow: var(--shadow);
}
.stat .num { font-size: 26px; font-weight: 800; color: var(--blue); line-height: 1.1; }
.stat .num small { font-size: 14px; }
.stat .lbl { font-size: 12px; color: var(--text-sub); margin-top: 4px; }

.goal {
  display: flex; align-items: center; gap: 12px;
  background: var(--blue-soft); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 14px;
}
.goal .ring { font-size: 22px; }
.goal .txt { flex: 1; font-size: 15px; color: var(--text-sub); }
.goal .txt b { color: var(--text); font-size: 17px; }
.progressbar { height: 8px; background: var(--border); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.progressbar > i { display: block; height: 100%; background: var(--blue); border-radius: 99px; transition: width .3s; }

/* ---------- ボタン ---------- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: var(--tap); padding: 14px 16px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); font-size: 16px; font-weight: 600;
  cursor: pointer; box-shadow: var(--shadow); text-decoration: none;
}
.btn:active { transform: scale(.99); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.big { min-height: 64px; font-size: 19px; font-weight: 800; }
.btn.ghost { background: transparent; box-shadow: none; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn .sub { font-weight: 500; font-size: 13px; opacity: .85; }

.menu-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.menu-grid .btn { flex-direction: column; min-height: 92px; gap: 4px; }
.menu-grid .btn .em { font-size: 26px; }
.menu-grid .btn .cap { font-size: 14px; }
.menu-grid .btn .badge {
  position: absolute; top: 8px; right: 10px; background: var(--red); color: #fff;
  border-radius: 99px; font-size: 11px; padding: 1px 7px; font-weight: 700;
}
.menu-grid .btn { position: relative; }

/* ---------- クイズ ---------- */
.quiz-top { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.quiz-top .prog { flex: 1; }
.quiz-top .prog .bar { height: 6px; background: var(--border); border-radius: 99px; overflow: hidden; }
.quiz-top .prog .bar > i { display: block; height: 100%; background: var(--blue); transition: width .3s; }
.quiz-top .prog .meta { font-size: 12px; color: var(--text-sub); margin-bottom: 4px; display: flex; justify-content: space-between; }

.q-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.tag { font-size: 12px; background: var(--surface-2); color: var(--text-sub);
  border: 1px solid var(--border); border-radius: 99px; padding: 3px 10px; font-weight: 600; }
.tag.blue { background: var(--blue-soft); color: var(--blue); border-color: var(--blue); }

.q-label { font-size: 22px; font-weight: 800; margin: 4px 0 2px; }
.q-text { font-size: 18px; line-height: 1.7; white-space: pre-wrap; }
.q-note { color: var(--text-sub); font-size: 14px; background: var(--surface-2);
  border: 1px dashed var(--border); border-radius: 10px; padding: 10px 12px; margin-top: 8px; }

/* PDF ビューア */
.pdfbox { margin-top: 12px; }
.pdfbox details { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--surface-2); }
.pdfbox summary { list-style: none; cursor: pointer; padding: 12px 14px; font-weight: 700; color: var(--blue); display: flex; align-items: center; gap: 8px; }
.pdfbox summary::-webkit-details-marker { display: none; }
.pdfbox .frame { width: 100%; height: 62vh; border: 0; border-top: 1px solid var(--border); background: #fff; }
.pdfbox .pdf-actions { display: flex; gap: 8px; padding: 10px; flex-wrap: wrap; }
.pdfbox .pdf-actions a { font-size: 13px; }
.pdfbox .hint { font-size: 12px; color: var(--text-sub); padding: 0 12px 10px; }

/* 選択肢 */
.choices { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.choice {
  display: flex; align-items: center; gap: 12px; width: 100%;
  min-height: var(--tap); padding: 12px 14px;
  border: 2px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); font-size: 17px; text-align: left; cursor: pointer;
}
.choice .no {
  flex: 0 0 auto; width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 800;
  background: var(--blue-soft); color: var(--blue); border: 1px solid var(--blue);
}
.choice .ct { flex: 1; }
.choice:active { transform: scale(.995); }
.choice.correct { border-color: var(--green); background: var(--green-soft); }
.choice.correct .no { background: var(--green); color: #fff; border-color: var(--green); }
.choice.wrong { border-color: var(--red); background: var(--red-soft); }
.choice.wrong .no { background: var(--red); color: #fff; border-color: var(--red); }
.choice[disabled] { cursor: default; }
.choice .mark { margin-left: auto; font-size: 20px; font-weight: 800; }

/* 結果 */
.result { margin-top: 16px; padding: 14px; border-radius: var(--radius); border: 1px solid var(--border); }
.result.ok { background: var(--green-soft); border-color: var(--green); }
.result.ng { background: var(--red-soft); border-color: var(--red); }
.result.skip { background: var(--surface-2); }
.result .head { font-size: 18px; font-weight: 800; display: flex; align-items: center; gap: 8px; }
.result.ok .head { color: var(--green); }
.result.ng .head { color: var(--red); }
.result .exp { margin-top: 8px; font-size: 15px; color: var(--text-sub); white-space: pre-wrap; }

.sticky-actions {
  position: sticky; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 5;
  display: flex; gap: 10px; margin-top: 16px;
}

/* ---------- リスト（復習・選択） ---------- */
.list { display: flex; flex-direction: column; gap: 10px; }
.list-item {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; cursor: pointer; box-shadow: var(--shadow);
}
.list-item .li-main { flex: 1; min-width: 0; }
.list-item .li-title { font-weight: 700; font-size: 15px; }
.list-item .li-sub { font-size: 12px; color: var(--text-sub); margin-top: 2px; }
.list-item .li-right { font-size: 13px; color: var(--muted); white-space: nowrap; }
.pill { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 99px; font-weight: 700; }
.pill.ng { background: var(--red-soft); color: var(--red); }
.pill.ok { background: var(--green-soft); color: var(--green); }

.tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.tabs .tab { flex: 1; padding: 10px; text-align: center; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface); font-weight: 700; cursor: pointer; color: var(--text-sub); }
.tabs .tab.active { background: var(--blue); color: #fff; border-color: var(--blue); }

.empty { text-align: center; color: var(--text-sub); padding: 40px 16px; }
.empty .em { font-size: 40px; }

/* セグメント選択 */
.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.seg button {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 99px; padding: 8px 14px; font-size: 14px; font-weight: 600; cursor: pointer; min-height: 40px;
}
.seg button.on { background: var(--blue); color: #fff; border-color: var(--blue); }

/* 進捗バー（分野別） */
.bars { display: flex; flex-direction: column; gap: 12px; }
.bar-row .bl { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 4px; }
.bar-row .bl .pct { font-weight: 800; }
.bar-row .track { height: 10px; background: var(--border); border-radius: 99px; overflow: hidden; }
.bar-row .track > i { display: block; height: 100%; border-radius: 99px; }

/* トグル行 */
.row { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--border); }
.row:last-child { border-bottom: 0; }
.row .rl { flex: 1; }
.row .rl small { display: block; color: var(--text-sub); font-size: 12px; }
.switch { position: relative; width: 52px; height: 30px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .sl { position: absolute; inset: 0; background: var(--border); border-radius: 99px; transition: .2s; }
.switch .sl::before { content: ""; position: absolute; width: 24px; height: 24px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + .sl { background: var(--blue); }
.switch input:checked + .sl::before { transform: translateX(22px); }

select.field, input.field {
  width: 100%; min-height: var(--tap); border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text); font-size: 16px; padding: 8px 12px;
}

/* ---------- ボトムナビ ---------- */
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -1px 6px rgba(15,23,42,.06);
}
.bottomnav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 0 8px; color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 700;
}
.bottomnav a .ic { font-size: 22px; line-height: 1; }
.bottomnav a.active { color: var(--blue); }

/* タイマー（クイックスタート） */
.qtimer { font-variant-numeric: tabular-nums; font-weight: 800; }

/* トースト */
.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--surface); padding: 10px 18px; border-radius: 99px; font-size: 14px;
  z-index: 50; box-shadow: var(--shadow); opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none;
}
.toast.show { opacity: .96; transform: translateX(-50%) translateY(-4px); }

/* 追記エディタ オーバーレイ */
.editor-overlay {
  position: fixed; inset: 0; z-index: 60; background: rgba(2, 6, 23, .55);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0; overflow-y: auto;
}
.editor-card {
  background: var(--surface); width: 100%; max-width: 640px;
  border-radius: 18px 18px 0 0; padding: 18px 16px calc(20px + env(safe-area-inset-bottom));
  box-shadow: 0 -4px 24px rgba(0,0,0,.3); max-height: 92vh; overflow-y: auto;
}
.editor-card .ed-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 12px; }
.editor-card .ed-head b { font-size: 18px; }
.editor-card .ed-l { display: block; font-size: 13px; font-weight: 700; color: var(--text-sub); margin: 12px 2px 4px; }
.editor-card textarea.field { resize: vertical; line-height: 1.6; }
.editor-card .ed-actions { display: flex; gap: 8px; margin-top: 16px; position: sticky; bottom: 0; }
.editor-card .ed-actions .btn { min-height: 48px; }

.muted { color: var(--text-sub); }
.center { text-align: center; }
.mt { margin-top: 14px; }
.danger { color: var(--red); }
.hr { height: 1px; background: var(--border); border: 0; margin: 14px 0; }
