:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --primary: #1976d2;
  --success: #2e7d32;
  --error: #c62828;
  --text: #1a1a2e;
  --muted: #5c6b7a;
  --radius: 14px;
}

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

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

.container { max-width: 720px; margin: 0 auto; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px 20px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  margin-bottom: 16px;
}

h1 { font-size: 1.6rem; text-align: center; margin-bottom: 12px; }

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

.warning {
  background: #ffebee;
  color: var(--error);
  border-radius: 10px;
  padding: 14px;
  font-size: 0.92rem;
  font-weight: 600;
  margin: 16px 0;
  text-align: center;
}

.header-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 12px;
}

.question-text {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 16px 0 20px;
  line-height: 1.45;
}

.option {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  border: 2px solid #e0e6ed;
  border-radius: 12px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.option:active { transform: scale(0.99); }

.option input {
  width: 22px;
  height: 22px;
  margin-top: 2px;
  flex-shrink: 0;
  accent-color: var(--primary);
}

.option span { flex: 1; font-size: 0.95rem; }

.option.selected { border-color: var(--primary); background: #e3f2fd; }
.option.correct { border-color: var(--success); background: #e8f5e9; color: var(--success); }
.option.wrong { border-color: var(--error); background: #ffebee; color: var(--error); }
.option.disabled { pointer-events: none; opacity: 1; }

.feedback {
  text-align: center;
  font-size: 1.1rem;
  font-weight: 700;
  margin: 16px 0;
  min-height: 1.5em;
}

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

.btn {
  display: block;
  width: 100%;
  border: none;
  border-radius: 12px;
  padding: 16px;
  font-size: 1.05rem;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
  margin-top: 8px;
  -webkit-tap-highlight-color: transparent;
}

.btn:active { opacity: 0.9; }
.btn-start { background: #43a047; }
.btn-check { background: #1e88e5; }
.btn-next { background: #fb8c00; }
.btn-retry { background: #fb8c00; }
.btn-end { background: #e53935; }

.score {
  text-align: center;
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--primary);
  margin: 20px 0;
}

.congrats {
  text-align: center;
  color: var(--success);
  font-size: 1.2rem;
  font-weight: 700;
  margin: 20px 0;
  white-space: pre-line;
}

.result-warn {
  text-align: center;
  font-weight: 700;
  color: var(--error);
  margin: 16px 0;
}

.hidden { display: none !important; }

.loading { text-align: center; color: var(--muted); padding: 40px; }

/* —— Menu trybów —— */
.mode-section { margin-top: 24px; }

.mode-heading {
  font-size: 1rem;
  font-weight: 700;
  color: var(--muted);
  text-align: center;
  margin-bottom: 16px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.mode-card {
  border: 2px solid #e0e6ed;
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
  background: #fafbfc;
}

.mode-card-save { padding: 0; overflow: hidden; }

.mode-card-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}

.mode-icon {
  font-size: 1.5rem;
  line-height: 1;
  flex-shrink: 0;
}

.mode-card h3,
.mode-toggle h3 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
  text-align: left;
}

.mode-desc {
  font-size: 0.88rem;
  color: var(--muted);
  line-height: 1.4;
}

.mode-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 16px;
  border: none;
  background: transparent;
  cursor: pointer;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
}

.mode-toggle-text { flex: 1; }

.mode-chevron {
  font-size: 0.75rem;
  color: var(--muted);
  transition: transform 0.2s;
  flex-shrink: 0;
}

.mode-toggle[aria-expanded="true"] .mode-chevron {
  transform: rotate(180deg);
}

.save-panel {
  padding: 0 16px 16px;
  border-top: 1px solid #e0e6ed;
  background: #fff;
}

.save-block { margin-top: 14px; }

.count-field { margin-bottom: 4px; }

.field-hint {
  font-size: 0.82rem;
  color: var(--muted);
  margin: -4px 0 10px;
  line-height: 1.4;
}

.field-hint strong {
  color: var(--primary);
  font-weight: 700;
}

.field-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 8px;
}

.field-input,
.field-select {
  display: block;
  width: 100%;
  padding: 14px 16px;
  font-size: 1rem;
  font-family: inherit;
  border: 2px solid #e0e6ed;
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  margin-bottom: 10px;
  transition: border-color 0.15s;
}

.field-input:focus,
.field-select:focus {
  outline: none;
  border-color: var(--primary);
}

.field-select:disabled {
  background: #f0f2f5;
  color: var(--muted);
  cursor: not-allowed;
}

.save-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 0 4px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.save-divider::before,
.save-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: #e0e6ed;
}

.save-empty-hint {
  font-size: 0.88rem;
  color: var(--muted);
  text-align: center;
  margin-top: 12px;
  font-style: italic;
}

.btn-save-new { background: #5e35b1; }
.btn-save-load { background: #00897b; }
.btn-exam { background: #3949ab; }

.mode-card-exam {
  border-color: #c5cae9;
  background: linear-gradient(180deg, #fafbff 0%, #f5f6ff 100%);
}

.exam-preview-toggle {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  cursor: pointer;
  margin: 14px 0 4px;
  -webkit-tap-highlight-color: transparent;
}

.exam-preview-toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.exam-preview-toggle .challenge-toggle-box {
  border-color: #3949ab;
}

.exam-preview-toggle input:checked + .challenge-toggle-box {
  background: #3949ab;
  border-color: #283593;
}

.exam-preview-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.exam-preview-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
}

.exam-preview-desc {
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.4;
}

.exam-result-note {
  text-align: center;
  color: var(--muted);
  font-size: 0.95rem;
  margin-bottom: 8px;
}

.exam-review-filters {
  display: flex;
  gap: 8px;
  margin: 14px 0 12px;
  flex-wrap: wrap;
}

.exam-filter-btn {
  flex: 1;
  min-width: 90px;
  padding: 10px 12px;
  border: 2px solid #e0e6ed;
  border-radius: 10px;
  background: #fff;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.exam-filter-btn.active {
  border-color: var(--primary);
  background: #e3f2fd;
  color: var(--primary);
}

.exam-filter-btn[data-filter="correct"].active {
  border-color: var(--success);
  background: #e8f5e9;
  color: var(--success);
}

.exam-filter-btn[data-filter="wrong"].active {
  border-color: var(--error);
  background: #ffebee;
  color: var(--error);
}

.exam-review-detail {
  margin-top: 14px;
  padding: 16px;
  border: 2px solid #e0e6ed;
  border-radius: 12px;
  background: #fafbfc;
}

.exam-review-detail .question-text {
  margin-top: 0;
  font-size: 1rem;
}

.exam-review-detail .option {
  cursor: default;
  margin-bottom: 8px;
}

.exam-review-detail .option.user-pick:not(.correct):not(.wrong) {
  border-color: var(--primary);
  background: #e3f2fd;
}

.exam-status-tag {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 20px;
  margin-bottom: 12px;
}

.exam-status-tag.ok {
  color: var(--success);
  background: #e8f5e9;
}

.exam-status-tag.bad {
  color: var(--error);
  background: #ffebee;
}

.header-bar .exam-badge {
  font-size: 0.75rem;
  font-weight: 600;
  color: #3949ab;
  background: #e8eaf6;
  padding: 4px 10px;
  border-radius: 20px;
}

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

.save-badge {
  font-size: 0.75rem;
  font-weight: 600;
  color: #5e35b1;
  background: #ede7f6;
  padding: 4px 10px;
  border-radius: 20px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}

.header-bar {
  flex-wrap: wrap;
}

/* —— Challenge —— */
.challenge-bar {
  margin: 20px 0 8px;
  border: 2px solid #ffe0b2;
  border-radius: 12px;
  background: linear-gradient(135deg, #fff8e1 0%, #fff3e0 100%);
  padding: 14px 16px;
}

.challenge-toggle {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.challenge-toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.challenge-toggle-box {
  width: 24px;
  height: 24px;
  border: 2px solid #fb8c00;
  border-radius: 6px;
  flex-shrink: 0;
  margin-top: 2px;
  background: #fff;
  position: relative;
  transition: background 0.15s, border-color 0.15s;
}

.challenge-toggle input:checked + .challenge-toggle-box {
  background: #fb8c00;
  border-color: #e65100;
}

.challenge-toggle input:checked + .challenge-toggle-box::after {
  content: "✓";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 14px;
  font-weight: 800;
}

.challenge-toggle-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.challenge-toggle-title {
  font-size: 1rem;
  font-weight: 800;
  color: #e65100;
}

.challenge-toggle-desc {
  font-size: 0.85rem;
  color: #8d6e63;
  line-height: 1.4;
}

.challenge-timer {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.95rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: #1565c0;
  background: #e3f2fd;
  padding: 6px 12px;
  border-radius: 20px;
  border: 2px solid #90caf9;
}

.challenge-timer.timer-warning {
  color: #e65100;
  background: #fff3e0;
  border-color: #ffb74d;
}

.challenge-timer.timer-critical {
  color: #c62828;
  background: #ffebee;
  border-color: #ef5350;
  animation: timer-pulse 0.8s ease-in-out infinite;
}

@keyframes timer-pulse {
  50% { transform: scale(1.04); }
}

.timer-icon { font-size: 0.9rem; }
