:root {
  --primary: #4F46E5;
  --primary-dark: #3730A3;
  --primary-light: #EEF2FF;
  --green: #10B981;
  --red: #EF4444;
  --gold: #F59E0B;
  --purple: #7C3AED;
  --bg: #F5F7FF;
  --card: #FFFFFF;
  --text: #1E1B4B;
  --muted: #6B7280;
  --border: #E0E7FF;
  --radius: 14px;
  --shadow: 0 2px 12px rgba(79,70,229,0.08);
}

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

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
}

/* ── Layout ── */
.screen { display:none; min-height:100vh; flex-direction:column; }
.screen.active { display:flex; }

.topbar {
  background: white;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
  position: sticky; top:0; z-index:100;
}
.logo { font-weight:800; font-size:20px; color:var(--primary); display:flex; align-items:center; gap:8px; }
.logo span { background:linear-gradient(135deg,var(--primary),var(--purple)); color:white; width:32px; height:32px; border-radius:8px; display:flex; align-items:center; justify-content:center; font-size:16px; }

.page-content { padding:20px; max-width:780px; margin:0 auto; width:100%; flex:1; }

/* ── Cards ── */
.card { background:white; border-radius:var(--radius); padding:20px; box-shadow:var(--shadow); margin-bottom:16px; }
.card-title { font-size:16px; font-weight:700; margin-bottom:14px; }

/* ── Buttons ── */
.btn {
  padding:10px 20px; border-radius:10px; font-size:15px; font-weight:600;
  cursor:pointer; border:none; transition:all .2s; display:inline-flex; align-items:center; gap:6px;
}
.btn-primary { background:var(--primary); color:white; }
.btn-primary:hover { background:var(--primary-dark); transform:translateY(-1px); }
.btn-secondary { background:var(--bg); color:var(--text); border:2px solid var(--border); }
.btn-secondary:hover { border-color:var(--primary); color:var(--primary); }
.btn-success { background:var(--green); color:white; }
.btn-danger  { background:var(--red);   color:white; }
.btn-full    { width:100%; justify-content:center; padding:13px; }
.btn:disabled { opacity:.5; cursor:not-allowed; transform:none !important; }

/* ── Forms ── */
.form-group { margin-bottom:14px; }
.form-group label { display:block; font-weight:600; font-size:13px; margin-bottom:6px; color:var(--muted); text-transform:uppercase; letter-spacing:.5px; }
.form-group input, .form-group select, .form-group textarea {
  width:100%; padding:11px 14px; border:2px solid var(--border);
  border-radius:10px; font-size:15px; outline:none; transition:border-color .2s;
  font-family:inherit;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color:var(--primary); }
.form-group textarea { min-height:100px; resize:vertical; }

/* ── Alerts ── */
.alert { padding:12px 16px; border-radius:10px; font-size:14px; font-weight:500; margin-bottom:14px; display:flex; align-items:center; gap:8px; }
.alert-error   { background:#FEF2F2; color:#991B1B; border:1.5px solid #FECACA; }
.alert-success { background:#ECFDF5; color:#065F46; border:1.5px solid #6EE7B7; }
.alert-info    { background:var(--primary-light); color:var(--primary-dark); border:1.5px solid var(--border); }

/* ── Login screen ── */
#screen-login {
  background: linear-gradient(135deg, #4F46E5 0%, #7C3AED 60%, #EC4899 100%);
  align-items:center; justify-content:center; padding:20px;
}
.login-box {
  background:rgba(255,255,255,.12); backdrop-filter:blur(20px);
  border:1px solid rgba(255,255,255,.25); border-radius:24px;
  padding:40px 36px; width:100%; max-width:400px; color:white;
}
.login-box h1 { font-size:28px; font-weight:800; text-align:center; margin-bottom:4px; }
.login-box .sub { text-align:center; opacity:.8; margin-bottom:28px; font-size:14px; }
.login-box .form-group label { color:rgba(255,255,255,.8); }
.login-box input {
  background:rgba(255,255,255,.15); border-color:rgba(255,255,255,.3); color:white;
}
.login-box input::placeholder { color:rgba(255,255,255,.5); }
.login-box input:focus { border-color:rgba(255,255,255,.7); }
.btn-login { background:white; color:var(--primary); font-size:16px; font-weight:800; width:100%; padding:14px; border-radius:12px; border:none; cursor:pointer; transition:all .2s; margin-top:8px; }
.btn-login:hover { transform:translateY(-2px); box-shadow:0 8px 20px rgba(0,0,0,.2); }
.login-error { background:rgba(255,0,0,.15); border:1px solid rgba(255,100,100,.4); color:white; border-radius:8px; padding:10px 14px; font-size:13px; margin-bottom:12px; display:none; }

/* ── Topbar user info ── */
.topbar-user { display:flex; align-items:center; gap:10px; }
.topbar-name { font-weight:700; font-size:14px; }
.topbar-grade { font-size:12px; color:var(--muted); }
.avatar-sm { width:34px; height:34px; border-radius:50%; background:linear-gradient(135deg,var(--primary),var(--purple)); color:white; display:flex; align-items:center; justify-content:center; font-weight:700; font-size:13px; }
.btn-logout { background:none; border:none; color:var(--muted); cursor:pointer; font-size:13px; font-weight:600; padding:4px 8px; border-radius:6px; }
.btn-logout:hover { color:var(--red); background:#FEF2F2; }

/* ── Subject pills ── */
.filter-row { display:flex; gap:8px; flex-wrap:wrap; margin-bottom:16px; }
.pill { padding:6px 14px; border-radius:20px; border:2px solid var(--border); background:white; font-size:13px; font-weight:600; cursor:pointer; transition:all .15s; }
.pill:hover, .pill.active { border-color:var(--primary); background:var(--primary-light); color:var(--primary); }

/* ── Set cards ── */
.sets-grid { display:flex; flex-direction:column; gap:12px; }
.set-card {
  background:white; border-radius:var(--radius); padding:16px 18px;
  border:2px solid var(--border); cursor:pointer; transition:all .2s;
  display:flex; align-items:center; gap:14px;
}
.set-card:hover { border-color:var(--primary); transform:translateX(4px); box-shadow:var(--shadow); }
.set-icon { font-size:28px; flex-shrink:0; }
.set-info { flex:1; min-width:0; }
.set-title { font-weight:700; font-size:15px; margin-bottom:3px; }
.set-meta { font-size:12px; color:var(--muted); display:flex; gap:10px; flex-wrap:wrap; }
.set-badge { padding:2px 8px; border-radius:20px; font-size:11px; font-weight:700; }
.badge-weekly  { background:#EEF2FF; color:var(--primary); }
.badge-summer  { background:#FFF7ED; color:#C2410C; }
.badge-session { background:#F0FDF4; color:#166534; }
.badge-exam    { background:#FDF4FF; color:#7E22CE; }
.set-score { text-align:right; flex-shrink:0; }
.set-score .score-num { font-size:18px; font-weight:800; color:var(--primary); }
.set-score .score-lbl { font-size:11px; color:var(--muted); }
.set-score .done-check { color:var(--green); font-size:20px; }

/* ── Quiz screen ── */
#screen-quiz .page-content { max-width:680px; }
.quiz-topbar-right { display:flex; align-items:center; gap:12px; }
.timer {
  background:white; border:2px solid var(--border);
  padding:6px 14px; border-radius:20px; font-weight:700; font-size:15px;
  min-width:70px; text-align:center; transition:all .3s;
}
.timer.urgent { border-color:var(--red); color:var(--red); animation:blink .5s infinite alternate; }
@keyframes blink { from{opacity:1} to{opacity:.5} }

.quiz-progress { margin-bottom:20px; }
.progress-label { display:flex; justify-content:space-between; font-size:13px; color:var(--muted); margin-bottom:6px; font-weight:600; }
.progress-bar { background:var(--border); border-radius:10px; height:8px; }
.progress-fill { background:linear-gradient(90deg,var(--primary),var(--purple)); height:100%; border-radius:10px; transition:width .4s ease; }

.question-card { background:white; border-radius:var(--radius); padding:24px; box-shadow:var(--shadow); margin-bottom:16px; }
.q-num { font-size:12px; color:var(--muted); font-weight:700; text-transform:uppercase; letter-spacing:1px; margin-bottom:10px; }
.q-text { font-size:17px; font-weight:600; line-height:1.6; margin-bottom:6px; }
.q-image { max-width:100%; border-radius:10px; margin:12px 0; max-height:280px; object-fit:contain; }
.audio-player { width:100%; margin:10px 0; }

.options { display:flex; flex-direction:column; gap:10px; margin-top:16px; }
.option {
  display:flex; align-items:flex-start; gap:12px;
  padding:13px 16px; border:2px solid var(--border);
  border-radius:12px; cursor:pointer; transition:all .15s;
  font-size:15px; font-weight:500; background:white; width:100%; text-align:left;
  line-height:1.5;
}
.option:hover:not(:disabled) { border-color:var(--primary); background:var(--primary-light); }
.option.selected { border-color:var(--primary); background:var(--primary-light); }
.option.correct  { border-color:var(--green); background:#ECFDF5; }
.option.wrong    { border-color:var(--red);   background:#FEF2F2; }
.option:disabled { cursor:default; }
.opt-letter {
  width:28px; height:28px; border-radius:50%; background:var(--bg);
  display:flex; align-items:center; justify-content:center;
  font-weight:800; font-size:13px; flex-shrink:0; transition:all .15s;
}
.option.selected .opt-letter { background:var(--primary); color:white; }
.option.correct  .opt-letter { background:var(--green);   color:white; }
.option.wrong    .opt-letter { background:var(--red);     color:white; }
.opt-img { max-width:120px; border-radius:6px; margin-top:4px; }

.essay-area { width:100%; min-height:160px; padding:12px; border:2px solid var(--border); border-radius:10px; font-size:15px; font-family:inherit; outline:none; resize:vertical; margin-top:12px; }
.essay-area:focus { border-color:var(--primary); }

.feedback { border-radius:10px; padding:12px 16px; font-size:14px; font-weight:600; margin-bottom:14px; display:none; line-height:1.5; }
.feedback.show { display:block; }
.feedback.ok   { background:#ECFDF5; color:#065F46; border:1.5px solid #6EE7B7; }
.feedback.bad  { background:#FEF2F2; color:#991B1B; border:1.5px solid #FECACA; }

/* ── Result screen ── */
#screen-result { align-items:center; justify-content:center; padding:20px; }
.result-card { background:white; border-radius:24px; padding:36px 32px; max-width:460px; width:100%; text-align:center; box-shadow:0 12px 40px rgba(79,70,229,.15); }
.result-emoji { font-size:64px; animation:pop .5s ease; margin-bottom:12px; }
@keyframes pop { 0%{transform:scale(0)} 70%{transform:scale(1.15)} 100%{transform:scale(1)} }
.result-card h2 { font-size:24px; font-weight:800; margin-bottom:6px; }
.result-card .result-sub { color:var(--muted); margin-bottom:24px; font-size:14px; }
.score-box { background:linear-gradient(135deg,var(--primary),var(--purple)); color:white; border-radius:16px; padding:20px; margin-bottom:20px; }
.score-big { font-size:52px; font-weight:900; line-height:1; }
.score-max { font-size:20px; opacity:.7; }
.score-pct { font-size:13px; opacity:.8; margin-top:4px; }
.result-stats { display:flex; justify-content:center; gap:24px; margin-bottom:20px; }
.res-stat .val { font-size:20px; font-weight:800; }
.res-stat .lbl { font-size:11px; color:var(--muted); }
.btn-group { display:flex; gap:10px; }
.btn-group .btn { flex:1; }

/* ── History ── */
.history-item {
  display:flex; align-items:center; gap:12px;
  padding:14px 16px; background:white;
  border-radius:var(--radius); border:2px solid var(--border);
  margin-bottom:10px; cursor:pointer; transition:all .15s;
}
.history-item:hover { border-color:var(--primary); }
.hist-icon { font-size:24px; }
.hist-info { flex:1; }
.hist-title { font-weight:700; font-size:14px; }
.hist-meta  { font-size:12px; color:var(--muted); margin-top:2px; }
.hist-score { text-align:right; }
.hist-score .pct { font-size:18px; font-weight:800; }
.hist-score .lbl { font-size:11px; color:var(--muted); }
.pct-green { color:var(--green); }
.pct-gold  { color:var(--gold); }
.pct-red   { color:var(--red); }

/* ── Responsive ── */
@media (max-width:500px) {
  .login-box { padding:28px 20px; }
  .question-card { padding:16px; }
  .q-text { font-size:15px; }
  .result-card { padding:24px 16px; }
  .score-big { font-size:40px; }
}

/* ── Math Practice ── */
.math-practice-banner {
  display:flex; align-items:center; gap:14px;
  background:linear-gradient(135deg,#FFF7ED,#FEF3C7);
  border:2px solid #FCD34D; border-radius:var(--radius);
  padding:14px 18px; margin-bottom:16px; cursor:pointer;
  transition:all .2s;
}
.math-practice-banner:hover { border-color:var(--gold); transform:translateX(4px); }

.math-op-btn {
  padding:10px 18px; border-radius:10px; font-size:16px; font-weight:700;
  cursor:pointer; border:2px solid var(--border); background:white;
  transition:all .15s; color:var(--muted);
}
.math-op-btn.active { border-color:var(--primary); background:var(--primary-light); color:var(--primary); }

.math-row {
  display:flex; align-items:center; gap:10px;
  background:white; border:2px solid var(--border);
  border-radius:12px; padding:12px 16px; margin-bottom:10px;
  transition:all .2s;
}
.math-row-ok  { border-color:var(--green); background:#F0FDF4; }
.math-row-err { border-color:var(--red);   background:#FEF2F2; }

.math-idx { font-size:13px; color:var(--muted); font-weight:700; min-width:24px; }

.math-eq { display:flex; align-items:center; gap:8px; flex:1; flex-wrap:wrap; }

.math-num {
  font-size:22px; font-weight:800; color:var(--text);
  min-width:32px; text-align:center;
}
.math-op-sym {
  font-size:20px; font-weight:800; color:var(--primary); min-width:20px; text-align:center;
}
.math-blank {
  width:64px; height:40px; text-align:center; font-size:20px; font-weight:800;
  border:2px solid var(--primary); border-radius:8px; outline:none;
  color:var(--primary); transition:border-color .15s;
}
.math-blank:focus { border-color:var(--purple); box-shadow:0 0 0 3px rgba(79,70,229,.15); }
.math-blank:disabled { background:var(--bg); color:var(--muted); border-color:var(--border); }

.math-done-btn {
  width:36px; height:36px; border-radius:8px; border:none;
  background:var(--primary); color:white; font-size:16px; font-weight:700;
  cursor:pointer; flex-shrink:0; transition:all .15s;
}
.math-done-btn:hover:not(:disabled) { background:var(--primary-dark); }
.math-done-btn:disabled { opacity:.6; cursor:default; }
.math-row-ok  .math-done-btn { background:var(--green); }
.math-row-err .math-done-btn { background:var(--red); }

.math-hint {
  font-size:13px; font-weight:700; color:var(--red);
  margin-left:4px; white-space:nowrap;
}

.math-result-box {
  background:white; border-radius:24px; padding:32px;
  text-align:center; box-shadow:0 12px 40px rgba(79,70,229,.15);
  margin-bottom:24px;
}
.math-result-title { font-size:22px; font-weight:800; margin:8px 0; }
.math-result-score {
  font-size:56px; font-weight:900; color:var(--primary);
  line-height:1; margin:12px 0 4px;
}
.math-result-pct { font-size:16px; color:var(--muted); font-weight:600; }
