:root {
  --bg: #0f1724;
  --bg-grad: radial-gradient(1200px 600px at 50% -10%, #1b2a44 0%, #0f1724 55%);
  --card: #18233a;
  --card-2: #1f2c47;
  --text: #e8eefc;
  --muted: #93a1bf;
  --primary: #4f8cff;
  --primary-d: #3a6fd6;
  --green: #1fbf6b;
  --green-bg: rgba(31, 191, 107, 0.18);
  --red: #f0506e;
  --red-bg: rgba(240, 80, 110, 0.18);
  --border: #2a3a5c;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

/* Light theme overrides */
body.light {
  --bg: #eef2f9;
  --bg-grad: radial-gradient(1200px 600px at 50% -10%, #dfe8f7 0%, #eef2f9 55%);
  --card: #ffffff;
  --card-2: #f1f5fb;
  --text: #1a2438;
  --muted: #5f6c84;
  --primary: #2f6bff;
  --primary-d: #2456d6;
  --green: #11a85c;
  --green-bg: rgba(17, 168, 92, 0.14);
  --red: #e23a5e;
  --red-bg: rgba(226, 58, 94, 0.12);
  --border: #d6deed;
  --shadow: 0 10px 30px rgba(40, 60, 100, 0.12);
}

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

body { transition: background 0.25s, color 0.25s; }

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

.app { max-width: 760px; margin: 0 auto; }

.topbar { text-align: center; padding: 18px 0 22px; position: relative; }
.theme-toggle {
  position: absolute; top: 12px; right: 0;
  background: var(--card); color: var(--text);
  border: 1px solid var(--border); border-radius: 50%;
  width: 40px; height: 40px; font-size: 1.1rem; cursor: pointer;
  display: grid; place-items: center;
  box-shadow: var(--shadow); transition: transform 0.1s, background 0.2s;
}
.theme-toggle:hover { transform: scale(1.06); }
.theme-toggle:active { transform: scale(0.96); }
.topbar h1 { font-size: 1.7rem; letter-spacing: -0.02em; }
.tagline { color: var(--muted); font-size: 0.92rem; margin-top: 4px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px;
}

.screen { animation: fade 0.25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px);} to { opacity: 1; transform: none;} }

h2 { font-size: 1.25rem; margin-bottom: 10px; }
.muted { color: var(--muted); font-size: 0.92rem; }
.hidden { display: none !important; }

.field { margin: 20px 0; }
.field > label, .field > .field-label { display: block; font-weight: 600; margin-bottom: 8px; font-size: 0.95rem; }

.subject-list { display: grid; grid-template-columns: 1fr; gap: 8px; }
@media (min-width: 560px) { .subject-list { grid-template-columns: 1fr 1fr; } }

.subj {
  display: flex; align-items: center; gap: 10px;
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: border-color 0.15s, background 0.15s;
}
.subj:hover { border-color: var(--primary); }
.subj input { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }
.subj .cnt { margin-left: auto; color: var(--muted); font-size: 0.8rem; }

select {
  width: 100%; padding: 11px 12px;
  background: var(--card-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  font-size: 0.95rem;
}

.row { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 18px; }

.btn {
  border: none; border-radius: 10px;
  padding: 12px 20px; font-size: 0.98rem; font-weight: 600;
  cursor: pointer; transition: transform 0.05s, background 0.15s, opacity 0.15s;
  color: #fff;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); }
.btn-primary:hover { background: var(--primary-d); }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-ghost:hover { border-color: var(--primary); }
.btn-danger { background: var(--red); }
.btn-danger:hover { opacity: 0.9; }
.btn-sm { padding: 7px 12px; font-size: 0.85rem; }

.error { color: var(--red); margin-top: 12px; font-size: 0.9rem; }

/* ---- Quiz ---- */
.quiz-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.progress { color: var(--muted); font-size: 0.9rem; display: flex; gap: 8px; align-items: center; }
.progress .dot { opacity: 0.5; }
#scoreLabel { color: var(--text); font-weight: 600; }

.progress-bar { height: 6px; background: var(--card-2); border-radius: 99px; overflow: hidden; margin-bottom: 20px; }
.progress-fill { height: 100%; width: 0%; background: var(--primary); border-radius: 99px; transition: width 0.3s ease; }

.subject-tag {
  display: inline-block; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--primary); background: rgba(79,140,255,0.12);
  padding: 3px 9px; border-radius: 99px; margin-bottom: 12px;
}
.question { font-size: 1.18rem; line-height: 1.45; margin-bottom: 22px; }

.options { display: flex; flex-direction: column; gap: 12px; }
.option {
  text-align: left; width: 100%;
  background: var(--card-2); color: var(--text);
  border: 1.5px solid var(--border); border-radius: 12px;
  padding: 14px 16px; font-size: 1rem; cursor: pointer;
  display: flex; align-items: center; gap: 12px;
  transition: border-color 0.15s, background 0.15s;
}
.option:hover:not(:disabled) { border-color: var(--primary); }
.option:disabled { cursor: default; }
.option .key {
  flex: 0 0 26px; height: 26px; border-radius: 50%;
  background: var(--bg); border: 1px solid var(--border);
  display: grid; place-items: center; font-size: 0.85rem; font-weight: 700; color: var(--muted);
}

/* states */
.option.correct { border-color: var(--green); background: var(--green-bg); }
.option.correct .key { background: var(--green); color: #fff; border-color: var(--green); }
.option.wrong { border-color: var(--red); background: var(--red-bg); }
.option.wrong .key { background: var(--red); color: #fff; border-color: var(--red); }

.blink-green { animation: blinkGreen 0.4s ease 0s 2; }
.blink-red { animation: blinkRed 0.4s ease 0s 2; }
@keyframes blinkGreen {
  0%,100% { background: var(--green-bg); }
  50% { background: var(--green); color: #fff; }
}
@keyframes blinkRed {
  0%,100% { background: var(--red-bg); }
  50% { background: var(--red); color: #fff; }
}

.quiz-foot { margin-top: 22px; display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; }
.feedback { font-weight: 600; font-size: 0.95rem; }
.feedback.ok { color: var(--green); }
.feedback.no { color: var(--red); }

/* ---- Result ---- */
.result-score { font-size: 2.6rem; font-weight: 800; text-align: center; margin: 14px 0 4px; }
#finalPercent { text-align: center; margin-bottom: 18px; }
.breakdown { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
.breakdown .brow { display: flex; justify-content: space-between; font-size: 0.9rem; background: var(--card-2); padding: 9px 12px; border-radius: 8px; }
.breakdown .brow b { color: var(--text); }

/* ---- Review ---- */
.review-list { display: flex; flex-direction: column; gap: 14px; margin-top: 14px; max-height: 70vh; overflow-y: auto; }
.rev-item { background: var(--card-2); border: 1px solid var(--border); border-radius: 10px; padding: 14px; }
.rev-q { font-weight: 600; margin-bottom: 8px; }
.rev-opt { font-size: 0.9rem; padding: 4px 0; color: var(--muted); }
.rev-opt.correct { color: var(--green); }
.rev-opt.chosen-wrong { color: var(--red); text-decoration: line-through; }
.rev-badge { font-size: 0.72rem; padding: 2px 8px; border-radius: 99px; margin-left: 8px; }
.rev-badge.ok { background: var(--green-bg); color: var(--green); }
.rev-badge.no { background: var(--red-bg); color: var(--red); }

.footer { text-align: center; color: var(--muted); font-size: 0.8rem; padding: 22px 0; display: flex; flex-direction: column; gap: 4px; }
.footer .credit { font-size: 0.82rem; }
.footer .credit b { color: var(--primary); font-weight: 700; }
