:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1f2328;
  --muted: #656d76;
  --primary: #1f6feb;
  --correct: #1a7f37;
  --wrong: #cf222e;
  --border: #d0d7de;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.brand { font-weight: 700; text-decoration: none; color: var(--text); }
.app-header nav { display: flex; align-items: center; gap: 1rem; font-size: 0.9rem; }
.user-name { color: var(--muted); }

main { max-width: 720px; margin: 0 auto; padding: 1rem; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.center { text-align: center; }

.button {
  display: inline-block;
  min-height: 44px;
  padding: 0.6rem 1.2rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  color: var(--text);
  text-decoration: none;
  font-size: 1rem;
  cursor: pointer;
}

.button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.button:disabled { opacity: 0.5; cursor: default; }

input[type="text"] {
  min-height: 44px;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
  width: 100%;
  max-width: 320px;
}

.error { color: var(--wrong); font-weight: 600; }

.progress {
  height: 12px;
  background: #e6e8eb;
  border-radius: 6px;
  overflow: hidden;
}
.progress-bar { height: 100%; background: var(--primary); }
.progress-label { margin: 0.5rem 0 0.25rem; font-size: 1.1rem; }
.muted { color: var(--muted); font-size: 0.9rem; }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }

.subject-list { list-style: none; padding: 0; margin: 0; }
.subject {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.4rem;
  padding: 0.75rem 0;
  border-top: 1px solid var(--border);
}
.subject-name { font-weight: 600; }
.subject-count { color: var(--muted); font-size: 0.9rem; }
.subject-actions { display: flex; gap: 0.5rem; align-items: center; }
.button.small { min-height: 36px; padding: 0.3rem 0.7rem; font-size: 0.85rem; }
.done { color: var(--correct); font-weight: 600; }

.quiz-meta {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.9rem;
}
.quiz-body { font-size: 1.15rem; margin: 1.25rem 0; }
.quiz-choices { display: flex; flex-direction: column; gap: 0.75rem; }
.quiz-choices .button { font-size: 1.1rem; padding: 0.9rem; }

.quiz-result { margin-top: 1.5rem; border-top: 1px solid var(--border); padding-top: 1rem; }
.verdict { font-size: 1.2rem; font-weight: 700; }
.verdict.correct { color: var(--correct); }
.verdict.wrong { color: var(--wrong); }
.explanation {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  margin: 0.75rem 0;
  white-space: pre-wrap;
}

/* 画面が広いときは科目行を横並びにする */
@media (min-width: 600px) {
  .subject {
    grid-template-columns: 1fr 140px 70px auto;
    align-items: center;
    gap: 1rem;
  }
  .quiz-choices { flex-direction: row; }
  .quiz-choices .button { flex: 1; }
}

.admin-nav { display: flex; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.admin-nav a { color: var(--primary); }

.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th, .table td {
  text-align: left;
  padding: 0.5rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.table th { color: var(--muted); font-weight: 600; }

/* 横に広い表は表の中だけを横スクロールさせ、ページ全体は横に伸ばさない */
.card { overflow-x: auto; }

.inline-form { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.checkbox { display: block; margin: 0.75rem 0; font-size: 0.9rem; }
.import-actions { display: flex; gap: 0.5rem; margin: 0.75rem 0; }
code { background: var(--bg); padding: 0.1rem 0.35rem; border-radius: 4px; }

/* 種別タブ。スマホ幅でも2つが1行に並び、長い名前は折り返す */
.category-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.category-tab {
  flex: 1 1 0;
  min-width: 0;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  text-align: center;
  text-decoration: none;
  font-weight: 600;
  overflow-wrap: anywhere;
}
.category-tab[aria-current="page"] {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.reset-category { margin-top: 0.75rem; }

/* 管理画面の進捗表はスマホでは横スクロールさせる（列を縦に潰さない） */
.table.nowrap th, .table.nowrap td { white-space: nowrap; }
