/* ==========================================================================
   VBFA15 Husbyggnads- och VA-teknik — läsdelen
   Ljus "papper"-yta, tegelröd accent, seriftext för läsning och
   systemsans för allt gränssnitt. Inga webbfonter (ingen CLS, inga requests).
   ========================================================================== */

:root {
  --paper: #fbf8f5;
  --card: #ffffff;
  --ink: #23201d;
  --ink-soft: #4a433c;
  --muted: #756a60;
  --line: #e7dfd5;
  --line-soft: #f1eae1;
  --accent: #2f5d9e;
  --accent-dark: #234a80;
  --accent-tint: #edf2fa;
  --accent-tint-2: #dfe8f6;
  --ok: #2f6f4f;
  --ok-tint: #e8f2ec;
  --bad: #a8432c;
  --bad-dark: #8a3623;
  --bad-tint: #fbeeea;
  --bad-tint-2: #f6e2db;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: Charter, "Bitstream Charter", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --shadow: 0 1px 2px rgba(35, 32, 29, .05), 0 8px 24px -16px rgba(35, 32, 29, .18);
  --radius: 12px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
}

a { color: var(--accent-dark); }
a:hover { color: var(--accent); }

[hidden] { display: none !important; }

/* ------------------------------- topbar --------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 16px;
  align-items: center;
  padding: 10px 20px;
  background: rgba(251, 248, 245, .94);
  backdrop-filter: saturate(160%) blur(8px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.brand .glyph {
  display: grid;
  place-items: center;
  width: 40px; height: 40px;
  flex: 0 0 auto;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 21px;
  line-height: 1;
}

.brand h1 {
  margin: 0;
  font-size: 1.06rem;
  font-weight: 650;
  letter-spacing: -.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand .sub {
  margin: 1px 0 0;
  font-size: .78rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-right { display: flex; align-items: center; gap: 12px; justify-self: end; }

.hub-back {
  font-size: .82rem;
  text-decoration: none;
  color: var(--muted);
  white-space: nowrap;
}
.hub-back:hover { color: var(--accent); }

.tabs {
  grid-column: 1 / -1;
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: .9rem;
  font-weight: 550;
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}
.tab:hover { background: var(--line-soft); color: var(--ink); }
.tab.active { background: var(--accent-tint); color: var(--accent-dark); }

.nav-toggle {
  display: none;
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font-size: 1rem;
  width: 38px; height: 38px;
  border-radius: 9px;
  cursor: pointer;
}

/* --------------------------------- layout -------------------------------- */

main { padding: 0 20px 64px; }

.view { display: none; }
.view.active { display: block; }

.read-layout {
  display: grid;
  grid-template-columns: 288px minmax(0, 1fr);
  gap: 36px;
  max-width: 1240px;
  margin: 0 auto;
  align-items: start;
}

/* --------------------------------- sidebar ------------------------------- */

.toc {
  position: sticky;
  top: 108px;
  max-height: calc(100vh - 130px);
  overflow-y: auto;
  padding: 18px 4px 24px 0;
  scrollbar-width: thin;
}

.part-switch { display: flex; flex-direction: column; gap: 6px; margin-bottom: 18px; }

.part-btn {
  appearance: none;
  text-align: left;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 10px;
  padding: 9px 11px;
  cursor: pointer;
  font: inherit;
  color: var(--ink);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 8px;
  align-items: baseline;
}
.part-btn:hover { border-color: var(--accent-tint-2); }
.part-btn .pt { font-size: .88rem; font-weight: 600; }
.part-btn .ph { font-size: .72rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.part-btn .pm { grid-column: 1 / -1; font-size: .74rem; color: var(--muted); }
.part-btn.active { background: var(--accent-tint); border-color: var(--accent-tint-2); }
.part-btn.active .pt { color: var(--accent-dark); }
.part-btn.empty { opacity: .72; }

.toc-search { position: relative; margin-bottom: 14px; }
.toc-search input {
  width: 100%;
  font: inherit;
  font-size: .88rem;
  padding: 9px 30px 9px 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
}
.toc-search input:focus { outline: 2px solid var(--accent-tint-2); border-color: var(--accent); }
.toc-search .clear {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  border: 0; background: transparent; color: var(--muted);
  font-size: 1rem; cursor: pointer; padding: 4px 6px; line-height: 1;
}

.toc-head {
  font-size: .7rem;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 8px 2px;
}

.toc ol { list-style: none; margin: 0; padding: 0; }

.ch-row {
  display: grid;
  grid-template-columns: 1.6rem 1fr auto;
  gap: 8px;
  align-items: baseline;
  width: 100%;
  text-align: left;
  appearance: none;
  border: 0;
  background: transparent;
  font: inherit;
  font-size: .9rem;
  color: var(--ink-soft);
  padding: 7px 8px;
  border-radius: 8px;
  cursor: pointer;
}
.ch-row:hover { background: var(--line-soft); color: var(--ink); }
.ch-row .n { color: var(--muted); font-variant-numeric: tabular-nums; font-size: .8rem; }
.ch-row .t { font-weight: 500; }
.ch-row .p { font-size: .72rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.ch-row.active { background: var(--accent-tint); color: var(--accent-dark); }
.ch-row.active .t { font-weight: 650; }
.ch-row.done .p { color: var(--ok); }

.toc .sec-list { margin: 2px 0 10px 2.4rem; display: none; }
.toc li.open .sec-list { display: block; }

.sec-link {
  display: block;
  width: 100%;
  text-align: left;
  appearance: none;
  border: 0;
  border-left: 2px solid var(--line);
  background: transparent;
  font: inherit;
  font-size: .83rem;
  color: var(--muted);
  padding: 5px 8px 5px 11px;
  cursor: pointer;
}
.sec-link:hover { color: var(--ink); border-left-color: var(--accent-tint-2); }
.sec-link.current { color: var(--accent-dark); border-left-color: var(--accent); font-weight: 550; }
.sec-link.read::after { content: " ✓"; color: var(--ok); }

.hits { margin: 0; padding: 0; list-style: none; }
.hit {
  display: block; width: 100%; text-align: left;
  appearance: none; border: 0; background: transparent; font: inherit;
  padding: 8px; border-radius: 8px; cursor: pointer; color: var(--ink-soft);
}
.hit:hover { background: var(--line-soft); }
.hit .hk { display: block; font-size: .72rem; color: var(--muted); }
.hit .hs { display: block; font-size: .87rem; font-weight: 550; }
.hit mark { background: var(--accent-tint-2); color: inherit; border-radius: 3px; padding: 0 1px; }

/* ------------------------------- reading pane --------------------------- */

.doc { min-width: 0; padding: 22px 0 0; }

.doc-head { margin-bottom: 26px; }

.crumb {
  font-size: .76rem;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 6px;
}

.doc-head h2 {
  font-family: var(--serif);
  font-size: clamp(1.7rem, 1.2rem + 1.8vw, 2.3rem);
  line-height: 1.12;
  letter-spacing: -.015em;
  margin: 0 0 10px;
  font-weight: 700;
}

.doc-head .lead { margin: 0; color: var(--muted); font-size: .92rem; }

.bar { height: 4px; border-radius: 99px; background: var(--line); overflow: hidden; margin-top: 14px; max-width: 340px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .25s ease; }

article.chapter { max-width: 68ch; }

article.chapter section { margin: 0 0 40px; scroll-margin-top: 118px; }

/* kapitelvideo: fasad (miniatyr) → YouTube-spelare, hoppknappar per del och per avsnitt */
.vid { position: relative; aspect-ratio: 16 / 9; margin-top: 20px; border-radius: 10px; overflow: hidden; background: #1d1a17; }
.vid iframe, .vid-facade { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.vid-facade { padding: 0; cursor: pointer; background: #1d1a17; }
.vid-facade img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: .92; transition: opacity .15s; }
.vid-facade:hover img { opacity: 1; }
.vid-play { position: absolute; left: 50%; top: 50%; width: 68px; height: 48px; margin: -24px 0 0 -34px; border-radius: 12px; background: var(--accent); box-shadow: 0 4px 16px rgba(0,0,0,.35); }
.vid-play::after { content: ""; position: absolute; left: 27px; top: 14px; border-style: solid; border-width: 10px 0 10px 17px; border-color: transparent transparent transparent #fff; }
.vid-cap { position: absolute; left: 12px; bottom: 10px; padding: 4px 9px; border-radius: 6px; background: rgba(20,17,14,.72); color: #fff; font-size: .8rem; }
.vid-delar { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.vid-del, .sec-vid { font: inherit; font-size: .78rem; cursor: pointer; border: 1px solid var(--line); background: var(--paper); color: var(--ink-soft); border-radius: 99px; padding: 4px 10px; }
.vid-del:hover, .sec-vid:hover { border-color: var(--accent-tint-2); background: var(--accent-tint); color: var(--accent-dark); }
.vid-del .vt { font-variant-numeric: tabular-nums; color: var(--accent-dark); margin-right: 6px; }
.sec-vid { flex: none; white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--accent-dark); }

.sec-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 6px;
  margin-bottom: 16px;
}

.sec-head h3 {
  font-family: var(--serif);
  font-size: 1.32rem;
  line-height: 1.22;
  letter-spacing: -.01em;
  margin: 0;
  font-weight: 700;
}

.read-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  font: inherit;
  font-size: .75rem;
  padding: 4px 10px;
  border-radius: 99px;
  cursor: pointer;
  white-space: nowrap;
  flex: 0 0 auto;
}
.read-btn:hover { border-color: var(--accent-tint-2); color: var(--ink); }
.read-btn[aria-pressed="true"] { background: var(--ok-tint); border-color: #cfe3d7; color: var(--ok); }

/* brödtext */
article.chapter p,
article.chapter li,
article.chapter dd,
article.chapter dt {
  font-family: var(--serif);
  font-size: 1.0625rem;
  line-height: 1.62;
  color: var(--ink);
}

article.chapter p { margin: 0 0 14px; }

article.chapter h4 {
  font-family: var(--sans);
  font-size: .82rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--accent-dark);
  margin: 26px 0 10px;
  font-weight: 650;
}

article.chapter ul,
article.chapter ol { margin: 0 0 16px; padding-left: 1.35em; }
article.chapter li { margin-bottom: 6px; }
article.chapter li::marker { color: var(--accent); }

article.chapter dl { margin: 0 0 16px; }
article.chapter dt { font-weight: 700; margin-top: 10px; }
article.chapter dd { margin: 2px 0 0; padding-left: 1em; border-left: 2px solid var(--line); }

article.chapter strong { font-weight: 700; }
article.chapter code {
  font-family: var(--mono);
  font-size: .9em;
  background: var(--line-soft);
  padding: 1px 5px;
  border-radius: 5px;
}

/* tabeller */
.table-wrap { overflow-x: auto; margin: 0 0 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
article.chapter table { border-collapse: collapse; width: 100%; font-family: var(--sans); font-size: .88rem; }
article.chapter th,
article.chapter td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: top; line-height: 1.45; }
article.chapter thead th { background: var(--accent-tint); color: var(--accent-dark); font-size: .82rem; letter-spacing: .01em; font-weight: 650; border-bottom: 1px solid var(--line); }  /* inga versaler: λ, δ och enheter som m·K får inte bli Λ, Δ, M·K */
article.chapter tbody tr:last-child td { border-bottom: 0; }
article.chapter tbody tr:nth-child(even) td { background: #fdfbf9; }

/* figurer */
article.chapter figure {
  margin: 24px 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
}
article.chapter figure img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 6px;
  cursor: zoom-in;
  background: #fff;
}
article.chapter figcaption {
  font-family: var(--sans);
  font-size: .82rem;
  line-height: 1.5;
  color: var(--muted);
  margin-top: 10px;
  padding: 0 2px;
}

/* rutor */
.callout, .note {
  margin: 20px 0;
  padding: 12px 16px;
  border-radius: 10px;
  font-family: var(--serif);
  font-size: 1rem;
  line-height: 1.55;
}
.callout { background: var(--accent-tint); border-left: 3px solid var(--accent); color: #1c2f52; }
.note { background: #f4f2ee; border-left: 3px solid #c9beb1; color: var(--ink-soft); font-size: .95rem; }
.callout p:last-child, .note p:last-child { margin-bottom: 0; }
.callout p, .note p { font-size: inherit; }

/* kapitelfot */
.doc-foot {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--line);
  padding-top: 18px;
  margin-top: 8px;
  max-width: 68ch;
}
.step {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: .88rem;
  padding: 9px 14px;
  border-radius: 10px;
  cursor: pointer;
  max-width: 46%;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.step:hover { border-color: var(--accent-tint-2); }
.step:disabled { opacity: .4; cursor: default; }
.step .sl { display: block; font-size: .7rem; color: var(--muted); }

/* tom del */
.empty-part {
  max-width: 62ch;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px 26px;
  box-shadow: var(--shadow);
}
.empty-part h3 { font-family: var(--serif); font-size: 1.3rem; margin: 0 0 10px; }
.empty-part p { font-family: var(--serif); font-size: 1.02rem; line-height: 1.6; color: var(--ink-soft); margin: 0 0 12px; }
.empty-part ul { font-family: var(--serif); margin: 0 0 4px; padding-left: 1.3em; color: var(--ink-soft); }

/* ------------------------------- min status ----------------------------- */

.status-wrap { max-width: 900px; margin: 24px auto 0; }
.status-wrap h2 { font-family: var(--serif); font-size: 1.8rem; margin: 0 0 6px; }
.status-wrap .lead { color: var(--muted); margin: 0 0 24px; font-size: .94rem; }

.stat-row { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 26px; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 18px; min-width: 132px; box-shadow: var(--shadow);
}
.stat b { display: block; font-family: var(--serif); font-size: 1.7rem; line-height: 1; }
.stat span { font-size: .78rem; color: var(--muted); }

.prog-list { display: grid; gap: 8px; }
.prog-item {
  display: grid;
  grid-template-columns: 1.8rem 1fr 7rem 3.6rem;
  gap: 12px;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  width: 100%;
  text-align: left;
  appearance: none;
  font: inherit;
  cursor: pointer;
  color: var(--ink);
}
.prog-item:hover { border-color: var(--accent-tint-2); }
.prog-item .n { color: var(--muted); font-size: .8rem; font-variant-numeric: tabular-nums; }
.prog-item .t { font-weight: 550; font-size: .92rem; }
.prog-item .v { font-size: .78rem; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }

/* ------------------------------- lightbox ------------------------------- */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(30, 26, 23, .82);
  cursor: zoom-out;
}
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .4);
}
.lightbox .lb-cap {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 14px 24px;
  color: #f3ece6;
  font-size: .85rem;
  text-align: center;
  background: linear-gradient(transparent, rgba(20, 17, 15, .85));
}

/* -------------------------------- footer -------------------------------- */

.footnote {
  max-width: 1240px;
  margin: 0 auto;
  padding: 24px 20px 40px;
  color: var(--muted);
  font-size: .8rem;
  line-height: 1.55;
  border-top: 1px solid var(--line);
}

/* ------------------------------ responsivt ------------------------------ */

@media (max-width: 900px) {
  .read-layout { grid-template-columns: 1fr; gap: 0; }
  .nav-toggle { display: block; }
  .toc {
    position: static;
    max-height: none;
    overflow: visible;
    display: none;
    padding: 14px 0 6px;
    border-bottom: 1px solid var(--line);
    margin-bottom: 12px;
  }
  .toc.open { display: block; }
  .topbar { grid-template-columns: 1fr auto auto; padding: 8px 14px; }
  main { padding: 0 14px 48px; }
  article.chapter section { scroll-margin-top: 150px; }
  .prog-item { grid-template-columns: 1.6rem 1fr 4.5rem; }
  .prog-item .v { display: none; }
}

/* kontowidgeten (e-postfält + knapp) får egen rad när headern blir trång */
@media (max-width: 680px) {
  .topbar { grid-template-columns: 1fr auto; row-gap: 6px; }
  .brand h1 { font-size: .98rem; }
  .top-right {
    grid-column: 1 / -1;
    justify-self: start;
    justify-content: space-between;
    width: 100%;
    flex-wrap: wrap;
  }
  .top-right .kb-acc-form input { max-width: 42vw; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .bar > i { transition: none; }
}

/* --------------------------------- print -------------------------------- */

@media print {
  .topbar, .toc, .doc-foot, .read-btn, .nav-toggle, .footnote { display: none !important; }
  body { background: #fff; }
  main { padding: 0; }
  .read-layout { display: block; }
  article.chapter { max-width: none; }
  article.chapter section { break-inside: auto; }
  article.chapter figure { break-inside: avoid; box-shadow: none; }
}

/* ============================ QUIZ & TENTOR ============================= */

.ova-wrap { max-width: 860px; margin: 24px auto 40px; padding: 0 20px; display: grid; gap: 14px; }
.ova-wrap h2 { font-family: var(--serif); font-size: 1.8rem; margin: 0; }
.ova-wrap .lead { color: var(--muted); margin: 0; font-size: .95rem; }
.ova-wrap .muted, .muted { color: var(--muted); font-weight: 400; }

.qz-modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; margin-top: 6px; }
.qz-mode { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; display: grid; gap: 10px; align-content: start; box-shadow: var(--shadow); }
.qz-mode h3 { margin: 0; font-family: var(--serif); font-size: 1.25rem; }
.qz-mode p { margin: 0; font-size: .9rem; color: var(--ink-soft); }
.qz-mode.test { border-color: var(--accent-tint-2); background: linear-gradient(180deg, var(--accent-tint) 0, var(--card) 70%); }
.qz-check { display: flex; align-items: center; gap: 8px; font-size: .88rem; }
.qz-check select { font: inherit; padding: 4px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); }
.qz-go { font: inherit; font-weight: 650; font-size: .92rem; color: #fff; background: var(--accent); border: 0; border-radius: 10px; padding: 9px 16px; cursor: pointer; justify-self: start; }
.qz-go:hover { background: var(--accent-dark); }
.qz-go:disabled { opacity: .45; cursor: default; }
.qz-go.hand-in { background: var(--ok); }
.qz-note { background: var(--ok-tint); color: var(--ok); border-radius: 10px; padding: 10px 14px; margin: 0; font-size: .9rem; }

.qz-pick-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.qz-pick-head h3 { margin: 0; font-size: 1rem; }
.qz-quick button { font: inherit; font-size: .8rem; border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 3px 10px; cursor: pointer; margin-left: 4px; }
.qz-part { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.qz-part-head { display: flex; gap: 8px; align-items: center; padding: 10px 14px; background: var(--line-soft); font-size: .92rem; cursor: pointer; }
.qz-chs { display: grid; }
.qz-ch { display: grid; grid-template-columns: auto 28px minmax(0, 1fr) auto; gap: 8px; align-items: center; padding: 8px 14px; border-top: 1px solid var(--line-soft); cursor: pointer; font-size: .9rem; }
.qz-ch:hover { background: var(--paper); }
.qz-ch .n { color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.qz-ch .s { font-size: .78rem; color: var(--muted); white-space: nowrap; }
.qz-ch:not(.on) .t { color: var(--muted); }
.qz-ch b.good { color: var(--ok); } .qz-ch b.mid { color: #9a6a12; } .qz-ch b.low { color: var(--bad); }
@media (max-width: 560px) { .qz-ch { grid-template-columns: auto 22px minmax(0, 1fr); } .qz-ch .s { grid-column: 3; white-space: normal; } }

.qz-run-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.qz-back { justify-self: start; font: inherit; font-size: .88rem; background: none; border: 0; color: var(--accent-dark); cursor: pointer; padding: 4px 0; }
.qz-mode-tag { font-size: .72rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ok); background: var(--ok-tint); border-radius: 6px; padding: 3px 8px; }
.qz-mode-tag.test { color: var(--accent-dark); background: var(--accent-tint); }
.qz-count { margin-left: auto; font-size: .85rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.qz-bar { max-width: none; margin-top: 0; }

.qz-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); display: grid; gap: 10px; }
.qz-card.right { border-color: #bcd9c7; }
.qz-card.wrong { border-color: var(--bad-tint-2); }
.qz-src { margin: 0; font-size: .76rem; color: var(--muted); font-weight: 600; }
.qz-q { margin: 0; font-family: var(--serif); font-size: 1.18rem; font-weight: 600; line-height: 1.4; }
h4.qz-q { font-size: 1.02rem; }
.qz-hint { margin: -4px 0 0; font-size: .82rem; color: var(--accent-dark); }
.qz-alts { display: grid; gap: 8px; }
.qz-alt { font: inherit; font-size: .95rem; text-align: left; display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink); cursor: pointer; line-height: 1.4; }
.qz-alt:hover:not(:disabled) { border-color: var(--accent-tint-2); background: var(--paper); }
.qz-alt .box { flex: 0 0 auto; width: 18px; height: 18px; margin-top: 1px; border: 2px solid var(--line); border-radius: 50%; }
.qz-alt .box.sq { border-radius: 4px; }
.qz-alt.on { border-color: var(--accent); background: var(--accent-tint); }
.qz-alt.on .box { border-color: var(--accent); background: radial-gradient(circle, var(--accent) 45%, transparent 50%); }
.qz-alt.on .box.sq { background: var(--accent); box-shadow: inset 0 0 0 2px var(--card); }
.qz-alt.correct { border-color: var(--ok); background: var(--ok-tint); }
.qz-alt.correct .box { border-color: var(--ok); }
.qz-alt.incorrect { border-color: var(--bad); background: var(--bad-tint); text-decoration: line-through; text-decoration-color: rgba(168, 67, 44, .5); }
.qz-alt:disabled { cursor: default; }
.qz-fb { font-size: .93rem; line-height: 1.5; background: var(--paper); border-radius: 10px; padding: 10px 14px; }
.qz-card.right .qz-fb b { color: var(--ok); } .qz-card.wrong .qz-fb b { color: var(--bad-dark); }
.qz-read { display: inline-block; margin-left: 4px; font-size: .86rem; font-weight: 600; white-space: nowrap; }
.qz-nav { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.qz-dots { display: flex; flex-wrap: wrap; gap: 5px; }
.qz-dots .dot { font: inherit; font-size: .72rem; width: 28px; height: 28px; border-radius: 7px; border: 1px solid var(--line); background: var(--card); color: var(--muted); cursor: pointer; font-variant-numeric: tabular-nums; }
.qz-dots .dot.has { background: var(--accent-tint); border-color: var(--accent-tint-2); color: var(--accent-dark); }
.qz-dots .dot.cur { outline: 2px solid var(--accent); outline-offset: 1px; }

.qz-score { display: flex; gap: 18px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.qz-score h2 { font-size: 1.5rem; }
.qz-score p { margin: 2px 0 0; color: var(--ink-soft); }
.qz-score .ring { flex: 0 0 auto; width: 88px; height: 88px; border-radius: 50%; display: grid; place-items: center; background: conic-gradient(var(--ok) calc(var(--p) * 1%), var(--line) 0); }
.qz-score .ring b { display: grid; place-items: center; width: 70px; height: 70px; border-radius: 50%; background: var(--card); font-family: var(--serif); font-size: 1.25rem; }
.qz-sub { margin: 10px 0 0; font-size: 1rem; }
.qz-bych { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 14px; }
.qz-bych .row { display: grid; grid-template-columns: minmax(0, 1fr) 120px 44px; gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line-soft); font-size: .88rem; }
.qz-bych .row:last-child { border-bottom: 0; }
.qz-bych .bar { margin: 0; }
.qz-bych .v { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.qz-res-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.qz-review { display: grid; gap: 10px; }
.qz-card.small { padding: 14px 16px; gap: 6px; box-shadow: none; }
.qz-ans { margin: 0; padding-left: 18px; font-size: .9rem; display: grid; gap: 3px; }
.qz-ans li.correct { color: var(--ok); font-weight: 600; }
.qz-ans li.incorrect { color: var(--bad-dark); text-decoration: line-through; }
.qz-ex { margin: 0; font-size: .88rem; color: var(--ink-soft); }

/* Tentor */
.tn-intro { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 16px; }
.tn-intro summary { cursor: pointer; font-weight: 650; font-size: .95rem; }
.tn-intro .chapter { margin-top: 8px; }
.tn-list { display: grid; gap: 8px; }
.tn-row { font: inherit; text-align: left; display: grid; grid-template-columns: 84px minmax(0, 1fr) 120px; gap: 12px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; cursor: pointer; color: var(--ink); }
.tn-row:hover { border-color: var(--accent-tint-2); }
.tn-row .bar { margin: 0; }
.tn-t b { display: block; font-size: .95rem; }
.tn-t small { color: var(--muted); font-size: .8rem; }
@media (max-width: 560px) { .tn-row { grid-template-columns: 1fr; gap: 6px; } }
.tn-kind { justify-self: start; font-size: .7rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; border-radius: 6px; padding: 3px 8px; }
.tn-kind.teori { background: var(--ok-tint); color: var(--ok); }
.tn-kind.rakn { background: var(--accent-tint); color: var(--accent-dark); }
.tn-head { display: grid; gap: 6px; }
.tn-prog { margin: 0; font-size: .88rem; color: var(--muted); }
.tn-reset { font: inherit; font-size: .8rem; margin-left: 8px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 2px 9px; cursor: pointer; color: var(--muted); }
.tn-probs { display: grid; gap: 14px; }
.tn-prob { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--line); border-radius: var(--radius); padding: 14px 18px; }
.tn-prob.done-ratt { border-left-color: var(--ok); }
.tn-prob.done-delvis { border-left-color: #c9962a; }
.tn-prob.done-fel { border-left-color: var(--bad); }
.tn-ptop { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; margin-bottom: 4px; }
.tn-num { font-family: var(--sans); font-weight: 700; font-size: .95rem; }
.tn-tag { font-family: var(--sans); font-size: .8rem; color: var(--muted); }
.tn-from { margin-left: auto; font-family: var(--sans); font-size: .75rem; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; white-space: nowrap; }
.tn-actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin: 10px 0 0; font-family: var(--sans); }
.tn-answer { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); }
.tn-alabel { display: inline-block; font-family: var(--sans); font-size: .7rem; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--ok); margin-bottom: 4px; }
.tn-sg { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 12px; font-family: var(--sans); font-size: .88rem; color: var(--muted); }
.tn-sg .sg { font: inherit; font-size: .85rem; font-weight: 600; border: 1.5px solid var(--line); background: var(--card); border-radius: 8px; padding: 4px 12px; cursor: pointer; color: var(--ink); }
.tn-sg .sg.ratt.sel { background: var(--ok-tint); border-color: var(--ok); color: var(--ok); }
.tn-sg .sg.delvis.sel { background: #f8ecd2; border-color: #c9962a; color: #8a6312; }
.tn-sg .sg.fel.sel { background: var(--bad-tint); border-color: var(--bad); color: var(--bad-dark); }
article.chapter.tn-probs { max-width: none; }
article.chapter.tn-probs section.tn-prob { margin: 0; }
.tn-intro article.chapter { max-width: none; }

/* Läst-knappen sitter sist i avsnittet; hela kapitlet kan bockas av längst ner */
.sec-foot { display: flex; justify-content: flex-end; margin-top: 18px; padding-top: 12px; border-top: 1px dashed var(--line); }
.ch-done { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin: 8px 0 32px; padding: 16px 18px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); font-family: var(--sans); }
.ch-done-t { margin: 0; color: var(--ink-soft); font-size: .92rem; }
.ch-done-btn { font: inherit; font-weight: 650; font-size: .92rem; color: #fff; background: var(--accent); border: 0; border-radius: 10px; padding: 9px 16px; cursor: pointer; }
.ch-done-btn:hover { background: var(--accent-dark); }
.ch-done-btn[aria-pressed="true"] { background: var(--ok-tint); color: var(--ok); box-shadow: inset 0 0 0 1px #cfe3d7; }

/* Beräkningsuppgifter: värden som behövs + easy mode (formlerna som på papper) */
.tn-easyrow { margin: 4px 0 0; font-family: var(--sans); font-size: .85rem; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.tn-easy { font: inherit; font-weight: 650; border: 1.5px solid var(--line); background: var(--card); border-radius: 999px; padding: 4px 14px; cursor: pointer; color: var(--ink); }
.tn-easy.on { background: var(--accent-tint); border-color: var(--accent); color: var(--accent-dark); }
.tn-varden { margin: 10px 0 0; padding: 10px 14px; background: var(--paper); border: 1px solid var(--line); border-radius: 8px; font-size: .92rem; }
.tn-varden p, .tn-varden ul { margin: 4px 0; }
.tn-varden table { font-size: .85rem; }
.tn-bokbox, .tn-svarbox { margin-top: 12px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); }
.tn-bokbox ul { margin: 4px 0 0; padding-left: 1.2em; font-size: .92rem; }
.tn-bokbox li { margin: 2px 0; }
.tn-blabel { display: inline-block; font-family: var(--sans); font-size: .7rem; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); margin-bottom: 2px; }
.tn-svarbox p { margin: 4px 0 8px; font-weight: 600; }
.tn-vlabel, .tn-flabel { display: block; font-family: var(--sans); font-size: .7rem; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); margin-bottom: 2px; }
.tn-formler { margin: 10px 0 0; padding: 12px 16px 12px 44px; border-radius: 4px; position: relative; color: #1d3a72;
  font-family: "Bradley Hand", "Segoe Print", "Comic Sans MS", "Chalkboard SE", cursive; font-size: 1.02rem; line-height: 28px;
  background-color: #fffef6;
  background-image: linear-gradient(90deg, transparent 32px, #e8a0a0 32px, #e8a0a0 33px, transparent 33px),
    repeating-linear-gradient(#fffef6 0 27px, #c9d8ee 27px 28px);
  box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.tn-formler .tn-flabel { color: #9a5a5a; font-family: var(--sans); line-height: 1.4; }
.tn-formler p, .tn-formler ol, .tn-formler ul { margin: 0; }
.tn-formler li, .tn-formler p, .tn-formler td { font-family: inherit; font-size: inherit; line-height: inherit; color: inherit; }
.tn-formler ol { padding-left: 1.2em; }
.tn-formler .katex { color: #1d3a72; font-size: 1.02em; }
.tn-formler .katex-display { margin: 2px 0; text-align: left; }
.tn-formler .katex-display > .katex { text-align: left; }

/* Räkneprov */
.rk-svar { display: grid; gap: 8px; margin: 12px 0 0; font-family: var(--sans); }
.rk-f { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: .9rem; }
.rk-lab { min-width: 9em; font-weight: 600; }
.rk-f input { font: inherit; width: 8.5em; padding: 5px 9px; border: 1.5px solid var(--line); border-radius: 8px; background: var(--card); color: var(--ink); }
.rk-f input:focus { outline: none; border-color: var(--accent); }
.rk-unit { color: var(--muted); }
.rk-f.ok input { border-color: var(--ok); background: var(--ok-tint); }
.rk-f.nej input { border-color: var(--accent); background: var(--accent-tint); }
.rk-res { font-weight: 650; font-size: .85rem; }
.rk-f.ok .rk-res { color: var(--ok); }
.rk-f.nej .rk-res { color: var(--accent-dark); }
.qz-mode.rakn { border-color: var(--accent-tint-2); }
/* grid-barn får krympa under tabellens bredd — tabellen scrollar i .table-wrap i stället */
.ova-wrap > *, .tn-probs > *, .tn-head > *, .tn-prob > * { min-width: 0; }
button.rk-los { font: inherit; font-size: .9rem; background: none; border: 0; padding: 0; cursor: pointer; color: var(--accent-dark); text-decoration: underline; text-underline-offset: 3px; }
@media (max-width: 560px) { .rk-lab { flex-basis: 100%; } .rk-f input { width: 9em; } }
.tn-actions .qz-read { white-space: normal; min-width: 0; }

/* ===================================================== interaktiva modeller (viz.js) */
.viz { margin: 26px 0; padding: 16px 18px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--card);
  font-family: var(--sans); font-size: .9rem; color: var(--ink); box-shadow: 0 1px 0 var(--line-soft); }
.viz:empty { display: none; }
.vz-title { font-weight: 650; font-size: .78rem; letter-spacing: .06em; text-transform: uppercase; color: var(--accent-dark); margin: 0 0 10px; }
.vz-sub { font-weight: 600; margin: 0 0 8px; font-size: .86rem; }
.vz-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 18px; align-items: start; }
@media (max-width: 760px) { .vz-grid { grid-template-columns: 1fr; } }
.vz-svg { width: 100%; height: auto; display: block; background: #fbfcfe; border-radius: 6px; border: 1px solid var(--line-soft); }
.vz-svg.map { background: #f4f8fd; }
.vz-side { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.vz-sl { display: grid; grid-template-columns: 7.5em minmax(0, 1fr) auto auto; align-items: center; gap: 8px; margin: 2px 0; }
.vz-sl input[type=range] { width: 100%; accent-color: var(--accent); }
.vz-sl output { font-variant-numeric: tabular-nums; min-width: 3.2em; text-align: right; font-weight: 600; }
.vz-sl-l, .vz-u { color: var(--muted); }
.vz-read { display: flex; flex-direction: column; gap: 5px; margin: 8px 0 0; line-height: 1.45; }
.vz-read b { font-weight: 650; }
.vz-real { color: var(--ink-soft); background: var(--accent-tint); border-radius: 5px; padding: 6px 9px; }
.vz-hint { color: var(--muted); font-size: .8rem; margin: 8px 0 0; line-height: 1.45; }
.vz-row { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; margin-top: 10px; }
.vz-row .vz-sl { flex: 1 1 320px; }
.vz-ck { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
.vz-ck input { accent-color: var(--accent); }
.vz-sel select, .vz-cols input { font: inherit; padding: 4px 6px; border: 1px solid var(--line); border-radius: 5px; background: #fff; color: var(--ink); }
.vz-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.vz-tabs button, .vz-btn { font: inherit; font-size: .84rem; padding: 5px 11px; border-radius: 999px; border: 1px solid var(--line); background: #fff; color: var(--ink-soft); cursor: pointer; }
.vz-tabs button[aria-selected=true] { background: var(--accent); border-color: var(--accent); color: #fff; }
.vz-btn { align-self: flex-start; margin-top: 4px; }
.vz-tabs button:hover, .vz-btn:hover { border-color: var(--accent); }
.vz-ptext { margin: 8px 0 0; line-height: 1.5; color: var(--ink-soft); }
.vz-calc { margin-top: 16px; padding-top: 12px; border-top: 1px dashed var(--line); }
.vz-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .vz-cols { grid-template-columns: 1fr; } }
.vz-cols fieldset { border: 1px solid var(--line-soft); border-radius: 8px; padding: 8px 12px 10px; margin: 0; min-width: 0; }
.vz-cols legend { font-weight: 600; font-size: .8rem; color: var(--muted); padding: 0 4px; }
.vz-cols label { display: grid; grid-template-columns: 3.6em minmax(0, 1fr); align-items: center; gap: 6px; margin: 4px 0; }
.vz-cols input { width: 100%; font-variant-numeric: tabular-nums; }
.vz-mini { margin: 6px 0 0; font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
/* SVG-element */
.vz-axis { stroke: #8a95a5; stroke-width: 1; fill: none; }
.vz-ell { stroke: var(--ink); stroke-width: 2; fill: none; }
.vz-psi { stroke: #c2410c; stroke-width: 1.5; stroke-dasharray: 5 4; fill: none; }
.vz-norm { stroke: var(--accent); stroke-width: 2; fill: none; }
.vz-arc { fill: none; stroke-width: 1.5; } .vz-arc.phi { stroke: var(--accent); } .vz-arc.psi { stroke: #c2410c; }
.vz-pt { fill: var(--ink); stroke: #fff; stroke-width: 1.5; }
.vz-tl { font: 600 12px var(--sans); fill: var(--ink); }
.vz-tl.dim { fill: #8a95a5; font-weight: 500; font-size: 11px; }
.vz-tl.phi, .vz-tl.norm, .vz-tl.acc { fill: var(--accent); } .vz-tl.psi { fill: #c2410c; }
b.phi, b.norm { color: var(--accent); } b.psi { color: #c2410c; }
.vz-grat { stroke: #cdd7e5; stroke-width: .7; fill: none; } .vz-grat.strong { stroke: #a9b8cd; stroke-width: 1; }
.vz-cm { stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 4 3; fill: none; }
.vz-land { stroke: #7d8a7a; stroke-width: .8; fill: none; stroke-linejoin: round; }
.vz-tis { fill: rgba(194, 65, 12, .22); stroke: #c2410c; stroke-width: .8; }
.vz-gc { stroke: var(--accent); stroke-width: 2.2; fill: none; }
.vz-lx { stroke: #b45309; stroke-width: 2.2; stroke-dasharray: 6 4; fill: none; }
b.gc { color: var(--accent); } b.lx { color: #b45309; }
.vz-city { fill: #fff; stroke: var(--ink); stroke-width: 2; }
.vz-terr { fill: #e9e2d0; stroke: #8b6b3d; stroke-width: 2; }
.vz-ellline { stroke: #5b6b82; stroke-width: 2; fill: none; }
.vz-geoid { stroke: #0f766e; stroke-width: 2; fill: none; stroke-dasharray: 7 4; }
.vz-tl.geoid { fill: #0f766e; } .vz-tl.terr { fill: #8b6b3d; }
.vz-br { stroke-width: 3; fill: none; stroke-linecap: round; }
.vz-br.n { stroke: #0f766e; } .vz-br.H { stroke: #8b6b3d; } .vz-br.h { stroke: var(--accent); }
.vz-tl.n, b.n { fill: #0f766e; color: #0f766e; } .vz-tl.H, b.H { fill: #8b6b3d; color: #8b6b3d; } .vz-tl.h, b.h { fill: var(--accent); color: var(--accent); }
.vz-lod { stroke: #0f766e; stroke-width: 1.8; fill: none; } .vz-tl.lod { fill: #0f766e; }
.vz-enorm { stroke: #5b6b82; stroke-width: 1.2; stroke-dasharray: 3 3; fill: none; }
.vz-old { fill: rgba(120, 130, 145, .15); stroke: #8a95a5; stroke-width: 1.5; }
.vz-new { fill: rgba(47, 93, 158, .18); stroke: var(--accent); stroke-width: 2; }
.vz-paxis { stroke: var(--accent); stroke-width: 1.2; stroke-dasharray: 4 3; fill: none; }
.vz-chain { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 0; }
.vz-chain li { display: flex; align-items: center; }
.vz-box { font: inherit; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 7px 10px; min-width: 92px;
  border: 1.5px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer; color: var(--ink); }
.vz-box b { font-size: .95rem; } .vz-box span { font-size: .72rem; color: var(--muted); white-space: nowrap; }
.vz-box:hover, .vz-box.on { border-color: var(--accent); background: var(--accent-tint); }
.vz-arrow { flex-direction: column; justify-content: center; width: 64px; position: relative; height: 34px; }
.vz-arrow::before { content: ""; position: absolute; left: 4px; right: 8px; top: 21px; border-top: 2px solid #5b6b82; }
.vz-arrow::after { content: ""; position: absolute; right: 2px; top: 16px; border: 6px solid transparent; border-left: 8px solid #5b6b82; border-right: 0; }
.vz-arrow.e::before { border-top: 2px dashed #c2410c; } .vz-arrow.e::after { border-left-color: #c2410c; }
.vz-arrow span { position: absolute; top: 0; left: 0; right: 0; text-align: center; font-size: .66rem; color: var(--muted); }
.vz-arrow.e span { color: #c2410c; font-weight: 600; }

/* Fristående formler: egen horisontell scroll i stället för att klippas i smala vyer */
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 2px 0 6px; -webkit-overflow-scrolling: touch; }
.katex-display > .katex { white-space: nowrap; }
/* modellerna ska inte ärva kapitlets serif-stycken */
article.chapter .viz p, article.chapter .viz label { font-family: var(--sans); font-size: inherit; line-height: 1.45; }
article.chapter .viz .vz-box b, article.chapter .viz .vz-box span, article.chapter .viz .vz-arrow span, article.chapter .viz .vz-read span { font-family: var(--sans); }
article.chapter .viz p.vz-title { font-size: .76rem; margin: 0 0 10px; }
article.chapter .viz p.vz-hint { font-size: .8rem; }
article.chapter .viz p { margin: 8px 0 0; }
.vz-svg { max-width: 520px; margin: 0 auto; }
.vz-svg.map { max-width: none; }
.vz-svg.sq { max-width: 420px; }
/* KaTeX:s dolda MathML-lager är absolut positionerat — utan detta rymmer det ur scrollrutorna och breddar sidan på mobil */
.table-wrap, .katex-display, .vz-svg { position: relative; }
