/* ------------------------------------------------------------------
   過去問 暗記カード — スマホ優先のレスポンシブスタイル
   ------------------------------------------------------------------ */

:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #dde3ea;
  --text: #1c2430;
  --muted: #66707d;
  --accent: #2f6bd8;
  --accent-soft: #e8f0fe;
  --correct: #1a8a52;
  --correct-soft: #e4f6ec;
  --wrong: #c73c3c;
  --wrong-soft: #fdeaea;
  --star: #f0a92c;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(20, 30, 45, .08), 0 6px 18px rgba(20, 30, 45, .05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --surface: #1b212a;
    --border: #2c3540;
    --text: #e7ecf2;
    --muted: #9aa5b2;
    --accent: #6296f0;
    --accent-soft: #22303f;
    --correct: #4cc98a;
    --correct-soft: #172f24;
    --wrong: #f07272;
    --wrong-soft: #331e1e;
    --star: #f5b944;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }

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

a { color: var(--accent); }

/* ---------- ヘッダー ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 700;
  text-decoration: none;
  color: var(--text);
  font-size: 1.05rem;
}

.site-nav {
  display: flex;
  gap: 6px;
}

.site-nav a {
  padding: 6px 12px;
  border-radius: 999px;
  text-decoration: none;
  font-size: .9rem;
  color: var(--muted);
}

.site-nav a:hover { background: var(--accent-soft); color: var(--accent); }

.logout-form { margin: 0; display: inline; }

.logout-form button {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: .85rem;
  font-family: inherit;
  cursor: pointer;
}

.logout-form button:hover { border-color: var(--wrong); color: var(--wrong); }

/* ---------- ログイン画面 ---------- */
.login-box {
  max-width: 420px;
  margin: 40px auto;
  padding: 32px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
}

.login-box h1 { margin-bottom: 8px; }
.login-box .lead { margin-bottom: 24px; }
.login-box .result { text-align: left; }

.login-form { text-align: left; }

.field { display: block; margin-bottom: 16px; }

.field span {
  display: block;
  font-size: .85rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  padding: 13px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
}

.field input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.container {
  max-width: 780px;
  margin: 0 auto;
  padding: 20px 16px 60px;
  padding-bottom: max(60px, env(safe-area-inset-bottom));
}

h1 { font-size: 1.4rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 28px 0 10px; }

.lead { color: var(--muted); margin: 0 0 20px; font-size: .92rem; }

/* ---------- カード ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}

/* ---------- トップの統計 ---------- */
.stat-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 20px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 8px;
  text-align: center;
}

.stat b { display: block; font-size: 1.25rem; line-height: 1.2; }
.stat span { font-size: .72rem; color: var(--muted); }

@media (max-width: 420px) {
  .stat-row { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- フォーム ---------- */
fieldset {
  border: none;
  padding: 0;
  margin: 0 0 20px;
}

legend {
  font-weight: 600;
  font-size: .95rem;
  padding: 0;
  margin-bottom: 10px;
}

.chip-group { display: flex; flex-wrap: wrap; gap: 8px; }

.chip input { position: absolute; opacity: 0; pointer-events: none; }

.chip span {
  display: inline-block;
  padding: 9px 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-size: .9rem;
  cursor: pointer;
  user-select: none;
  transition: background .15s, border-color .15s, color .15s;
}

.chip input:checked + span {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.hint { font-size: .8rem; color: var(--muted); margin-top: 8px; }

/* ---------- ボタン ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 15px 20px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
}

.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-row { display: flex; gap: 10px; }

/* ---------- 出題画面 ---------- */
.quiz-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.meta { display: flex; flex-wrap: wrap; gap: 6px; }

.badge {
  font-size: .75rem;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  white-space: nowrap;
}

.badge-multi { background: var(--star); color: #3a2600; }

.fav-btn {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
}

.fav-btn.is-on { color: var(--star); border-color: var(--star); }

.progress {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: .82rem;
  color: var(--muted);
  margin-bottom: 12px;
}

.progress-bar {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar i { display: block; height: 100%; background: var(--accent); }

/* ---------- 画像 ---------- */
.image-wrap {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
  margin-bottom: 16px;
}

.image-wrap img {
  display: block;
  width: 100%;
  height: auto;
  cursor: zoom-in;
}

.image-wrap img.zoomed {
  cursor: zoom-out;
  width: auto;
  max-width: none;
}

.image-wrap.is-zoomed { overflow-x: auto; }

.image-caption {
  font-size: .78rem;
  color: var(--muted);
  margin: -8px 0 16px;
}

/* ---------- 選択肢 ---------- */
.choices {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.choice input { position: absolute; opacity: 0; pointer-events: none; }

.choice span {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 58px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  transition: background .12s, border-color .12s, color .12s;
}

.choice input:checked + span {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.choice input:disabled + span { cursor: default; }

/* 採点後の色分け */
.choice.is-answer span {
  border-color: var(--correct);
  background: var(--correct-soft);
  color: var(--correct);
}

.choice.is-wrongpick span {
  border-color: var(--wrong);
  background: var(--wrong-soft);
  color: var(--wrong);
}

.choice .mark {
  position: absolute;
  margin-top: -38px;
  margin-left: 30px;
  font-size: .85rem;
}

/* ---------- 結果 ---------- */
.result {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 12px;
  margin-bottom: 16px;
  font-weight: 700;
}

.result.correct { background: var(--correct-soft); color: var(--correct); }
.result.wrong { background: var(--wrong-soft); color: var(--wrong); }
.result .icon { font-size: 1.5rem; }
.result small { display: block; font-weight: 500; font-size: .8rem; opacity: .85; }

/* ---------- 一覧 ---------- */
.list { list-style: none; padding: 0; margin: 0; }

.list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 8px;
}

.list a { text-decoration: none; font-weight: 600; }
.list .sub { font-size: .78rem; color: var(--muted); font-weight: 400; }

/* ---------- 成績表 ---------- */
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { padding: 10px 8px; border-bottom: 1px solid var(--border); text-align: left; }
.table th { color: var(--muted); font-weight: 600; font-size: .8rem; }
.table td:last-child, .table th:last-child { text-align: right; }

.big-score { text-align: center; padding: 10px 0 4px; }
.big-score b { font-size: 2.6rem; line-height: 1; display: block; }
.big-score span { color: var(--muted); font-size: .85rem; }

.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
