:root {
  --bg: #f4f6f3;
  --card-bg: #ffffff;
  --primary: #3f8f3f;
  --primary-dark: #2f6e2f;
  --text: #22291f;
  --muted: #6a7466;
  --correct: #2f9e44;
  --wrong: #d64545;
  --border: #e0e4dc;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  justify-content: center;
}

.app {
  width: 100%;
  max-width: 480px;
  padding: 24px 16px 48px;
}

.screen { display: none; }
.screen.active { display: block; }

h1 {
  font-size: 1.6rem;
  margin: 8px 0 4px;
  text-align: center;
}

.subtitle {
  text-align: center;
  color: var(--muted);
  margin: 0 0 24px;
}

.mode-choice {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 24px;
}

.mode-btn {
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.mode-btn:hover { border-color: var(--primary); }

.mode-btn.selected {
  border-color: var(--primary);
  background: #eef7ea;
}

.mode-title { font-weight: 600; font-size: 1.05rem; }
.mode-desc { color: var(--muted); font-size: 0.9rem; }

.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;
  transition: background 0.15s;
}

.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }

.btn-primary:disabled {
  background: #b9c2b4;
  cursor: not-allowed;
}

.progress {
  margin-bottom: 20px;
}

#progress-text {
  display: block;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 6px;
}

.progress-bar {
  background: var(--border);
  border-radius: 8px;
  height: 8px;
  overflow: hidden;
}

#progress-fill {
  height: 100%;
  background: var(--primary);
  width: 0%;
  transition: width 0.25s;
}

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.06);
  text-align: center;
}

.timer-bar-wrap {
  height: 8px;
  background: var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 16px;
}

.timer-bar-fill {
  height: 100%;
  width: 100%;
  background: var(--wrong);
  border-radius: 8px;
}

#quiz-image {
  width: 100%;
  max-width: 260px;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  background: #f0f2ee;
  border-radius: 10px;
  margin-bottom: 16px;
}

#quiz-name {
  margin: 0 0 4px;
  font-size: 1.3rem;
}

.question {
  color: var(--muted);
  margin: 0 0 18px;
}

.mc-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.mc-option {
  padding: 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.mc-option:hover:not(:disabled) { border-color: var(--primary); }

.mc-option.correct {
  border-color: var(--correct);
  background: #e9f7ec;
  color: var(--correct);
}

.mc-option.wrong {
  border-color: var(--wrong);
  background: #fbeaea;
  color: var(--wrong);
}

.mc-option:disabled { cursor: default; }

.text-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

#text-input {
  flex: 1 1 180px;
  min-width: 0;
  box-sizing: border-box;
  padding: 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 1.1rem;
}

#text-input:focus { outline: none; border-color: var(--primary); }

.text-form .btn-primary { width: auto; flex: 1 1 auto; padding: 14px 20px; }

.feedback {
  min-height: 28px;
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 12px;
}

.feedback.correct { color: var(--correct); }
.feedback.wrong { color: var(--wrong); }

.score-circle {
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: #eef7ea;
  border: 4px solid var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 24px auto;
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary-dark);
}

#score-text {
  text-align: center;
  color: var(--muted);
  margin-bottom: 20px;
}

.mistake-list {
  margin-bottom: 20px;
}

.mistake-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  background: var(--card-bg);
}

.mistake-item img {
  width: 48px;
  height: 48px;
  object-fit: contain;
  border-radius: 6px;
  background: #f0f2ee;
  flex-shrink: 0;
}

.mistake-info { font-size: 0.9rem; }
.mistake-info .name { font-weight: 600; }
.mistake-info .nums { color: var(--muted); }
.mistake-info .given { color: var(--wrong); }
.mistake-info .correct-num { color: var(--correct); }

.stats-section {
  margin-top: 28px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.stats-mode h3 {
  margin: 0 0 10px;
  font-size: 1rem;
  color: var(--text);
}

.stats-columns {
  display: flex;
  gap: 12px;
}

.stat-list {
  flex: 1;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  min-width: 0;
}

.stat-list h4 {
  margin: 0 0 8px;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--muted);
}

.stat-list.best h4 { color: var(--correct); }
.stat-list.worst h4 { color: var(--wrong); }

.stat-list ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-list li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.82rem;
}

.round-date { color: var(--muted); }
.round-score { font-weight: 600; white-space: nowrap; }
.round-score.muted { font-weight: 400; color: var(--muted); font-style: italic; }
.round-empty { color: var(--muted); font-style: italic; }

.toggle-full-btn {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 8px;
  background: none;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--primary-dark);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.toggle-full-btn:hover { background: #eef7ea; }

.full-list {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  max-height: 320px;
  overflow-y: auto;
}

.full-list.hidden { display: none; }

.btn-secondary {
  display: block;
  margin: 12px auto 0;
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.95rem;
  cursor: pointer;
}
.btn-secondary:hover { text-decoration: underline; }
