/* ===================== MtihaniPro styles ===================== */
:root {
  --blue: #1554C0;
  --blue-dark: #0E2A5E;
  --blue-soft: #E8F0FE;
  --yellow: #FFC72C;
  --yellow-dark: #E5A800;
  --green: #1F9D55;
  --red: #E03131;
  --ink: #1A2233;
  --muted: #6A7488;
  --line: #E2E7F0;
  --card: #FFFFFF;
  --bg: #F4F7FC;
  --radius: 16px;
  --shadow: 0 6px 20px rgba(14, 42, 94, 0.10);
  --shadow-sm: 0 2px 8px rgba(14, 42, 94, 0.08);
  --maxw: 480px;
  --nav-h: 64px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: var(--maxw);
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
  position: relative;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: var(--blue);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.brand { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.brand-logo { width: 30px; height: 30px; border-radius: 8px; }
.brand-name { font-weight: 800; font-size: 1.15rem; letter-spacing: 0.3px; }
.brand-accent { color: var(--yellow); }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.streak-badge {
  background: rgba(255,255,255,0.16); color: #fff;
  padding: 5px 10px; border-radius: 999px; font-weight: 700; font-size: 0.85rem;
}
.lang-toggle {
  background: var(--yellow); color: var(--blue-dark);
  border: none; border-radius: 999px; padding: 6px 14px;
  font-weight: 800; cursor: pointer; font-size: 0.85rem; min-width: 46px;
}
.lang-toggle:active { transform: scale(0.96); }

/* ---------- Screens ---------- */
.screen { display: none; padding: 16px; animation: fade 0.25s ease; }
.screen.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px);} to { opacity: 1; transform: none;} }

.section-title { font-size: 1.05rem; font-weight: 800; margin: 8px 0 12px; }

/* ---------- Hero ---------- */
.hero {
  background: linear-gradient(135deg, var(--blue) 0%, var(--blue-dark) 100%);
  color: #fff; border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow); margin-bottom: 18px;
}
.hero h1 { margin: 0 0 6px; font-size: 1.35rem; font-weight: 800; }
.hero-sub { margin: 0; opacity: 0.92; font-size: 0.92rem; }
.plan-banner {
  margin-top: 14px; font-size: 0.82rem; font-weight: 700;
  background: rgba(255,199,44,0.18); color: var(--yellow);
  display: inline-block; padding: 6px 12px; border-radius: 999px;
}

/* ---------- Subject grid ---------- */
.subject-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.subject-card {
  background: var(--card); border-radius: var(--radius); padding: 14px;
  box-shadow: var(--shadow-sm); border: 1px solid var(--line);
  cursor: pointer; position: relative; text-align: left;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.subject-card:active { transform: scale(0.98); }
.subject-card .subj-top { display: flex; align-items: center; justify-content: space-between; }
.subject-card .subj-icon { font-size: 1.8rem; }
.subject-card .subj-name { font-weight: 800; font-size: 0.98rem; margin: 10px 0 2px; }
.subject-card .subj-topic { font-size: 0.74rem; color: var(--muted); }
.lock-chip {
  position: absolute; top: 10px; right: 10px;
  background: var(--yellow); color: var(--blue-dark);
  font-size: 0.62rem; font-weight: 800; padding: 3px 7px; border-radius: 999px;
}
.subject-card.locked { opacity: 0.92; }

/* progress ring */
.ring { --p: 0; width: 44px; height: 44px; position: relative; }
.ring svg { transform: rotate(-90deg); }
.ring .ring-label {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 0.62rem; font-weight: 800; color: var(--blue);
}

/* ---------- Buttons ---------- */
.btn-primary, .btn-secondary, .btn-ghost, .btn-outline {
  font-family: inherit; font-weight: 800; cursor: pointer;
  border-radius: 12px; padding: 14px 18px; font-size: 1rem; border: none;
  width: 100%; transition: transform 0.1s ease, background 0.15s ease;
}
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:active { transform: scale(0.98); }
.btn-secondary { background: var(--yellow); color: var(--blue-dark); }
.btn-outline { background: #fff; color: var(--blue); border: 2px solid var(--blue); }
.btn-ghost {
  background: transparent; color: var(--blue); width: auto; padding: 8px 6px; font-size: 0.9rem;
}
.btn-row { display: flex; gap: 10px; margin-top: 14px; }
.btn-row > * { flex: 1; }

/* ---------- Quiz ---------- */
.quiz-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.quiz-meta { display: flex; align-items: center; gap: 10px; }
.quiz-subject { font-weight: 800; color: var(--blue); }
.quiz-timer {
  font-weight: 800; background: var(--blue-soft); color: var(--blue-dark);
  padding: 5px 10px; border-radius: 999px; font-variant-numeric: tabular-nums;
}
.quiz-timer.warn { background: #FDECEC; color: var(--red); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.6; } }
.progress-line { height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; }
.progress-line-fill { height: 100%; width: 0%; background: var(--yellow); transition: width 0.3s ease; }
.quiz-counter { font-size: 0.8rem; color: var(--muted); margin: 8px 0 12px; font-weight: 700; }

.question-card {
  background: var(--card); border-radius: var(--radius); padding: 18px;
  box-shadow: var(--shadow-sm); border: 1px solid var(--line);
}
.q-topic {
  display: inline-block; font-size: 0.68rem; font-weight: 800; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--blue); background: var(--blue-soft);
  padding: 3px 9px; border-radius: 999px; margin-bottom: 10px;
}
.q-text { font-size: 1.08rem; font-weight: 700; margin: 0 0 16px; }
.choices { display: flex; flex-direction: column; gap: 10px; }
.choice {
  text-align: left; background: #fff; border: 2px solid var(--line);
  border-radius: 12px; padding: 13px 14px; font-size: 0.98rem; font-family: inherit;
  cursor: pointer; display: flex; align-items: center; gap: 10px; color: var(--ink);
  transition: border-color 0.12s ease, background 0.12s ease;
}
.choice .letter {
  flex: 0 0 26px; height: 26px; border-radius: 50%; background: var(--blue-soft);
  color: var(--blue); font-weight: 800; display: flex; align-items: center; justify-content: center;
  font-size: 0.82rem;
}
.choice:active { transform: scale(0.995); }
.choice.correct { border-color: var(--green); background: #E9F8EF; }
.choice.correct .letter { background: var(--green); color: #fff; }
.choice.wrong { border-color: var(--red); background: #FDECEC; }
.choice.wrong .letter { background: var(--red); color: #fff; }
.choice.disabled { cursor: default; pointer-events: none; }
.choice.chosen { border-color: var(--blue); }

.feedback {
  margin-top: 14px; padding: 14px; border-radius: 12px; font-size: 0.92rem;
  border-left: 5px solid var(--blue);
}
.feedback.ok { background: #E9F8EF; border-color: var(--green); }
.feedback.no { background: #FDECEC; border-color: var(--red); }
.feedback .fb-title { font-weight: 800; margin-bottom: 4px; }
.quiz-actions { margin-top: 16px; }

/* ---------- Results ---------- */
.result-hero {
  text-align: center; background: linear-gradient(135deg, var(--blue), var(--blue-dark));
  color: #fff; border-radius: var(--radius); padding: 24px 18px; box-shadow: var(--shadow);
}
.result-score { font-size: 3rem; font-weight: 800; line-height: 1; }
.result-div {
  display: inline-block; margin-top: 10px; font-weight: 800; font-size: 1rem;
  padding: 6px 16px; border-radius: 999px; background: var(--yellow); color: var(--blue-dark);
}
.result-msg { margin-top: 12px; font-size: 0.95rem; opacity: 0.95; }
.result-stats { display: flex; gap: 10px; margin: 16px 0; }
.stat-box {
  flex: 1; background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px; text-align: center; box-shadow: var(--shadow-sm);
}
.stat-box .num { font-size: 1.5rem; font-weight: 800; color: var(--blue); }
.stat-box .lbl { font-size: 0.72rem; color: var(--muted); font-weight: 700; }
.review-item {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px; margin-bottom: 10px; box-shadow: var(--shadow-sm);
}
.review-item .rq { font-weight: 700; margin-bottom: 8px; }
.review-line { font-size: 0.88rem; margin: 3px 0; }
.review-line.yours { color: var(--red); }
.review-line.correct { color: var(--green); }
.review-exp { font-size: 0.85rem; color: var(--muted); margin-top: 6px; font-style: italic; }

/* ---------- Progress / Maendeleo ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow-sm);
}
.card h3 { margin: 0 0 12px; font-size: 1rem; }
.metric-row { display: flex; gap: 10px; margin-bottom: 14px; }
.metric {
  flex: 1; background: var(--blue-soft); border-radius: 12px; padding: 12px; text-align: center;
}
.metric .num { font-size: 1.6rem; font-weight: 800; color: var(--blue); }
.metric .lbl { font-size: 0.72rem; color: var(--muted); font-weight: 700; }
.bar-item { margin-bottom: 12px; }
.bar-head { display: flex; justify-content: space-between; font-size: 0.85rem; font-weight: 700; margin-bottom: 5px; }
.bar-head .pct { color: var(--muted); }
.bar-track { height: 10px; background: var(--line); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; background: var(--blue); transition: width 0.4s ease; }
.bar-fill.low { background: var(--red); }
.bar-fill.mid { background: var(--yellow-dark); }
.bar-fill.high { background: var(--green); }
.weak-list { list-style: none; padding: 0; margin: 0; }
.weak-list li {
  display: flex; justify-content: space-between; padding: 10px 12px; border-radius: 10px;
  background: #FDECEC; margin-bottom: 8px; font-weight: 700; font-size: 0.9rem; color: var(--red);
}
.empty-note { color: var(--muted); font-size: 0.9rem; text-align: center; padding: 12px; }

/* ---------- Upgrade ---------- */
.upgrade-hero {
  background: linear-gradient(135deg, var(--yellow), var(--yellow-dark));
  color: var(--blue-dark); border-radius: var(--radius); padding: 22px; text-align: center;
  box-shadow: var(--shadow); margin-bottom: 16px;
}
.upgrade-hero h2 { margin: 0 0 6px; font-size: 1.4rem; }
.price-cards { display: flex; gap: 10px; margin-bottom: 16px; }
.price-card {
  flex: 1; background: var(--card); border: 2px solid var(--line); border-radius: 14px;
  padding: 16px 12px; text-align: center; box-shadow: var(--shadow-sm);
}
.price-card.best { border-color: var(--blue); position: relative; }
.price-card.best::after {
  content: "BORA"; position: absolute; top: -10px; left: 50%; transform: translateX(-50%);
  background: var(--blue); color: #fff; font-size: 0.6rem; font-weight: 800;
  padding: 3px 10px; border-radius: 999px;
}
.price-card .amt { font-size: 1.4rem; font-weight: 800; color: var(--blue); }
.price-card .per { font-size: 0.72rem; color: var(--muted); }
.feature-list { list-style: none; padding: 0; margin: 0 0 16px; }
.feature-list li { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 0.92rem; }
.feature-list li::before { content: "✅ "; }
.pay-box {
  background: var(--blue-soft); border-radius: 12px; padding: 14px; margin-bottom: 14px;
  font-size: 0.9rem;
}
.pay-box strong { color: var(--blue-dark); }
.code-input {
  width: 100%; padding: 14px; border: 2px solid var(--line); border-radius: 12px;
  font-size: 1rem; font-family: inherit; text-transform: uppercase; letter-spacing: 1px;
  margin-bottom: 10px;
}
.code-input:focus { outline: none; border-color: var(--blue); }

/* premium active card */
.premium-active {
  text-align: center; background: linear-gradient(135deg, var(--green), #157a41);
  color: #fff; border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow);
}
.premium-active .big { font-size: 2.4rem; }

/* ---------- Settings ---------- */
.setting-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 0; border-bottom: 1px solid var(--line);
}
.setting-row:last-child { border-bottom: none; }
.setting-row .desc { font-size: 0.78rem; color: var(--muted); }
.switch { position: relative; width: 50px; height: 28px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0; background: var(--line); border-radius: 999px; cursor: pointer;
  transition: background 0.2s;
}
.slider::before {
  content: ""; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: transform 0.2s;
}
.switch input:checked + .slider { background: var(--blue); }
.switch input:checked + .slider::before { transform: translateX(22px); }
.btn-small {
  background: var(--blue-soft); color: var(--blue); border: none; border-radius: 10px;
  padding: 10px 14px; font-weight: 800; font-family: inherit; cursor: pointer; font-size: 0.85rem;
}
.btn-small.danger { background: #FDECEC; color: var(--red); }
.app-footer { text-align: center; color: var(--muted); font-size: 0.75rem; margin-top: 18px; }

/* ---------- Bottom nav ---------- */
.bottomnav {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 0;
  width: 100%; max-width: var(--maxw); height: var(--nav-h);
  background: #fff; border-top: 1px solid var(--line);
  display: flex; z-index: 30;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.navbtn {
  flex: 1; background: none; border: none; cursor: pointer; font-family: inherit;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); padding: 6px 0;
}
.navbtn .navicon { font-size: 1.2rem; }
.navbtn .navlabel { font-size: 0.66rem; font-weight: 700; }
.navbtn.active { color: var(--blue); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px); transform: translateX(-50%);
  background: var(--blue-dark); color: #fff; padding: 12px 18px; border-radius: 12px;
  font-size: 0.88rem; font-weight: 700; z-index: 50; box-shadow: var(--shadow);
  max-width: 90%; text-align: center; animation: fade 0.2s ease;
}

/* daily limit banner */
.limit-box {
  background: #FFF7E0; border: 2px dashed var(--yellow-dark); border-radius: var(--radius);
  padding: 18px; text-align: center; margin-bottom: 14px;
}
.limit-box h3 { margin: 0 0 6px; color: var(--blue-dark); }
.limit-box p { margin: 0 0 12px; font-size: 0.9rem; color: var(--ink); }

.quota-pill {
  font-size: 0.78rem; font-weight: 700; color: var(--muted);
  background: var(--blue-soft); padding: 6px 12px; border-radius: 999px; display: inline-block;
  margin-top: 6px;
}

/* subject start sheet */
.mode-list { display: flex; flex-direction: column; gap: 12px; margin-top: 6px; }
.mode-card {
  text-align: left; background: var(--card); border: 2px solid var(--line); border-radius: 14px;
  padding: 16px; cursor: pointer; font-family: inherit; color: var(--ink);
}
.mode-card:active { transform: scale(0.99); }
.mode-card .mc-title { font-weight: 800; font-size: 1rem; display: flex; align-items: center; gap: 8px; }
.mode-card .mc-desc { font-size: 0.82rem; color: var(--muted); margin-top: 4px; }
.mode-card.locked { opacity: 0.7; }

@media (min-width: 520px) {
  .subject-grid { grid-template-columns: repeat(3, 1fr); }
}

/* form fields (cloud login + auth front door) */
.field { margin-bottom: 12px; text-align: left; }
.field label { display: block; font-size: 0.82rem; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.input {
  width: 100%; box-sizing: border-box; font-family: inherit; font-size: 1rem;
  padding: 12px 14px; border: 2px solid var(--line); border-radius: 12px;
  background: #fff; color: var(--ink);
}
.input:focus { outline: none; border-color: var(--blue); }

/* sign-in front door (first open) */
body.auth-mode .topbar,
body.auth-mode .bottomnav { display: none; }
body.auth-mode #app { padding: 0; }
#screen-auth { padding: 0; }
.auth-body {
  min-height: 100vh; min-height: 100dvh;
  display: flex; align-items: center; justify-content: center; padding: 28px 22px;
  background: linear-gradient(135deg, var(--blue) 0%, var(--blue-dark) 100%);
}
.auth-inner {
  width: 100%; max-width: 380px; background: var(--card);
  border-radius: 20px; padding: 26px 22px; text-align: center;
  box-shadow: 0 18px 40px rgba(14, 42, 94, 0.28);
}
.auth-logo { font-size: 2.6rem; line-height: 1; margin-bottom: 6px; }
.auth-title { font-size: 1.4rem; font-weight: 800; color: var(--blue-dark); margin: 6px 0; }
.auth-sub { font-size: 0.9rem; color: var(--muted); margin: 0 0 18px; line-height: 1.45; }
.auth-body .btn-primary { margin-top: 4px; }
.auth-body .btn-outline { margin-top: 10px; }
.auth-skip {
  margin-top: 12px; background: transparent; border: none; cursor: pointer;
  font-family: inherit; font-size: 0.88rem; color: var(--muted); text-decoration: underline;
}
.auth-note { margin-top: 14px; font-size: 0.72rem; color: var(--muted); opacity: 0.85; }

/* progress nudge modal */
.nudge-overlay {
  position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end;
  justify-content: center; background: rgba(14, 42, 94, 0.5); padding: 16px;
}
.nudge-card {
  width: 100%; max-width: 440px; background: var(--card); border-radius: 18px;
  padding: 22px; box-shadow: 0 -8px 40px rgba(14, 42, 94, 0.3); animation: fade 0.2s ease;
}
.nudge-title { font-size: 1.2rem; font-weight: 800; color: var(--blue-dark); margin: 0 0 8px; }
.nudge-msg { font-size: 0.92rem; color: var(--muted); line-height: 1.5; margin: 0 0 16px; }
.nudge-card .btn-outline { margin-top: 10px; }
@media (min-width: 520px) {
  .nudge-overlay { align-items: center; }
}
