/* EIDIP Tutorium – calm, large, projector-friendly. Warm light theme only. */
:root {
  --bg: #fbf7f0;
  --fg: #2b2620;
  --muted: #7a6f62;
  --faint: #e8dfd2;
  --panel: #f4ede2;
  --code-bg: #f6f0e6;
  --accent: #c2571a;
  --ok: #2f8a4a;
  --bad: #c43d32;
  --warn: #a8690a;
  --hl-bar: rgba(194, 87, 26, 0.10);
  --hl-edge: #c2571a;
  /* syntax */
  --k: #9b3f8f; --s: #4f7d1c; --n: #b5532a; --c: #9a8f82; --t: #2d63a8; --b: #1b7a80; --f: #8a5a00;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html {
  font-size: clamp(17px, 0.75vw + 12px, 28px);
  -webkit-text-size-adjust: 100%;
}
html.view-screen { font-size: clamp(18px, 0.85vw + 11px, 32px); }
html.view-console { font-size: clamp(14px, 0.5vw + 9px, 22px); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  line-height: 1.45;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
code, pre, .mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.loading { color: var(--muted); text-align: center; margin-top: 30vh; }
html.offline body::before {
  content: ""; position: fixed; top: 10px; right: 10px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--bad); z-index: 50;
}

/* ---------- stage ---------- */
.stage {
  max-width: min(62rem, 1100px);
  margin: 0 auto;
  padding: 1.4rem 1.25rem 6rem;
}
html.view-screen .stage { max-width: min(92vw, 1100px); padding: 2.4rem 2rem 2rem; }
/* the projector never scrolls: slides are fitted to the screen (fitSlide in app.js) */
html.view-screen, html.view-screen body { overflow: hidden; }
.topline {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  min-height: 2rem; font-size: 0.75rem; color: var(--muted);
  letter-spacing: 0.04em; text-transform: uppercase;
}
.live-btn {
  border: 1px solid var(--accent); color: var(--accent); background: transparent;
  border-radius: 999px; padding: 0.35rem 0.9rem; font-size: 0.85rem; text-transform: none; letter-spacing: 0;
  min-height: 44px;
}
.stu-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; padding: 0 0.5rem calc(0.5rem + env(safe-area-inset-bottom));
  pointer-events: none;
}
.stu-nav button {
  pointer-events: auto; width: 48px; height: 48px; border: 0; border-radius: 50%;
  background: transparent; color: var(--muted); font-size: 1.8rem; line-height: 1;
}
.stu-nav button:disabled { opacity: 0.2; }

/* ---------- slide ---------- */
.slide h1 {
  font-size: 1.9em; font-weight: 600; line-height: 1.15; letter-spacing: -0.01em;
  margin: 0.5em 0 1.1em;
}
.slide .body { font-size: 1.1em; line-height: 1.6; margin: 0 0 1.4em; }
.slide .body p { margin: 0 0 0.8em; }
.slide .body ul, .slide .body ol { margin: 0 0 0.8em; padding-left: 1.3em; }
.slide .body li { margin-bottom: 0.6em; padding-left: 0.2em; }
.slide .body li::marker { color: var(--muted); }
.slide .body > :last-child { margin-bottom: 0; }
.slide :not(pre) > code {
  font-size: 0.9em; background: var(--faint); padding: 0.05em 0.3em; border-radius: 4px;
}
.hint, .warn { border-left: 3px solid var(--accent); padding: 0.3em 0 0.3em 1em; margin: 1em 0; color: var(--muted); }
.warn { border-color: var(--warn); }

.code { margin: 0 0 1.4em; }
.code figcaption { font-family: var(--mono); font-size: 0.7em; color: var(--muted); margin-bottom: 0.3em; }
.code pre {
  margin: 0; background: var(--code-bg); border: 1px solid var(--faint); border-radius: 10px;
  padding: 1em 0; overflow-x: auto; font-size: 0.875em; line-height: 1.6;
}
.code code.hljs { display: block; min-width: max-content; background: none; padding: 0; }
.code .ln { display: block; padding: 0 1.2em; white-space: pre; border-left: 3px solid transparent; transition: background-color .25s, opacity .25s; }
.code .ln.hl { background: var(--hl-bar); border-left-color: var(--hl-edge); }
.code .ln.dim { opacity: 0.55; }
@media (max-width: 600px) { .code pre { font-size: 0.8em; } }

.output {
  margin: 0 0 1.4em; padding: 0.8em 1.2em; font-size: 0.875em; white-space: pre-wrap;
  background: var(--code-bg); border-radius: 10px; border: 1px solid var(--faint);
  color: var(--fg); position: relative;
}
.output.solution { border-color: var(--ok); }

/* hljs colours */
.hljs-keyword, .hljs-meta .hljs-keyword { color: var(--k); }
.hljs-string, .hljs-char { color: var(--s); }
.hljs-number, .hljs-literal { color: var(--n); }
.hljs-comment { color: var(--c); font-style: italic; }
.hljs-type, .hljs-class .hljs-title, .hljs-title.class_ { color: var(--t); }
.hljs-built_in { color: var(--b); }
.hljs-title.function_, .hljs-title { color: var(--f); }
.hljs-meta { color: var(--muted); }

/* ---------- questions ---------- */
.q { margin: 1.6em 0 0; }
.q .prompt { font-size: 1.15em; margin-bottom: 0.9em; }
.q .prompt p { margin: 0; }
.opts { display: grid; gap: 0.7em; }
.opt {
  display: flex; align-items: center; gap: 0.8em; text-align: left; width: 100%;
  padding: 0.75em 1em; min-height: 48px; border-radius: 10px;
  background: var(--panel); border: 1.5px solid var(--faint);
  transition: border-color .12s, background .12s;
}
.opt:not(:disabled):hover { border-color: var(--muted); }
.opt .mark {
  flex: none; width: 1em; height: 1em; border-radius: 50%; border: 2px solid var(--muted);
}
.opts.multi .opt .mark { border-radius: 4px; }
.opt.sel { border-color: var(--accent); }
.opt.sel .mark { background: var(--accent); border-color: var(--accent); box-shadow: inset 0 0 0 2px var(--panel); }
.opt.correct { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, var(--panel)); }
.opt.correct .mark { border-color: var(--ok); }
.opt.wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 10%, var(--panel)); }
.opt:disabled { opacity: 1; }

input.gap {
  font: inherit; color: inherit; background: color-mix(in srgb, var(--accent) 8%, transparent);
  border: 0; border-bottom: 2px solid var(--accent); border-radius: 3px 3px 0 0;
  padding: 0 0.25ch; margin: 0 0.1ch; min-width: 4ch; outline: none; vertical-align: baseline;
}
input.gap:focus { background: color-mix(in srgb, var(--accent) 18%, transparent); }
input.gap:disabled { opacity: 1; -webkit-text-fill-color: currentColor; }
input.gap.right, .text-in.right { border-color: var(--ok); }
input.gap.wrong, .text-in.wrong { border-color: var(--bad); text-decoration: line-through; text-decoration-color: var(--bad); }
.sol { color: var(--ok); margin-left: 0.5ch; }

.text-in {
  display: block; width: 100%; font-size: max(16px, 1em); color: inherit;
  background: var(--code-bg); border: 1.5px solid var(--faint); border-radius: 10px;
  padding: 0.6em 0.8em; outline: none; resize: vertical; line-height: 1.5;
}
.text-in:focus { border-color: var(--accent); }
.text-in:disabled { opacity: 1; -webkit-text-fill-color: currentColor; }
.q-text .output { margin-top: 0.6em; }
@media (max-width: 600px) { input.gap { font-size: max(16px, 1em); } }

.submit { display: flex; align-items: center; gap: 1em; margin-top: 1em; }
.send {
  background: var(--accent); color: var(--bg); border: 0; border-radius: 10px;
  padding: 0.6em 1.3em; min-height: 48px; font-weight: 600;
}
.send:disabled { background: var(--faint); color: var(--muted); }
.status { color: var(--muted); font-size: 0.9em; }
.verdict { margin-top: 0.9em; font-weight: 600; font-size: 1.1em; }
.verdict.right { color: var(--ok); }
.verdict.wrong { color: var(--bad); }
.verdict.none { color: var(--muted); }
.explain { margin-top: 0.8em; color: var(--muted); font-size: 1em; }
.reveal { margin-top: 1.4em; padding-top: 1em; border-top: 1px solid var(--faint); }

/* ---------- results (projector / console) ---------- */
.results { margin-top: 1.4em; display: grid; gap: 0.45em; font-size: 0.9em; }
.bar-row { display: grid; grid-template-columns: minmax(6em, 2fr) 3fr 2.5em; gap: 0.8em; align-items: center; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 0.9em; background: var(--faint); border-radius: 5px; overflow: hidden; }
.bar .fill { display: block; height: 100%; background: var(--muted); border-radius: 5px; transition: width .3s; }
.bar-row.correct .fill { background: var(--ok); }
.bar-row.correct .bar-label { color: var(--ok); }
.bar-n { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.pct { font-size: 1.4em; font-weight: 600; }
.top { margin: 0; padding: 0; list-style: none; display: grid; gap: 0.3em; }
.top li { display: flex; justify-content: space-between; gap: 1em; padding: 0.2em 0.6em; border-left: 3px solid var(--faint); }
.top li.correct { border-color: var(--ok); }
.top li.wrong { border-color: var(--bad); }
.top code { white-space: pre-wrap; word-break: break-word; }

.badge {
  position: fixed; right: 1rem; bottom: 0.8rem; font-size: 0.7rem; color: var(--muted);
  font-variant-numeric: tabular-nums; background: var(--bg); padding: 0.2em 0.5em; border-radius: 6px;
}

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 40; background: var(--bg);
  display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 4vh;
  backdrop-filter: blur(4px);
}
.join { cursor: pointer; }
.join-url { font-size: clamp(2rem, 7vw, 8rem); font-weight: 700; letter-spacing: -0.02em; }
.qr { background: #fff; padding: 1.5vh; border-radius: 12px; width: min(52vh, 80vw); }
.qr svg { display: block; width: 100%; height: auto; }
.toc { align-items: stretch; justify-content: flex-start; overflow-y: auto; padding: 4vh 4vw; }
.toc-list { columns: 3 18rem; column-gap: 3rem; font-size: 0.85rem; }
.toc-sec { break-inside: avoid; margin-bottom: 1.2em; }
.toc-sec h2 { font-size: 0.8em; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin: 0 0 0.3em; }
.toc ol { margin: 0; padding-left: 2.2em; }
.toc li::marker { color: var(--muted); font-size: 0.85em; }
.toc li button { background: none; border: 0; padding: 0.15em 0; text-align: left; }
.toc li button:hover { color: var(--accent); }
.toc li.cur button { color: var(--accent); font-weight: 600; }

/* ---------- presenter console ---------- */
.console {
  display: grid; height: 100vh; height: 100dvh;
  grid-template-columns: minmax(0, 1.55fr) minmax(18rem, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
}
.c-top {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 2rem; flex-wrap: wrap;
  padding: 0.6rem 1.2rem; border-bottom: 1px solid var(--faint); font-variant-numeric: tabular-nums;
}
.c-where b { font-size: 1.1em; }
.c-time { display: flex; gap: 1.5rem; }
.c-time #t-slide { font-weight: 600; }
.c-time .over { color: var(--warn); }
.c-time #t-total { cursor: pointer; }
.c-stats { margin-left: auto; font-size: 1.1em; }
.c-main { overflow-y: auto; padding: 1rem 1.4rem 1.4rem; border-right: 1px solid var(--faint); display: flex; flex-direction: column; }
.c-current { font-size: 0.95rem; }
.c-current .slide h1 { margin-top: 0; }
.c-main .results { font-size: 1rem; margin-top: 1rem; padding: 0.8rem 1rem; background: var(--panel); border-radius: 10px; }
.c-btns { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: auto; padding-top: 1rem; }
.c-btns button {
  background: var(--panel); border: 1px solid var(--faint); border-radius: 8px; padding: 0.45em 0.9em;
}
.c-btns button:hover { border-color: var(--muted); }
.c-btns button.on { border-color: var(--accent); color: var(--accent); }
.c-side { display: grid; grid-template-rows: auto minmax(0, 1fr); min-height: 0; }
.c-next { padding: 0.8rem 1.2rem; border-bottom: 1px solid var(--faint); }
.c-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-bottom: 0.4rem; }
.c-preview {
  font-size: 0.55rem; max-height: 30vh; overflow: hidden; pointer-events: none;
  border: 1px solid var(--faint); border-radius: 8px; padding: 0.8em 1.2em; opacity: 0.85;
  -webkit-mask-image: linear-gradient(to bottom, #000 80%, transparent);
  mask-image: linear-gradient(to bottom, #000 80%, transparent);
}
.c-preview .slide h1 { margin-top: 0; }
.c-notes { overflow-y: auto; padding: 1.2rem 1.6rem 2rem; font-size: 1.3rem; line-height: 1.5; }
.c-notes.hidden { visibility: hidden; }
.c-notes ul { padding-left: 1.1em; margin: 0 0 0.6em; }
.c-notes li { margin-bottom: 0.3em; }
.c-notes p { margin: 0 0 0.6em; }
.notes-sol { margin-bottom: 0.8em; padding: 0.4em 0.7em; border-left: 3px solid var(--ok); background: var(--panel); border-radius: 0 8px 8px 0; font-size: 0.85em; }
.notes-sol code, .c-notes code { font-size: 0.9em; }

@media (max-width: 800px) {
  .console { grid-template-columns: 1fr; grid-template-rows: auto auto auto; height: auto; }
  .c-main { border-right: 0; }
}

/* presenter: answer counts drawn inside the option rows */
.opt.counted { position: relative; background-image: linear-gradient(to right, color-mix(in srgb, var(--accent) 16%, transparent) var(--pct, 0%), transparent var(--pct, 0%)); }
.opt .cnt { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 600; color: var(--muted); padding-left: 1em; }
.opt.correct .cnt { color: var(--ok); }

/* small tables on Erklär-Folien */
.slide .body table { border-collapse: separate; border-spacing: 0; margin: 0.6em 0 1.2em; font-size: 0.92em; }
/* borders belong to cells (not collapsed) so rows hidden by build steps leave no empty grid */
.slide .body th, .slide .body td { border: 0 solid color-mix(in srgb, var(--fg) 30%, transparent); border-width: 0 1px 1px 0; padding: 0.45em 1em; text-align: left; vertical-align: top; }
.slide .body tr > :first-child { border-left-width: 1px; }
.slide .body table > tr:first-child > *, .slide .body thead > tr:first-child > *, .slide .body table > tbody:first-child > tr:first-child > * { border-top-width: 1px; }
.slide .body th { color: var(--muted); font-weight: 600; }
.slide .body table.digits td { min-width: 2em; text-align: center; font-family: var(--mono); font-size: 1.2em; }

/* ---------- build steps ---------- */
[data-step] { transition: opacity .25s ease; }
.step-hidden { opacity: 0 !important; pointer-events: none; }
.step-future { opacity: 0.35 !important; }
.c-step { margin-left: 0.8em; color: var(--accent); font-weight: 600; }

/* ---------- code callouts ---------- */
.annot-wrap { margin: 0 0 1.4em; }
.annot-wrap > .annot { margin-bottom: 1.4em; }
.annot-wrap > .annot:last-child { margin-bottom: 0; }
.annot { position: relative; }
.annot .annot-code { margin: 0; width: fit-content; max-width: 100%; }
.annot-labels { list-style: none; margin: 0; padding: 0; }
.annot:not(.compact) .annot-labels li { position: absolute; left: 0; top: 0; width: max-content; max-width: 11em; }
.annot-labels li { line-height: 1.25; font-size: 0.62em; color: var(--muted); }
.annot-labels b { display: block; color: var(--cc, var(--accent)); font-weight: 700; font-size: 1.2em; }
.annot-labels .annot-n { display: none; }
.annot-arrows { position: absolute; left: 0; top: 0; pointer-events: none; overflow: visible; }
.annot-arrows .conn { fill: none; stroke: var(--cc); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.annot-arrows .conn.dotted { stroke-width: 2.5; stroke-dasharray: 1 5; }
.annot-arrows .ahead, .annot-arrows .dot { fill: var(--cc); }
.annot-arrows .tokbox { fill: color-mix(in srgb, var(--cc) 13%, transparent); stroke: color-mix(in srgb, var(--cc) 60%, transparent); stroke-width: 1.5; }
/* wide screens: bigger callout figures (code ≥ 30px at 1920), extra room on the right if needed */
@media (min-width: 1000px) {
  html.view-screen .annot, html.view-student .annot { font-size: 1.3em; }
  html.view-screen .annot.has-right, html.view-student .annot.has-right { width: calc(100% + (100vw - 100%) / 2 - 3vw); }
}
/* projector: centre short callout slides vertically */
html.view-screen .stage { min-height: 100vh; display: flex; flex-direction: column; }
html.view-screen .stage > .slide { flex: 1; display: flex; flex-direction: column; }
html.view-screen .slide.has-annot > .slide-main { flex: 1; display: flex; flex-direction: column; justify-content: center; padding-bottom: 6vh; }
/* compact (phones): numbered badges + list, no arrows */
.annot.compact .annot-arrows { display: none; }
.annot.compact .annot-labels { margin-top: 1em; display: grid; gap: 0.6em; }
.annot.compact .annot-labels li { display: flex; gap: 0.5em; flex-wrap: wrap; align-items: baseline; font-size: 1em; }
.annot.compact .annot-labels b { display: inline; font-size: 1em; }
.annot.compact .annot-labels .annot-n { display: inline; color: var(--cc, var(--accent)); font-weight: 700; }
.annot.compact .tok { transition: background-color .25s; }
.annot.compact .tok.on { background: color-mix(in srgb, var(--cc, var(--accent)) 14%, transparent); border-radius: 3px; }
.annot.compact .tok-end.on::after {
  content: attr(data-n); color: var(--cc, var(--accent)); font-family: var(--sans); font-weight: 700;
  font-size: 0.8em; vertical-align: super; margin-left: 1px;
}
.annot .nomatch { opacity: 0.6; }

/* body rendered after the code (bodyAfter) */
.slide .body.after { margin-top: 0.4em; }

/* small phones: ≤ 45-char code lines fit without scrolling */
@media (max-width: 420px) {
  .stage { padding-left: 1rem; padding-right: 1rem; }
  .code pre { font-size: 0.68em; }
  .code .ln { padding: 0 0.8em; }
  .output { font-size: 0.75em; }
  .annot.compact .annot-labels { font-size: 0.92em; }
}

/* two columns on wide screens: code left, question / long body right */
@media (min-width: 1200px) {
  .slide-main.two-col, html.view-screen .slide.has-annot > .slide-main.two-col {
    display: grid; grid-template-columns: minmax(0, 58fr) minmax(0, 42fr); column-gap: 2.6em; align-items: start;
  }
  html.view-screen .slide.has-annot > .slide-main.two-col { align-content: center; }
  .slide-main.two-col .q { margin-top: 0; }
  .slide-main.two-col .col-left > :last-child, .slide-main.two-col .col-right > :last-child { margin-bottom: 0; }
  .slide-main.two-col .col-right .body:first-child { margin-top: 0; }
  html.view-screen .stage:has(.two-col) { max-width: min(94vw, 1500px); }
}

/* ---------- structured presenter notes (v3) ---------- */
.n-wrap { max-width: 34em; }
.n-key { font-size: 1.3em; font-weight: 700; line-height: 1.3; margin: 0 0 1.1em; color: var(--fg); }
.n-sec { margin: 0 0 1.15em; }
.n-h {
  font-variant: small-caps; text-transform: lowercase; letter-spacing: 0.08em; font-size: 0.85em;
  font-weight: 600; color: var(--muted); margin-bottom: 0.3em;
}
.n-say, .n-pit, .n-wrong { list-style: none; margin: 0; padding: 0; }
.n-say li, .n-pit li { margin: 0 0 0.35em; padding: 0.1em 0 0.1em 0.8em; border-left: 3px solid var(--faint); transition: opacity .2s, background-color .2s; }
.n-say li.cur { border-left-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); border-radius: 0 6px 6px 0; }
.n-say li.future { opacity: 0.4; }
.n-pit li { border-left-color: var(--warn); }
.n-ask { font-style: italic; }
.n-answer { font-weight: 700; color: var(--ok); }
.n-answer .n-sep { color: var(--muted); font-weight: 400; }
.n-why { margin: 0.35em 0 0; padding-left: 1.6em; }
.n-why li { margin: 0 0 0.2em; padding-left: 0.2em; }
.n-why li::marker { color: var(--muted); font-size: 0.85em; }
.n-explain { color: var(--muted); margin-top: 0.3em; }
.n-wrong li { display: flex; align-items: baseline; gap: 0.5em; flex-wrap: wrap; margin: 0 0 0.45em; }
.n-chip {
  font-family: var(--mono); font-size: 0.85em; padding: 0.05em 0.45em; border-radius: 6px;
  background: color-mix(in srgb, var(--bad) 9%, transparent); border: 1px solid color-mix(in srgb, var(--bad) 25%, transparent);
}
.n-arrow { color: var(--muted); }
.n-next { color: var(--muted); }
.c-notes code { font-size: 0.9em; }

/* ---------- laser pointer ---------- */
.laser-dot {
  position: fixed; left: -11px; top: -11px; width: 22px; height: 22px; border-radius: 50%;
  background: radial-gradient(circle, #ff6a5f 0%, #e0322b 55%, rgba(224, 50, 43, 0.85) 70%);
  box-shadow: 0 0 10px 4px rgba(224, 50, 43, 0.55), 0 0 26px 10px rgba(224, 50, 43, 0.25);
  pointer-events: none; z-index: 1000; opacity: 0; transition: transform 40ms linear, opacity .15s;
}
.laser-dot.on { opacity: 1; }
html.laser-on article.slide:not([data-mode="preview"]), html.laser-on article.slide:not([data-mode="preview"]) * { cursor: none !important; }

/* join QR on a slide (slide.join = true): QR with the link underneath */
.join-inline { display: flex; flex-direction: column; align-items: center; gap: 2vh; margin-top: 2vh; }
.join-inline .qr { width: min(42vh, 70vw); }
.join-inline .join-url { font-size: clamp(1.8rem, 4.5vw, 5rem); }
