:root {
  --bg: #0f1115;
  --surface: #1a1d24;
  --surface-2: #232730;
  --border: #2a2f3a;
  --text: #e6e8eb;
  --muted: #9aa3b2;
  --accent: #4cb4ff;
  --accent-soft: rgba(76, 180, 255, 0.12);
  --ok: #4ade80;
  --ok-soft: rgba(74, 222, 128, 0.12);
  --bad: #ff4d6d;
  --bad-soft: rgba(255, 77, 109, 0.12);
  --warn: #f0b95c;
}

* { box-sizing: border-box; }

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

.app {
  max-width: 760px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

/* ---------- Screens ---------- */
.screen {
  display: none;
  animation: fadeIn 0.3s ease;
}

.screen.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------- Hero ---------- */
.hero {
  text-align: center;
  padding: 2rem 1rem 3rem;
}

.hero h1 {
  margin: 0;
  font-size: 2.4rem;
  background: linear-gradient(90deg, var(--accent), #7cc7ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero .sub {
  color: var(--muted);
  margin-top: 0.5rem;
  font-size: 1.1rem;
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.5rem;
  margin-bottom: 1.25rem;
}

.card h2 {
  margin: 0 0 1rem;
  color: var(--accent);
  font-size: 1.15rem;
}

/* ---------- Difficulty buttons ---------- */
.difficulty {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
}

.diff-btn {
  background: var(--surface-2);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 1rem 0.5rem;
  cursor: pointer;
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  transition: all 0.15s ease;
  font-family: inherit;
}

.diff-btn:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.diff-btn.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.diff-emoji {
  font-size: 1.8rem;
}

.diff-name {
  font-weight: 600;
  font-size: 1.05rem;
}

.diff-desc {
  color: var(--muted);
  font-size: 0.85rem;
}

/* ---------- Topics ---------- */
.topics {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.topic-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 0.5rem 0.85rem;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s ease;
  font-size: 0.95rem;
  user-select: none;
}

.topic-chip input {
  accent-color: var(--accent);
  cursor: pointer;
}

.topic-chip:has(input:checked) {
  background: var(--accent-soft);
  border-color: var(--accent);
}

/* ---------- Big button ---------- */
.big-btn {
  display: block;
  width: 100%;
  padding: 1rem;
  border-radius: 12px;
  border: none;
  background: var(--accent);
  color: #06121e;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
  margin-top: 1rem;
}

.big-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(76, 180, 255, 0.25);
}

.big-btn:disabled {
  background: var(--surface-2);
  color: var(--muted);
  cursor: not-allowed;
}

/* ---------- Progress ---------- */
.progress-bar {
  background: var(--surface);
  height: 6px;
  border-radius: 999px;
  margin-bottom: 1rem;
  overflow: hidden;
}

.progress-fill {
  background: linear-gradient(90deg, var(--accent), #7cc7ff);
  height: 100%;
  width: 0%;
  transition: width 0.3s ease;
}

.quiz-header {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.95rem;
  margin-bottom: 1rem;
  padding: 0 0.25rem;
}

/* ---------- Question ---------- */
.question-card {
  position: relative;
}

.topic-tag {
  position: absolute;
  top: -0.6rem;
  left: 1.25rem;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid var(--border);
}

#question-text {
  font-size: 1.3rem;
  margin: 0.5rem 0 1.5rem;
  color: var(--text);
}

.options {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.option {
  background: var(--surface-2);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 0.9rem 1rem;
  text-align: left;
  cursor: pointer;
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.option:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.option .letter {
  display: inline-flex;
  width: 28px;
  height: 28px;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border-radius: 6px;
  font-weight: 600;
  color: var(--muted);
  flex-shrink: 0;
  font-size: 0.9rem;
}

.option.correct {
  border-color: var(--ok);
  background: var(--ok-soft);
}

.option.correct .letter {
  background: var(--ok);
  color: var(--bg);
}

.option.wrong {
  border-color: var(--bad);
  background: var(--bad-soft);
}

.option.wrong .letter {
  background: var(--bad);
  color: var(--bg);
}

.option:disabled {
  cursor: not-allowed;
}

.option code {
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
  color: var(--warn);
}

/* ---------- Feedback ---------- */
.feedback {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.25rem;
  margin-top: 1rem;
  animation: slideUp 0.3s ease;
}

.feedback.hidden {
  display: none;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.feedback.right {
  border-color: var(--ok);
}

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

.feedback-icon {
  font-size: 2rem;
  text-align: center;
}

.feedback h3 {
  text-align: center;
  margin: 0.25rem 0 0.75rem;
}

.feedback.right h3 {
  color: var(--ok);
}

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

#feedback-explanation {
  color: var(--muted);
  margin: 0 0 0.5rem;
}

#feedback-explanation code {
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--warn);
  font-size: 0.9em;
}

/* ---------- End screen ---------- */
.score-card {
  text-align: center;
}

.big-score {
  font-size: 4rem;
  font-weight: 700;
  line-height: 1;
  margin: 0.5rem 0;
}

#final-score { color: var(--accent); }
.score-divider { color: var(--muted); margin: 0 0.5rem; }
#final-total { color: var(--muted); }

.percent {
  font-size: 1.3rem;
  color: var(--muted);
  margin-bottom: 1rem;
}

#verdict {
  font-size: 1.1rem;
  margin: 0;
}

#mistakes-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.mistake {
  background: var(--bad-soft);
  border-left: 3px solid var(--bad);
  padding: 0.75rem 1rem;
  border-radius: 4px;
  font-size: 0.95rem;
}

.mistake .q {
  font-weight: 500;
  margin-bottom: 0.25rem;
}

.mistake .a {
  color: var(--ok);
  font-size: 0.9em;
}

.mistake .a strong {
  color: var(--ok);
}

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
  .app { padding: 1rem 0.75rem; }
  .hero h1 { font-size: 1.8rem; }
  .difficulty { grid-template-columns: 1fr 1fr; }
  #question-text { font-size: 1.1rem; }
  .big-score { font-size: 3rem; }
}
