:root {
  --bg: #f7f5f0;
  --card-bg: #ffffff;
  --ink: #1e2430;
  --muted: #6b7280;
  --accent: #2f6fed;
  --accent-ink: #ffffff;
  --good: #1f9d55;
  --bad: #d92d20;
  --border: #e3e1da;
  --radius: 18px;
  font-size: 18px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: env(safe-area-inset-top, 24px) 20px env(safe-area-inset-bottom, 24px);
}

.loading {
  margin-top: 40vh;
  color: var(--muted);
  font-size: 1.2rem;
}

button {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: 12px;
}

/* ---------- Picker screen ---------- */

.picker {
  width: 100%;
  max-width: 640px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding-top: 24px;
}

.picker h1 {
  font-size: 1.6rem;
  margin: 0;
  text-align: center;
}

.picker .subtitle {
  text-align: center;
  color: var(--muted);
  margin-top: -12px;
  font-size: 0.95rem;
}

.mode-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.mode-btn {
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: left;
}

.mode-btn.active {
  border-color: var(--accent);
  background: #eef4ff;
}

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

.mode-label {
  font-weight: 700;
  font-size: 1.05rem;
}

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

.list-options {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.list-option {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
}

.list-option.checked {
  border-color: var(--accent);
  background: #eef4ff;
}

.list-option input {
  width: 26px;
  height: 26px;
  accent-color: var(--accent);
}

.list-option .meta {
  flex: 1;
}

.list-option .label {
  font-weight: 600;
}

.list-option .count {
  color: var(--muted);
  font-size: 0.85rem;
}

.tier-tag {
  font-size: 0.75rem;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 10px;
}

.picker-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.word-total {
  color: var(--muted);
  font-size: 0.95rem;
}

.start-btn {
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 1.1rem;
  font-weight: 700;
  padding: 16px 28px;
  border-radius: var(--radius);
  flex: 1;
  max-width: 280px;
}

.start-btn:disabled {
  background: var(--border);
  color: var(--muted);
  cursor: not-allowed;
}

/* ---------- Card screen ---------- */

.session {
  width: 100%;
  max-width: 640px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding-top: 12px;
}

.session-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.95rem;
}

.session-header .tally .good-count { color: var(--good); font-weight: 700; }
.session-header .tally .bad-count { color: var(--bad); font-weight: 700; }

.quit-btn {
  background: none;
  color: var(--muted);
  text-decoration: underline;
  padding: 6px 4px;
}

.progress-track {
  width: 100%;
  height: 10px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.25s ease;
}

.star-row {
  font-size: 2.4rem;
  color: #f5b301;
  letter-spacing: 6px;
  line-height: 1;
}

.missed-panel {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}

.missed-title {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 10px;
}

.missed-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.missed-list li {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  font-weight: 600;
}

.card {
  background: var(--card-bg);
  border-radius: 24px;
  padding: 32px 24px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.06);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
  min-height: 40vh;
  justify-content: center;
}

.cue {
  font-size: 0.85rem;
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.word {
  font-size: 3rem;
  font-weight: 800;
  line-height: 1.1;
  word-break: break-word;
}

.word-hint {
  color: var(--muted);
  font-size: 0.95rem;
}

.reveal-panel {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
}

.reveal-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  text-align: left;
  font-size: 1rem;
}

.reveal-item .reveal-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 2px;
}

.reveal-item .reveal-value.unavailable {
  color: var(--muted);
  font-style: italic;
}

.protocol-btns {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: 100%;
}

.protocol-btn {
  background: var(--card-bg);
  border: 2px solid var(--border);
  padding: 14px 6px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink);
}

.protocol-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: #eef4ff;
}

.repeat-btn {
  background: var(--card-bg);
  border: 2px solid var(--border);
  padding: 14px 6px;
  font-size: 0.95rem;
  font-weight: 600;
  width: 100%;
}

.grade-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.grade-btn {
  padding: 22px;
  font-size: 1.4rem;
  font-weight: 800;
  color: #fff;
}

.grade-btn.correct { background: var(--good); }
.grade-btn.incorrect { background: var(--bad); }

.grade-btn:active {
  filter: brightness(0.9);
}

/* ---------- Solo mode ---------- */

.solo-card {
  gap: 18px;
}

.speak-btn {
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 1.6;
  padding: 20px 32px;
  border-radius: var(--radius);
}

.answer-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 8px;
}

.word-input {
  width: 100%;
  font-size: 1.4rem;
  text-align: center;
  padding: 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--ink);
}

.word-input:focus {
  outline: none;
  border-color: var(--accent);
}

.feedback {
  width: 100%;
  border-radius: var(--radius);
  padding: 18px;
  text-align: center;
}

.feedback-correct {
  background: #e8f7ee;
  border: 2px solid var(--good);
}

.feedback-incorrect {
  background: #fdecea;
  border: 2px solid var(--bad);
}

.feedback-status {
  font-size: 1.3rem;
  font-weight: 800;
}

.feedback-correct .feedback-status { color: var(--good); }
.feedback-incorrect .feedback-status { color: var(--bad); }

.feedback-spelling {
  font-size: 1.6rem;
  font-weight: 700;
  margin-top: 6px;
}

@media (max-width: 420px) {
  .word { font-size: 2.2rem; }
  .protocol-btns { grid-template-columns: repeat(2, 1fr); }
  .mode-row { grid-template-columns: 1fr; }
}
