:root {
  --bg: #eef2f7;
  --card: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --accent: #0ea5e9;
  --correct: #059669;
  --correct-bg: #d1fae5;
  --incorrect: #dc2626;
  --incorrect-bg: #fee2e2;
  --border: #e2e8f0;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', Arial, sans-serif;
  background: linear-gradient(160deg, #eef2ff 0%, #faf5ff 45%, #ecfeff 100%);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

#app {
  width: 100%;
  max-width: 560px;
}

.screen { display: none; }
.screen.active {
  display: block;
  background: var(--card);
  border-radius: 16px;
  border-top: 5px solid var(--primary);
  padding: 32px;
  box-shadow: 0 10px 30px rgba(79, 70, 229, 0.12);
}

h1 {
  margin: 0 0 4px;
  font-size: 28px;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.subtitle { margin: 0 0 24px; color: var(--muted); }

label { display: block; font-weight: 600; margin-bottom: 6px; }

input[type="number"] {
  width: 100%;
  padding: 10px 12px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 20px;
}

.categories { margin-bottom: 24px; }
.categories > p { font-weight: 600; margin-bottom: 8px; }

#category-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.category-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: normal;
  padding: 8px 10px;
  background: var(--bg);
  border-radius: 8px;
  border-left: 3px solid var(--cat, var(--border));
  cursor: pointer;
  font-size: 14px;
}

.category-item .count { color: var(--muted); font-size: 12px; }

.cat-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--cat, var(--muted));
  flex: none;
}

.category-buttons { display: flex; gap: 8px; }
.category-buttons button {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
}

button.primary {
  width: 100%;
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  background: var(--primary);
  border: none;
  border-radius: 10px;
  cursor: pointer;
}
button.primary:hover { background: var(--primary-dark); }

.error { color: var(--incorrect); font-size: 14px; margin-top: 10px; min-height: 18px; }

.back-link, .quit-link {
  background: none;
  border: none;
  color: var(--primary-dark);
  font-size: 13px;
  cursor: pointer;
  padding: 0;
  margin-bottom: 16px;
  display: inline-block;
}

.year-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.year-tile {
  padding: 24px 12px;
  font-size: 18px;
  font-weight: 700;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.year-tile:not(:disabled):hover { background: #dbeafe; border-color: var(--primary); }
.year-tile:disabled {
  cursor: not-allowed;
  color: var(--muted);
  opacity: 0.6;
}
.year-tile .soon {
  font-size: 11px;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.quiz-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  font-size: 14px;
  color: var(--muted);
}
.quiz-header .quit-link { margin-bottom: 0; }

.tag {
  background: color-mix(in srgb, var(--cat, var(--primary)) 15%, white);
  color: color-mix(in srgb, var(--cat, var(--primary)) 78%, black);
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 12px;
}

.diagram-container {
  display: none;
  justify-content: center;
  margin-bottom: 16px;
  color: var(--text);
}
.diagram-svg { width: 100%; max-width: 320px; height: auto; }

.question-text {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 20px;
  line-height: 1.4;
}

.answer-section {
  background: var(--bg);
  border-radius: 10px;
  padding: 16px 20px;
  margin-bottom: 20px;
}
.answer-section h3 { margin: 0 0 8px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.answer-section ol { margin: 0 0 12px; padding-left: 20px; }
.answer-section li { margin-bottom: 4px; }
.final-answer { font-size: 18px; font-weight: 700; margin: 0; color: var(--primary-dark); }

.hidden { display: none !important; }

.answer-form {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.answer-form input[type="text"] {
  flex: 1;
  padding: 12px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.answer-form input[type="text"]:disabled { background: var(--bg); color: var(--muted); }
.answer-form button.primary { width: auto; padding: 12px 20px; }
.answer-form button.primary:disabled { background: var(--muted); cursor: not-allowed; }

.feedback-text {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 16px;
}
.feedback-text.correct { color: var(--correct); }
.feedback-text.incorrect { color: var(--incorrect); }

.score-text { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.score-percent {
  font-size: 48px;
  font-weight: 800;
  margin: 0 0 24px;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.mode-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
.mode-tile {
  padding: 20px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  text-align: left;
}
.mode-tile:hover { background: #eef2ff; border-color: var(--primary); }
.mode-title { font-size: 17px; font-weight: 700; }
.mode-desc { font-size: 12px; color: var(--muted); line-height: 1.4; }

#practice-mode-btn { border-left: 4px solid var(--correct); }
#exam-mode-btn { border-left: 4px solid #d97706; }
#interactive-mode-btn { border-left: 4px solid var(--primary); }

.choice-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-bottom: 16px;
}
.choice-btn {
  padding: 14px 12px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: transform .06s ease, border-color .15s ease, background .15s ease;
}
.choice-btn:hover:not(:disabled) { border-color: var(--primary); background: #eef2ff; }
.choice-btn:active:not(:disabled) { transform: translateY(1px); }
.choice-btn:disabled { cursor: default; opacity: 1; }
.choice-btn.selected { border-color: var(--primary); background: #eef2ff; font-weight: 600; }
.choice-btn.is-correct { border-color: var(--correct); background: var(--correct-bg); color: #065f46; }
.choice-btn.is-incorrect { border-color: var(--incorrect); background: var(--incorrect-bg); color: #991b1b; }

.exam-time-info { font-size: 14px; color: var(--muted); margin: -12px 0 20px; }

button.secondary {
  width: 100%;
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  background: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  margin-bottom: 10px;
}
button.secondary:hover { background: var(--bg); }

.timer {
  font-weight: 700;
  color: var(--text);
}
.timer.low-time { color: var(--incorrect); }

.exam-nav { display: flex; gap: 8px; margin-bottom: 12px; }
.exam-nav button { flex: 1; }
.exam-nav button:disabled { opacity: 0.4; cursor: not-allowed; }
.exam-qgrid { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.exam-qgrid button {
  width: 34px; height: 34px; padding: 0; font-size: 13px; font-weight: 600;
  border: 1px solid var(--border); border-radius: 8px; background: none; color: var(--text); cursor: pointer;
}
.exam-qgrid button.answered { background: color-mix(in srgb, var(--primary) 15%, white); border-color: var(--primary); }
.exam-qgrid button.correct { background: var(--correct); border-color: var(--correct); color: #fff; }
.exam-qgrid button.incorrect { background: var(--incorrect); border-color: var(--incorrect); color: #fff; }
.exam-qgrid button.skipped { background: #facc15; border-color: #eab308; color: #111; }
.exam-legend { font-size: 13px; color: var(--muted); margin: 0 0 10px; }
.exam-legend .lg { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin: 0 4px 0 10px; vertical-align: middle; }
.exam-legend .lg:first-child { margin-left: 0; }
.exam-legend .lg.correct { background: var(--correct); }
.exam-legend .lg.incorrect { background: var(--incorrect); }
.exam-legend .lg.skipped { background: #facc15; }
.exam-qgrid button.current { outline: 2px solid var(--primary-dark); }

.exam-status-text { font-size: 15px; font-weight: 600; margin-bottom: 8px; }
.exam-status-text.ok { color: var(--correct); }
.exam-status-text.timeout { color: var(--incorrect); }

.exam-review { margin: 24px 0; text-align: left; }
.exam-review h3, .exam-history h3 { font-size: 15px; margin-bottom: 10px; }
.exam-review-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.exam-review-item {
  padding: 10px 14px;
  border-radius: 8px;
  border-left: 4px solid var(--border);
  background: var(--bg);
  font-size: 14px;
}
.exam-review-item.correct { border-left-color: var(--correct); }
.exam-review-item.incorrect { border-left-color: var(--incorrect); }
.exam-review-q { font-weight: 600; margin: 0 0 4px; }
.exam-review-a { margin: 0; color: var(--muted); }
.exam-review-correct { margin: 2px 0 0; color: var(--incorrect); }

.exam-history { margin-bottom: 24px; text-align: left; }
.exam-history-list { display: flex; flex-direction: column; gap: 6px; }
.exam-history-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  background: var(--bg);
  border-radius: 8px;
  font-size: 13px;
}
.exam-history-date { color: var(--muted); }
.exam-history-score { font-weight: 700; }
.exam-history-reason { color: var(--muted); }
.exam-history-empty { color: var(--muted); font-size: 13px; }

.q-card {
  background: #fff;
  border: 1px solid var(--border);
  border-left: 5px solid var(--primary);
  border-radius: 10px;
  padding: 14px 16px;
}
.review-your-answer {
  margin: 0 0 14px;
  padding: 10px 14px;
  border-radius: 8px;
  font-weight: 600;
  border-left: 5px solid var(--border);
  background: var(--bg);
}
.review-your-answer.correct { background: var(--correct-bg); border-left-color: var(--correct); color: #065f46; }
.review-your-answer.incorrect { background: var(--incorrect-bg); border-left-color: var(--incorrect); color: #991b1b; }
.review-your-answer.skipped { background: #fef9c3; border-left-color: #eab308; color: #854d0e; }

.answer-section { border: 1px dashed var(--border); }
.answer-section h3 { border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.final-answer {
  background: var(--correct-bg);
  border-left: 5px solid var(--correct);
  color: #065f46;
  border-radius: 8px;
  padding: 10px 14px;
}

.choice-btn { display: flex; align-items: center; gap: 12px; text-align: left; }
.choice-letter {
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  background: var(--bg);
  border: 1px solid var(--border);
}
.choice-btn.selected .choice-letter { background: var(--primary); border-color: var(--primary); color: #fff; }
.choice-btn.is-correct .choice-letter { background: var(--correct); border-color: var(--correct); color: #fff; }
.choice-btn.is-incorrect .choice-letter { background: var(--incorrect); border-color: var(--incorrect); color: #fff; }

/* ---------- Accounts, admin and mobile ---------- */

input[type="text"], input[type="email"], input[type="password"] {
  width: 100%;
  padding: 10px 12px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 14px;
  font-family: inherit;
}
.auth-form button.primary { width: 100%; }
.auth-switch { margin: 18px 0 0; text-align: center; color: var(--muted); font-size: 14px; }
.back-link.inline { margin: 0; font-size: 14px; font-weight: 600; }

.user-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 0 4px 10px;
  font-size: 14px;
  color: var(--muted);
}
.user-bar-actions { display: flex; gap: 14px; }
.bar-link { background: none; border: none; color: var(--primary-dark); font-size: 14px; font-weight: 600; cursor: pointer; padding: 6px 0; }

.no-access { text-align: center; color: var(--muted); }
.no-access .secondary { margin-top: 12px; }

.admin-msg { min-height: 20px; margin: 0 0 12px; font-size: 14px; font-weight: 600; }
.admin-msg.ok { color: var(--correct); }
.admin-msg.error { color: var(--incorrect); }
.admin-card { border: 1px solid var(--border); border-radius: 12px; padding: 14px; margin-bottom: 14px; }
.admin-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.admin-email { font-size: 13px; color: var(--muted); word-break: break-all; }
.role-badge { font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; background: var(--bg); color: var(--muted); white-space: nowrap; }
.role-badge.admin { background: #e0e7ff; color: var(--primary-dark); }
.admin-note { margin: 0 0 10px; font-size: 13px; color: var(--muted); }
.admin-subject-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin-bottom: 8px; }
.admin-subject-label { width: 90px; font-weight: 600; font-size: 14px; }
.admin-year { display: inline-flex; align-items: center; gap: 2px; font-weight: 500; font-size: 14px; margin: 0; padding: 4px 0; }
.admin-year input { width: 18px; height: 18px; margin: 0 4px 0 0; }
.admin-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
button.small { width: auto; padding: 8px 14px; font-size: 13px; }
button.danger { color: var(--incorrect); border-color: var(--incorrect); }

@media (max-width: 600px) {
  body {
    display: block;
    padding: calc(12px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left));
  }
  .screen.active { padding: 20px 16px; }
  h1 { font-size: 24px; }
  .question-text { font-size: 18px; }
  .choice-btn, button.primary, button.secondary { min-height: 48px; }
}

/* ---------- Modern theme ---------- */

:root {
  --bg: #f1f5f9;
  --border: #e5e7eb;
  --primary: #5b5bf0;
  --primary-dark: #4338ca;
  --radius: 16px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

body {
  font-family: var(--font);
  background:
    radial-gradient(900px 500px at 10% -10%, rgba(91, 91, 240, 0.16), transparent 60%),
    radial-gradient(800px 500px at 100% 0%, rgba(14, 165, 233, 0.14), transparent 60%),
    #f8fafc;
  background-attachment: fixed;
}

.screen.active {
  border-top: none;
  border-radius: 24px;
  box-shadow: var(--shadow-md);
  border: 1px solid rgba(226, 232, 240, 0.8);
  animation: screen-in 0.25s ease;
}
@keyframes screen-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .screen.active { animation: none; }
}

h1 { font-weight: 800; letter-spacing: -0.02em; }
.subtitle { color: var(--muted); font-size: 15px; }
.brand-logo { display: block; width: 64px; height: 64px; border-radius: 16px; margin-bottom: 14px; box-shadow: var(--shadow-md); }
.tagline { margin: 2px 0 18px; font-size: 15px; color: var(--muted); }

input[type="text"], input[type="email"], input[type="password"], input[type="number"] {
  background: #fff;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(91, 91, 240, 0.15);
}
button:focus-visible { outline: 3px solid rgba(91, 91, 240, 0.4); outline-offset: 2px; }

button.primary {
  background: linear-gradient(135deg, var(--primary), #3b82f6);
  border-radius: 14px;
  box-shadow: 0 6px 16px rgba(91, 91, 240, 0.28);
  transition: transform 0.12s, box-shadow 0.12s, filter 0.12s;
}
button.primary:hover { background: linear-gradient(135deg, var(--primary-dark), #2563eb); }
button.primary:active { transform: translateY(1px); box-shadow: 0 3px 10px rgba(91, 91, 240, 0.28); }
button.primary:disabled { filter: grayscale(0.6); opacity: 0.7; cursor: not-allowed; }

button.secondary {
  background: #fff;
  border-radius: 14px;
  border: 1.5px solid var(--border);
  box-shadow: var(--shadow-sm);
  transition: background 0.12s, border-color 0.12s;
}
button.secondary:hover:not(:disabled) { background: #f8fafc; border-color: #cbd5e1; }

.year-tile, .mode-tile {
  background: #fff;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}
.year-tile:not(:disabled):hover, .mode-tile:hover {
  background: #fff;
  border-color: var(--primary);
  box-shadow: 0 10px 24px rgba(91, 91, 240, 0.16);
  transform: translateY(-2px);
}
.year-tile:disabled { background: #f8fafc; box-shadow: none; }

.category-item {
  background: #fff;
  border: 1.5px solid var(--border);
  border-left: 4px solid var(--cat, var(--border));
  border-radius: 12px;
  transition: background 0.12s;
}
.category-item:hover { background: #f8fafc; }
.category-buttons button { border-radius: 10px; background: #fff; }

.tag {
  border-radius: 999px;
  letter-spacing: 0.01em;
}
.quiz-header { padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.q-card {
  border: none;
  border-left: 5px solid var(--primary);
  border-radius: var(--radius);
  background: #f8fafc;
  box-shadow: none;
}
.question-text { font-weight: 650; letter-spacing: -0.01em; }

.choice-btn {
  border: 1.5px solid var(--border);
  border-radius: 14px;
  background: #fff;
  box-shadow: var(--shadow-sm);
  transition: transform 0.12s, border-color 0.12s, background 0.12s, box-shadow 0.12s;
}
.choice-btn:hover:not(:disabled) {
  background: #f5f5ff;
  border-color: var(--primary);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(91, 91, 240, 0.12);
}

.answer-section { border-radius: var(--radius); background: #f8fafc; }
.feedback-text { border-radius: 12px; }

.exam-qgrid button { border-radius: 10px; transition: transform 0.1s; }
.exam-qgrid button:hover { transform: translateY(-1px); }
.score-percent { font-weight: 800; }
.exam-history-item { border-radius: 12px; background: #f8fafc; }

.user-bar {
  background: rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(226, 232, 240, 0.8);
  border-radius: 999px;
  padding: 6px 8px 6px 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}
.bar-link { padding: 6px 12px; border-radius: 999px; }
.bar-link:hover { background: #eef2ff; }

.admin-card { border-radius: var(--radius); box-shadow: var(--shadow-sm); border: 1.5px solid var(--border); }
.timer { font-variant-numeric: tabular-nums; background: #f1f5f9; padding: 4px 10px; border-radius: 999px; }
.timer.low-time { background: var(--incorrect-bg); }
