:root {
  --bd-green: #006a4e;
  --bd-green-dark: #004d38;
  --bd-red: #f42a41;
  --paper-bg: #fcfaf2;
  --paper-border: #d6cfc0;
  --ink: #111827;
  --omr-pink: #d94662;
  --omr-bg: #fff9fa;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Noto Sans Bengali', 'Kalpurush', 'SolaimanLipi', sans-serif;
  background: #e7e5df;
  color: var(--ink);
  line-height: 1.55;
  text-rendering: optimizeLegibility;
}

/* Top Toolbar */
.toolbar {
  position: sticky; top: 0; z-index: 100;
  background: linear-gradient(90deg, var(--bd-green-dark), var(--bd-green));
  color: #fff;
  padding: 10px 18px;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px;
  box-shadow: 0 3px 12px rgba(0,0,0,0.2);
  border-bottom: 3px solid var(--bd-red);
}
.tb-left, .tb-mid, .tb-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tb-title { font-weight: 700; font-size: 16px; letter-spacing: 0.2px; }
.tb-mid label { font-size: 12.5px; display: flex; align-items: center; gap: 6px; background: rgba(255,255,255,0.12); padding: 4px 10px; border-radius: 6px; }
.tb-mid select { background: #fff; color: #111; border: none; border-radius: 4px; padding: 3px 8px; font-family: inherit; font-weight: 600; font-size: 12.5px; }
.chk { cursor: pointer; user-select: none; display: inline-flex; align-items: center; gap: 5px; }

.tb-btn {
  padding: 7px 14px; border-radius: 6px; border: 1px solid rgba(255,255,255,0.3);
  background: rgba(255,255,255,0.14); color: #fff; font-family: inherit; font-weight: 600; font-size: 13px;
  cursor: pointer; text-decoration: none; transition: 0.15s;
}
.tb-btn:hover { background: rgba(255,255,255,0.25); }
.tb-btn.primary { background: var(--bd-red); border-color: #ff6b7b; color: #fff; font-weight: 700; }
.tb-btn.primary:hover { background: #d91e34; }
.tb-btn.primary:disabled { opacity: 0.55; cursor: not-allowed; }
.tb-btn.ghost { background: transparent; border-color: rgba(255,255,255,0.35); }
.tb-btn.big { padding: 10px 22px; font-size: 15px; }

.timer {
  background: #0b1f19; color: #fde047; font-weight: 700; font-size: 16px;
  padding: 5px 12px; border-radius: 6px; border: 1px solid rgba(253,224,71,0.4);
  min-width: 90px; text-align: center; font-variant-numeric: tabular-nums;
}

/* Main Split Hall */
.hall {
  max-width: 1440px; margin: 16px auto; padding: 0 14px;
  display: grid; grid-template-columns: 1fr 370px; gap: 18px; align-items: start;
}
@media (max-width: 1024px) {
  .hall { grid-template-columns: 1fr; }
}

/* Authentic BPSC Question Paper */
.paper {
  background: var(--paper-bg);
  border: 1.5px solid var(--paper-border);
  box-shadow: 0 6px 24px rgba(0,0,0,0.12);
  padding: 26px 30px;
  font-family: 'Tiro Bangla', 'SolaimanLipi', 'Kalpurush', 'Noto Serif Bengali', serif;
  font-feature-settings: "kern" 1, "liga" 1, "clig" 1;
  text-rendering: optimizeLegibility;
  color: #0b0f17;
  position: relative;
  overflow: hidden;
}
.watermark {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%) rotate(-32deg);
  font-size: 92px; font-weight: 700; color: rgba(0, 106, 78, 0.04);
  pointer-events: none; user-select: none; white-space: nowrap;
}

.p-head {
  text-align: center; border-bottom: 2px double #111; padding-bottom: 8px; margin-bottom: 8px;
}
.p-gov { font-size: 12px; font-weight: 600; letter-spacing: 0.5px; }
.p-org { font-size: 19px; font-weight: 700; margin-top: 1px; }
.p-exam { font-size: 14.5px; font-weight: 700; margin-top: 2px; color: #1f2937; }
.p-meta {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 8px; padding-top: 6px; border-top: 1px solid #333;
  font-size: 13px; font-weight: 700;
}
.p-setbox {
  border: 2px solid #111; padding: 2px 12px; font-size: 13.5px; background: #fff;
}

.p-ins {
  font-size: 11.5px; border: 1px solid #444; background: #f7f4ea;
  padding: 6px 10px; margin-bottom: 14px; line-height: 1.45;
}

.p-cols {
  column-count: 2;
  column-gap: 24px;
  column-rule: 1px solid #888;
}
@media (max-width: 720px) {
  .p-cols { column-count: 1; }
}

.subj-banner {
  break-inside: avoid;
  background: #ece7d5; border-left: 4px solid var(--bd-green);
  padding: 3px 8px; margin: 8px 0 6px 0;
  font-size: 12px; font-weight: 700; color: #111;
}

.q-block {
  break-inside: avoid;
  margin-bottom: 12px; padding-bottom: 8px;
  border-bottom: 1px dotted #c7c2b6;
  font-size: 15px;
  line-height: 1.6;
}
.q-stem { font-weight: 600; margin-bottom: 4px; color: #0b0f17; }
.q-opts {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px;
  padding-left: 6px; font-size: 14px; line-height: 1.5;
}
.q-opt {
  cursor: pointer; padding: 2px 5px; border-radius: 3px; transition: 0.1s;
}
.q-opt:hover { background: rgba(0,106,78,0.08); }
.q-opt.draft { background: #fef08a; font-weight: 600; }
.q-opt.correct-rev { background: #bbf7d0; font-weight: 700; color: #065f46; }
.q-opt.wrong-rev { background: #fecdd3; text-decoration: line-through; color: #9f1239; }
.q-exp {
  margin-top: 6px; padding: 6px 9px; background: #eef6f3; border-left: 3px solid var(--bd-green);
  font-size: 13px; line-height: 1.55; color: #1e293b; font-family: 'Noto Sans Bengali', 'Kalpurush', sans-serif;
}

.p-foot {
  margin-top: 16px; padding-top: 10px; border-top: 2px solid #111;
  text-align: center; font-size: 12.5px; font-weight: 600;
}

/* Right-side Authentic Pink/Red BPSC OMR Sheet */
.omr {
  position: sticky; top: 68px;
  background: var(--omr-bg);
  border: 2px solid var(--omr-pink);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.12);
  max-height: calc(100vh - 84px);
  display: flex; flex-direction: column;
}
.omr-inner { display: flex; flex-direction: column; height: 100%; max-height: calc(100vh - 88px); }
.omr-head {
  background: var(--omr-pink); color: #fff; padding: 8px 12px;
  display: flex; justify-content: space-between; align-items: center;
}
.omr-title { font-weight: 700; font-size: 14px; letter-spacing: 0.3px; }
.omr-close { display: none; background: none; border: none; color: #fff; font-size: 16px; cursor: pointer; }

.omr-cand {
  padding: 8px 12px; border-bottom: 1px solid #f3c6cf; font-size: 12px;
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px;
}
.omr-setcode { grid-column: span 2; display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.omr-setcode .sc {
  width: 22px; height: 22px; border-radius: 50%; border: 1.5px solid var(--omr-pink);
  display: inline-flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; color: var(--omr-pink);
}
.omr-setcode .sc.active { background: #111; border-color: #111; color: #fff; }

.omr-mode { padding: 5px 12px; background: #ffeef2; border-bottom: 1px solid #f3c6cf; font-size: 11.5px; color: #881337; }
.omr-count { padding: 6px 12px; font-size: 12.5px; font-weight: 700; color: #111; border-bottom: 1px solid #f3c6cf; display: flex; justify-content: space-between; }

.omr-grid {
  padding: 8px 10px; overflow-y: auto; flex: 1;
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px;
}
.omr-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 2px 4px; border-bottom: 1px dashed #f5d0d8; font-size: 12px;
}
.omr-qno { font-weight: 700; color: #9f1239; width: 32px; cursor: pointer; }
.omr-bubbles { display: flex; gap: 4px; }
.omr-b {
  width: 22px; height: 22px; border-radius: 50%;
  border: 1.5px solid var(--omr-pink); color: var(--omr-pink);
  background: #fff; font-size: 11px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; transition: 0.1s; user-select: none;
}
.omr-b:hover { transform: scale(1.08); }
.omr-b.filled { background: #111 !important; border-color: #111 !important; color: #fff !important; }
.omr-b.multi { background: #b91c1c !important; border-color: #991b1b !important; color: #fff !important; }

.fab {
  display: none; position: fixed; bottom: 16px; right: 16px; z-index: 90;
  background: var(--omr-pink); color: #fff; border: none; border-radius: 999px;
  padding: 10px 18px; font-family: inherit; font-weight: 700; box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}

/* Overlays / Modals */
.overlay, .print-dialog {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(15, 23, 42, 0.72); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.overlay[hidden], .print-dialog[hidden] { display: none !important; }

.card {
  background: #fff; color: #111; border-radius: 12px; max-width: 520px; width: 100%;
  padding: 22px 24px; box-shadow: 0 20px 50px rgba(0,0,0,0.35);
  border-top: 5px solid var(--bd-green);
}
.card.wide { max-width: 760px; max-height: 90vh; overflow-y: auto; }
.card-head { margin-bottom: 12px; border-bottom: 1px solid #e5e7eb; padding-bottom: 8px; }
.card-sub { font-size: 13.5px; color: #4b5563; font-weight: 600; margin-top: 2px; }

.form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.form label { font-size: 12.5px; font-weight: 600; display: flex; flex-direction: column; gap: 4px; }
.form input { padding: 7px 10px; border: 1px solid #cbd5e1; border-radius: 6px; font-family: inherit; font-size: 13.5px; }

.rules { margin: 10px 0 16px 18px; font-size: 13px; color: #334155; space-y: 4px; }
.rules li { margin-bottom: 5px; }
.card-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.card-actions .tb-btn.ghost { color: #1e293b; border-color: #cbd5e1; }
.card-actions .tb-btn.ghost:hover { background: #f1f5f9; }

.res-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 12px 0; }
.res-stat { background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 8px; padding: 10px; text-align: center; }
.res-stat .v { font-size: 20px; font-weight: 700; color: var(--bd-green); }
.res-table { width: 100%; border-collapse: collapse; font-size: 12.5px; margin-top: 10px; }
.res-table th, .res-table td { border: 1px solid #e2e8f0; padding: 6px 8px; text-align: left; }
.res-table th { background: #f1f5f9; }

.answer-key, .print-omr { display: none; }

/* Phones: keep everything inside the screen width, and keep the sticky
   toolbar short so the question paper gets the space */
@media screen and (max-width: 720px) {
  .toolbar { padding: 8px 12px; gap: 8px; }
  .tb-left, .tb-mid, .tb-right { width: 100%; min-width: 0; gap: 6px; }
  .tb-mid label { flex: 1 1 100%; min-width: 0; }
  .tb-mid label:has(#selCode), .tb-mid label.chk { flex: 1 1 auto; }
  .tb-mid select { flex: 1 1 auto; min-width: 0; max-width: 100%; text-overflow: ellipsis; }
  .tb-right { justify-content: space-between; }
  .tb-right .tb-btn { padding: 6px 10px; }
  /* during the exam only the timer and buttons stay pinned */
  body.exam-running .tb-mid { display: none; }
  body.exam-running .tb-left { width: auto; }
  body.exam-running .tb-right { width: auto; flex: 1; justify-content: flex-end; }
  .paper { padding-left: 14px; padding-right: 14px; }
  .q-opts { grid-template-columns: 1fr; }
  .form { grid-template-columns: 1fr; }
  .form input, .form select { min-width: 0; width: 100%; box-sizing: border-box; }
}

@media print {
  body { background: #fff; }
  .no-print { display: none !important; }
  .hall { display: block; margin: 0; padding: 0; max-width: none; }
  .paper { box-shadow: none; border: none; padding: 8mm 10mm; page-break-after: always; background: #fff; }
  body.hide-paper #paper { display: none !important; }
  body.show-omr .print-omr { display: block !important; page-break-after: always; padding: 10mm; }
  body.show-key .answer-key { display: block !important; }
}
