@font-face {
  font-family: "Raghu Malayalam";
  src: url("/fonts/RaghuMalayalamSans-Regular.ttf") format("truetype");
  font-weight: 400 700;
  font-display: swap;
}

:root {
  --bg: #ffffff;
  --bg-soft: #f2f8f4;
  --surface: #ffffff;
  --ink: #10241a;
  --ink-soft: #4c6459;
  --ink-faint: #8aa196;
  --border: #dcece2;
  --green: #157a4a;
  --green-deep: #0d5c38;
  --green-pale: #e4f6ec;
  --on-green: #ffffff;
  --correct: #1fa25a;
  --correct-bg: #e6f7ec;
  --incorrect: #e0483f;
  --incorrect-bg: #fdeae8;
  --shadow: 0 1px 2px rgba(16, 36, 26, 0.06), 0 8px 24px -12px rgba(16, 36, 26, 0.12);
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;

  --font-ml: "Raghu Malayalam", "Noto Sans Malayalam", sans-serif;
  --font-en: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a1712; --bg-soft: #0f1e17; --surface: #12241b;
    --ink: #eaf6ef; --ink-soft: #9fbcac; --ink-faint: #5d7d6d;
    --border: #1e3529; --green: #34c77e; --green-deep: #1fa25a; --green-pale: #16311f;
    --on-green: #062616; --correct: #34c77e; --correct-bg: #14301f;
    --incorrect: #f2695f; --incorrect-bg: #341e1c;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px -12px rgba(0, 0, 0, 0.5);
  }
}
:root[data-theme="dark"] {
  --bg: #0a1712; --bg-soft: #0f1e17; --surface: #12241b;
  --ink: #eaf6ef; --ink-soft: #9fbcac; --ink-faint: #5d7d6d;
  --border: #1e3529; --green: #34c77e; --green-deep: #1fa25a; --green-pale: #16311f;
  --on-green: #062616; --correct: #34c77e; --correct-bg: #14301f;
  --incorrect: #f2695f; --incorrect-bg: #341e1c;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px -12px rgba(0, 0, 0, 0.5);
}
:root[data-theme="light"] {
  --bg: #ffffff; --bg-soft: #f2f8f4; --surface: #ffffff;
  --ink: #10241a; --ink-soft: #4c6459; --ink-faint: #8aa196;
  --border: #dcece2; --green: #157a4a; --green-deep: #0d5c38; --green-pale: #e4f6ec;
  --on-green: #ffffff; --correct: #1fa25a; --correct-bg: #e6f7ec;
  --incorrect: #e0483f; --incorrect-bg: #fdeae8;
  --shadow: 0 1px 2px rgba(16, 36, 26, 0.06), 0 8px 24px -12px rgba(16, 36, 26, 0.12);
}

* { box-sizing: border-box; }
html, body { background: var(--bg); }
body {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-en);
  -webkit-font-smoothing: antialiased;
  padding-bottom: 84px;
}
[lang="ml"], .lang-ml { font-family: var(--font-ml); }
a { color: inherit; text-decoration: none; }
::selection { background: var(--green); color: var(--on-green); }
button { font-family: inherit; }

/* language toggle mechanism */
html[data-lang="ml"] .en-only { display: none !important; }
html[data-lang="en"] .ml-only { display: none !important; }

.wrap { max-width: 480px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 720px) { .wrap { max-width: 640px; } }

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 480px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
@media (min-width: 720px) { .topbar-inner { max-width: 640px; } }
.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 800;
  font-size: 1.15rem;
  color: var(--ink);
  font-family: var(--font-en);
  letter-spacing: -0.01em;
}
.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--green);
  color: var(--on-green);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-en);
  font-weight: 800;
  font-size: 1rem;
  flex-shrink: 0;
}

.topbar-actions { display: flex; align-items: center; gap: 8px; }
.theme-toggle {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--ink-soft);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.theme-toggle:hover { border-color: var(--green); color: var(--green); }
.theme-toggle svg { width: 17px; height: 17px; }
.theme-toggle .icon-moon { display: none; }
html[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
html[data-theme="dark"] .theme-toggle .icon-moon { display: block; }

.lang-toggle {
  display: inline-flex;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}
.lang-toggle button {
  border: none;
  background: transparent;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink-faint);
  cursor: pointer;
}
.lang-toggle button.active {
  background: var(--green);
  color: var(--on-green);
}
.lang-toggle button[data-set="ml"] { font-family: var(--font-ml); }

/* ---------- hero ---------- */
.hero {
  margin-top: 16px;
  background: linear-gradient(155deg, var(--green) 0%, var(--green-deep) 100%);
  color: var(--on-green);
  border-radius: var(--radius-lg);
  padding: 22px 20px 20px;
  box-shadow: var(--shadow);
}
.hero-eyebrow {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.85;
  margin-bottom: 10px;
}
.hero-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(255,255,255,0.25);
}
.hero h1 {
  font-family: var(--font-ml);
  font-size: 1.5rem;
  line-height: 1.35;
  font-weight: 700;
  margin: 0 0 6px;
  text-wrap: balance;
}
.hero-sub {
  font-size: 0.9rem;
  opacity: 0.9;
  margin-bottom: 18px;
}
.hero-meta {
  display: flex;
  gap: 16px;
  margin-bottom: 18px;
  font-size: 0.8rem;
  opacity: 0.9;
}
.hero-meta b { font-weight: 700; font-variant-numeric: tabular-nums; }
.hero-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  color: var(--green-deep);
  font-weight: 700;
  font-size: 0.94rem;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  width: 100%;
  justify-content: center;
}

/* ---------- topic chip row ---------- */
.chip-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 16px 0 4px;
  margin: 0 -16px;
  padding-left: 16px;
  padding-right: 16px;
  scrollbar-width: none;
}
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0;
  appearance: none;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--ink-soft);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 999px;
  white-space: nowrap;
  cursor: pointer;
}
.chip.active {
  background: var(--green-pale);
  border-color: var(--green);
  color: var(--green-deep);
}

/* ---------- topic grid empty state (filtered to a category with no quizzes yet) ---------- */
.topic-grid-empty {
  color: var(--ink-faint);
  font-size: 0.88rem;
  padding: 24px 0 8px;
  text-align: center;
}

/* ---------- section heading ---------- */
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 26px 0 12px;
}
.section-head h2 {
  font-size: 1.02rem;
  font-weight: 800;
  margin: 0;
}
.section-head .see-all { font-size: 0.82rem; color: var(--green); font-weight: 700; }

/* ---------- quiz card ---------- */
.quiz-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.progress-track {
  display: flex;
  gap: 4px;
  padding: 14px 16px 0;
}
.progress-seg {
  height: 4px;
  flex: 1;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.progress-seg.done { background: var(--green); }
.progress-seg.now { background: var(--green); opacity: 0.5; }

.quiz-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 0;
}
.quiz-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--green-pale);
  color: var(--green-deep);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: 999px;
  font-family: var(--font-ml);
}
.quiz-count { font-size: 0.76rem; color: var(--ink-faint); font-variant-numeric: tabular-nums; font-family: var(--font-en); }

.quiz-card-body { padding: 16px; }
.quiz-question {
  font-family: var(--font-ml);
  font-size: 1.08rem;
  font-weight: 700;
  line-height: 1.5;
  text-wrap: balance;
  margin-bottom: 16px;
}
.quiz-options {
  display: grid;
  gap: 10px;
  list-style: none;
  margin: 0;
  padding: 0;
}
.quiz-options li { display: contents; }
.qopt {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: start;
  background: var(--bg-soft);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 13px 14px;
  font-family: var(--font-ml);
  font-size: 0.98rem;
  color: var(--ink);
  cursor: pointer;
  min-height: 48px;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.1s ease;
}
.qopt:hover:not(:disabled) { border-color: var(--green); }
.qopt:active:not(:disabled) { transform: scale(0.99); }
.qopt:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
.qopt .qletter {
  font-family: var(--font-en);
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ink-faint);
  background: var(--surface);
  border: 1.5px solid var(--border);
  width: 24px; height: 24px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.qopt.is-correct { background: var(--correct-bg); border-color: var(--correct); color: var(--correct); }
.qopt.is-correct .qletter { border-color: var(--correct); color: var(--correct); background: transparent; }
.qopt.is-wrong { background: var(--incorrect-bg); border-color: var(--incorrect); color: var(--incorrect); }
.qopt.is-wrong .qletter { border-color: var(--incorrect); color: var(--incorrect); background: transparent; }
.qopt:disabled { cursor: default; }
.qopt:disabled:not(.is-correct):not(.is-wrong) { opacity: 0.5; }

.quiz-explain {
  margin-top: 14px;
  padding: 13px 14px;
  background: var(--green-pale);
  border-radius: var(--radius-md);
  font-family: var(--font-ml);
  font-size: 0.92rem;
  color: var(--ink);
  display: none;
}
.quiz-explain.show { display: block; }

.quiz-nav {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 0 16px 16px;
}
.quiz-nav a, .quiz-nav .btn-disabled {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--green);
  color: var(--on-green);
  font-weight: 700;
  font-size: 0.9rem;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
}
.quiz-nav .btn-disabled { background: var(--border); color: var(--ink-faint); pointer-events: none; }

/* ---------- topic grid ---------- */
.topic-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.topic-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.topic-card[hidden] {
  display: none;
}
.topic-card-empty {
  opacity: 0.55;
  cursor: default;
}
.topic-card-empty .topic-icon {
  background: var(--bg-soft);
  color: var(--ink-faint);
}
.topic-icon {
  width: 34px; height: 34px;
  border-radius: 10px;
  background: var(--green-pale);
  color: var(--green-deep);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-ml);
  font-weight: 700;
  font-size: 0.95rem;
}
.topic-name { font-family: var(--font-ml); font-weight: 700; font-size: 0.92rem; text-wrap: balance; }
.topic-count { font-size: 0.74rem; color: var(--ink-faint); font-family: var(--font-en); }

.category-section { margin-bottom: 8px; }
.category-title {
  font-family: var(--font-ml);
  font-weight: 800;
  font-size: 1rem;
  margin: 28px 0 10px;
}

/* ---------- recent list ---------- */
.recent-list { display: flex; flex-direction: column; gap: 8px; }
.recent-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
}
.recent-date {
  width: 44px; height: 44px;
  border-radius: 12px;
  background: var(--bg-soft);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 0.68rem;
  color: var(--ink-faint);
  font-weight: 700;
  flex-shrink: 0;
  line-height: 1.15;
  font-family: var(--font-en);
}
.recent-date b { font-size: 1rem; color: var(--ink); }
.recent-info { flex: 1; min-width: 0; }
.recent-topic { font-family: var(--font-ml); font-weight: 700; font-size: 0.92rem; }
.recent-sub { font-size: 0.76rem; color: var(--ink-faint); margin-top: 2px; font-family: var(--font-en); }
.recent-arrow { color: var(--ink-faint); flex-shrink: 0; }

.pagination {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 24px 0;
  font-family: var(--font-en);
  font-size: 0.85rem;
}
.pagination a, .pagination span {
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  color: var(--ink-soft);
}
.pagination a:hover { border-color: var(--green); color: var(--green); }

footer.site {
  margin-top: 30px;
  padding: 18px 0 10px;
  text-align: center;
  font-size: 0.78rem;
  color: var(--ink-faint);
  font-family: var(--font-en);
}
footer.site a { color: var(--green); font-weight: 600; }

/* ---------- bottom tab bar (mobile) ---------- */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 20;
}
.tabbar-inner {
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  width: 100%;
}
@media (min-width: 720px) { .tabbar-inner { max-width: 640px; } }
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 10px 0 8px;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--ink-faint);
  font-family: var(--font-en);
}
.tab.active { color: var(--green); }
.tab svg { width: 21px; height: 21px; }
