/* Czcionki lokalne (bez internetu) */
@font-face { font-family: "Instrument Sans"; font-weight: 400; font-display: swap; src: url("../fonts/instrument-sans-latin-ext-400-normal.woff2") format("woff2"); unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20CF; }
@font-face { font-family: "Instrument Sans"; font-weight: 400; font-display: swap; src: url("../fonts/instrument-sans-latin-400-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+2190-21FF, U+2212, U+2215; }
@font-face { font-family: "Instrument Sans"; font-weight: 500; font-display: swap; src: url("../fonts/instrument-sans-latin-ext-500-normal.woff2") format("woff2"); unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20CF; }
@font-face { font-family: "Instrument Sans"; font-weight: 500; font-display: swap; src: url("../fonts/instrument-sans-latin-500-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+2190-21FF, U+2212, U+2215; }
@font-face { font-family: "Instrument Sans"; font-weight: 600; font-display: swap; src: url("../fonts/instrument-sans-latin-ext-600-normal.woff2") format("woff2"); unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20CF; }
@font-face { font-family: "Instrument Sans"; font-weight: 600; font-display: swap; src: url("../fonts/instrument-sans-latin-600-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+2190-21FF, U+2212, U+2215; }
@font-face { font-family: "JetBrains Mono"; font-weight: 500; font-display: swap; src: url("../fonts/jetbrains-mono-latin-ext-500-normal.woff2") format("woff2"); unicode-range: U+0100-024F; }
@font-face { font-family: "JetBrains Mono"; font-weight: 500; font-display: swap; src: url("../fonts/jetbrains-mono-latin-500-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+2000-206F, U+2190-21FF, U+2212, U+2215; }

:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --text: #181818;
  --muted: #4b4740;
  --line: #d9d2c5;
  --accent: #0d6a6f;
  --accent-text: #ffffff;
  --accent-soft: #e2efef;
  --focus: #0d6a6f;

  --font: "Instrument Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
  --toc-w: 300px;
  --topbar-h: 56px;
  font-size: 18px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #141414;
  --surface: #1e1e1e;
  --text: #ede8df;
  --muted: #bcb5a9;
  --line: #3a3833;
  --accent: #5fc3c9;
  --accent-text: #0b1d1e;
  --accent-soft: #1b2e2f;
  --focus: #5fc3c9;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
a { color: var(--accent); text-underline-offset: 0.15em; }
[hidden] { display: none !important; }

.skip { position: absolute; left: -9999px; top: 0; }
.skip:focus { left: 8px; top: 8px; z-index: 50; background: var(--surface); padding: 8px 12px; }

/* Pasek górny */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  height: var(--topbar-h); padding: 0 16px;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.brand { margin: 0; font-weight: 600; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.counter { margin: 0; font-family: var(--mono); font-size: 0.85rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

.btn {
  font: inherit; font-size: 0.9rem; font-weight: 500;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px;
  min-height: 40px; padding: 0 14px; cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn-primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn-primary:hover { border-color: var(--text); }
.btn:disabled { opacity: 0.4; cursor: default; }

.progress { height: 4px; background: var(--line); position: sticky; top: var(--topbar-h); z-index: 20; }
.progress-bar { height: 100%; width: 0; background: var(--accent); }

/* Układ */
.layout { display: grid; grid-template-columns: var(--toc-w) 1fr; min-height: calc(100vh - var(--topbar-h) - 4px); }
body.toc-hidden .layout { grid-template-columns: 1fr; }
body.toc-hidden .toc { display: none; }

.toc {
  border-right: 1px solid var(--line);
  padding: 16px 12px;
  position: sticky; top: calc(var(--topbar-h) + 4px);
  height: calc(100vh - var(--topbar-h) - 4px); overflow-y: auto;
}
.toc ol { list-style: none; margin: 0; padding: 0; }
.toc a {
  display: grid; grid-template-columns: 2.2em 1fr auto; gap: 4px; align-items: baseline;
  padding: 10px 10px; border-radius: 8px;
  color: var(--text); text-decoration: none; line-height: 1.3;
}
.toc a:hover { background: var(--surface); }
.toc .num, .toc .min { font-family: var(--mono); font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.toc a[aria-current="page"] { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.toc a[aria-current="page"] .num, .toc a[aria-current="page"] .min { color: var(--accent-text); }
.toc .break { font-size: 0.8rem; color: var(--muted); padding: 2px 10px 6px calc(2.2em + 14px); }

.main { display: flex; flex-direction: column; min-width: 0; padding: 40px clamp(20px, 5vw, 72px) 24px; }
.chapter { flex: 1; max-width: 46rem; outline: none; }
.loading { color: var(--muted); }

.eyebrow { margin: 0 0 8px; font-family: var(--mono); font-size: 0.85rem; color: var(--muted); }
.chapter h1 { font-size: clamp(1.9rem, 4vw, 2.8rem); line-height: 1.1; margin: 0 0 28px; font-weight: 600; letter-spacing: -0.01em; text-wrap: balance; }
.chapter h2 { font-size: 1rem; margin: 0 0 6px; font-weight: 600; }

.points { margin: 0 0 28px; padding: 0 0 0 1.2em; }
.points li { margin: 0 0 14px; padding-left: 0.2em; font-size: 1.15rem; line-height: 1.45; }
.points li::marker { color: var(--accent); }

.quote { margin: 0 0 28px; font-size: 1.25rem; font-weight: 500; line-height: 1.4; }
.quote::before { content: "„"; }
.quote::after { content: "”"; }

.exercise {
  margin: 0 0 28px; padding: 18px 20px;
  background: var(--accent-soft); border: 1px solid var(--accent); border-radius: 10px;
}
.exercise .label { margin: 0 0 6px; font-family: var(--mono); font-size: 0.8rem; color: var(--accent); text-transform: uppercase; letter-spacing: 0.04em; }
.exercise p { margin: 0; font-size: 1.1rem; }
.exercise p + p { margin-top: 8px; }

.note { margin: 0 0 28px; color: var(--muted); font-size: 0.95rem; }

/* Wideo */
.video { margin: 0 0 28px; }
.video-frame { position: relative; aspect-ratio: 16 / 9; background: #000; border-radius: 10px; overflow: hidden; }
.video-frame iframe, .video-frame video { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.video-link { margin: 8px 0 0; font-size: 0.9rem; }
.video-error { padding: 16px; border: 1px solid var(--line); border-radius: 10px; color: var(--muted); }

/* Nawigacja dół */
.pager { display: flex; justify-content: space-between; gap: 12px; max-width: 46rem; padding-top: 28px; margin-top: auto; }
.btn-pager { min-height: 48px; padding: 0 22px; font-size: 1rem; }

/* Ekran końcowy */
.final { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 40px; align-items: center; }
.qr { background: #fff; padding: 16px; border-radius: 12px; border: 1px solid var(--line); line-height: 0; }
.qr svg { width: min(360px, 70vw); height: auto; display: block; }
.final-url { font-family: var(--mono); font-size: 1rem; word-break: break-all; margin: 12px 0 0; }
.contact { font-size: 1.15rem; min-width: 0; overflow-wrap: anywhere; }
.contact p { margin: 0 0 6px; }
.contact .org { font-weight: 600; font-size: 1.4rem; margin-bottom: 10px; }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 40;
  max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: 8px;
  background: var(--text); color: var(--bg); font-size: 0.9rem;
}

/* Tryb prezentacji: duże fonty, czytelne z końca sali */
body.present { font-size: clamp(20px, 1.75vw, 40px); }
body.present .main { padding-top: 3vh; }
body.present .chapter, body.present .pager { max-width: 62rem; }
body.present .chapter h1 { font-size: 2.6em; }
body.present .points li { font-size: 1.35em; margin-bottom: 0.6em; }
body.present .exercise p { font-size: 1.25em; }
body.present .quote { font-size: 1.4em; }
body.present .eyebrow { font-size: 0.85em; }
body.present .btn-pager { font-size: 0.9em; }
body.present .qr svg { width: min(46vh, 60vw); }
body.present .contact { font-size: 1.3em; }
body.present .final-url { font-size: 1em; }

/* Telefon: lista rozdziałów jako rozwijane menu */
@media (max-width: 860px) {
  :root { font-size: 17px; }
  .layout { grid-template-columns: 1fr; }
  .toc {
    display: none;
    position: fixed; top: calc(var(--topbar-h) + 4px); left: 0; right: 0; z-index: 30;
    height: auto; max-height: calc(100vh - var(--topbar-h) - 4px);
    background: var(--bg); border-right: 0; border-bottom: 1px solid var(--line);
    box-shadow: 0 12px 24px rgb(0 0 0 / 0.15);
  }
  body.toc-open .toc { display: block; }
  body.toc-hidden .toc { display: none; }
  .main { padding: 24px 18px 20px; }
  .brand { font-size: 0.95rem; }
  #presentBtn { display: none; }
  .final { grid-template-columns: 1fr; gap: 24px; }
  .qr { justify-self: start; }
  .points li { font-size: 1.05rem; }
  .btn-pager { flex: 1; }
}
@media (max-width: 420px) {
  .menu-label { display: none; }
  .topbar { gap: 6px; padding: 0 10px; }
  .btn { padding: 0 10px; }
}

@media print {
  .topbar, .progress, .toc, .pager, .toast { display: none !important; }
  .layout { display: block; }
}
