/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #eef1f6;
  color: #1a1a2e;
  min-height: 100vh;
}

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 16px 40px;
}

/* ── Screens ── */
.screen { display: none; }
.screen.active { display: block; }

/* ── Shared Header ── */
.screen-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 0 12px;
  border-bottom: 1px solid #d0d7e3;
  margin-bottom: 20px;
}
.screen-header h2 { font-size: 1.1rem; color: #1e3a5f; }

.back-btn {
  background: none;
  border: none;
  color: #1e6fb8;
  font-size: 0.95rem;
  cursor: pointer;
  padding: 4px 0;
  flex-shrink: 0;
}
.back-btn:hover { text-decoration: underline; }

/* ── Buttons ── */
.primary-btn {
  display: block;
  width: 100%;
  padding: 14px;
  background: #1e3a5f;
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.primary-btn:hover:not(:disabled) { background: #163050; }
.primary-btn:disabled { background: #a0aec0; cursor: not-allowed; }

.secondary-btn {
  flex: 1;
  padding: 12px;
  background: #fff;
  color: #1e3a5f;
  border: 2px solid #1e3a5f;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.secondary-btn:hover:not(:disabled) { background: #eef1f6; }
.secondary-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.link-btn {
  background: none;
  border: none;
  color: #1e6fb8;
  font-size: 0.9rem;
  cursor: pointer;
  padding: 4px 8px;
}
.link-btn:hover { text-decoration: underline; }

/* ── Home Screen ── */
.home-header {
  padding: 32px 0 24px;
  text-align: center;
}
.home-header h1 {
  font-size: 2rem;
  color: #1e3a5f;
  font-weight: 700;
}
.subtitle {
  color: #5a7290;
  margin-top: 6px;
  font-size: 1rem;
}

.mode-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.mode-card {
  background: #fff;
  border: 2px solid #d0d7e3;
  border-radius: 12px;
  padding: 20px 22px;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
  width: 100%;
}
.mode-card:hover {
  border-color: #1e3a5f;
  box-shadow: 0 2px 8px rgba(30, 58, 95, 0.12);
}
.mode-name {
  font-size: 1.1rem;
  font-weight: 700;
  color: #1e3a5f;
  margin-bottom: 4px;
}
.mode-desc {
  font-size: 0.88rem;
  color: #5a7290;
}

.home-progress {
  margin-top: 28px;
  background: #fff;
  border-radius: 12px;
  padding: 16px 20px;
  border: 1px solid #d0d7e3;
}
.home-progress:empty { display: none; }
.home-progress h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #5a7290;
  margin-bottom: 10px;
}
.progress-stat {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.92rem;
  padding: 4px 0;
  color: #1a1a2e;
}
.stat-val { 
  color: #5a7290;
  display: flex;
  align-items: center;
  gap: 8px;
}

.resume-icon-btn {
  background: #1e3a5f;
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  font-size: 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.resume-icon-btn:hover { background: #163050; }

.clear-icon-btn {
  background: #c62828;
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  line-height: 1;
}
.clear-icon-btn:hover { background: #a02020; }

/* ── Chapter Selection ── */
.loading-msg {
  text-align: center;
  color: #5a7290;
  padding: 40px 0;
  font-size: 1rem;
}

.chapter-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.chapter-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
  margin-bottom: 20px;
}

.chapter-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 1.5px solid #d0d7e3;
  border-radius: 8px;
  padding: 10px 14px;
  cursor: pointer;
  font-size: 0.93rem;
  transition: border-color 0.12s;
}
.chapter-item:hover { border-color: #1e3a5f; }
.chapter-item input[type=checkbox] { accent-color: #1e3a5f; width: 16px; height: 16px; }

.wrong-only-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.93rem;
  margin-bottom: 20px;
  cursor: pointer;
  color: #3a3a5a;
}
.wrong-only-row input { accent-color: #c62828; width: 16px; height: 16px; }

/* ── Study Screen ── */
.session-info {
  margin-left: auto;
  display: flex;
  gap: 14px;
  font-size: 0.85rem;
  color: #5a7290;
}

.progress-track {
  height: 5px;
  background: #d0d7e3;
  border-radius: 3px;
  margin-bottom: 20px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: #1e3a5f;
  border-radius: 3px;
  transition: width 0.3s ease;
  width: 0%;
}

.card-area { padding-top: 4px; }

.card {
  background: #fff;
  border-radius: 14px;
  padding: 28px 26px;
  box-shadow: 0 2px 12px rgba(30, 58, 95, 0.09);
  min-height: 200px;
  margin-bottom: 18px;
  border: 1.5px solid #d0d7e3;
}

.card-meta {
  font-size: 0.78rem;
  color: #a0aec0;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 14px;
}

.card-front {
  font-size: 1.25rem;
  font-weight: 600;
  color: #1e3a5f;
  line-height: 1.5;
}

.card-divider {
  border: none;
  border-top: 1.5px dashed #d0d7e3;
  margin: 20px 0;
}

.card-back {
  font-size: 1rem;
  color: #2d3748;
  line-height: 1.75;
}

/* Reference mode back — each match on its own row */
.ref-match {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 0;
  border-bottom: 1px solid #eef1f6;
}
.ref-match:last-child { border-bottom: none; }
.ref-tag {
  font-weight: 700;
  color: #1e3a5f;
  font-size: 0.95rem;
}
.ref-text {
  color: #4a5568;
  font-size: 0.93rem;
}

.hidden { display: none !important; }

.card-actions { display: flex; flex-direction: column; gap: 10px; }

.grade-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.grade-btn {
  padding: 14px;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: filter 0.12s;
}
.grade-btn:hover { filter: brightness(0.92); }

.wrong-btn  { background: #fdecea; color: #c62828; }
.correct-btn { background: #e8f5e9; color: #2e7d32; }

/* ── Results Screen ── */
.results-title {
  text-align: center;
  font-size: 1.4rem;
  color: #1e3a5f;
  padding: 32px 0 20px;
}

.results-content {
  background: #fff;
  border-radius: 14px;
  padding: 28px;
  border: 1.5px solid #d0d7e3;
  margin-bottom: 20px;
  text-align: center;
}

.score-circle {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: #eef1f6;
  border: 4px solid #1e3a5f;
  margin-bottom: 16px;
}
.score-pct { font-size: 2rem; font-weight: 800; color: #1e3a5f; }
.score-label { font-size: 0.8rem; color: #5a7290; }

.score-detail {
  display: flex;
  justify-content: center;
  gap: 24px;
  font-size: 1rem;
  font-weight: 600;
}
.score-correct { color: #2e7d32; }
.score-wrong   { color: #c62828; }

.results-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.results-actions .primary-btn { flex: 1; }
