:root {
  --primary: #1a365d;
  --accent: #2b6cb0;
  --bg: #f7fafc;
  --card: #ffffff;
  --success: #38a169;
  --success-dark: #276749;
  --danger: #e53e3e;
  --danger-dark: #c53030;
  --border: #e2e8f0;
  --muted: #718096;
  --text: #2d3748;
}

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

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

header {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  padding: 2rem 1rem;
  text-align: center;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

header.page {
  text-align: left;
  padding: 1.5rem 1rem;
}

header h1 { font-size: 1.8rem; margin-bottom: 0.5rem; }
header.page h1 { font-size: 1.5rem; margin: 0.4rem 0; }
header p { opacity: 0.9; }
header a { color: #bee3f8; text-decoration: none; font-size: 0.9rem; }
header a:hover { text-decoration: underline; }

.identity {
  margin-top: 0.75rem;
  font-size: 0.85rem;
  opacity: 0.95;
  line-height: 1.45;
}

.identity-line { display: block; }

.identity-avg {
  display: block;
  margin-top: 0.15rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.03em;
  opacity: 0.9;
}

.identity button {
  background: transparent;
  border: none;
  color: #bee3f8;
  text-decoration: underline;
  cursor: pointer;
  font: inherit;
}

.container { max-width: 1100px; margin: 0 auto; padding: 2rem 1rem; }
.container.narrow { max-width: 820px; padding: 1.5rem 1rem 3rem; }
.container.exam { max-width: 860px; }

.intro,
.lo-box {
  background: var(--card);
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 2rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  border-left: 5px solid var(--accent);
}

.lo-box {
  background: #ebf8ff;
  border-radius: 0 8px 8px 0;
  border-left-width: 4px;
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
  font-size: 0.95rem;
}

.note {
  background: #fffaf0;
  border: 1px solid #fbd38d;
  padding: 1rem;
  border-radius: 8px;
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
}

.card {
  background: var(--card);
  border-radius: 10px;
  padding: 1.25rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  transition: transform 0.15s, box-shadow 0.15s;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 15px rgba(0, 0, 0, 0.1);
}

.card h3 {
  color: var(--primary);
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
}

.card p {
  font-size: 0.9rem;
  color: #4a5568;
  flex-grow: 1;
  margin-bottom: 1rem;
}

.badge {
  display: inline-block;
  background: #edf2f7;
  color: var(--primary);
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  margin-bottom: 0.5rem;
}

.card-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: white;
  text-decoration: none;
  border: 2px solid var(--accent);
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
  flex: 1;
  min-width: 120px;
  text-align: center;
}

.btn:hover { background: var(--primary); border-color: var(--primary); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-secondary {
  background: white;
  color: var(--accent);
}

.btn-secondary:hover {
  background: #edf2f7;
  color: var(--primary);
  border-color: var(--primary);
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
}

.btn-danger:hover { background: var(--danger-dark); border-color: var(--danger-dark); }

.featured {
  grid-column: 1 / -1;
  background: linear-gradient(135deg, #2b6cb0, #3182ce);
  color: white;
  border: none;
}

.featured h3 { color: white; }
.featured p { color: rgba(255, 255, 255, 0.9); }
.featured .badge {
  background: rgba(255, 255, 255, 0.2);
  color: white;
}

.featured .btn-primary {
  background: white;
  color: var(--accent);
  border-color: white;
  font-weight: 600;
}

.featured .btn-primary:hover {
  background: #edf2f7;
  color: var(--primary);
}

.featured .btn-secondary {
  background: transparent;
  color: white;
  border-color: rgba(255, 255, 255, 0.85);
}

.featured .btn-secondary:hover {
  background: rgba(255, 255, 255, 0.15);
  color: white;
  border-color: white;
}

footer {
  text-align: center;
  padding: 2rem;
  color: var(--muted);
  font-size: 0.85rem;
}

footer a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

footer a:hover { text-decoration: underline; }

.question {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
  margin-bottom: 1.25rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.q-num {
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}

.q-text { font-weight: 600; margin-bottom: 0.9rem; }

.choices { display: flex; flex-direction: column; gap: 0.3rem; }

.choice {
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
  padding: 0.55rem 0.75rem;
  margin: 0;
  background: #f7fafc;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
}

.choice:hover { background: #edf2f7; }

.choice input[type="radio"] {
  margin-top: 0.35rem;
  accent-color: var(--accent);
}

.choice-body { flex: 1; padding-top: 0.15rem; }

.letter {
  flex-shrink: 0;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  border: 2px solid #cbd5e0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  background: white;
  color: var(--primary);
}

.learn-mode .choice { cursor: default; }

.reveal-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0.45rem 0.9rem;
  font-size: 0.9rem;
  cursor: pointer;
  margin-top: 0.75rem;
  font-family: inherit;
}

.reveal-btn:hover { background: var(--primary); }

.answer {
  display: none;
  margin-top: 1rem;
  padding: 1rem;
  background: #f0fff4;
  border-left: 4px solid var(--success-dark);
  border-radius: 0 6px 6px 0;
  font-size: 0.95rem;
}

.answer.show { display: block; }
.answer strong { color: var(--success-dark); }

.nav {
  display: flex;
  justify-content: space-between;
  margin-top: 2rem;
  gap: 1rem;
}

.nav a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.progress {
  position: sticky;
  top: 0;
  background: #fff;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  z-index: 10;
  font-size: 0.9rem;
  color: #4a5568;
}

.score-banner {
  background: #ebf8ff;
  border: 1px solid #90cdf4;
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
}

.score-banner h2 {
  color: var(--primary);
  margin-bottom: 0.35rem;
}

.score-banner .pct {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--accent);
}

.choice.correct-row {
  background: #f0fff4;
  border-color: #9ae6b4;
}

.choice.wrong-row {
  background: #fff5f5;
  border-color: #feb2b2;
}

.letter.correct-circle {
  border-color: var(--success);
  border-width: 3px;
  color: var(--success-dark);
  background: #f0fff4;
  box-shadow: 0 0 0 2px rgba(56, 161, 105, 0.28);
}

.letter.wrong-circle {
  border-color: var(--danger);
  border-width: 3px;
  color: var(--danger-dark);
  background: #fff5f5;
}

.mark {
  font-size: 0.8rem;
  font-weight: 700;
  margin-left: 0.35rem;
}

.mark.ok { color: var(--success-dark); }
.mark.bad { color: var(--danger-dark); }

.test-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin: 1.5rem 0 0.5rem;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.history-table th,
.history-table td {
  text-align: left;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

.history-table th {
  background: #edf2f7;
  color: var(--primary);
  font-size: 0.85rem;
}

.history-table tr:last-child td { border-bottom: none; }

.empty {
  background: var(--card);
  padding: 1.5rem;
  border-radius: 10px;
  color: #4a5568;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 54, 93, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 1rem;
}

.overlay[hidden] { display: none; }

.modal {
  background: white;
  border-radius: 12px;
  padding: 1.75rem;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
}

.modal h2 {
  color: var(--primary);
  margin-bottom: 0.5rem;
}

.modal p { color: #4a5568; margin-bottom: 1rem; }

.modal label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.35rem;
}

.modal input {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
  margin-bottom: 0.75rem;
}

.modal .error { color: var(--danger-dark); font-size: 0.85rem; margin-bottom: 0.75rem; }

.status-msg {
  font-size: 0.9rem;
  color: #4a5568;
  margin-top: 0.5rem;
}

.status-msg.error { color: var(--danger-dark); }
.status-msg.ok { color: var(--success-dark); }

@media (max-width: 520px) {
  header h1 { font-size: 1.4rem; }
  .card-actions { flex-direction: column; }
}
