/* Flat · sharp · responsive · minimal */
:root {
  --bg: #fff;
  --text: #111;
  --muted: #666;
  --line: #e5e5e5;
  --accent: #007a7a;
  --ok: #15803d;
  --bad: #b91c1c;
  --ok-bg: #f7f7f7;
  --bad-bg: #f7f7f7;
  --tap: #f5f5f5;
  --font-en: "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --content: 100%;
  --pad: clamp(12px, 3.5vw, 20px);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --nav-h: 44px;
  --topbar-pad-top: 14px;
  --topbar-pad-bottom: 10px;
  --topbar-h: calc(var(--topbar-pad-top) + var(--topbar-pad-bottom) + var(--nav-h) + var(--safe-top));
  --bottombar-h: calc(49px + var(--safe-bottom));
}

*, *::before, *::after { box-sizing: border-box; }

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-en), "Anek Bangla", -apple-system, BlinkMacSystemFont, sans-serif;
  line-height: 1.5;
}

button, input { font: inherit; }
button { cursor: pointer; color: inherit; }
.hidden { display: none !important; }

.en {
  font-family: var(--font-en);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg);
  padding-top: var(--safe-top);
}

.topbar-inner {
  max-width: var(--content);
  width: 100%;
  min-height: calc(var(--topbar-pad-top) + var(--topbar-pad-bottom) + var(--nav-h));
  margin: 0 auto;
  padding: var(--topbar-pad-top) max(var(--pad), var(--safe-left)) var(--topbar-pad-bottom) max(var(--pad), var(--safe-right));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: clamp(12px, 3vw, 20px);
}

.topbar-start,
.topbar-end {
  display: flex;
  align-items: center;
  min-width: 0;
}

.topbar-start {
  flex: 1 1 auto;
  justify-content: flex-start;
}

.topbar-end {
  flex: 0 0 auto;
  justify-content: flex-end;
}

.brand {
  display: block;
  max-width: 100%;
  padding: 0;
  border: 0;
  background: none;
}

.brand-logos {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: clamp(10px, 2.5vw, 14px);
  min-width: 0;
}

.brand-divider {
  flex-shrink: 0;
  align-self: center;
  width: 1px;
  height: calc(var(--nav-h) - 8px);
  background: var(--line);
}

.brand-logo {
  display: block;
  object-fit: contain;
  flex-shrink: 0;
}

.brand-logo-borno {
  width: 28px;
  height: 28px;
}

.brand-logo-hulk {
  height: var(--nav-h);
  width: auto;
  max-width: min(168px, 46vw);
  object-position: left center;
}

.play-store-btn {
  flex-shrink: 0;
  display: block;
  line-height: 0;
  text-decoration: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.play-store-btn:active {
  opacity: 0.85;
  transform: scale(0.98);
}

.play-store-badge {
  display: block;
  height: calc(var(--nav-h) - 4px);
  width: auto;
  max-width: min(132px, 34vw);
  object-fit: contain;
}

@media (min-width: 600px) {
  :root {
    --nav-h: 48px;
    --topbar-pad-top: 16px;
    --topbar-pad-bottom: 12px;
  }

  .brand-logo-borno {
    width: 32px;
    height: 32px;
  }

  .play-store-badge {
    max-width: 140px;
  }

  .brand-logo-hulk {
    max-width: 200px;
  }
}

@media (max-width: 380px) {
  :root {
    --nav-h: 38px;
    --topbar-pad-top: 12px;
    --topbar-pad-bottom: 8px;
  }

  .brand-logos {
    gap: 8px;
  }

  .brand-logo-borno {
    width: 24px;
    height: 24px;
  }

  .brand-logo-hulk {
    max-width: 38vw;
  }

  .play-store-badge {
    max-width: 30vw;
  }
}

#app {
  max-width: var(--content);
  margin: 0 auto;
  padding: 0 max(var(--pad), var(--safe-left)) calc(16px + var(--safe-bottom)) max(var(--pad), var(--safe-right));
  width: 100%;
}

#quizView {
  padding-bottom: var(--bottombar-h);
}

.view { padding-top: 8px; }

#homeView {
  padding-bottom: clamp(88px, 22vw, 112px);
}

.borno-float {
  position: fixed;
  right: max(10px, var(--safe-right));
  bottom: calc(10px + var(--safe-bottom));
  z-index: 45;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  text-decoration: none;
  color: inherit;
  transition: transform 0.15s ease;
}

.borno-float.is-quiz {
  bottom: calc(var(--bottombar-h) + 6px);
}

.borno-float.hidden {
  display: none;
}

.borno-float:active {
  transform: scale(0.97);
}

.borno-doubt {
  display: inline-block;
  padding: 7px 12px;
  background: var(--accent);
  color: #fff;
  font-family: var(--font-en);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.2;
  text-align: right;
  max-width: min(168px, 46vw);
  white-space: normal;
  box-shadow: 0 2px 10px rgba(0, 122, 122, 0.22);
}

.borno-char {
  width: clamp(72px, 20vw, 100px);
  height: auto;
  display: block;
  pointer-events: none;
}

.section-label {
  margin: 0;
  padding: 16px 0 12px;
  font-size: clamp(16px, 4vw, 19px);
  font-weight: 600;
  line-height: 1.35;
  border-bottom: 1px solid var(--line);
}

.subject-list {
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
}

.subject-row {
  display: flex;
  align-items: stretch;
  min-height: 52px;
  border-bottom: 1px solid var(--line);
}

.subject-row-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  min-width: 0;
  padding: 12px 14px;
  border: 0;
  background: none;
  text-align: left;
}

.subject-row-main:active { background: var(--tap); }

.sr-name {
  font-size: clamp(14px, 3.6vw, 15px);
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.sr-meta { margin-top: 2px; font-size: 12px; color: var(--muted); }
.sr-meta .in-progress { color: var(--accent); }
.sr-meta .last-score { color: var(--ok); }

.sr-download {
  flex-shrink: 0;
  align-self: stretch;
  width: 48px;
  border: 0;
  border-left: 1px solid var(--line);
  background: none;
  color: var(--muted);
  display: grid;
  place-items: center;
  text-decoration: none;
}

.sr-start {
  flex-shrink: 0;
  align-self: stretch;
  width: 48px;
  border: 0;
  border-left: 1px solid var(--line);
  background: none;
  color: var(--accent);
  display: grid;
  place-items: center;
}

.sr-start:active { background: var(--tap); }

.empty-note {
  padding: 20px 0;
  font-size: 14px;
  color: var(--muted);
  text-align: center;
}

.back-btn {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: auto;
  height: auto;
  margin: 0;
  padding: 4px;
  border: 0;
  background: none;
  color: var(--text);
}

.back-btn:active {
  opacity: 0.6;
}

.quiz-top {
  position: sticky;
  top: var(--topbar-h);
  z-index: 20;
  background: var(--bg);
  margin: 0 calc(-1 * var(--pad));
  padding: 0 var(--pad) 8px;
  border-bottom: 1px solid var(--line);
}

.quiz-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 10px;
  padding: 2px 0 8px;
}

.quiz-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1 1 180px;
  min-width: 0;
}

.quiz-title-row h2 {
  margin: 0;
  font-size: clamp(15px, 3.8vw, 18px);
  font-weight: 600;
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: anywhere;
}

.quiz-answers-btn {
  flex-shrink: 0;
  white-space: nowrap;
}

.quiz-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px 10px;
  flex: 0 1 auto;
  margin-left: auto;
}

.switch-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--muted);
}

.switch-label input { width: 13px; height: 13px; margin: 0; accent-color: var(--accent); }

.text-btn {
  padding: 0;
  border: 0;
  background: none;
  font-size: 12px;
  color: var(--accent);
}

.text-btn.active {
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.progress-bar { height: 2px; background: var(--line); }
.progress-fill { height: 100%; width: 0%; background: var(--accent); }

.quiz-stats {
  padding: 6px 0 2px;
  font-size: clamp(11px, 2.8vw, 12px);
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.quiz-stats .ok { color: var(--ok); }
.quiz-stats .bad { color: var(--bad); }
.stat-dot { margin: 0 8px; color: var(--line); }

.stat-banner {
  margin: 6px 0 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--bad);
}

.result-panel {
  margin: 0;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
  scroll-margin-top: calc(var(--topbar-h) + 72px);
}

.result-kicker { margin: 0 0 6px; font-size: 12px; font-weight: 600; color: var(--accent); }
.result-main { margin: 0; font-size: 15px; line-height: 1.5; }
.result-main strong { font-weight: 600; }
.result-detail { margin: 6px 0 0; font-size: 13px; color: var(--muted); }
.result-detail .ok { color: var(--ok); }
.result-detail .bad { color: var(--bad); }

.question-list {
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--line);
}

.question-card {
  display: flex;
  flex-direction: column;
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
  scroll-margin-top: calc(var(--topbar-h) + 80px);
}

.q-head {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 8px;
  align-items: start;
  margin-bottom: 10px;
}

.q-num {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  line-height: 1.55;
  padding-top: 1px;
}

.q-text {
  font-size: clamp(14px, 3.8vw, 16px);
  font-weight: 500;
  line-height: 1.55;
  min-width: 0;
  overflow-wrap: anywhere;
}

.mcq-rich img, .mcq-img {
  display: block;
  max-width: 100%;
  width: auto;
  height: auto;
  margin: 6px 0;
}

.options {
  display: flex;
  flex-direction: column;
  margin-top: 0;
  border: 1px solid var(--line);
}

.option {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  min-height: 44px;
  padding: 11px 12px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  text-align: left;
  font-size: clamp(14px, 3.6vw, 15px);
  line-height: 1.45;
}

.option:last-child { border-bottom: 0; }
.option:active:not(:disabled) { background: var(--tap); }
.option:disabled { cursor: default; }
.option.chosen { background: var(--tap); }
.option.correct { background: var(--ok-bg); }
.option.wrong { background: var(--bad-bg); }

.opt-label {
  font-weight: 600;
  color: var(--muted);
  text-align: center;
}

.opt-body { min-width: 0; overflow-wrap: anywhere; }
.opt-body img { max-width: min(100%, 160px); margin: 0; object-fit: contain; }
.opt-mark { font-weight: 700; color: var(--ok); }
.option.wrong .opt-mark { color: var(--bad); }

.mcq-img-fallback {
  display: none;
  font-size: 11px;
  color: var(--muted);
}
.mcq-img-fallback.is-visible { display: block; }

.q-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  margin-top: 10px;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.4;
}

.q-meta-chapter {
  flex: 0 1 auto;
  min-width: 0;
}

.q-meta-tags {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.q-tag {
  display: inline-flex;
  align-items: center;
  margin: 0;
  padding: 2px 8px;
  border: 1px solid var(--line);
  font-size: 10px;
  line-height: 1.3;
  color: var(--muted);
  white-space: nowrap;
}

.solution-wrap { margin-top: 10px; }

.solution-toggle {
  padding: 0;
  border: 0;
  background: none;
  font-size: 12px;
  color: var(--accent);
}

.solution-content {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  font-size: 13px;
  white-space: pre-wrap;
}

.bottom-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: flex;
  gap: 0;
  border-top: 1px solid var(--line);
  background: var(--bg);
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

.bottom-bar-inner {
  display: flex;
  width: 100%;
  max-width: var(--content);
  margin: 0 auto;
  padding: 0 max(var(--pad), var(--safe-left)) 0 max(var(--pad), var(--safe-right));
}

.btn {
  flex: 1;
  min-height: 49px;
  padding: 14px 12px;
  border: 0;
  border-right: 1px solid var(--line);
  background: var(--bg);
  font-size: clamp(13px, 3.4vw, 14px);
  font-weight: 500;
}

.btn:last-child { border-right: 0; }
.btn-primary { background: var(--accent); color: #fff; }
.bottom-bar .btn.hidden { display: none; }

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: flex-end;
}

.modal {
  width: 100%;
  max-width: min(var(--content), 100%);
  margin: 0 auto;
  background: var(--bg);
  padding: 20px max(var(--pad), var(--safe-left)) calc(20px + var(--safe-bottom)) max(var(--pad), var(--safe-right));
  max-height: min(90vh, 100dvh - var(--safe-top) - var(--safe-bottom));
  overflow: auto;
}

.modal-close {
  float: right;
  border: 0;
  background: none;
  font-size: 24px;
  line-height: 1;
  color: var(--muted);
}

.modal-title { margin: 0 0 2px; font-size: 16px; font-weight: 600; clear: both; }
.modal-sub { margin: 0 0 16px; font-size: 14px; color: var(--muted); }

.setup-section {
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.setup-label { margin: 0 0 10px; font-size: 13px; font-weight: 500; }
.setup-note { margin-top: 4px; font-size: 12px; color: var(--muted); }
.setup-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.setup-row .setup-label { margin-bottom: 0; }

.chip-group {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  border: 1px solid var(--line);
}

.opt-chip {
  padding: 10px 8px;
  border: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  font-size: 13px;
  text-align: center;
}

.opt-chip:nth-child(3n) { border-right: 0; }
.opt-chip:nth-last-child(-n+3) { border-bottom: 0; }
.opt-chip.active {
  color: var(--accent);
  background: var(--tap);
  outline: 1px solid var(--accent);
  outline-offset: -1px;
}

.toggle { position: relative; display: inline-block; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle-track {
  display: block;
  width: 44px;
  height: 24px;
  background: var(--line);
  border: 1px solid var(--line);
  position: relative;
}
.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  background: #fff;
  border: 1px solid var(--line);
}
.toggle input:checked + .toggle-track { background: var(--accent); border-color: var(--accent); }
.toggle input:checked + .toggle-track .toggle-thumb { transform: translateX(20px); border-color: var(--accent); }

.modal-start { width: 100%; margin-top: 8px; border: 1px solid var(--accent); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; }
* { -webkit-tap-highlight-color: transparent; }

@media (min-width: 481px) {
  .modal-overlay { align-items: center; padding: 16px; }
  .modal { border: 1px solid var(--line); max-height: 85vh; }
}

@media (min-width: 520px) {
  :root { --content: 480px; }
}

@media (min-width: 600px) {
  :root { --content: 720px; --pad: 20px; }
  .section-label { font-size: 18px; }
  .subject-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    border: 1px solid var(--line);
    border-top: 0;
  }
  .subject-list .empty-note { grid-column: 1 / -1; }
  .subject-row {
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    margin: 0;
  }
  .subject-row:nth-child(2n) { border-right: 0; }
  .subject-row:last-child { border-bottom: 0; }
}

@media (min-width: 768px) {
  .question-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    border: 1px solid var(--line);
    border-top: 0;
  }

  .question-card {
    height: 100%;
    padding: 18px 16px;
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    margin: 0;
  }

  .question-card:nth-child(2n) { border-right: 0; }
  .question-card:nth-last-child(-n+2) { border-bottom: 0; }
  .question-card:last-child:nth-child(odd) { border-bottom: 0; }

  .mcq-rich img, .mcq-img { max-width: min(100%, 320px); }
}

@media (min-width: 900px) {
  :root { --content: 1040px; }
  .section-label { font-size: 19px; }
  .subject-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .subject-row:nth-child(2n) { border-right: 1px solid var(--line); }
  .subject-row:nth-child(3n) { border-right: 0; }
  .subject-row:last-child { border-bottom: 1px solid var(--line); }
  .subject-row:nth-last-child(-n+3) { border-bottom: 0; }
}

@media (min-width: 1200px) {
  :root { --content: 1120px; }
}

@media (hover: hover) and (pointer: fine) {
  .subject-row-main:hover { background: var(--tap); }
  .sr-start:hover { background: var(--tap); color: var(--text); }
  .sr-download:hover { background: var(--tap); color: var(--text); }
  .back-btn:hover { opacity: 0.7; }
  .text-btn:hover { opacity: 0.8; }
  .option:hover:not(:disabled) { background: var(--tap); }
  .btn:hover:not(.btn-primary) { background: var(--tap); }
  .btn-primary:hover { background: #006868; color: #fff; }
  .solution-toggle:hover { background: var(--tap); }
  .opt-chip:hover { background: var(--tap); }
  .modal-close:hover { color: var(--text); }
  .borno-float:hover { transform: translateY(-2px); }
  .borno-float:hover .borno-doubt { background: #006868; }
  .play-store-btn:hover { opacity: 0.88; transform: translateY(-1px); }
}
