*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-2: #22263a;
  --border: #2e3350;
  --accent: #4f6ef7;
  --accent-glow: rgba(79, 110, 247, 0.25);
  --success: #22c55e;
  --error: #ef4444;
  --text: #e2e8f0;
  --muted: #8892a4;
  --radius: 12px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

/* ── Layout ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 520px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.card-header {
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  padding: 20px 28px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.shield-icon {
  width: 36px;
  height: 36px;
  background: var(--accent-glow);
  border: 1px solid var(--accent);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.shield-icon svg {
  width: 20px;
  height: 20px;
  fill: var(--accent);
}

.card-header h1 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.card-header p {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.card-body {
  padding: 28px;
}

/* ── Progress bar ── */
.progress-wrap {
  margin-bottom: 28px;
}

.progress-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 8px;
}

.progress-bar-bg {
  height: 4px;
  background: var(--surface-2);
  border-radius: 99px;
  overflow: hidden;
}

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

/* ── Step dots ── */
.steps {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 28px;
}

.step-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
  transition: all 0.3s ease;
  position: relative;
}

.step-dot.active {
  border-color: var(--accent);
  background: var(--accent-glow);
  color: var(--accent);
}

.step-dot.done {
  border-color: var(--success);
  background: rgba(34, 197, 94, 0.15);
  color: var(--success);
}

/* ── Challenge panels ── */
.challenge {
  display: none;
  animation: fadeIn 0.35s ease;
}

.challenge.active {
  display: block;
}

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

.challenge-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
}

.challenge-question {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 20px;
  line-height: 1.5;
}

/* ── Input ── */
.input-row {
  display: flex;
  gap: 10px;
}

.challenge-input {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}

.challenge-input:focus {
  border-color: var(--accent);
}

.challenge-input.error {
  border-color: var(--error);
  animation: shake 0.35s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%       { transform: translateX(-6px); }
  60%       { transform: translateX(6px); }
}

/* ── Reading passage ── */
.passage {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 18px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--muted);
  margin-bottom: 20px;
}

.passage strong {
  color: var(--text);
}

/* ── Multiple choice ── */
.choices {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}

.choice-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 11px 16px;
  color: var(--text);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.choice-btn:hover {
  border-color: var(--accent);
  background: var(--accent-glow);
}

.choice-btn.correct {
  border-color: var(--success);
  background: rgba(34, 197, 94, 0.1);
  color: var(--success);
}

.choice-btn.wrong {
  border-color: var(--error);
  background: rgba(239, 68, 68, 0.1);
  color: var(--error);
  animation: shake 0.35s ease;
}

/* ── Puzzle (sequence tiles) ── */
.puzzle-desc {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 16px;
  line-height: 1.5;
}

.puzzle-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
  justify-content: center;
}

.tile {
  width: 56px;
  height: 56px;
  background: var(--surface-2);
  border: 2px solid var(--border);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
  user-select: none;
}

.tile:hover {
  border-color: var(--accent);
  background: var(--accent-glow);
  transform: scale(1.05);
}

.tile.selected {
  border-color: var(--accent);
  background: var(--accent-glow);
  color: var(--accent);
}

.tile.correct-tile {
  border-color: var(--success);
  background: rgba(34, 197, 94, 0.1);
  color: var(--success);
  cursor: default;
  transform: none;
}

.tile.wrong-tile {
  border-color: var(--error);
  background: rgba(239, 68, 68, 0.1);
  color: var(--error);
  animation: shake 0.35s ease;
}

.sequence-display {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.seq-slot {
  width: 36px;
  height: 36px;
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  transition: all 0.2s;
}

.seq-slot.filled {
  border-color: var(--accent);
  color: var(--text);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: 8px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.15s;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  opacity: 0.88;
}

.btn-ghost {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 8px 14px;
  font-size: 13px;
}

.btn-ghost:hover {
  color: var(--text);
  border-color: var(--accent);
}

/* ── Feedback ── */
.feedback {
  font-size: 13px;
  margin-top: 12px;
  min-height: 18px;
  transition: opacity 0.2s;
}

.feedback.ok  { color: var(--success); }
.feedback.err { color: var(--error); }

/* ── Success screen ── */
#success-screen {
  display: none;
  text-align: center;
  padding: 20px 0 8px;
  animation: fadeIn 0.4s ease;
}

.success-icon {
  width: 64px;
  height: 64px;
  background: rgba(34, 197, 94, 0.15);
  border: 2px solid var(--success);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
}

.success-icon svg {
  width: 32px;
  height: 32px;
  stroke: var(--success);
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#success-screen h2 {
  font-size: 20px;
  margin-bottom: 8px;
}

#success-screen p {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 24px;
}

.redirect-bar-bg {
  height: 4px;
  background: var(--surface-2);
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 8px;
}

.redirect-bar-fill {
  height: 100%;
  background: var(--success);
  border-radius: 99px;
  width: 0%;
  transition: width 0.15s linear;
}

.redirect-note {
  font-size: 12px;
  color: var(--muted);
}

/* ── Loading overlay ── */
#loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 20px 0 8px;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

#loading p {
  font-size: 14px;
  color: var(--muted);
}
