Add light/dark theme switch
CI / Deploy / test (push) Successful in 46s
CI / Deploy / deploy (push) Skipped

Theme follows the system by default; the header switch cycles
auto/light/dark and is stored per browser. The presenter has its own
switch (T), dark by default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Opus 5.5 committed 2026-11-07 16:15:14 +01:00
1 parent f0c6687100
commit 58145e9753
9 files changed
+187 -18

No files matched your search

+60 -15
View File
@@ -28,10 +28,33 @@
--c4: #2f8fe0;
--c5: #8e44c9;
--qa: #1f6bb0; /* Q&A accent, AA contrast with white text */
--notice-bg: #fff6e0;
--notice-ink: #6b4a00;
color-scheme: light;
}
/*
* Theme: data-theme="light|dark" on <html> (set by the theme switch, stored per browser),
* without it the system setting decides. Keep both dark blocks in sync.
*/
:root[data-theme="dark"] {
--bg: #12131d;
--surface: #1b1d2b;
--surface-2: #24263a;
--text: #eceefa;
--muted: #a1a6c3;
--border: #30334a;
--primary: #7f75ff;
--primary-soft: #2a2752;
--qa: #7cc4ff;
--shadow: none;
--notice-bg: #3a2f12;
--notice-ink: #f3d98f;
color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
:root:not(.present) {
:root:not([data-theme="light"]) {
--bg: #12131d;
--surface: #1b1d2b;
--surface-2: #24263a;
@@ -42,6 +65,9 @@
--primary-soft: #2a2752;
--qa: #7cc4ff;
--shadow: none;
--notice-bg: #3a2f12;
--notice-ink: #f3d98f;
color-scheme: dark;
}
}
@@ -156,8 +182,7 @@ h3 { font-size: 1.05rem; margin-top: 1.6em; }
.message.warning { border-color: var(--warn); }
.message.hidden { display: none; }
.notice { padding: 12px 16px; border-radius: 8px; background: #fff6e0; color: #6b4a00; margin-bottom: 24px; font-size: .95rem; }
@media (prefers-color-scheme: dark) { .notice { background: #3a2f12; color: #f3d98f; } }
.notice { padding: 12px 16px; border-radius: 8px; background: var(--notice-bg); color: var(--notice-ink); margin-bottom: 24px; font-size: .95rem; }
.devnote { margin-top: 24px; padding: 16px; border: 2px dashed var(--warn); border-radius: var(--radius); }
.icon-circle { width: 64px; height: 64px; margin: 0 auto 16px; border-radius: 50%; display: grid; place-items: center; font-size: 28px; background: var(--primary-soft); color: var(--primary); }
@@ -427,19 +452,34 @@ button.qa-steps__step:hover:not(:disabled) { color: var(--text); border-color: v
.qa-steps .is-current .qa-steps__step { background: var(--qa); border-color: var(--qa); color: var(--surface); font-weight: 700; cursor: default; }
/* ---------------------------------------------------------------- presenter */
/* Dark by default (beamer); the presenter's own switch can make it light (data-theme="light"). */
body.present {
--bg: #0f1020;
--surface-2: #1f2140;
--text: #f3f4ff;
--muted: #a3a7cf;
background: radial-gradient(1200px 600px at 10% -10%, #2a1f6e 0%, transparent 60%), var(--bg);
--tint: 255, 255, 255; /* overlays on the stage: rgba(var(--tint), alpha) */
--stage-glow: #2a1f6e;
--stage-ok: #3ddc97; /* brighter green for contrast on the dark stage */
--overlay-bg: rgba(8, 9, 20, .92);
background: radial-gradient(1200px 600px at 10% -10%, var(--stage-glow) 0%, transparent 60%), var(--bg);
color: var(--text);
overflow: hidden;
}
.stage { display: grid; grid-template-rows: auto 1fr auto; height: 100vh; padding: 20px 4vw; }
:root[data-theme="light"] body.present {
--bg: #f5f6fb;
--surface-2: #e4e7f4;
--text: #1d1f33;
--muted: #4f5473;
--tint: 20, 22, 50;
--stage-glow: #dcd8ff;
--stage-ok: var(--ok);
--overlay-bg: rgba(245, 246, 251, .95);
}
.stage__top { display: flex; justify-content: space-between; align-items: center; gap: 16px; font-size: clamp(1rem, 1.6vw, 1.4rem); color: var(--muted); }
.stage__top strong { color: var(--text); }
.stage__code { letter-spacing: .12em; background: rgba(255, 255, 255, .1); padding: 2px 10px; border-radius: 8px; }
.stage__code { letter-spacing: .12em; background: rgba(var(--tint), .1); padding: 2px 10px; border-radius: 8px; }
.stage__qr { border: 0; padding: 4px; background: #fff; border-radius: 8px; cursor: zoom-in; }
.stage__qr img { display: block; width: 72px; height: 72px; }
.stage__main { display: flex; flex-direction: column; justify-content: center; min-height: 0; overflow: auto; padding: 2vh 0; }
@@ -454,7 +494,7 @@ body.present {
.stage--closed .stage__type::after { content: " · Abstimmung geschlossen"; color: var(--muted); }
.stage .bar__track { height: 1.1em; }
.stage .columns { height: 34vh; }
.stage .average { padding: 2vh 2.5vw; gap: 2vh 4vw; background: rgba(255, 255, 255, .06); }
.stage .average { padding: 2vh 2.5vw; gap: 2vh 4vw; background: rgba(var(--tint), .06); }
.stage .average__value strong { font-size: clamp(4rem, 9vw, 8rem); }
.stage .average__of { font-size: clamp(1.6rem, 3vw, 2.8rem); }
.stage .average__label, .stage .average__count, .stage .average__ends { font-size: clamp(.9rem, 1.4vw, 1.3rem); }
@@ -463,15 +503,15 @@ body.present {
.stage .answers { columns: 340px; }
.stage .quiz-timer { font-size: clamp(3rem, 7vw, 6rem); }
.stage .quiz-tile { font-size: clamp(1.2rem, 2.2vw, 2rem); }
/* brighter green for contrast on the dark stage */
.stage .quiz-summary strong, .stage .bar--correct .bar__label { color: #3ddc97; }
.stage .bar--correct .bar__fill { background: #3ddc97; }
.stage .quiz-summary strong, .stage .bar--correct .bar__label { color: var(--stage-ok); }
.stage .bar--correct .bar__fill { background: var(--stage-ok); }
.stage .qa-steps { font-size: .7em; }
.stage .qa-steps__step { border-color: rgba(255, 255, 255, .25); }
.stage .qa-item { background: rgba(255, 255, 255, .06); }
.stage .qa-steps__step { border-color: rgba(var(--tint), .25); }
.stage .qa-item { background: rgba(var(--tint), .06); }
.stage { --qa: #7cc4ff; }
:root[data-theme="light"] .stage { --qa: #1f6bb0; }
.stage .qa-steps .is-current .qa-steps__step { color: var(--bg); }
.stage .qa-focus { background: rgba(255, 255, 255, .08); padding: 3vh 3vw; }
.stage .qa-focus { background: rgba(var(--tint), .08); padding: 3vh 3vw; }
.stage .qa-focus__meta { font-size: .7em; }
.stage .qa-focus__text { font-size: clamp(1.8rem, 3.6vw, 3.2rem); line-height: 1.2; }
.stage .qa-list--compact { font-size: .75em; }
@@ -479,8 +519,8 @@ body.present {
.stage__controls { display: flex; gap: 8px; align-items: center; justify-content: center; flex-wrap: wrap; opacity: .35; transition: opacity .2s; padding-top: 12px; }
.stage__controls:hover, .stage__controls:focus-within { opacity: 1; }
.ctrl { min-width: 44px; height: 40px; padding: 0 12px; border-radius: 8px; border: 1px solid rgba(255, 255, 255, .2); background: rgba(255, 255, 255, .06); color: var(--text); font: inherit; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.ctrl:hover { background: rgba(255, 255, 255, .15); }
.ctrl { min-width: 44px; height: 40px; padding: 0 12px; border-radius: 8px; border: 1px solid rgba(var(--tint), .2); background: rgba(var(--tint), .06); color: var(--text); font: inherit; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.ctrl:hover { background: rgba(var(--tint), .15); }
.ctrl { gap: 6px; }
/* Visible keyboard shortcuts – nobody hovers for tooltips during a talk. */
.ctrl__key { font: inherit; font-size: .8em; font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
@@ -492,6 +532,11 @@ body.present {
}
.ctrl-counter { color: var(--muted); min-width: 64px; text-align: center; font-variant-numeric: tabular-nums; }
.qr-overlay { position: fixed; inset: 0; background: rgba(8, 9, 20, .92); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; cursor: zoom-out; z-index: 10; }
.qr-overlay { position: fixed; inset: 0; background: var(--overlay-bg); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; cursor: zoom-out; z-index: 10; }
.qr-overlay img { width: min(70vh, 80vw); height: auto; background: #fff; border-radius: 16px; padding: 16px; }
.qr-overlay p { font-size: 1.4rem; }
/* ---------------------------------------------------------------- theme switch */
.theme-switch { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--border); background: transparent; color: var(--text); font: inherit; font-size: .9rem; cursor: pointer; }
.theme-switch:hover { border-color: var(--primary); }
.theme-switch__icon { font-size: 1.05em; line-height: 1; }
+58
View File
@@ -10,6 +10,8 @@
* - [data-countdown] quiz timer (data-remaining = seconds), fires `plenario:timeup` on document
* - [data-quiz-options] slide form: "add answer" button for quiz slides
* - [data-sortable] admin slide list: drag & drop / arrow keys via [data-drag-handle], POSTs ids[] to the URL
* - [data-theme-switch] cycles the colour scheme (data-theme on <html>, stored in localStorage),
* see templates/element/theme_init.php for the pre-paint part
*
* Results JSON shape: see src/Service/ResultsService.php
*/
@@ -917,11 +919,18 @@
case 'Q':
toggleQr();
break;
case 't':
case 'T':
if (themeSwitch) {
themeSwitch.click();
}
break;
case 'Escape':
overlay.hidden = true;
break;
}
});
var themeSwitch = q('[data-theme-switch]');
var poller = poll(refresh, interval);
document.addEventListener('plenario:timeup', function () {
@@ -1523,9 +1532,58 @@
}
}
// ------------------------------------------------------------------ theme switch
var THEME_ICONS = { auto: '◐', light: '☀', dark: '☾' };
function initThemeSwitch(button) {
var key = button.getAttribute('data-theme-key');
var modes = button.getAttribute('data-theme-modes').split(',');
var root = document.documentElement;
function current() {
var theme = root.getAttribute('data-theme') || 'auto';
return modes.indexOf(theme) >= 0 ? theme : modes[0];
}
function label(mode) {
return button.getAttribute('data-label-' + mode);
}
function render() {
var mode = current();
var next = modes[(modes.indexOf(mode) + 1) % modes.length];
button.querySelector('[data-theme-icon]').textContent = THEME_ICONS[mode];
button.querySelector('[data-theme-label]').textContent = label(mode);
var text = button.getAttribute('data-label-prefix') + ': ' + label(mode) + ', '
+ button.getAttribute('data-label-next') + ' ' + label(next);
button.setAttribute('aria-label', text);
button.title = text + (button.hasAttribute('aria-keyshortcuts') ? ' (' + button.getAttribute('aria-keyshortcuts') + ')' : '');
}
button.addEventListener('click', function () {
var next = modes[(modes.indexOf(current()) + 1) % modes.length];
if (next === 'auto') {
root.removeAttribute('data-theme');
} else {
root.setAttribute('data-theme', next);
}
try {
localStorage.setItem(key, next);
} catch (e) {
// private mode: the choice just lasts until reload
}
render();
});
render();
button.hidden = false;
}
// ------------------------------------------------------------------ boot
document.addEventListener('DOMContentLoaded', function () {
document.querySelectorAll('[data-theme-switch]').forEach(initThemeSwitch);
initCopy();
initShare();
document.querySelectorAll('[data-youtube-form]').forEach(initYouTubeForm);