/* ── リセット・基本 ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:   #3b82f6;
  --primary-d: #2563eb;
  --correct:   #16a34a;
  --wrong:     #dc2626;
  --bg:        #f8fafc;
  --card:      #ffffff;
  --border:    #e2e8f0;
  --text:      #1e293b;
  --muted:     #64748b;
  --radius:    10px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── 画面制御 ────────────────────────────────────────────────────── */
.screen { display: none; }
.screen.active { display: block; }
.hidden { display: none !important; }

/* ── ヘッダー ────────────────────────────────────────────────────── */
header {
  background: var(--primary);
  color: #fff;
  padding: 16px 20px;
  text-align: center;
}
header h1 { font-size: 1.4rem; }
.subtitle { font-size: 0.85rem; opacity: 0.85; margin-top: 2px; }

.quiz-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.9rem;
  text-align: left;
}
.quiz-header #quiz-topic-name {
  flex: 1;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── ボタン ──────────────────────────────────────────────────────── */
.btn-primary {
  display: block;
  width: 100%;
  padding: 14px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 16px;
  transition: background 0.15s;
}
.btn-primary:hover { background: var(--primary-d); }

.btn-secondary {
  display: block;
  width: 100%;
  padding: 12px;
  background: var(--card);
  color: var(--primary);
  border: 2px solid var(--primary);
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 10px;
  transition: background 0.15s;
}
.btn-secondary:hover { background: #eff6ff; }

.btn-icon {
  background: none;
  border: none;
  color: #fff;
  font-size: 0.9rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  white-space: nowrap;
}
.btn-icon:hover { background: rgba(255,255,255,0.2); }

/* ── トップ画面 ──────────────────────────────────────────────────── */
#screen-top main { padding: 16px; max-width: 640px; margin: 0 auto; }

.grade-section { margin-bottom: 24px; }
.grade-heading {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

.topic-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }

.topic-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
  transition: box-shadow 0.15s, border-color 0.15s;
}
.topic-item:hover { border-color: var(--primary); box-shadow: 0 2px 8px rgba(59,130,246,0.15); }

.topic-num {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 600;
  min-width: 22px;
}
.topic-name { flex: 1; font-size: 0.95rem; }

.topic-pct {
  font-size: 0.8rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
}
.topic-pct.none   { background: #f1f5f9; color: var(--muted); }
.topic-pct.good   { background: #dcfce7; color: var(--correct); }
.topic-pct.ok     { background: #fef9c3; color: #854d0e; }
.topic-pct.low    { background: #fee2e2; color: var(--wrong); }

/* ── 問題画面 ────────────────────────────────────────────────────── */
#screen-quiz main { padding: 16px; max-width: 640px; margin: 0 auto; }

.difficulty-badge {
  display: inline-block;
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 20px;
  margin-bottom: 10px;
}
.diff-1 { background: #dcfce7; color: #15803d; }
.diff-2 { background: #fef9c3; color: #854d0e; }
.diff-3 { background: #fee2e2; color: #b91c1c; }

#question-text {
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1.6;
  margin-bottom: 6px;
}
.translation { font-size: 0.85rem; color: var(--muted); margin-bottom: 16px; }

/* 4択 */
#choices-area { display: flex; flex-direction: column; gap: 10px; }

.choice-btn {
  width: 100%;
  padding: 14px;
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.choice-btn:hover:not(:disabled) { border-color: var(--primary); background: #eff6ff; }
.choice-btn.correct { border-color: var(--correct); background: #dcfce7; font-weight: 700; }
.choice-btn.wrong   { border-color: var(--wrong);   background: #fee2e2; }

/* 穴埋め */
#fill-area { display: flex; gap: 10px; align-items: stretch; }

#fill-input {
  flex: 1;
  padding: 12px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.15s;
}
#fill-input:focus { border-color: var(--primary); }
#fill-input.input-correct { border-color: var(--correct); background: #dcfce7; }
#fill-input.input-wrong   { border-color: var(--wrong);   background: #fee2e2; }

#fill-area .btn-primary { margin-top: 0; width: auto; padding: 12px 20px; }

/* 並び替え */
#word-order-area { display: flex; flex-direction: column; gap: 12px; }

.word-order-zone {
  background: var(--card);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 10px;
  min-height: 64px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-start;
  align-content: flex-start;
}
.zone-label { font-size: 0.75rem; color: var(--muted); width: 100%; }

.word-chip {
  padding: 8px 14px;
  border-radius: 20px;
  border: 2px solid var(--border);
  background: #f8fafc;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s;
}
.word-chip:hover:not(:disabled) { border-color: var(--primary); background: #eff6ff; }
.word-chip.selected { border-color: var(--primary); background: #dbeafe; }

/* 解説 */
#result-area { margin-top: 16px; }

.result-banner {
  text-align: center;
  font-size: 1.3rem;
  font-weight: 800;
  padding: 12px;
  border-radius: var(--radius);
  margin-bottom: 8px;
}
.result-banner.correct { background: #dcfce7; color: var(--correct); }
.result-banner.wrong   { background: #fee2e2; color: var(--wrong); }

#result-correct-answer {
  text-align: center;
  font-weight: 600;
  color: var(--wrong);
  margin-bottom: 8px;
  font-size: 0.95rem;
}

.explanation {
  background: var(--card);
  border-left: 4px solid var(--primary);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 12px 14px;
  font-size: 0.9rem;
  line-height: 1.7;
  color: var(--text);
}

/* ── 結果画面 ────────────────────────────────────────────────────── */
#screen-result main {
  padding: 24px 16px;
  max-width: 480px;
  margin: 0 auto;
  text-align: center;
}

.result-score-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 24px;
  margin-bottom: 24px;
}
.score-label { font-size: 0.85rem; color: var(--muted); margin-bottom: 8px; }
.score-value { font-size: 3.5rem; font-weight: 900; color: var(--primary); line-height: 1; }
.score-detail { font-size: 0.9rem; color: var(--muted); margin-top: 8px; }

.result-actions { display: flex; flex-direction: column; gap: 0; }

/* ── ローディング ─────────────────────────────────────────────────── */
.loading { color: var(--muted); text-align: center; padding: 40px; }

/* ── レスポンシブ ─────────────────────────────────────────────────── */
@media (min-width: 480px) {
  #fill-area .btn-primary { min-width: 80px; }
}
