:root {
  --bg: #f7f6f1;
  --card: #ffffff;
  --border: #e3decf;
  --text: #1f1f1f;
  --muted: #6b6b6b;
  --accent: #7a3a1f;
  --accent-light: #c87d5b;
  --good: #2d6a4f;
  --bad: #9d2235;
  --warn: #b07c00;
  --shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Noto Sans Bengali", "Segoe UI", "Inter", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
}
h1, h2, h3 { margin: 0 0 0.6rem; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; margin-top: 1rem; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.2rem;
  background: var(--accent);
  color: #fff;
  position: sticky; top: 0; z-index: 10;
  box-shadow: var(--shadow);
}
.topbar h1 { color: #fff; font-weight: 600; }
.topbar-meta { font-size: 0.85rem; }

.lang-btn {
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255,255,255,0.4);
  padding: 0.2rem 0.55rem;
  margin-left: 0.3rem;
  font-size: 0.85rem;
  cursor: pointer;
  border-radius: 3px;
}
.lang-btn.active {
  background: #fff;
  color: var(--accent);
  font-weight: 600;
}

.screen { display: none; padding: 1.2rem; max-width: 960px; margin: 0 auto; }
.screen.active { display: block; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1.1rem 1.3rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.muted { color: var(--muted); font-size: 0.9rem; }

/* Setup screen */
.mode-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.7rem; }
.mode-card { cursor: pointer; }
.mode-card input[type=radio] { display: none; }
.mode-card-body {
  border: 2px solid var(--border);
  border-radius: 5px;
  padding: 0.7rem 0.9rem;
  transition: all 0.15s;
}
.mode-card input[type=radio]:checked + .mode-card-body {
  border-color: var(--accent);
  background: #fdf7ee;
}
.mode-title { font-weight: 600; margin-bottom: 0.2rem; }
.mode-desc { font-size: 0.85rem; color: var(--muted); }

.filter-row { display: flex; gap: 1rem; flex-wrap: wrap; }
fieldset {
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.6rem 0.9rem;
  margin: 0 0 0.7rem;
  flex: 1;
  min-width: 200px;
}
fieldset.full-width { flex-basis: 100%; }
legend { font-size: 0.85rem; color: var(--muted); padding: 0 0.4rem; }
.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 0.3rem 0.7rem;
  font-size: 0.9rem;
}
.checkbox-grid label { cursor: pointer; }

.filter-stats {
  margin-top: 0.5rem;
  font-size: 0.95rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
#match-count { font-weight: 600; }
.match-breakdown { font-size: 0.85rem; color: var(--muted); }

.opt-row {
  display: flex; flex-wrap: wrap; gap: 1rem 1.5rem; align-items: center; margin-bottom: 1rem;
}
.opt-row label { font-size: 0.9rem; display: flex; align-items: center; gap: 0.4rem; }
.opt-row select { padding: 0.25rem 0.4rem; }

button {
  font-family: inherit;
  font-size: 0.95rem;
  cursor: pointer;
}
.primary-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.55rem 1.2rem;
  border-radius: 4px;
  font-weight: 600;
}
.primary-btn:hover { background: var(--accent-light); }
.primary-btn:disabled { background: #aaa; cursor: not-allowed; }
.secondary-btn {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 0.5rem 1.1rem;
  border-radius: 4px;
}
.secondary-btn:hover { background: #fdf7ee; }
.link-btn {
  background: transparent;
  border: none;
  color: var(--accent);
  text-decoration: underline;
  padding: 0;
}

/* Quiz screen */
.quiz-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fff;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 5px;
  margin-bottom: 1rem;
  font-size: 0.95rem;
}
.timer { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--accent); }
.timer.warn { color: var(--warn); }
.timer.danger { color: var(--bad); }

.question-card { padding: 1.4rem 1.5rem; }

.q-stem {
  font-size: 1.1rem;
  margin: 0.5rem 0 1rem;
  line-height: 1.6;
}
.q-stem.bn { font-weight: 500; }
.q-stem.en { color: var(--muted); font-size: 1rem; font-style: italic; border-left: 3px solid var(--border); padding-left: 0.7rem; }

.q-options { list-style: none; padding: 0; margin: 0 0 1rem; }
.q-options li {
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 5px;
  margin-bottom: 0.5rem;
  cursor: pointer;
  transition: all 0.1s;
}
.q-options li:hover { background: #fdf7ee; }
.q-options li.selected { border-color: var(--accent); background: #fdf7ee; }
.q-options li.correct { border-color: var(--good); background: #e7f3eb; }
.q-options li.wrong { border-color: var(--bad); background: #fbe7eb; }
.q-options li.disabled { cursor: default; opacity: 0.85; }
.q-options li.disabled:hover { background: transparent; }
.q-options li.disabled.correct:hover { background: #e7f3eb; }
.q-options li.disabled.wrong:hover { background: #fbe7eb; }

.opt-key {
  font-weight: 700;
  color: var(--accent);
  min-width: 1.4rem;
}
.opt-text { flex: 1; }
.opt-text .en { color: var(--muted); font-size: 0.9rem; font-style: italic; display: block; margin-top: 0.2rem; }

.q-feedback {
  margin: 0.8rem 0;
  padding: 0.7rem 1rem;
  border-radius: 4px;
  font-size: 0.92rem;
  display: none;
}
.q-feedback.show { display: block; }
.q-feedback.good { background: #e7f3eb; border-left: 4px solid var(--good); }
.q-feedback.bad  { background: #fbe7eb; border-left: 4px solid var(--bad); }
.q-feedback .meta-line { color: var(--muted); margin-top: 0.3rem; font-size: 0.85rem; }

.q-feedback .explanation {
  margin: 0.55rem 0 0.3rem;
  padding: 0.4rem 0;
  border-top: 1px solid rgba(0,0,0,0.08);
  font-size: 0.95rem;
  line-height: 1.5;
}
.q-feedback .explanation .bn { font-weight: 500; }
.q-feedback .explanation .en {
  color: var(--muted);
  font-style: italic;
  font-size: 0.9rem;
  margin-top: 0.2rem;
}
.q-feedback .tip {
  margin: 0.4rem 0;
  padding: 0.35rem 0.6rem;
  background: #f3edff;
  border-left: 3px solid #6c3a8c;
  font-size: 0.88rem;
  border-radius: 2px;
}
.q-feedback .tip .en { color: var(--muted); font-style: italic; font-size: 0.85rem; }
.tip-label { font-weight: 700; color: #6c3a8c; }

/* Results-list expandable explanation */
.result-explanation {
  margin-top: 0.4rem;
  font-size: 0.85rem;
  padding-left: 0.2rem;
  border-left: 2px solid var(--border);
}
.result-explanation summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 0.8rem;
  user-select: none;
}
.result-explanation summary:hover { text-decoration: underline; }
.result-explanation > div { margin: 0.3rem 0 0.3rem 0.5rem; }
.result-explanation .tip { background: #f3edff; padding: 0.25rem 0.5rem; border-left: 2px solid #6c3a8c; border-radius: 2px; }

.q-actions {
  display: flex; justify-content: space-between; gap: 0.5rem;
  border-top: 1px solid var(--border); padding-top: 0.9rem; margin-top: 0.5rem;
}

/* Results screen */
.score-block {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1rem; padding: 1rem; background: #fdf7ee; border-radius: 5px;
}
.score-main { font-size: 1.8rem; font-weight: 700; color: var(--accent); }
.score-main #score-raw { font-size: 1rem; font-weight: 400; color: var(--muted); margin-left: 0.5rem; }
.verdict { font-size: 1.1rem; font-weight: 600; }
.verdict.pass { color: var(--good); }
.verdict.fail { color: var(--bad); }

.by-law-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.5rem; margin: 0.5rem 0;
}
.by-law-grid > div {
  border: 1px solid var(--border); border-radius: 4px; padding: 0.5rem 0.7rem;
}
.by-law-grid .law { font-size: 0.85rem; color: var(--muted); }
.by-law-grid .score { font-size: 1.1rem; font-weight: 600; }

.results-list { max-height: 480px; overflow-y: auto; border: 1px solid var(--border); border-radius: 5px; padding: 0.5rem 0; }
.result-row {
  padding: 0.6rem 0.9rem; border-bottom: 1px solid var(--border);
  display: flex; gap: 0.6rem; align-items: flex-start; cursor: pointer;
}
.result-row:hover { background: #fdf7ee; }
.result-row:last-child { border-bottom: none; }
.result-mark { width: 1.5rem; font-weight: 700; }
.result-mark.good { color: var(--good); }
.result-mark.bad { color: var(--bad); }
.result-mark.skip { color: var(--muted); }
.result-text { flex: 1; }
.result-text .meta { font-size: 0.8rem; color: var(--muted); margin-top: 0.2rem; }

.results-actions { display: flex; gap: 0.5rem; margin-top: 1rem; }

/* Browse screen */
.browse-controls {
  display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.7rem; align-items: center;
}
.browse-controls input, .browse-controls select {
  padding: 0.35rem 0.5rem; border: 1px solid var(--border); border-radius: 4px; font-size: 0.9rem;
}
.browse-controls input { flex: 1; min-width: 200px; }
.browse-results { max-height: 600px; overflow-y: auto; border: 1px solid var(--border); border-radius: 5px; }
.browse-row {
  padding: 0.6rem 0.9rem; border-bottom: 1px solid var(--border);
}
.browse-row:last-child { border-bottom: none; }
.browse-row .stem { margin: 0.2rem 0; }
.browse-row .meta { font-size: 0.8rem; color: var(--muted); }
.browse-row .answer { font-size: 0.85rem; color: var(--good); margin-top: 0.2rem; }

/* Language toggling */
.lang-bn-only .en, .lang-bn-only .q-stem.en { display: none !important; }
.lang-en-only .bn, .lang-en-only .q-stem.bn { display: none !important; }

.source-badge.generated {
  display: inline-block;
  margin-bottom: 0.75rem;
  padding: 0.22rem 0.6rem;
  font-size: 0.78rem;
  letter-spacing: 0.03em;
  color: #8a5a00;
  background: #fdf3dc;
  border-left: 3px solid #d39a18;
  border-radius: 2px;
  font-weight: 600;
}

fieldset.disabled {
  opacity: 0.45;
}
fieldset.disabled legend {
  color: var(--muted);
}

/* ---- Auth: header user info ---- */
.topbar-meta { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.user-info { font-size: 0.85rem; color: rgba(255,255,255,0.92); }
.user-info .user-name  { font-weight: 600; }
.user-info .user-phone { opacity: 0.85; }
.user-info .muted      { color: rgba(255,255,255,0.55); }
.user-info .link-btn {
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255,255,255,0.4);
  padding: 0.15rem 0.5rem;
  margin-left: 0.25rem;
  font-size: 0.8rem;
  cursor: pointer;
  border-radius: 3px;
}
.user-info .link-btn:hover { background: rgba(255,255,255,0.1); }

/* ---- Auth screen ---- */
.auth-card { max-width: 420px; margin: 2rem auto 0; }
.auth-form { display: grid; gap: 0.7rem; margin-top: 0.8rem; }
.auth-form label {
  display: grid;
  gap: 0.25rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.auth-form input[type=email],
.auth-form input[type=password] {
  font: inherit;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
}
.auth-form input:focus { outline: 2px solid var(--accent-light); outline-offset: 1px; }
.auth-form .primary-btn { margin-top: 0.3rem; }
.auth-divider {
  display: flex; align-items: center; gap: 0.6rem;
  color: var(--muted); font-size: 0.8rem;
  margin: 1rem 0 0.6rem;
}
.auth-divider::before, .auth-divider::after {
  content: ""; flex: 1; height: 1px; background: var(--border);
}
.auth-foot { margin-top: 1rem; font-size: 0.82rem; }
.auth-error {
  background: #fdecea;
  color: #9d2235;
  border-left: 3px solid #9d2235;
  padding: 0.55rem 0.75rem;
  font-size: 0.88rem;
  border-radius: 3px;
  margin-top: 0.6rem;
}

/* ---- Demo-mode gating ---- */
.lock-tag {
  display: inline-block;
  margin-left: 0.5rem;
  padding: 0.05rem 0.45rem;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--muted);
  background: #efece2;
  border: 1px solid var(--border);
  border-radius: 999px;
  vertical-align: middle;
}
.demo-only-note {
  margin-top: 0.8rem;
  padding: 0.55rem 0.75rem;
  background: #fdf3dc;
  border-left: 3px solid #d39a18;
  color: #6b4a00;
  font-size: 0.85rem;
  border-radius: 3px;
}
body:not(.demo-mode) .demo-only-note { display: none; }
body.demo-mode .demo-locked { display: none !important; }
body.demo-mode .demo-locked-card { display: none !important; }
body:not(.demo-mode) .lock-tag { display: none; }

@media (max-width: 720px) {
  .mode-row { grid-template-columns: 1fr; }
  .topbar h1 { font-size: 1.05rem; }
  .q-stem { font-size: 1rem; }
  .topbar { flex-wrap: wrap; gap: 0.4rem; }
  .topbar-meta { width: 100%; justify-content: flex-start; }
}
