:root {
  --primary: #0b3c6d; --primary-dark: #082c50; --accent: #d9791a;
  --bg: #f3f5f8; --surface: #fff; --text: #17202a; --muted: #515d6b; --border: #c9d1db;
  --green: #1d7a38; --red: #bd2c2c; --purple: #66399a; --soft: #eaf0f7;
}
* { box-sizing: border-box; }
html { font-size: 16px; }
body {
  margin: 0; background: var(--bg); color: var(--text); line-height: 1.65;
  font-family: "Noto Sans Gujarati", "Nirmala UI", "Shruti", "Gujarati Sangam MN", system-ui, sans-serif;
  overflow-wrap: break-word;
}
[hidden] { display: none !important; }
h1 { font-size: 1.5rem; margin: .5rem 0; line-height: 1.4; }
h2 { font-size: 1.15rem; margin: 1.25rem 0 .5rem; line-height: 1.4; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; color: var(--primary); }
a { color: var(--primary); }
img { max-width: 100%; height: auto; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.loading { text-align: center; padding: 3rem 1rem; }

/* ---------- માળખું ---------- */
.wrap { max-width: 1060px; margin: 0 auto; padding: 0 16px; }
.shell { min-height: 100vh; display: flex; flex-direction: column; }
.shell > main { flex: 1; width: 100%; padding-top: 8px; padding-bottom: 32px; }
.site-header { background: var(--primary); color: #fff; border-bottom: 4px solid var(--accent); }
.site-header .wrap { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 16px; }
.brand { color: #fff; text-decoration: none; display: flex; flex-direction: column; padding: 8px 0; line-height: 1.35; }
.brand strong { font-size: 1.15rem; }
.brand span { font-size: .85rem; }
.site-header nav { display: flex; flex-wrap: wrap; }
.site-header nav a { color: #fff; text-decoration: none; padding: 10px 12px; border-bottom: 3px solid transparent; }
.site-header nav a[aria-current] { border-bottom-color: #fff; font-weight: 700; }
.site-footer { background: #e3e8ee; border-top: 1px solid var(--border); color: var(--muted); font-size: .85rem; padding: 10px 0; }
.page.narrow { max-width: 520px; margin: 3rem auto; padding: 0 16px; }
.sub { color: var(--muted); margin-top: 0; }

/* ---------- સામાન્ય ઘટકો ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 4px; padding: 14px 16px; margin: 10px 0; }
.btn {
  display: inline-block; font: inherit; line-height: 1.35; cursor: pointer; text-align: center; text-decoration: none;
  min-height: 42px; padding: 9px 14px; border-radius: 4px; border: 1px solid var(--primary);
  background: #fff; color: var(--primary);
}
.btn:hover:not(:disabled) { background: var(--soft); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn.success { background: var(--green); border-color: var(--green); color: #fff; }
.btn.success:hover:not(:disabled) { background: #155c2a; }
.btn.purple { border-color: var(--purple); color: var(--purple); }
.btn.danger { border-color: var(--red); color: var(--red); }
.btn.small { min-height: 34px; padding: 4px 10px; font-size: .9rem; }
.btn.block { display: block; width: 100%; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.badge { display: inline-block; font-size: .78rem; border-radius: 3px; padding: 1px 8px; border: 1px solid; font-weight: 400; }
.badge.custom { background: #fff4e0; color: #7a4300; border-color: #d99a45; }
.badge.verified { background: #e6f4ea; color: #12572a; border-color: #5aa874; }
.chip { font-size: .8rem; background: var(--soft); border: 1px solid var(--border); border-radius: 3px; padding: 0 8px; }
.chip.demo { background: #fff4e0; border-color: #d99a45; color: #7a4300; }
.chip.correct { background: #e6f4ea; color: #12572a; }
.chip.incorrect { background: #fdeaea; color: #8c1c1c; }
.alert { display: block; background: #fff8e6; border: 1px solid #dcb056; border-left-width: 5px; border-radius: 3px; padding: 8px 12px; margin: 10px 0; }
.alert.danger { background: #fdeeee; border-color: var(--red); }
.warn, .errors { color: #8c1c1c; }
ul.errors, ol.errors, .alert ul { padding-left: 28px; }
.check { display: flex; gap: 8px; align-items: flex-start; margin: 14px 0; cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 3px 0 0; flex: none; }

.exam-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.exam-card { display: flex; flex-direction: column; align-items: flex-start; margin: 0; }
.exam-card h2 { margin: 0 0 6px; }
.exam-card .facts { align-self: stretch; }
.exam-card .btn { align-self: stretch; margin-top: auto; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(80px, 1fr)); gap: 6px 12px; margin: 12px 0; }
.facts dt { font-size: .8rem; color: var(--muted); }
.facts dd { margin: 0; font-weight: 700; }
.instructions li { margin-bottom: 4px; }

table { border-collapse: collapse; width: 100%; background: #fff; }
th, td { border: 1px solid var(--border); padding: 7px 10px; text-align: left; vertical-align: top; }
thead th { background: var(--soft); }
table.summary th { font-weight: 400; }
table.summary td { text-align: right; font-weight: 700; width: 5rem; }
.table-wrap { overflow-x: auto; }

/* ---------- પ્રશ્ન સૂચિના ચિહ્નો (રંગ + આકાર) ---------- */
.pal {
  position: relative; display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 42px; height: 40px; font: inherit; font-weight: 700; font-size: .95rem; border: 1px solid transparent; padding: 0;
}
button.pal { cursor: pointer; }
.pal.notVisited { background: #fff; color: var(--text); border-color: #8d99a8; border-radius: 3px; }
.pal.notAnswered { background: var(--red); color: #fff; border-radius: 3px 3px 16px 16px; }
.pal.answered { background: var(--green); color: #fff; border-radius: 16px 16px 3px 3px; }
.pal.marked, .pal.answeredMarked { background: var(--purple); color: #fff; border-radius: 50%; width: 42px; height: 42px; }
.pal.answeredMarked::after {
  content: "✓"; position: absolute; right: -3px; bottom: -3px; width: 18px; height: 18px; line-height: 18px;
  font-size: 12px; border-radius: 50%; background: var(--green); border: 1px solid #fff; color: #fff; text-align: center;
}
.pal.current { box-shadow: 0 0 0 3px var(--accent); }
.legend { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 6px; }
.legend li { display: flex; align-items: center; gap: 10px; font-size: .88rem; line-height: 1.35; }
.legend .pal { width: 34px; height: 32px; }
.legend .pal.marked, .legend .pal.answeredMarked { height: 34px; width: 34px; }
.legend.card { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }

/* ---------- પરીક્ષા સ્ક્રીન ---------- */
.exam { display: flex; flex-direction: column; height: 100vh; height: 100dvh; background: #fff; }
.exam-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--primary); color: #fff; padding: 6px 12px; border-bottom: 4px solid var(--accent); }
.exam-name { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 10px; flex: 1; min-width: 0; line-height: 1.35; }
.timer { display: flex; align-items: center; gap: 8px; background: #fff; color: var(--text); border-radius: 4px; padding: 3px 12px; line-height: 1.35; }
.timer span { font-size: .8rem; }
.timer strong { font-size: 1.2rem; font-variant-numeric: tabular-nums; }
.timer.low { background: var(--red); color: #fff; }
.exam > .alert { margin: 0; }
.tabs { display: flex; gap: 4px; overflow-x: auto; padding: 6px 12px; border-bottom: 1px solid var(--border); flex: none; position: relative; }
.shell .tabs { padding: 4px 0 10px; }
.tab { font: inherit; font-size: .9rem; white-space: nowrap; background: #fff; color: var(--primary); border: 1px solid var(--border); border-radius: 3px; padding: 5px 12px; cursor: pointer; }
.tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.exam-body { flex: 1; display: flex; min-height: 0; }
.question-panel { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.q-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.exam .q-head { padding: 8px 16px; border-bottom: 1px solid var(--border); background: var(--bg); }
.q-content { flex: 1; overflow-y: auto; padding: 12px 16px 24px; }
.q-text { font-size: 1.12rem; margin: .4rem 0 .8rem; white-space: pre-wrap; }
.q-text.en { font-size: 1rem; color: var(--muted); }
.q-image { display: block; max-height: 300px; margin-bottom: 12px; }
.options { display: grid; gap: 10px; max-width: 760px; }
.option { display: flex; align-items: center; gap: 12px; border: 1px solid var(--border); border-radius: 4px; padding: 11px 14px; cursor: pointer; }
.option:hover { background: var(--soft); }
.option:has(input:checked) { background: var(--soft); border-color: var(--primary); }
.option:has(input:focus-visible) { outline: 3px solid var(--accent); }
.option input { width: 20px; height: 20px; margin: 0; flex: none; accent-color: var(--primary); }
.option input:checked ~ span { font-weight: 700; }
.letter { font-weight: 700; color: var(--primary); flex: none; min-width: 1.2em; }
.action-bar { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--border); background: var(--bg); }
.action-bar #btn-next { margin-left: auto; }
.palette { width: 290px; flex: none; display: flex; flex-direction: column; gap: 8px; border-left: 1px solid var(--border); background: var(--soft); padding: 10px 12px; min-height: 0; }
.palette-title { display: flex; justify-content: space-between; align-items: center; }
.palette-title h2 { margin: 0; font-size: 1rem; }
.palette-scroll { flex: 1; overflow-y: auto; padding: 4px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 10px 6px; justify-items: center; padding-top: 4px; }
.palette-open, .palette-close, .backdrop { display: none; }

/* ---------- પરિણામ ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin: 12px 0; }
.stat { background: #fff; border: 1px solid var(--border); border-top: 4px solid var(--primary); border-radius: 4px; padding: 10px 12px; }
.stat span { display: block; font-size: .85rem; color: var(--muted); }
.stat strong { font-size: 1.35rem; line-height: 1.4; }
.stat.good { border-top-color: var(--green); }
.stat.bad { border-top-color: var(--red); }
.stat.main { border-top-color: var(--accent); }
.formula { font-size: .9rem; color: var(--muted); }
.review { border-left: 5px solid var(--border); }
.review.correct { border-left-color: var(--green); }
.review.incorrect { border-left-color: var(--red); }
.review p { margin: .4rem 0; }
.review-options { list-style: none; padding: 0; display: grid; gap: 6px; }
.review-options li { display: flex; flex-wrap: wrap; gap: 4px 10px; border: 1px solid var(--border); border-radius: 3px; padding: 6px 10px; }
.review-options li.right { background: #e6f4ea; border-color: var(--green); }
.review-options li.wrong { background: #fdeaea; border-color: var(--red); }
.review-options em { margin-left: auto; font-style: normal; font-size: .85rem; font-weight: 700; }
.review-options em + em { margin-left: 0; }
.explain { background: var(--soft); padding: 8px 10px; border-radius: 3px; }
.source { font-size: .82rem; color: var(--muted); }

/* ---------- પ્રશ્ન બેંક ---------- */
.toolbar { margin: 8px 0; }
label { display: block; font-size: .9rem; }
input:not([type]), input[type="search"], select, textarea {
  display: block; width: 100%; font: inherit; font-size: 1rem; color: var(--text); background: #fff;
  border: 1px solid #8d99a8; border-radius: 4px; padding: 7px 9px;
}
input[readonly] { background: #eef0f3; }
.filters, .cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.editor { display: grid; gap: 12px; }
.editor .check { display: flex; margin: 0; }
fieldset { border: 1px solid var(--border); border-radius: 4px; }
.option-edit { display: flex; align-items: center; gap: 10px; margin: 6px 0; }
.option-edit input[type="radio"] { width: 22px; height: 22px; flex: none; }
.q-row { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.q-row > div:first-child { min-width: 0; }
.q-row .q-text { font-size: 1rem; margin: 0 0 6px; }
.pager { justify-content: center; margin-top: 12px; }

/* ---------- સંવાદ અને સૂચના ---------- */
.modal { border: 1px solid var(--border); border-top: 5px solid var(--primary); border-radius: 6px; padding: 16px 20px; width: min(480px, calc(100vw - 24px)); max-height: calc(100vh - 24px); color: var(--text); }
.modal::backdrop { background: rgba(10, 20, 35, .6); }
.modal h2 { margin-top: 0; }
.modal-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.toast { position: fixed; left: 50%; bottom: 130px; pointer-events: none; transform: translateX(-50%); z-index: 50; background: #17202a; color: #fff; padding: 9px 16px; border-radius: 4px; max-width: calc(100vw - 32px); width: max-content; box-shadow: 0 2px 8px rgba(0,0,0,.3); }

/* ---------- મોબાઇલ ---------- */
@media (max-width: 800px) {
  .palette-open { display: inline-block; }
  .palette-close { display: inline-block; }
  .palette { position: fixed; top: 0; bottom: 0; right: 0; width: min(320px, 90vw); z-index: 20; transform: translateX(105%); visibility: hidden; }
  .palette.open { transform: none; visibility: visible; }
  .backdrop.open { display: block; position: fixed; inset: 0; background: rgba(10,20,35,.5); z-index: 10; }
  .exam-bar { flex-wrap: wrap; padding: 6px 10px; }
  .exam-name { flex-basis: 100%; font-size: .9rem; }
  .exam-bar .palette-open { background: #fff; }
  .tabs { padding-left: 10px; padding-right: 10px; }
  .exam .q-head { padding: 6px 10px; }
  .q-content { padding: 10px; }
  .action-bar { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; padding: 8px; }
  .action-bar .btn { grid-column: span 2; padding: 6px 4px; font-size: .9rem; min-height: 44px; }
  .action-bar #btn-next { margin-left: 0; }
  .action-bar #btn-mark, .action-bar #btn-savenext { grid-column: span 3; }
  .action-bar #btn-prev { order: 1; }
  .action-bar #btn-clear { order: 2; }
  .action-bar #btn-next { order: 3; }
  .action-bar #btn-mark { order: 4; }
  .action-bar #btn-savenext { order: 5; }
  .q-row { flex-direction: column; align-items: flex-start; }

  table.data thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.data, table.data tbody, table.data tr, table.data td { display: block; }
  table.data tr { border: 1px solid var(--border); margin-bottom: 10px; }
  table.data td { display: flex; justify-content: space-between; gap: 12px; border: 0; border-bottom: 1px solid #e5e9ee; text-align: right; }
  table.data td::before { content: attr(data-label); color: var(--muted); text-align: left; }
}
/* નાની ઊંચાઈ (આડો ફોન): આખું પાનું સ્ક્રોલ થાય */
@media (max-height: 520px) {
  .exam { height: auto; min-height: 100dvh; }
  .q-content { overflow: visible; }
  .exam-bar { position: sticky; top: 0; z-index: 5; flex-wrap: nowrap; }
  .exam-name { flex-basis: auto; }
  .palette { position: sticky; top: 0; height: 100dvh; }
}
@media (max-height: 520px) and (max-width: 800px) {
  .palette { position: fixed; height: auto; }
  .palette-scroll { min-height: 60px; }
  .palette .legend { grid-template-columns: 1fr 1fr; }
}
