:root {
  --bg: #f6f8f7;
  --surface: #ffffff;
  --text: #1c2b29;
  --muted: #5b6b68;
  --line: #dfe6e4;
  --primary: #0f766e;
  --primary-ink: #ffffff;
  --accent: #b45309;
  --ok: #15803d;
  --ok-bg: #ecfdf3;
  --bad: #b91c1c;
  --bad-bg: #fef2f2;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 4px 14px rgba(0, 0, 0, .05);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1716;
    --surface: #17221f;
    --text: #e6efec;
    --muted: #9cb0ab;
    --line: #2a3a36;
    --primary: #2dd4bf;
    --primary-ink: #04201c;
    --accent: #fbbf24;
    --ok: #4ade80;
    --ok-bg: #112a1c;
    --bad: #f87171;
    --bad-bg: #2a1414;
    --shadow: none;
  }
}

:root[data-theme="dark"] {
  --bg: #0f1716;
  --surface: #17221f;
  --text: #e6efec;
  --muted: #9cb0ab;
  --line: #2a3a36;
  --primary: #2dd4bf;
  --primary-ink: #04201c;
  --accent: #fbbf24;
  --ok: #4ade80;
  --ok-bg: #112a1c;
  --bad: #f87171;
  --bad-bg: #2a1414;
  --shadow: none;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans Bengali", "Nirmala UI", "Segoe UI", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { line-height: 1.3; margin: .4em 0; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }

.wrap {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 16px;
}

main.wrap { flex: 1; padding-top: 24px; padding-bottom: 40px; }

/* header */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 60px;
  flex-wrap: wrap;
}
.logo { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 1.05rem; }
.logo:hover { text-decoration: none; }
.logo-mark {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--primary);
  color: var(--primary-ink);
  font-weight: 700;
}
.main-nav { display: flex; gap: 14px; flex-wrap: wrap; font-size: .95rem; }
.main-nav a { color: var(--muted); }
.main-nav a:hover { color: var(--primary); }

/* hero & cards */
.hero {
  background: linear-gradient(135deg, var(--primary), #1d4ed8);
  color: #fff;
  border-radius: var(--radius);
  padding: 28px 22px;
  margin-bottom: 28px;
}
.hero h1 { font-size: 1.7rem; margin-top: 0; }
.hero h1 span { color: #fde68a; }
.hero p { opacity: .95; margin: .4em 0 1em; max-width: 60ch; }
.stats { display: flex; gap: 22px; flex-wrap: wrap; }
.stats div { display: flex; flex-direction: column; }
.stats strong { font-size: 1.4rem; }
.stats span { font-size: .85rem; opacity: .9; }

.section-title { margin: 22px 0 12px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--text);
  box-shadow: var(--shadow);
}
.card:hover { border-color: var(--primary); text-decoration: none; }
.card-title { font-weight: 600; }
.card-sub { font-size: .85rem; color: var(--muted); }

.notice {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-top: 24px;
}

/* lists */
.list { display: flex; flex-direction: column; gap: 10px; }
.subject-row {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  color: var(--text);
}
.subject-row:hover { text-decoration: none; border-color: var(--primary); }
.subject-row > div:first-child { display: flex; flex-direction: column; }
.muted { color: var(--muted); font-size: .9rem; }
.crumb { font-size: .9rem; color: var(--muted); margin-bottom: 8px; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  padding: 9px 14px;
  font: inherit;
  font-size: .95rem;
  cursor: pointer;
  text-decoration: none;
  min-height: 40px;
}
.btn:hover:not(:disabled) { border-color: var(--primary); text-decoration: none; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-ghost { background: transparent; }
.btn:focus-visible, .option:focus-visible, select:focus-visible, input:focus-visible, .pal:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* forms */
select, input[type="number"] {
  font: inherit;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  min-height: 40px;
}
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  display: grid;
  gap: 14px;
  max-width: 480px;
  margin-bottom: 12px;
}
.panel label { display: flex; flex-direction: column; gap: 6px; font-size: .95rem; }
.panel label.check { flex-direction: row; align-items: center; gap: 8px; }
.toolbar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; }
.toolbar label { display: flex; gap: 8px; align-items: center; color: var(--muted); }

/* question */
.question-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.q-meta { font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
.q-text { font-size: 1.15rem; font-weight: 600; margin: 4px 0 14px; }
.options { display: grid; gap: 10px; }
.option {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  min-height: 48px;
}
.option:hover:not(:disabled) { border-color: var(--primary); }
.option:disabled { cursor: default; }
.option.selected { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.option.correct { border-color: var(--ok); background: var(--ok-bg); }
.option.wrong { border-color: var(--bad); background: var(--bad-bg); }
.opt-letter {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--line);
  font-size: .85rem;
  flex-shrink: 0;
}
.feedback { margin-top: 14px; padding: 12px 14px; border-radius: 10px; }
.feedback p { margin: .3em 0 0; }
.feedback.ok { background: var(--ok-bg); color: var(--ok); }
.feedback.bad { background: var(--bad-bg); color: var(--bad); }

.pager {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 14px;
}
.reset-row { margin-top: 12px; }

/* test */
.test-bar {
  position: sticky;
  top: 60px;
  z-index: 5;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.timer {
  font-variant-numeric: tabular-nums;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
}
.test-layout {
  display: grid;
  grid-template-columns: 1fr 260px;
  gap: 16px;
  align-items: start;
}
.palette {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  position: sticky;
  top: 130px;
}
.palette h3 { font-size: 1rem; margin-top: 0; }
.pal-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.pal {
  display: inline-grid;
  place-items: center;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: .85rem;
  cursor: pointer;
  padding: 0;
}
.pal.answered { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.pal.current { outline: 2px solid var(--accent); outline-offset: 1px; }
.pal.flagged { border: 2px dashed var(--accent); }
.legend { list-style: none; padding: 0; margin: 12px 0 0; font-size: .85rem; color: var(--muted); display: grid; gap: 6px; }
.legend li { display: flex; align-items: center; gap: 8px; }
.legend .pal { height: 22px; width: 28px; cursor: default; }

/* results */
.score-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
  margin: 14px 0;
}
.score-grid div {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
}
.score-grid strong { font-size: 1.4rem; }
.score-grid span { color: var(--muted); font-size: .85rem; }
.review {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
}
.review.ok { border-left-color: var(--ok); }
.review.bad { border-left-color: var(--bad); }
.review.skip { border-left-color: var(--muted); }
.review h3 { font-size: 1rem; }
.review p { margin: .3em 0; }

.site-footer {
  border-top: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: .9rem;
  padding: 18px 0;
}
.site-footer p { margin: 4px 0; }

/* phones */
@media (max-width: 720px) {
  h1 { font-size: 1.35rem; }
  .hero h1 { font-size: 1.4rem; }
  .test-layout { grid-template-columns: 1fr; }
  .palette { position: static; }
  .pal-grid { grid-template-columns: repeat(8, 1fr); }
  .test-bar { top: 0; }
  .main-nav { font-size: .9rem; gap: 10px; }
}

@media (max-width: 380px) {
  .wrap { padding: 0 12px; }
  .question-card { padding: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
