/* ============================================================
   Provpass och övning per delprov.
   Provet ska kännas som ett lugnt provhäfte: vitt papper, tydliga
   svarsalternativ och omslag i passets egen färg.
   ============================================================ */

.hidden { display: none !important; }

/* ---------- Omslag ---------- */
.cover-wrap { padding: var(--s-5) var(--s-4) var(--s-7); display: flex; justify-content: center; }
.cover {
  --cover-bg: var(--cover);
  width: 100%;
  max-width: 760px;
  padding: clamp(var(--s-5), 6vw, 48px);
  background: var(--cover-bg);
  color: #1d1a26;
  border-radius: var(--r-sm);
}
:root[data-theme="dark"] .cover { --cover-bg: color-mix(in srgb, var(--cover) 16%, var(--surface)); color: var(--text); }
.cover-brand { display: flex; justify-content: space-between; align-items: center; gap: var(--s-3); margin-bottom: var(--s-5); font-weight: 600; font-size: var(--step--1); }
.cover-brand a { color: inherit; }
.cover .date { text-align: right; font-size: var(--step--1); font-variant-numeric: tabular-nums; }
.cover h1 { font-size: clamp(2.4rem, 8vw, 3.4rem); margin: var(--s-3) 0 var(--s-4); letter-spacing: -0.03em; }
.cover h2 { font-size: var(--step-2); margin: var(--s-5) 0 var(--s-2); }
.cover .cover-sub { margin-top: 0; }
.cover ul { margin: 0 0 var(--s-3); padding-left: 1.3em; }
.cover li { margin: 3px 0; }
.cover-intro { margin: 0; }
.cover-table { overflow-x: auto; margin-top: var(--s-3); }
.cover table { border-collapse: separate; border-spacing: 3px; font-size: var(--step--1); }
.cover th, .cover td { background: rgb(255 255 255 / 0.85); padding: var(--s-1) var(--s-3); text-align: left; white-space: nowrap; }
:root[data-theme="dark"] .cover th, :root[data-theme="dark"] .cover td { background: rgb(0 0 0 / 0.25); }
.cover .start-row { margin-top: var(--s-6); display: flex; flex-wrap: wrap; gap: var(--s-3); align-items: center; }
.cover .notice { background: rgb(255 255 255 / 0.85); padding: var(--s-3) var(--s-4); font-weight: 600; border-radius: 2px; }
:root[data-theme="dark"] .cover .notice { background: rgb(0 0 0 / 0.25); }
.cover .fine { font-size: var(--step--1); margin-top: var(--s-5); margin-bottom: 0; opacity: 0.85; }
.cover .btn { font-size: var(--step-0); }

/* ---------- Topprad under provet ---------- */
.topbar { position: sticky; top: 0; z-index: 30; background: var(--surface); border-bottom: 1px solid var(--line); box-shadow: var(--shadow-1); }
.topbar-in { max-width: 1180px; margin: 0 auto; padding: var(--s-2) var(--s-4); display: flex; align-items: center; gap: var(--s-4); }
.topbar .title { font-size: var(--step-0); font-weight: 700; line-height: 1.2; letter-spacing: 0; margin: 0; }
.topbar .title small { display: block; font-weight: 400; color: var(--muted); font-size: 0.8rem; }
.spacer { flex: 1; }
.timer {
  font-variant-numeric: tabular-nums;
  font-size: 1.6rem; font-weight: 700;
  padding: 0 var(--s-3);
  border-radius: var(--r-sm);
  background: var(--primary-soft); color: var(--primary);
  min-width: 108px; text-align: center;
}
.timer.warn { background: var(--warn-soft); color: var(--warn); }
.timer.danger { background: var(--bad-soft); color: var(--bad); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }
.answered { font-size: var(--step--1); color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.tbar { height: 4px; background: var(--surface-2); }
.tbar > div { height: 100%; background: var(--primary); width: 0; transition: width 0.5s linear; }
.tbar.warn > div { background: var(--warn); }
.tbar.danger > div { background: var(--bad); }

/* ---------- Layout ---------- */
.layout { max-width: 1180px; margin: 0 auto; padding: var(--s-4) var(--s-4) 90px; display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: var(--s-5); align-items: start; }
.aside { position: sticky; top: 84px; max-height: calc(100vh - 100px); overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--s-3) var(--s-3) var(--s-4); }
.aside h3 { margin: 0 0 var(--s-1); font-size: var(--step-0); }
.aside p { margin: 0 0 var(--s-2); font-size: 0.8rem; color: var(--muted); }
.sheet-sec { font-size: 0.75rem; font-weight: 700; color: var(--primary); margin: var(--s-3) 0 3px; }
.srow { display: flex; align-items: center; gap: 6px; padding: 2px 0; }
.snum { width: 28px; text-align: right; font-size: 0.82rem; font-weight: 600; color: var(--muted); background: none; border: 0; padding: 0; font-variant-numeric: tabular-nums; }
.snum:hover { color: var(--primary); text-decoration: underline; }
.bub { width: 30px; height: 30px; border-radius: 50%; border: 1.5px solid var(--neutral); background: var(--surface); font-size: 0.78rem; color: var(--muted); padding: 0; line-height: 1; }
.bub:hover:not(:disabled) { border-color: var(--primary); background: var(--primary-soft); }
.bub.on { background: var(--primary); border-color: var(--primary); color: var(--on-primary); font-weight: 700; }
.bub:disabled { cursor: default; }
.bub.right { border-color: var(--ok); box-shadow: 0 0 0 2px var(--ok-soft) inset; color: var(--ok); font-weight: 700; }
.bub.on.right { background: var(--ok); color: var(--surface); }
.bub.on.wrongb { background: var(--bad); border-color: var(--bad); color: var(--surface); }
.fab { display: none; }

/* ---------- Delprov och uppgifter ---------- */
.sec-head { margin: var(--s-6) 0 var(--s-3); padding: var(--s-3) var(--s-4); background: var(--primary); color: var(--on-primary); border-radius: var(--r-md); display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px; align-items: baseline; }
#main > .sec-head:first-of-type, #resultsHost + .sec-head { margin-top: 0; }
.sec-head h2 { margin: 0; font-size: var(--step-1); }
.sec-head span { font-size: var(--step--1); opacity: 0.9; }
.figure { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--s-4); margin: var(--s-4) 0; }
.figure h3 { margin: 0 0 var(--s-2); font-size: var(--step-1); }
.figure img { display: block; max-width: 100%; height: auto; margin: 0 auto; cursor: zoom-in; background: var(--image-bg); }
:root[data-theme="dark"] .figure img { padding: var(--s-2); border-radius: var(--r-sm); }
.figure .cap { font-size: var(--step--1); color: var(--muted); margin-top: var(--s-2); }
.figure .hint { font-size: 0.78rem; color: var(--muted); text-align: center; margin-top: var(--s-1); }
.sub-head { margin: var(--s-4) 2px 6px; font-size: var(--step-1); font-weight: 600; }
.q {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--s-4) var(--s-4) var(--s-3);
  margin: var(--s-3) 0;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  scroll-margin-top: 92px;
}
.q:focus { outline: none; }
.q:focus-visible { box-shadow: var(--focus); }
.q .qn { font-weight: 700; font-size: var(--step-1); font-variant-numeric: tabular-nums; }
.q.answered-q { border-left: 5px solid var(--primary); }
.q.r-ok { border-left: 5px solid var(--ok); }
.q.r-bad { border-left: 5px solid var(--bad); }
.q.r-none { border-left: 5px solid var(--neutral); }
.qtext p { margin: 0 0 var(--s-2); }
.qtext .b { font-weight: 700; }
.qtext .fig { margin: var(--s-2) 0; }
.qtext .fig img { max-width: 100%; height: auto; display: block; background: var(--image-bg); cursor: zoom-in; }
:root[data-theme="dark"] .qtext .fig img, :root[data-theme="dark"] .optimg { padding: 4px; border-radius: 4px; }
.kv { display: grid; grid-template-columns: auto 1fr; column-gap: 22px; row-gap: 4px; margin: 10px 0 4px; }
.kv .l { font-style: italic; }
.stm { display: grid; grid-template-columns: 30px 1fr; row-gap: var(--s-2); margin: var(--s-3) 0 6px; }
.stm .sl { font-size: var(--step--1); padding-top: 1px; }
.lead-in { font-weight: 700; margin: var(--s-4) 0 var(--s-1); }
.opts { display: grid; gap: 6px; margin-top: var(--s-3); }
.opt {
  display: grid;
  grid-template-columns: 34px 1fr;
  align-items: center;
  text-align: left;
  background: var(--surface);
  border: 1.5px solid var(--line-strong);
  border-radius: var(--r-sm);
  padding: 7px var(--s-3);
  color: inherit;
  min-height: 44px;
}
.opt:hover:not(:disabled) { border-color: var(--primary); background: var(--primary-soft); }
.opt .ltr { font-weight: 700; color: var(--muted); }
.opt.sel { border-color: var(--primary); background: var(--primary-soft); }
.opt.sel .ltr { color: var(--primary); }
.opt:disabled { cursor: default; }
.opt.correct { border-color: var(--ok); background: var(--ok-soft); }
.opt.correct .ltr { color: var(--ok); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt.wrong .ltr { color: var(--bad); }
.verdict { margin-top: var(--s-3); font-size: var(--step--1); font-weight: 600; }
.verdict.ok { color: var(--ok); }
.verdict.bad { color: var(--bad); }
.verdict.none { color: var(--muted); }


/* Verbala delprov: luckor, ORD-rutnät och lästexter */
.blank { display: inline-block; min-width: 3.2em; border-bottom: 1.5px solid currentColor; margin: 0 0.15em; vertical-align: baseline; }
.ordgrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 var(--s-3); }
.ordgrid .q { grid-template-columns: 36px minmax(0, 1fr); padding: var(--s-3) var(--s-3) var(--s-3); }
.passage .pbody { display: flex; flex-direction: column; }
.scrollbox {
  height: clamp(260px, 46vh, 440px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--s-3) var(--s-4);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface);
  font-family: var(--font-read);
  font-size: 1rem;
  line-height: 1.65;
}
.scrollbox p { margin: 0 0 0.8em; max-width: var(--measure); }
.scrollbox h3 { font-family: var(--font-ui); font-size: var(--step-0); margin: var(--s-4) 0 var(--s-2); }
.scrollbox h3:first-child { margin-top: 0; }
.scrollbox .empty { color: var(--muted); font-family: var(--font-ui); font-style: italic; }
.gnote { font-style: italic; color: var(--muted); font-size: var(--step--1); margin: 0 0 var(--s-2); }
.gapno { display: inline-block; min-width: 1.6em; padding: 0 0.35em; border: 1.5px solid currentColor; border-radius: 4px; text-align: center; }

/* Kvantitativa specialfall: tabeller och bildalternativ */
.tri { display: grid; grid-template-columns: minmax(0, 7.5rem) minmax(0, 7.5rem) 1fr; gap: 0 10px; }
.trihead { display: grid; margin: 10px 0 -6px 46px; font-size: var(--step--1); text-decoration: underline; }
.trihead .tri { font-size: var(--step--1); }
.opts.optgrid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.opts.optgrid .opt { grid-template-columns: 24px 1fr; align-items: start; }
.optimg { display: block; max-width: 100%; height: auto; background: var(--image-bg); }
table.mini { border-collapse: collapse; margin: var(--s-2) 0 2px; font-size: var(--step--1); }
table.mini th { text-align: left; padding: 1px 16px 2px 14px; border-bottom: 1.5px solid currentColor; font-weight: 400; }
table.mini th:first-child { border-right: 1.5px solid currentColor; text-align: right; }
table.mini td { padding: 0 16px 0 14px; }
table.mini td:first-child { text-align: right; border-right: 1.5px solid currentColor; }
.kv > span > table.mini { margin-top: 4px; }

/* ---------- Resultat ---------- */
.results { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--s-5); margin-bottom: var(--s-5); }
.results h2 { margin: 0 0 var(--s-1); font-size: var(--step-2); }
.score-big { font-size: 3.4rem; font-weight: 800; color: var(--primary); line-height: 1.05; font-variant-numeric: tabular-nums; }
.score-big small { font-size: var(--step-2); color: var(--muted); font-weight: 600; }
.res-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--s-3); margin: var(--s-4) 0; }
.res-card { background: var(--bg); border-radius: var(--r-sm); padding: var(--s-3) var(--s-4); }
.res-card b { display: block; }
.res-bar { height: 8px; border-radius: 5px; background: var(--surface-2); margin-top: 6px; overflow: hidden; }
.res-bar > div { height: 100%; background: var(--primary); }
.qchips { display: flex; flex-wrap: wrap; gap: 5px; margin: var(--s-3) 0; }
.qchip { width: 36px; height: 36px; border-radius: var(--r-sm); border: 0; font-weight: 700; font-size: 0.8rem; color: #fff; }
.qchip.ok { background: var(--ok); }
.qchip.bad { background: var(--bad); }
.qchip.none { background: var(--neutral); }
:root[data-theme="dark"] .qchip { color: #15121c; }
.legend { font-size: var(--step--1); color: var(--muted); display: flex; gap: 14px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 11px; height: 11px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.legend .lg-ok { background: var(--ok); }
.legend .lg-bad { background: var(--bad); }
.legend .lg-none { background: var(--neutral); }
.res-actions { display: flex; flex-wrap: wrap; gap: var(--s-3); margin-top: var(--s-4); align-items: center; }
.res-actions label { font-size: var(--step--1); display: flex; align-items: center; gap: 6px; }
.pct-note { font-size: var(--step--1); color: var(--muted); margin-top: var(--s-2); max-width: 70ch; }

/* ---------- Dialog och bildförstoring ---------- */
.overlay { position: fixed; inset: 0; background: rgb(15 10 25 / 0.55); z-index: 80; display: flex; align-items: center; justify-content: center; padding: var(--s-4); }
.modal { background: var(--surface); border-radius: var(--r-md); padding: var(--s-5); max-width: 460px; width: 100%; box-shadow: var(--shadow-2); }
.modal h3 { margin: 0 0 var(--s-2); font-size: var(--step-1); }
.modal p { margin: 0 0 6px; }
.modal-warn { color: var(--bad); }
.modal .row { display: flex; gap: 10px; justify-content: flex-end; margin-top: var(--s-4); flex-wrap: wrap; }
.lightbox { position: fixed; inset: 0; background: rgb(10 8 16 / 0.9); z-index: 90; overflow: auto; padding: var(--s-4); display: flex; }
.lightbox img { margin: auto; background: #fff; max-width: 96vw; height: auto; cursor: zoom-in; }
.lightbox img.full { max-width: none; cursor: zoom-out; }
.lightbox .x { position: fixed; top: 12px; right: 16px; background: #fff; color: #1d1a26; border: 0; border-radius: 50%; width: 44px; height: 44px; font-size: 24px; z-index: 91; }

.load-error { padding: var(--s-6) var(--s-4); }

/* ---------- Mobil ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .aside { position: fixed; inset: auto 0 0 0; top: auto; max-height: 78vh; border-radius: var(--r-md) var(--r-md) 0 0; z-index: 60; transform: translateY(105%); transition: transform 0.25s; box-shadow: var(--shadow-2); }
  .aside.open { transform: none; }
  .fab { display: block; position: fixed; right: 14px; bottom: 14px; z-index: 65; background: var(--primary); color: var(--on-primary); border: 0; border-radius: var(--r-pill); padding: var(--s-3) var(--s-4); font-weight: 700; box-shadow: var(--shadow-2); }
  .topbar .title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .timer { font-size: 1.35rem; min-width: 90px; }
  .ordgrid { grid-template-columns: 1fr; }
}
@media (max-width: 420px) {
  .topbar-in { gap: var(--s-2); padding-inline: var(--s-3); }
  .answered { font-size: 0.78rem; }
  .q { grid-template-columns: 32px minmax(0, 1fr); padding-inline: var(--s-3); }
}

/* ---------- Utskrift ---------- */
@media print {
  .topbar, .aside, .fab, .res-actions, .qchips, .legend, .figure .hint { display: none !important; }
  .layout { display: block; padding: 0; }
  .q, .figure { break-inside: avoid; border: 1px solid #999; }
  .q.answered-q, .q.r-ok, .q.r-bad, .q.r-none { border-left-width: 4px; }
  .opt { border-color: #999; min-height: 0; padding: 3px 8px; }
  .scrollbox { height: auto; overflow: visible; border: 0; padding: 0; }
  .sec-head { background: none; color: #000; border: 2px solid #000; break-after: avoid; }
  .cover { background: none; padding: 0; }
}

/* ---------- Aktuell uppgift och kortkommandon ---------- */
.q.current { box-shadow: 0 0 0 2px var(--highlight); }
.q.current:focus-visible { box-shadow: 0 0 0 2px var(--highlight), var(--focus); }
.keys { display: grid; grid-template-columns: auto 1fr; gap: var(--s-2) var(--s-4); margin: var(--s-3) 0 0; font-size: var(--step--1); }
.keys dt { white-space: nowrap; }
.keys dd { margin: 0; color: var(--muted); }

/* ---------- Provtid och paus ---------- */
.time-choice { margin-top: var(--s-5); display: grid; gap: var(--s-1); max-width: 420px; }
.time-choice label { font-weight: 600; }
.time-choice select { background: rgb(255 255 255 / 0.9); }
:root[data-theme="dark"] .time-choice select { background: var(--surface); }
.time-choice .field-help { color: inherit; opacity: 0.85; }
#exam.is-paused .layout, #exam.is-paused .fab { visibility: hidden; }
.pause-overlay { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; padding: var(--s-4); background: var(--bg); }
.pause-card { max-width: 420px; text-align: center; }
.pause-card h2 { font-size: var(--step-3); }
.pause-card p { color: var(--muted); margin-bottom: var(--s-5); }
@media (max-width: 420px) { #pauseBtn { padding-inline: var(--s-2); } }

/* ---------- Tid per uppgift i resultatet ---------- */
#timePanel { margin: var(--s-5) 0 var(--s-3); }
.tp-title { font-size: var(--step-1); }
.tp-slow { color: var(--warn); font-weight: 600; }
.tp-ok { color: var(--ok); font-weight: 600; }
.tp-slowest { margin: var(--s-3) 0 var(--s-1); }

/* ---------- Utskrift av tomt prov ---------- */
#printHost { display: none; }
@media print {
  body.printing-blank > *:not(#printHost) { display: none !important; }
  body.printing-blank #printHost { display: block; }
  .ps-cover { border-bottom: 2px solid #000; margin-bottom: 12pt; padding-bottom: 8pt; }
  .ps-cover h1 { font-size: 22pt; margin: 0 0 4pt; }
  .ps-meta { font-weight: 700; }
  .ps-questions .q { grid-template-columns: 28pt 1fr; padding: 6pt 8pt; margin: 6pt 0; }
  .ps-questions .opt { border: 0; padding: 1pt 0; min-height: 0; }
  .ps-questions .figure img { max-height: 60vh; width: auto; }
  .ps-sheet { break-before: page; }
  .ps-sheet-grid { columns: 2; column-gap: 24pt; }
  .ps-table { border-collapse: collapse; margin-bottom: 10pt; break-inside: avoid; }
  .ps-table caption { text-align: left; font-weight: 700; padding-bottom: 2pt; }
  .ps-table th { text-align: right; padding: 1pt 6pt 1pt 0; font-weight: 400; width: 24pt; }
  .ps-table td { padding: 1pt 2pt; }
  .ps-bub { display: inline-block; width: 15pt; height: 15pt; border: 1px solid #000; border-radius: 50%; text-align: center; font-size: 8pt; line-height: 14pt; }
}
@media print { .q.current { box-shadow: none; } }
.scrollbox .author { text-align: right; }
.scrollbox .gloss { font-size: var(--step--1); color: var(--muted); margin: 0 0 0.3em; }
.scrollbox h4 { font-family: var(--font-ui); font-size: var(--step--1); letter-spacing: 0.04em; margin: var(--s-4) 0 var(--s-2); }
