diff --git a/Dockers/mama-boek-game/.dockerignore b/Dockers/mama-boek-game/.dockerignore new file mode 100644 index 0000000..b3066d8 --- /dev/null +++ b/Dockers/mama-boek-game/.dockerignore @@ -0,0 +1,7 @@ +README.md +.git +.gitignore +.env +.env.* +__pycache__/ +*.pyc diff --git a/Dockers/mama-boek-game/.env.example b/Dockers/mama-boek-game/.env.example new file mode 100644 index 0000000..0278a1f --- /dev/null +++ b/Dockers/mama-boek-game/.env.example @@ -0,0 +1,5 @@ +GIFT_CODE=VUL-JE-CADEAUBONCODE-IN + +# Optioneel: pas de naam en datum aan. +RECIPIENT=Mama +EVENT_DATE=vandaag diff --git a/Dockers/mama-boek-game/.gitignore b/Dockers/mama-boek-game/.gitignore new file mode 100644 index 0000000..cff5543 --- /dev/null +++ b/Dockers/mama-boek-game/.gitignore @@ -0,0 +1,3 @@ +.env +__pycache__/ +*.pyc diff --git a/Dockers/mama-boek-game/Dockerfile b/Dockers/mama-boek-game/Dockerfile new file mode 100644 index 0000000..b2f7ab5 --- /dev/null +++ b/Dockers/mama-boek-game/Dockerfile @@ -0,0 +1,19 @@ +FROM python:3.13-alpine + +ENV PYTHONUNBUFFERED=1 \ + PORT=8000 + +WORKDIR /app + +RUN addgroup -S game && adduser -S game -G game + +COPY --chown=game:game app/ /app/ + +USER game + +EXPOSE 8000 + +HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ + CMD python -c "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8000/healthz', timeout=2)" + +CMD ["python", "-u", "server.py"] diff --git a/Dockers/mama-boek-game/README.md b/Dockers/mama-boek-game/README.md new file mode 100644 index 0000000..aabfe94 --- /dev/null +++ b/Dockers/mama-boek-game/README.md @@ -0,0 +1,88 @@ +# Mama's Geheime Leeshoek + +Een klein verjaardagsspel in de browser, met een boekenthema. Mama opent acht +boeken in een gezellige boekenkast. Elk boek stelt een kleine vraag over lezen. +Bij een juist antwoord onthult het boek één letter. Samen vormen de acht letters +het wachtwoord van de geheime lade — en daarin ligt de cadeaubon. + +De antwoorden worden door de server gecontroleerd. De cadeauboncode staat nooit +in de statische bestanden en wordt pas vrijgegeven via `POST /api/reveal` +wanneer alle acht boeken gelezen zijn. + +## Snel starten + +1. Zet je cadeauboncode in een lokaal `.env`-bestand: + + ```bash + cp .env.example .env + ``` + + Pas daarna `GIFT_CODE` aan in `.env`. Naam en datum zijn optioneel: + + ```dotenv + GIFT_CODE=BOEK-1234-5678 + RECIPIENT=Mama + EVENT_DATE=18 november + ``` + +2. Start de container: + + ```bash + docker compose up -d --build + ``` + +3. Open `http://:8005`. + +## Hoe het spel werkt + +- Klik op een boek in de kast. Er is geen tijdsdruk en geen levens. +- Kies een antwoord. Bij een fout antwoord krijg je na twee pogingen een hint. +- Bij een juist antwoord verschijnt de letter van dat boek in het geheimwoord + onder de kast. Een gouden bladwijzer markeert het boek als gelezen. +- Na acht boeken klikt de geheime lade open. Klik erop om de cadeaubon te + onthullen. +- De voortgang wordt in de browser bewaard. Een per ongeluk gesloten tabblad + verliest dus geen leeswerk. + +De letters van de acht boeken spellen samen `LEESHOEK`. + +## Spel aanpassen + +- **Boeken, vragen en teksten**: pas `app/game.json` aan. Elk boek heeft een + titel, auteur, kleuren, embleem, flaptekst, citaat, vraag, drie antwoorden, + het juiste antwoord (`answer`, nul-gebaseerd), de letter, een hint en de + tekst die na het lezen verschijnt. +- **Cadeauboncode**: via `GIFT_CODE` in `.env` of in `docker-compose.yml`. + Zonder ingestelde code wordt de placeholder `VUL-JE-CADEAUBONCODE-IN` getoond. +- **Naam en datum**: via `RECIPIENT` en `EVENT_DATE`, of als standaardwaarden + in `app/game.json`. +- **Poort**: pas de mapping `8005:8000` in `docker-compose.yml` aan. +- **Opnieuw bouwen na aanpassingen**: + + ```bash + docker compose up -d --build + ``` + +## Lokaal draaien zonder Docker + +```bash +GIFT_CODE=MIJN-CODE python3 app/server.py +``` + +Open daarna `http://localhost:8000`. Er zijn geen extra Python-pakketten nodig. + +## Bestanden + +```text +. +├── Dockerfile +├── docker-compose.yml +├── .env.example +└── app + ├── game.json # boeken, vragen, antwoorden en teksten + ├── server.py # statische server, antwoordcontrole en code onthullen + └── static + ├── index.html # boekenkast, boekdialoog en cadeaubon + ├── style.css # vormgeving, boeken, lade en animaties + └── game.js # spel logica, geluid, voortgang en confetti +``` diff --git a/Dockers/mama-boek-game/app/game.json b/Dockers/mama-boek-game/app/game.json new file mode 100644 index 0000000..8a06470 --- /dev/null +++ b/Dockers/mama-boek-game/app/game.json @@ -0,0 +1,152 @@ +{ + "recipient": "Mama", + "eventDate": "vandaag", + "title": "Mama's Geheime Leeshoek", + "subtitle": "Lees de acht boeken, vind het geheimwoord en open de lade.", + "books": [ + { + "id": "zilveren-maan", + "title": "De Zilveren Maan", + "author": "L. van der Ster", + "color": "#183748", + "color2": "#2f5f75", + "ink": "#f6e8c6", + "emblem": "moon", + "intro": "Een nachtboek vol sterren, met een maan die nooit ondergaat.", + "quote": "Sommige verhalen lees je het liefst met de lichten uit.", + "question": "Je kruipt met een boek onder een deken. Wat ga je doen?", + "options": ["Lezen", "Slapen", "Koken"], + "answer": 0, + "letter": "L", + "hint": "Het begint met dezelfde letter als 'lamp'.", + "fact": "Precies: lezen. Elke bladzijde is een klein uitstapje.", + "done": "De Zilveren Maan is gelezen. De letter L schuift op zijn plek." + }, + { + "id": "laatste-hoofdstuk", + "title": "Het Laatste Hoofdstuk", + "author": "E. Moreau", + "color": "#4a1f2b", + "color2": "#7d3548", + "ink": "#f6e3cd", + "emblem": "feather", + "intro": "Een roman die eindigt waar elk verhaal eigenlijk pas begint.", + "quote": "Het einde is soms het begin van iets mooiers.", + "question": "Hoe heet het stuk na het einde van een verhaal, waarin de afloop nog even napruttelt?", + "options": ["Proloog", "Epiloog", "Inhoudstafel"], + "answer": 1, + "letter": "E", + "hint": "Het is het tegenovergestelde van een proloog.", + "fact": "Een epiloog. Soms is het mooiste hoofdstuk het allerlaatste.", + "done": "Het Laatste Hoofdstuk is uit. De letter E ligt klaar." + }, + { + "id": "bladzijden-van-glas", + "title": "Bladzijden van Glas", + "author": "M. de Winter", + "color": "#23404f", + "color2": "#3d6f82", + "ink": "#eaf4f4", + "emblem": "key", + "intro": "Een spannend verhaal dat je liever niet op papier wilt lezen.", + "quote": "Elke bladzijde glinstert een beetje gevaar.", + "question": "Hoe noem je een boek dat je op een scherm leest?", + "options": ["Luisterboek", "E-book", "Prentenboek"], + "answer": 1, + "letter": "E", + "hint": "De 'e' staat voor elektronisch.", + "fact": "Een e-book. Handig, maar niets verslaat de geur van papier.", + "done": "Bladzijden van Glas is dichtgeslagen. De letter E is gevonden." + }, + { + "id": "tuin-van-woorden", + "title": "De Tuin van Woorden", + "author": "S. Veldman", + "color": "#2e4a30", + "color2": "#557c4c", + "ink": "#f2edcd", + "emblem": "leaf", + "intro": "Een bundel over taal die groeit als een tuin in de lente.", + "quote": "Woorden zijn zaadjes. Geduld is de regen.", + "question": "Iemand die een boek schrijft, noem je een...", + "options": ["Lezer", "Schrijver", "Vertaler"], + "answer": 1, + "letter": "S", + "hint": "Zonder deze persoon geen verhaal.", + "fact": "Een schrijver. Elke tuin begint met één zaadje.", + "done": "De Tuin van Woorden is gelezen. De letter S schiet wortel." + }, + { + "id": "kaartenkamer", + "title": "De Kaartenkamer", + "author": "H. Lindeboom", + "color": "#6a4318", + "color2": "#9c6c2c", + "ink": "#fbf0d4", + "emblem": "ship", + "intro": "Een zeeverhaal vol geheime kaarten en verre kusten.", + "quote": "Wie leest, zeilt zonder ooit de deur uit te gaan.", + "question": "Hoe heet een onderdeel van een boek met een eigen titel en nummer?", + "options": ["Hoofdstuk", "Boekrug", "Bladwijzer"], + "answer": 0, + "letter": "H", + "hint": "Je zegt vaak: 'Ik ben bij het derde ...'.", + "fact": "Een hoofdstuk. Elk hoofdstuk is een eiland op zich.", + "done": "De Kaartenkamer is uit. De letter H is binnengevaren." + }, + { + "id": "het-omslag", + "title": "Het Omslag", + "author": "O. Ferrand", + "color": "#3c2a4f", + "color2": "#64497e", + "ink": "#f2e6f5", + "emblem": "star", + "intro": "Een boek over boeken, en over de verhalen die ze verbergen.", + "quote": "Oordeel niet naar het omslag, maar bewonder het gerust.", + "question": "Wat zit er om de bladzijden van een boek heen?", + "options": ["Omslag", "Leesbril", "Boekenlegger"], + "answer": 0, + "letter": "O", + "hint": "Je ziet het als het boek dicht op tafel ligt.", + "fact": "Het omslag. Soms koop je een boek gewoon omdat het mooi is.", + "done": "Het Omslag is gesloten. De letter O glanst op zijn plek." + }, + { + "id": "alles-weten", + "title": "Alles Weten", + "author": "E. de Vries", + "color": "#1f4a46", + "color2": "#3d7d70", + "ink": "#e9f6ee", + "emblem": "owl", + "intro": "Een dik naslagwerk voor nieuwsgierige avonden.", + "quote": "Nieuwsgierigheid is een zeer leesbare eigenschap.", + "question": "Welk boek staat vol weetjes, vaak op alfabetische volgorde?", + "options": ["Roman", "Encyclopedie", "Dichtbundel"], + "answer": 1, + "letter": "E", + "hint": "Vroeger stond er een hele kast vol van deze boeken.", + "fact": "Een encyclopedie. Nieuwsgierigheid is een prima leesgewoonte.", + "done": "Alles Weten is gelezen. De letter E staat erbij." + }, + { + "id": "warme-kamer", + "title": "De Warme Kamer", + "author": "K. Meijer", + "color": "#5b2d32", + "color2": "#8d4f51", + "ink": "#f9e7d7", + "emblem": "teacup", + "intro": "Een cozy verhaal voor lange middagen met thee en regen.", + "quote": "Een warm boek is een huis dat altijd open is.", + "question": "Hoe noem je de stevige buitenkant van een boek?", + "options": ["Kaft", "Rug", "Flap"], + "answer": 0, + "letter": "K", + "hint": "Het rijmt op 'kracht'.", + "fact": "De kaft. Een boek met een mooie kaft mag gezien worden.", + "done": "De Warme Kamer is uit. De letter K maakt het woord compleet." + } + ] +} diff --git a/Dockers/mama-boek-game/app/server.py b/Dockers/mama-boek-game/app/server.py new file mode 100644 index 0000000..db25313 --- /dev/null +++ b/Dockers/mama-boek-game/app/server.py @@ -0,0 +1,279 @@ +#!/usr/bin/env python3 +"""Kleine server voor Mama's Geheime Leeshoek. + +Serveert de statische game, controleert de antwoorden van de boeken en geeft de +cadeauboncode pas vrij wanneer alle boeken gelezen zijn. +""" + +from __future__ import annotations + +import json +import os +import sys +from dataclasses import dataclass +from http import HTTPStatus +from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer +from pathlib import Path +from typing import Any +from urllib.parse import urlparse + +BASE_DIR = Path(__file__).resolve().parent +STATIC_DIR = BASE_DIR / "static" +GAME_FILE = BASE_DIR / "game.json" +DEFAULT_CODE = "VUL-JE-CADEAUBONCODE-IN" +MAX_BODY_BYTES = 16 * 1024 +PUBLIC_BOOK_FIELDS = ( + "id", + "title", + "author", + "intro", + "quote", + "question", + "options", + "hint", + "color", + "color2", + "ink", + "emblem", +) + + +@dataclass(frozen=True) +class GameData: + books: dict[str, dict[str, Any]] + config: dict[str, Any] + gift_code: str + + +def load_game(path: Path) -> dict[str, Any]: + with path.open(encoding="utf-8") as handle: + game = json.load(handle) + + books = game.get("books") + if not isinstance(books, list) or not books: + raise ValueError("game.json moet een niet-lege 'books'-lijst bevatten.") + + ids = [book["id"] for book in books] + if len(ids) != len(set(ids)): + raise ValueError("Elke boek-id moet uniek zijn.") + + for book in books: + answer = book.get("answer") + options = book.get("options") + if not isinstance(options, list) or not options: + raise ValueError(f"Boek {book['id']} heeft geen antwoordopties.") + if ( + isinstance(answer, bool) + or not isinstance(answer, int) + or not 0 <= answer < len(options) + ): + raise ValueError(f"Boek {book['id']} heeft een ongeldig antwoord.") + for field in ("letter", "fact", "done", "hint"): + if not isinstance(book.get(field), str) or not book[field]: + raise ValueError(f"Boek {book['id']} mist '{field}'.") + + return game + + +def public_book(book: dict[str, Any]) -> dict[str, Any]: + return {field: book[field] for field in PUBLIC_BOOK_FIELDS if field in book} + + +def public_config(game: dict[str, Any]) -> dict[str, Any]: + return { + "recipient": os.environ.get("RECIPIENT", game.get("recipient", "Mama")), + "eventDate": os.environ.get("EVENT_DATE", game.get("eventDate", "vandaag")), + "title": os.environ.get("GAME_TITLE", game.get("title", "Mama's Geheime Leeshoek")), + "subtitle": os.environ.get( + "GAME_SUBTITLE", + game.get("subtitle", "Lees de acht boeken en open de geheime lade."), + ), + "books": [public_book(book) for book in game["books"]], + } + + +class GameServer(ThreadingHTTPServer): + def __init__(self, address: tuple[str, int], data: GameData) -> None: + self.data = data + super().__init__(address, GameRequestHandler) + + +class GameRequestHandler(SimpleHTTPRequestHandler): + server_version = "MamaBoekGame/1.0" + + def __init__(self, *args: Any, **kwargs: Any) -> None: + super().__init__(*args, directory=str(STATIC_DIR), **kwargs) + + @property + def data(self) -> GameData: + return self.server.data # type: ignore[attr-defined] + + def end_headers(self) -> None: + self.send_header("X-Content-Type-Options", "nosniff") + self.send_header("Referrer-Policy", "no-referrer") + self.send_header("X-Frame-Options", "SAMEORIGIN") + self.send_header( + "Cache-Control", + "no-store" if self.path.startswith("/api/") else "no-cache", + ) + super().end_headers() + + def do_GET(self) -> None: + path = urlparse(self.path).path + if path == "/api/config": + self.send_json(HTTPStatus.OK, self.data.config) + return + if path == "/healthz": + self.send_json(HTTPStatus.OK, {"ok": True}) + return + super().do_GET() + + def do_POST(self) -> None: + path = urlparse(self.path).path + if path not in ("/api/solve", "/api/reveal"): + self.send_json(HTTPStatus.NOT_FOUND, {"ok": False, "error": "Onbekend pad."}) + return + + payload = self.read_json() + if payload is None: + self.send_json( + HTTPStatus.BAD_REQUEST, + {"ok": False, "error": "Ongeldige aanvraag."}, + ) + return + + if path == "/api/solve": + self.handle_solve(payload) + else: + self.handle_reveal(payload) + + def handle_solve(self, payload: dict[str, Any]) -> None: + book_id = payload.get("bookId") + answer = payload.get("answer") + book = self.data.books.get(book_id) if isinstance(book_id, str) else None + + if book is None: + self.send_json( + HTTPStatus.NOT_FOUND, + {"ok": False, "error": "Dit boek staat niet in de kast."}, + ) + return + + if ( + isinstance(answer, bool) + or not isinstance(answer, int) + or not 0 <= answer < len(book["options"]) + ): + self.send_json( + HTTPStatus.BAD_REQUEST, + {"ok": False, "error": "Ongeldige aanvraag."}, + ) + return + + if answer == book["answer"]: + self.send_json( + HTTPStatus.OK, + { + "ok": True, + "letter": book["letter"], + "explanation": book["fact"], + "done": book["done"], + }, + ) + return + + self.send_json( + HTTPStatus.OK, + { + "ok": False, + "error": "Nog niet helemaal. Lees de vraag nog eens rustig.", + "hint": book["hint"], + }, + ) + + def handle_reveal(self, payload: dict[str, Any]) -> None: + completed = payload.get("completed") + if not isinstance(completed, list) or not all( + isinstance(item, str) for item in completed + ): + self.send_json( + HTTPStatus.BAD_REQUEST, + {"ok": False, "error": "Ongeldige aanvraag."}, + ) + return + + missing = sorted(set(self.data.books).difference(completed)) + if missing: + self.send_json( + HTTPStatus.CONFLICT, + { + "ok": False, + "error": "De leeshoek is nog niet volledig gelezen.", + "missing": missing, + }, + ) + return + + self.send_json( + HTTPStatus.OK, + { + "ok": True, + "code": self.data.gift_code, + "recipient": self.data.config["recipient"], + "eventDate": self.data.config["eventDate"], + }, + ) + + def read_json(self) -> dict[str, Any] | None: + try: + length = int(self.headers.get("Content-Length", "0")) + except ValueError: + return None + + if length <= 0 or length > MAX_BODY_BYTES: + return None + + try: + payload = json.loads(self.rfile.read(length)) + except (json.JSONDecodeError, UnicodeDecodeError): + return None + + return payload if isinstance(payload, dict) else None + + def send_json(self, status: HTTPStatus, payload: dict[str, Any]) -> None: + body = json.dumps(payload, ensure_ascii=False).encode("utf-8") + self.send_response(status) + self.send_header("Content-Type", "application/json; charset=utf-8") + self.send_header("Content-Length", str(len(body))) + self.end_headers() + self.wfile.write(body) + + +def main() -> None: + game = load_game(GAME_FILE) + gift_code = (os.environ.get("GIFT_CODE") or DEFAULT_CODE).strip() + data = GameData( + books={book["id"]: book for book in game["books"]}, + config=public_config(game), + gift_code=gift_code, + ) + + port = int(os.environ.get("PORT", "8000")) + if gift_code == DEFAULT_CODE: + print( + "WAARSCHUWING: GIFT_CODE is niet ingesteld; de placeholder wordt getoond.", + file=sys.stderr, + ) + + server = GameServer(("0.0.0.0", port), data) + print(f"Boekenspel draait op http://0.0.0.0:{port}", flush=True) + try: + server.serve_forever() + except KeyboardInterrupt: + pass + finally: + server.server_close() + + +if __name__ == "__main__": + main() diff --git a/Dockers/mama-boek-game/app/static/game.js b/Dockers/mama-boek-game/app/static/game.js new file mode 100644 index 0000000..2ca056c --- /dev/null +++ b/Dockers/mama-boek-game/app/static/game.js @@ -0,0 +1,1100 @@ +(() => { + "use strict"; + + const $ = (selector, root = document) => root.querySelector(selector); + const $$ = (selector, root = document) => Array.from(root.querySelectorAll(selector)); + + const STORAGE_KEY = "mama-boek-voortgang"; + const SOUND_KEY = "mama-boek-geluid"; + + const EMBLEMS = { + moon: ` + `, + feather: ` + `, + key: ` + `, + leaf: ` + `, + ship: ` + `, + star: ` + `, + owl: ` + `, + teacup: ` + ` + }; + + const els = { + shelves: $$(".shelf"), + slots: $("#slots"), + secret: $("#secret-word"), + secretHint: $("#secret-hint"), + log: $("#log"), + progressText: $("#progress-text"), + progressPercent: $("#progress-percent"), + progressTrack: $("#progress-track"), + progressBar: $("#progress-bar"), + drawer: $("#drawer"), + drawerLabel: $("#drawer-label"), + drawerHint: $("#drawer-hint"), + bookModal: $("#book-modal"), + bookDialog: $("#book-dialog"), + bookClose: $("#book-close"), + dialogEmblem: $("#dialog-emblem"), + dialogTitle: $("#book-dialog-title"), + dialogAuthor: $("#book-dialog-author"), + dialogIntro: $("#book-dialog-intro"), + dialogQuote: $("#book-dialog-quote"), + question: $("#book-question"), + options: $("#book-options"), + feedback: $("#book-feedback"), + hint: $("#book-hint"), + stamp: $("#letter-stamp"), + stampLetter: $("#stamp-letter"), + doneBtn: $("#book-done-btn"), + voucherModal: $("#voucher-modal"), + voucherLead: $("#voucher-lead"), + voucherCode: $("#voucher-code"), + voucherRecipient: $("#voucher-recipient"), + voucherDate: $("#voucher-date"), + voucherNote: $("#voucher-note"), + voucherClose: $("#voucher-close"), + copyButton: $("#copy-code"), + playAgain: $("#play-again"), + soundButton: $("#sound-toggle"), + confetti: $("#confetti") + }; + + const confettiContext = els.confetti.getContext("2d"); + const reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches; + + const state = { + config: null, + books: new Map(), + order: [], + solvedCount: 0, + soundOn: true, + finished: false, + currentBookId: null, + requestInFlight: false, + requestSerial: 0, + bookReturnFocus: null, + voucherReturnFocus: null, + audio: null, + confettiFrame: null, + confettiParticles: [] + }; + + try { + state.soundOn = window.localStorage.getItem(SOUND_KEY) !== "uit"; + } catch { + state.soundOn = true; + } + + function pick(list) { + return list[Math.floor(Math.random() * list.length)]; + } + + function renderEmblem(name) { + return EMBLEMS[name] || EMBLEMS.star; + } + + function setLog(message, kind = "normal") { + els.log.textContent = message; + els.log.classList.toggle("is-warning", kind === "warning"); + els.log.classList.toggle("is-done", kind === "done"); + } + + function updateSoundButton() { + els.soundButton.setAttribute("aria-pressed", String(state.soundOn)); + const label = state.soundOn ? "Geluid dempen" : "Geluid aanzetten"; + els.soundButton.setAttribute("aria-label", label); + els.soundButton.title = label; + } + + function ensureAudio() { + if (!state.soundOn) { + return null; + } + if (!state.audio) { + const AudioContextClass = window.AudioContext || window.webkitAudioContext; + if (!AudioContextClass) { + return null; + } + try { + state.audio = new AudioContextClass(); + } catch { + return null; + } + } + if (state.audio.state === "suspended") { + state.audio.resume().catch(() => {}); + } + return state.audio; + } + + function playTone({ freq = 200, endFreq = freq, type = "sine", duration = 0.16, gain = 0.15, delay = 0 }) { + const context = ensureAudio(); + if (!context) { + return; + } + const start = context.currentTime + delay; + const oscillator = context.createOscillator(); + const volume = context.createGain(); + oscillator.type = type; + oscillator.frequency.setValueAtTime(Math.max(20, freq), start); + oscillator.frequency.exponentialRampToValueAtTime(Math.max(20, endFreq), start + duration); + volume.gain.setValueAtTime(0.0001, start); + volume.gain.exponentialRampToValueAtTime(Math.max(0.0001, gain), start + 0.012); + volume.gain.exponentialRampToValueAtTime(0.0001, start + duration); + oscillator.connect(volume).connect(context.destination); + oscillator.start(start); + oscillator.stop(start + duration + 0.03); + } + + function playNoise({ duration = 0.2, gain = 0.2, frequency = 900, delay = 0 } = {}) { + const context = ensureAudio(); + if (!context) { + return; + } + const frames = Math.max(1, Math.floor(context.sampleRate * duration)); + const buffer = context.createBuffer(1, frames, context.sampleRate); + const data = buffer.getChannelData(0); + for (let index = 0; index < frames; index += 1) { + data[index] = (Math.random() * 2 - 1) * (1 - index / frames); + } + const source = context.createBufferSource(); + source.buffer = buffer; + const filter = context.createBiquadFilter(); + filter.type = "bandpass"; + filter.frequency.value = frequency; + filter.Q.value = 0.8; + const volume = context.createGain(); + volume.gain.value = gain; + source.connect(filter).connect(volume).connect(context.destination); + source.start(context.currentTime + delay); + } + + function playPageTurn() { + playNoise({ duration: 0.15, gain: 0.06, frequency: 1600 }); + playTone({ freq: 520, endFreq: 340, type: "sine", duration: 0.09, gain: 0.035 }); + } + + function playCorrect() { + playTone({ freq: 659.25, endFreq: 659.25, type: "triangle", duration: 0.16, gain: 0.09 }); + playTone({ freq: 987.77, endFreq: 987.77, type: "sine", duration: 0.2, gain: 0.075, delay: 0.1 }); + playTone({ freq: 1318.51, endFreq: 1318.51, type: "sine", duration: 0.28, gain: 0.06, delay: 0.2 }); + } + + function playWrong() { + playTone({ freq: 300, endFreq: 210, type: "triangle", duration: 0.12, gain: 0.06 }); + playTone({ freq: 180, endFreq: 140, type: "sine", duration: 0.18, gain: 0.05, delay: 0.08 }); + } + + function playUnlock() { + playNoise({ duration: 0.07, gain: 0.08, frequency: 2500 }); + playTone({ freq: 340, endFreq: 120, type: "square", duration: 0.13, gain: 0.05 }); + playTone({ freq: 660, endFreq: 660, type: "triangle", duration: 0.09, gain: 0.04, delay: 0.06 }); + } + + function playFanfare() { + const notes = [523.25, 659.25, 783.99, 1046.5]; + notes.forEach((frequency, index) => { + playTone({ + freq: frequency, + endFreq: frequency, + type: "triangle", + duration: 0.26, + gain: 0.11, + delay: index * 0.12 + }); + }); + playTone({ freq: 1318.51, endFreq: 1318.51, type: "sine", duration: 0.55, gain: 0.08, delay: 0.52 }); + } + + function loadProgress() { + try { + const raw = window.localStorage.getItem(STORAGE_KEY); + if (!raw) { + return {}; + } + const parsed = JSON.parse(raw); + const saved = parsed && typeof parsed === "object" ? parsed.solved : null; + if (!saved || typeof saved !== "object") { + return {}; + } + + const clean = {}; + Object.entries(saved).forEach(([id, value]) => { + if (!value || typeof value !== "object") { + return; + } + if (typeof value.letter !== "string" || value.letter.length !== 1) { + return; + } + clean[id] = { + letter: value.letter.toUpperCase(), + answer: Number.isInteger(value.answer) ? value.answer : null, + done: typeof value.done === "string" ? value.done : "", + explanation: typeof value.explanation === "string" ? value.explanation : "" + }; + }); + return clean; + } catch { + return {}; + } + } + + function saveProgress() { + const solved = {}; + state.books.forEach((book) => { + if (!book.solved) { + return; + } + solved[book.id] = { + letter: book.letter, + answer: book.answerIndex, + done: book.doneText, + explanation: book.explanation + }; + }); + + try { + window.localStorage.setItem(STORAGE_KEY, JSON.stringify({ solved })); + } catch { + } + } + + function buildBook(meta) { + const button = document.createElement("button"); + button.type = "button"; + button.className = "book"; + button.dataset.id = meta.id; + button.style.setProperty("--cover", meta.color || "#2e4a30"); + button.style.setProperty("--cover-2", meta.color2 || "#557c4c"); + button.style.setProperty("--book-ink", meta.ink || "#f7eedb"); + button.setAttribute("aria-label", `${meta.title} van ${meta.author} openen`); + + const cover = document.createElement("span"); + cover.className = "book-cover"; + + const frame = document.createElement("span"); + frame.className = "book-frame"; + frame.setAttribute("aria-hidden", "true"); + + const emblem = document.createElement("span"); + emblem.className = "book-emblem"; + emblem.setAttribute("aria-hidden", "true"); + emblem.innerHTML = renderEmblem(meta.emblem); + + const title = document.createElement("span"); + title.className = "book-title"; + title.textContent = meta.title; + + const author = document.createElement("span"); + author.className = "book-author"; + author.textContent = meta.author; + + const status = document.createElement("span"); + status.className = "book-state"; + status.setAttribute("aria-hidden", "true"); + + cover.append(frame, emblem, title, author, status); + + const bookmark = document.createElement("span"); + bookmark.className = "bookmark"; + bookmark.setAttribute("aria-hidden", "true"); + + button.append(cover, bookmark); + button.addEventListener("click", () => openBook(meta.id)); + return button; + } + + function buildBooks(config) { + els.shelves.forEach((shelf) => shelf.replaceChildren()); + state.books.clear(); + state.order = []; + + const saved = loadProgress(); + + config.books.forEach((meta, index) => { + const element = buildBook(meta); + const shelf = els.shelves[Math.floor(index / 4)] || els.shelves[els.shelves.length - 1]; + if (shelf) { + shelf.appendChild(element); + } + + const book = { + id: meta.id, + meta, + element, + solved: false, + attempts: 0, + letter: "", + answerIndex: null, + doneText: "", + explanation: "" + }; + + state.books.set(meta.id, book); + state.order.push(book); + + if (saved[meta.id]) { + applySolvedState(book, saved[meta.id]); + } + }); + + buildSlots(); + updateProgress(); + updateSlots(); + } + + function buildSlots() { + els.slots.replaceChildren(); + state.order.forEach((book, index) => { + const slot = document.createElement("span"); + slot.className = "slot"; + slot.dataset.id = book.id; + slot.dataset.index = String(index); + slot.setAttribute("aria-label", `Letter ${index + 1}: nog niet gevonden`); + els.slots.appendChild(slot); + }); + } + + function updateSlots() { + state.order.forEach((book, index) => { + const slot = els.slots.children[index]; + if (!slot) { + return; + } + + if (book.solved && book.letter) { + if (slot.textContent !== book.letter) { + slot.textContent = book.letter; + } + slot.classList.add("filled"); + slot.setAttribute("aria-label", `Letter ${index + 1}: ${book.letter}`); + } else { + slot.textContent = ""; + slot.classList.remove("filled"); + slot.setAttribute("aria-label", `Letter ${index + 1}: nog niet gevonden`); + } + }); + + const complete = state.order.length > 0 && state.order.every((book) => book.solved); + els.secret.classList.toggle("is-complete", complete); + els.secretHint.textContent = complete + ? "De letters vormen samen het wachtwoord van de lade." + : "Elk gelezen boek onthult één letter."; + } + + function updateProgress() { + const total = state.order.length; + state.solvedCount = state.order.filter((book) => book.solved).length; + const percentage = total === 0 ? 0 : Math.round((state.solvedCount / total) * 100); + + els.progressText.textContent = `${state.solvedCount} / ${total} boeken gelezen`; + els.progressPercent.textContent = `${percentage}%`; + els.progressBar.style.width = `${percentage}%`; + els.progressTrack.setAttribute("aria-valuenow", String(percentage)); + state.finished = total > 0 && state.solvedCount === total; + } + + function applySolvedState(book, saved) { + book.solved = true; + book.attempts = 0; + book.letter = saved.letter; + book.answerIndex = saved.answer; + book.doneText = saved.done; + book.explanation = saved.explanation; + book.element.classList.add("is-solved"); + book.element.setAttribute( + "aria-label", + `${book.meta.title} van ${book.meta.author}, gelezen` + ); + } + + function renderOptions(book) { + els.options.replaceChildren(); + const keys = ["A", "B", "C", "D", "E", "F"]; + + book.meta.options.forEach((text, index) => { + const button = document.createElement("button"); + button.type = "button"; + button.className = "option"; + button.dataset.index = String(index); + button.disabled = book.solved; + + const key = document.createElement("span"); + key.className = "option-key"; + key.setAttribute("aria-hidden", "true"); + key.textContent = keys[index] || String(index + 1); + + const label = document.createElement("span"); + label.className = "option-text"; + label.textContent = text; + + button.append(key, label); + button.addEventListener("click", () => answerBook(book, index)); + els.options.appendChild(button); + }); + + if (book.solved) { + $$(".option", els.options).forEach((button, index) => { + button.disabled = true; + if (index === book.answerIndex) { + button.classList.add("is-correct"); + } + }); + showSolvedState(book); + } + } + + function showSolvedState(book) { + els.feedback.className = "feedback is-correct"; + els.feedback.textContent = book.explanation || book.doneText + || `Juist. De letter ${book.letter} is gevonden.`; + els.hint.hidden = true; + els.hint.textContent = ""; + els.stampLetter.textContent = book.letter; + els.stamp.hidden = false; + els.stamp.classList.remove("is-visible"); + void els.stamp.offsetWidth; + els.stamp.classList.add("is-visible"); + els.doneBtn.hidden = false; + els.doneBtn.textContent = "Terug naar de kast"; + } + + function openBook(id) { + const book = state.books.get(id); + if (!book) { + return; + } + + state.currentBookId = id; + state.bookReturnFocus = document.activeElement; + state.requestSerial += 1; + state.requestInFlight = false; + + els.dialogEmblem.innerHTML = renderEmblem(book.meta.emblem); + els.dialogTitle.textContent = book.meta.title; + els.dialogAuthor.textContent = book.meta.author; + els.dialogIntro.textContent = book.meta.intro; + els.dialogQuote.textContent = book.meta.quote; + els.question.textContent = book.meta.question; + els.feedback.textContent = ""; + els.feedback.className = "feedback"; + els.hint.hidden = true; + els.hint.textContent = ""; + els.stamp.hidden = true; + els.stamp.classList.remove("is-visible"); + els.doneBtn.hidden = true; + els.doneBtn.textContent = "Terug naar de kast"; + + renderOptions(book); + + els.bookModal.hidden = false; + syncBodyLock(); + playPageTurn(); + + window.setTimeout(() => { + if (book.solved) { + els.doneBtn.focus(); + return; + } + const firstOption = $(".option", els.options); + (firstOption || els.bookClose).focus(); + }, 90); + } + + async function answerBook(book, index) { + if (book.solved || state.requestInFlight) { + return; + } + + const serial = ++state.requestSerial; + state.requestInFlight = true; + const isCurrent = () => serial === state.requestSerial && state.currentBookId === book.id; + const optionButtons = $$(".option", els.options); + optionButtons.forEach((button) => { + button.disabled = true; + }); + els.feedback.className = "feedback"; + els.feedback.textContent = "Even bladeren..."; + ensureAudio(); + + try { + const response = await fetch("/api/solve", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ bookId: book.id, answer: index }) + }); + const data = await response.json().catch(() => ({})); + + if (!response.ok) { + throw new Error(data.error || "De leeshoek is even niet bereikbaar."); + } + + if (data.ok) { + markSolved(book, data, index, isCurrent()); + return; + } + + if (book.solved || !isCurrent()) { + return; + } + + book.attempts += 1; + const chosen = optionButtons[index]; + if (chosen) { + chosen.classList.add("is-wrong"); + window.setTimeout(() => chosen.classList.remove("is-wrong"), 700); + } + + const page = $(".page-right", els.bookDialog); + page.classList.remove("is-shaking"); + void page.offsetWidth; + page.classList.add("is-shaking"); + window.setTimeout(() => page.classList.remove("is-shaking"), 360); + + els.feedback.className = "feedback is-error"; + els.feedback.textContent = data.error || "Nog niet helemaal. Probeer het nog eens."; + if (book.attempts >= 2) { + els.hint.textContent = data.hint || book.meta.hint; + els.hint.hidden = false; + } + + playWrong(); + const extra = book.attempts >= 2 + ? "De hint staat in het boek." + : "Lees rustig verder."; + setLog(`Nog niet helemaal bij "${book.meta.title}". ${extra}`, "warning"); + } catch (error) { + if (isCurrent()) { + els.feedback.className = "feedback is-error"; + els.feedback.textContent = `${error.message} Probeer het zo nog eens.`; + playWrong(); + } + } finally { + if (serial === state.requestSerial) { + state.requestInFlight = false; + if (!book.solved && isCurrent()) { + optionButtons.forEach((button) => { + button.disabled = false; + }); + const firstOption = $(".option", els.options); + if (firstOption) { + firstOption.focus(); + } + } + } + } + } + + function markSolved(book, data, answerIndex, updateDialog) { + book.solved = true; + book.letter = String(data.letter || "").toUpperCase(); + book.answerIndex = answerIndex; + book.doneText = data.done || ""; + book.explanation = data.explanation || ""; + book.element.classList.add("is-solved"); + book.element.setAttribute( + "aria-label", + `${book.meta.title} van ${book.meta.author}, gelezen` + ); + + updateProgress(); + updateSlots(); + saveProgress(); + playCorrect(); + setLog(book.doneText || `Juist. De letter ${book.letter} is gevonden.`, "done"); + + if (updateDialog) { + $$(".option", els.options).forEach((button, index) => { + button.disabled = true; + if (index === answerIndex) { + button.classList.add("is-correct"); + } + }); + showSolvedState(book); + window.setTimeout(() => els.doneBtn.focus(), 260); + } + + if (state.solvedCount === state.order.length) { + unlockDrawer({ announce: true, sound: true }); + } + } + + function lockDrawer() { + els.drawer.classList.remove("is-unlocked", "is-locked-shake"); + els.drawerLabel.textContent = "Geheime lade"; + els.drawerHint.textContent = "Nog op slot"; + els.drawer.setAttribute("aria-label", "Geheime lade, nog op slot"); + } + + function unlockDrawer({ announce = true, sound = true } = {}) { + const wasLocked = !els.drawer.classList.contains("is-unlocked"); + els.drawer.classList.add("is-unlocked"); + els.drawerLabel.textContent = "Open de geheime lade"; + els.drawerHint.textContent = "Klik om te openen"; + els.drawer.setAttribute("aria-label", "Open de geheime lade"); + + if (wasLocked && sound) { + playUnlock(); + } + if (wasLocked && announce) { + setLog( + "Alle acht boeken zijn gelezen. De letters vormen LEESHOEK — de lade klikt open!", + "done" + ); + } + } + + function handleDrawer() { + if (state.order.length === 0) { + setLog("De boekenkast is nog niet geladen. Probeer de pagina even opnieuw.", "warning"); + return; + } + + if (state.solvedCount !== state.order.length) { + const remaining = state.order.length - state.solvedCount; + els.drawer.classList.remove("is-locked-shake"); + void els.drawer.offsetWidth; + els.drawer.classList.add("is-locked-shake"); + window.setTimeout(() => els.drawer.classList.remove("is-locked-shake"), 420); + + const message = remaining === 1 + ? "De lade zit nog op slot. Er is nog één boek te lezen." + : `De lade zit nog op slot. Er zijn nog ${remaining} boeken te lezen.`; + setLog(message, "warning"); + playWrong(); + return; + } + + openVoucher(); + } + + function openVoucher() { + state.voucherReturnFocus = document.activeElement; + els.voucherModal.hidden = false; + syncBodyLock(); + els.voucherCode.textContent = "code wordt gezocht..."; + els.voucherNote.textContent = ""; + els.voucherNote.style.color = ""; + els.copyButton.textContent = "Kopieer"; + els.copyButton.classList.remove("is-copied"); + + window.setTimeout(() => els.voucherClose.focus(), 80); + requestVoucher(); + } + + async function requestVoucher() { + const completed = state.order.filter((book) => book.solved).map((book) => book.id); + + try { + const response = await fetch("/api/reveal", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ completed }) + }); + const data = await response.json().catch(() => ({})); + + if (!response.ok || !data.ok) { + throw new Error(data.error || "De code kon niet worden opgehaald."); + } + + els.voucherCode.textContent = data.code; + els.voucherRecipient.textContent = `Voor ${data.recipient || state.config.recipient}`; + els.voucherDate.textContent = data.eventDate || state.config.eventDate; + els.voucherNote.textContent = "De code staat klaar. Kopieer hem of houd deze pagina open."; + els.voucherNote.style.color = ""; + playFanfare(); + launchConfetti(); + } catch (error) { + els.voucherCode.textContent = "—"; + els.voucherNote.textContent = `${error.message} Probeer het opnieuw.`; + els.voucherNote.style.color = "#a33b22"; + } + } + + function syncBodyLock() { + const open = !els.bookModal.hidden || !els.voucherModal.hidden; + document.body.classList.toggle("has-modal", open); + } + + function closeBookModal() { + if (els.bookModal.hidden) { + return; + } + els.bookModal.hidden = true; + state.currentBookId = null; + state.requestInFlight = false; + state.requestSerial += 1; + syncBodyLock(); + + const target = state.bookReturnFocus; + if (target && typeof target.focus === "function") { + target.focus(); + } + } + + function closeVoucher() { + if (els.voucherModal.hidden) { + return; + } + els.voucherModal.hidden = true; + stopConfetti(); + syncBodyLock(); + + const target = state.voucherReturnFocus; + if (target && typeof target.focus === "function") { + target.focus(); + } else { + els.drawer.focus(); + } + } + + function resetGame() { + state.books.forEach((book) => { + book.solved = false; + book.attempts = 0; + book.letter = ""; + book.answerIndex = null; + book.doneText = ""; + book.explanation = ""; + book.element.classList.remove("is-solved"); + book.element.setAttribute( + "aria-label", + `${book.meta.title} van ${book.meta.author} openen` + ); + }); + + try { + window.localStorage.removeItem(STORAGE_KEY); + } catch { + } + + lockDrawer(); + updateProgress(); + updateSlots(); + els.secret.classList.remove("is-complete"); + els.log.className = "log"; + setLog("Nieuwe ronde, dezelfde kast. Kies een boek en begin opnieuw.", "done"); + closeVoucher(); + + state.currentBookId = null; + state.requestInFlight = false; + state.requestSerial += 1; + if (state.order[0]) { + state.order[0].element.focus(); + } + } + + function resizeConfetti() { + const ratio = Math.min(2, window.devicePixelRatio || 1); + els.confetti.width = Math.floor(window.innerWidth * ratio); + els.confetti.height = Math.floor(window.innerHeight * ratio); + confettiContext.setTransform(ratio, 0, 0, ratio, 0, 0); + } + + function launchConfetti() { + if (reduceMotion) { + return; + } + resizeConfetti(); + + const colors = ["#f0c96a", "#d9a441", "#f6ecd8", "#8c3b3b", "#6f8f6a", "#3b7a6e", "#62477c", "#fff7e3"]; + state.confettiParticles = Array.from({ length: 180 }, () => ({ + x: Math.random() * window.innerWidth, + y: -30 - Math.random() * window.innerHeight * 0.55, + vx: (Math.random() - 0.5) * 120, + vy: 80 + Math.random() * 170, + width: 5 + Math.random() * 7, + height: 8 + Math.random() * 11, + rotation: Math.random() * Math.PI, + spin: (Math.random() - 0.5) * 11, + color: pick(colors) + })); + + if (state.confettiFrame) { + window.cancelAnimationFrame(state.confettiFrame); + } + + let last = performance.now(); + const tick = (now) => { + const delta = Math.min(0.05, (now - last) / 1000); + last = now; + confettiContext.clearRect(0, 0, window.innerWidth, window.innerHeight); + + let visible = 0; + state.confettiParticles.forEach((particle) => { + particle.vy += 190 * delta; + particle.x += particle.vx * delta; + particle.y += particle.vy * delta; + particle.rotation += particle.spin * delta; + + if (particle.y < window.innerHeight + 40) { + visible += 1; + } + + confettiContext.save(); + confettiContext.translate(particle.x, particle.y); + confettiContext.rotate(particle.rotation); + confettiContext.fillStyle = particle.color; + confettiContext.fillRect( + -particle.width / 2, + -particle.height / 2, + particle.width, + particle.height + ); + confettiContext.restore(); + }); + + if (visible > 0) { + state.confettiFrame = window.requestAnimationFrame(tick); + } else { + state.confettiFrame = null; + confettiContext.clearRect(0, 0, window.innerWidth, window.innerHeight); + } + }; + + state.confettiFrame = window.requestAnimationFrame(tick); + window.setTimeout(stopConfetti, 8000); + } + + function stopConfetti() { + if (state.confettiFrame) { + window.cancelAnimationFrame(state.confettiFrame); + state.confettiFrame = null; + } + state.confettiParticles = []; + confettiContext.clearRect(0, 0, window.innerWidth, window.innerHeight); + } + + function legacyCopy(text) { + const field = document.createElement("textarea"); + field.value = text; + field.setAttribute("readonly", ""); + field.style.position = "fixed"; + field.style.opacity = "0"; + document.body.appendChild(field); + field.select(); + try { + document.execCommand("copy"); + } catch { + } + field.remove(); + } + + async function copyCode() { + const code = els.voucherCode.textContent.trim(); + const busy = !code || code === "..." || code.startsWith("code wordt") || code === "—"; + if (busy) { + return; + } + + try { + await navigator.clipboard.writeText(code); + } catch { + legacyCopy(code); + } + + els.copyButton.textContent = "Gekopieerd"; + els.copyButton.classList.add("is-copied"); + els.voucherNote.textContent = "De code staat op je klembord."; + els.voucherNote.style.color = ""; + window.setTimeout(() => { + els.copyButton.textContent = "Kopieer"; + els.copyButton.classList.remove("is-copied"); + }, 2200); + } + + function applyConfig(config) { + const setText = (selector, value) => { + const node = $(selector); + if (node && value) { + node.textContent = value; + } + }; + + setText("#recipient-name", config.recipient); + setText("#footer-name", config.recipient); + setText("#footer-date", config.eventDate); + setText("#plaque-recipient", `Voor ${config.recipient}`); + setText("#voucher-recipient", `Voor ${config.recipient}`); + setText("#voucher-date", config.eventDate); + setText("#game-title", config.title); + setText("#game-subtitle", config.subtitle); + setText( + "#voucher-lead", + `${config.recipient}, je hebt alle acht boeken gelezen. Achter de kast lag een envelop met iets om zelf een nieuw verhaal uit te kiezen.` + ); + + if (config.title) { + document.title = config.title; + } + } + + function trapFocus(event, container) { + if (event.key !== "Tab") { + return; + } + + const focusable = $$( + 'button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])', + container + ).filter((element) => element.getClientRects().length > 0); + + if (focusable.length === 0) { + return; + } + + const first = focusable[0]; + const last = focusable[focusable.length - 1]; + + if (event.shiftKey && document.activeElement === first) { + event.preventDefault(); + last.focus(); + } else if (!event.shiftKey && document.activeElement === last) { + event.preventDefault(); + first.focus(); + } + } + + function bindEvents() { + els.soundButton.addEventListener("click", () => { + state.soundOn = !state.soundOn; + try { + window.localStorage.setItem(SOUND_KEY, state.soundOn ? "aan" : "uit"); + } catch { + } + updateSoundButton(); + if (state.soundOn) { + playTone({ freq: 660, endFreq: 880, type: "triangle", duration: 0.12, gain: 0.08 }); + } + }); + + els.bookClose.addEventListener("click", closeBookModal); + els.doneBtn.addEventListener("click", closeBookModal); + els.voucherClose.addEventListener("click", closeVoucher); + els.playAgain.addEventListener("click", resetGame); + els.copyButton.addEventListener("click", copyCode); + els.drawer.addEventListener("click", handleDrawer); + + $$("[data-close]").forEach((node) => { + node.addEventListener("click", () => { + if (node.dataset.close === "book") { + closeBookModal(); + } else { + closeVoucher(); + } + }); + }); + + document.addEventListener("keydown", (event) => { + if (event.key === "Escape") { + if (!els.voucherModal.hidden) { + closeVoucher(); + return; + } + if (!els.bookModal.hidden) { + closeBookModal(); + } + return; + } + + if (!els.voucherModal.hidden) { + trapFocus(event, els.voucherModal); + } else if (!els.bookModal.hidden) { + trapFocus(event, els.bookDialog); + } + }); + + window.addEventListener("resize", () => { + if (state.confettiParticles.length > 0) { + resizeConfetti(); + } + }); + } + + async function init() { + updateSoundButton(); + bindEvents(); + lockDrawer(); + + try { + const response = await fetch("/api/config", { cache: "no-store" }); + if (!response.ok) { + throw new Error("De boekenkast is niet bereikbaar."); + } + const config = await response.json(); + state.config = config; + applyConfig(config); + buildBooks(config); + + if (state.solvedCount === state.order.length) { + unlockDrawer({ announce: false, sound: false }); + setLog( + "Welkom terug. Alle acht boeken zijn al gelezen — de lade staat op je te wachten.", + "done" + ); + } else if (state.solvedCount > 0) { + setLog( + `Welkom terug. Je was bij ${state.solvedCount} van ${state.order.length} boeken. De kast houdt je plekje warm.`, + "done" + ); + } else { + setLog("De kast staat klaar. Kies een boek en los de kleine opdracht op."); + } + } catch (error) { + setLog(`De boekenkast kon niet geladen worden: ${error.message}`, "warning"); + els.progressText.textContent = "Niet geladen"; + els.progressPercent.textContent = "—"; + } + } + + init(); +})(); diff --git a/Dockers/mama-boek-game/app/static/index.html b/Dockers/mama-boek-game/app/static/index.html new file mode 100644 index 0000000..76f059c --- /dev/null +++ b/Dockers/mama-boek-game/app/static/index.html @@ -0,0 +1,152 @@ + + + + + + + + Mama's Geheime Leeshoek + + + +
+
+

Een verhaal voor Mama

+

Mama's Geheime Leeshoek

+

Lees de acht boeken, vind het geheimwoord en open de lade.

+
+ +
+
+
+
+ 0 / 8 boeken gelezen + 0% +
+
+ +
+
+ + +
+ +
+
+ + +
+
+
+
+ +
+ De leeshoek + + Voor Mama +
+
+
+ +
+

Het geheimwoord

+
+

Elk gelezen boek onthult één letter.

+
+ +
+

De kast staat klaar. Kies een boek en los de kleine opdracht op.

+
+ +

Klik op een boek om het te openen. Er is geen tijdsdruk — elk verhaal wacht geduldig.

+
+ +
+ Met liefde geschreven voor Mama + vandaag +
+
+ + + + + + + + + + diff --git a/Dockers/mama-boek-game/app/static/style.css b/Dockers/mama-boek-game/app/static/style.css new file mode 100644 index 0000000..46cccc2 --- /dev/null +++ b/Dockers/mama-boek-game/app/static/style.css @@ -0,0 +1,1639 @@ +:root { + color-scheme: dark; + --ink: #0d1712; + --ink-2: #13231b; + --panel: #182a21; + --panel-2: #20362b; + --wood: #4a2f1d; + --wood-light: #7a4e2e; + --wood-dark: #2b190e; + --paper: #f6ecd8; + --paper-2: #ead9b7; + --cream: #f7eedb; + --muted: #b6c1b3; + --brass: #d9a441; + --brass-bright: #f0c96a; + --brass-dark: #9a6b23; + --burgundy: #8c3b3b; + --sage: #6f8f6a; + --teal: #3b7a6e; + --plum: #62477c; + --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif; + --sans: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, sans-serif; + --shadow: 0 26px 70px rgba(0, 0, 0, .5); +} + +* { + box-sizing: border-box; +} + +[hidden] { + display: none !important; +} + +html, +body { + min-height: 100%; +} + +body { + margin: 0; + padding: 0; + font-family: var(--sans); + background: + radial-gradient(ellipse at 50% -12%, rgba(217, 164, 65, .13), transparent 55%), + radial-gradient(ellipse at 86% 108%, rgba(59, 122, 110, .14), transparent 52%), + radial-gradient(ellipse at 8% 82%, rgba(140, 59, 59, .08), transparent 48%), + linear-gradient(180deg, #0f1a14, #0a110d 72%); + color: var(--cream); + overflow-x: hidden; +} + +body::before { + content: ""; + position: fixed; + inset: 0 0 auto; + height: 9px; + background: + repeating-linear-gradient(90deg, rgba(240, 201, 106, .9) 0 2px, transparent 2px 16px), + linear-gradient(180deg, #8a5f24, #3a2915); + z-index: 3000; +} + +body.has-modal { + overflow: hidden; +} + +button { + font: inherit; + color: inherit; +} + +.page { + width: min(1180px, 100%); + margin: 0 auto; + padding: clamp(22px, 4vw, 44px) clamp(12px, 3vw, 30px) 38px; +} + +.hero { + text-align: center; + margin-bottom: clamp(20px, 3.2vw, 34px); +} + +.eyebrow { + display: inline-flex; + flex-wrap: wrap; + justify-content: center; + gap: .35em; + margin: 0 0 14px; + padding: 7px 16px; + border: 1px solid rgba(217, 164, 65, .38); + border-radius: 999px; + background: rgba(217, 164, 65, .07); + color: var(--brass-bright); + font-size: clamp(.7rem, 1.5vw, .82rem); + font-weight: 800; + letter-spacing: .16em; + text-transform: uppercase; +} + +.eyebrow span { + color: var(--cream); +} + +h1 { + margin: 0; + font-family: var(--serif); + font-size: clamp(2.1rem, 6vw, 4.2rem); + font-weight: 700; + line-height: 1; + letter-spacing: -.015em; + text-wrap: balance; + text-shadow: 0 3px 0 rgba(0, 0, 0, .35), 0 0 50px rgba(217, 164, 65, .13); +} + +.hero::after { + content: ""; + display: block; + width: min(200px, 50%); + height: 1px; + margin: 18px auto 0; + background: linear-gradient(90deg, transparent, var(--brass), transparent); + box-shadow: 0 0 12px rgba(217, 164, 65, .4); +} + +.tagline { + margin: 14px auto 0; + max-width: 46ch; + color: var(--muted); + font-size: clamp(.95rem, 2vw, 1.15rem); + line-height: 1.5; +} + +.game-shell { + position: relative; + padding: clamp(12px, 2vw, 20px); + border: 1px solid #3c4a3d; + border-radius: 22px; + background: linear-gradient(180deg, #1a2b22, #131f19); + box-shadow: var(--shadow); +} + +.hud { + display: grid; + grid-template-columns: minmax(200px, 1fr) auto; + gap: clamp(12px, 2vw, 22px); + align-items: center; + margin-bottom: 14px; + padding: 0 clamp(2px, 1vw, 8px); +} + +.progress-copy { + display: flex; + justify-content: space-between; + gap: 12px; + margin-bottom: 7px; + color: var(--muted); + font-size: clamp(.72rem, 1.4vw, .84rem); + font-weight: 700; + letter-spacing: .08em; + text-transform: uppercase; +} + +#progress-percent { + color: var(--brass-bright); +} + +.progress-track { + height: 13px; + border: 1px solid #3c4a3d; + border-radius: 999px; + background: #0b130f; + overflow: hidden; + box-shadow: inset 0 2px 5px rgba(0, 0, 0, .55); +} + +#progress-bar { + display: block; + width: 0; + height: 100%; + border-radius: inherit; + background: + repeating-linear-gradient(-45deg, rgba(255, 255, 255, .18) 0 7px, transparent 7px 14px), + linear-gradient(90deg, #9a6b23, var(--brass), var(--brass-bright)); + transition: width .4s cubic-bezier(.2, .8, .3, 1); +} + +.icon-btn { + display: grid; + place-items: center; + width: 48px; + height: 48px; + padding: 0; + border: 1px solid #4a5c4b; + border-radius: 50%; + background: #101b15; + color: var(--muted); + cursor: pointer; + transition: color .15s, border-color .15s, transform .12s; +} + +.icon-btn:hover { + color: var(--cream); + border-color: #7d8f75; + transform: translateY(-1px); +} + +.icon-btn svg { + width: 25px; + height: 25px; +} + +.icon-btn .sound-off { + display: none; +} + +.icon-btn[aria-pressed="false"] .sound-on { + display: none; +} + +.icon-btn[aria-pressed="false"] .sound-off { + display: block; +} + +.stage { + padding: clamp(5px, 1.2vw, 10px); + border-radius: 18px; + background: #070d0a; + box-shadow: inset 0 2px 24px rgba(0, 0, 0, .8); +} + +.bookcase { + position: relative; + padding: clamp(14px, 2.4vw, 26px); + border: 1px solid #8a5b33; + border-radius: 15px; + background: + linear-gradient(90deg, rgba(0, 0, 0, .35), transparent 5%, transparent 95%, rgba(0, 0, 0, .35)), + linear-gradient(180deg, #54351f, #331f10 55%, #24150b); + box-shadow: + inset 0 0 0 2px rgba(255, 214, 150, .09), + inset 0 0 42px rgba(0, 0, 0, .55), + 0 18px 36px rgba(0, 0, 0, .4); + isolation: isolate; +} + +.bookcase::before { + content: ""; + position: absolute; + inset: 8px; + border: 1px solid rgba(0, 0, 0, .35); + border-radius: 10px; + pointer-events: none; + z-index: 0; +} + +.bookcase-decor { + position: absolute; + inset: clamp(5px, 1vw, 10px) clamp(12px, 2vw, 24px) auto; + height: 26px; + pointer-events: none; + z-index: 4; +} + +.string-lights { + position: relative; + display: flex; + justify-content: space-between; + height: 100%; + padding: 0 3%; +} + +.string-lights::before { + content: ""; + position: absolute; + left: 0; + right: 0; + top: 5px; + height: 1px; + background: linear-gradient(90deg, transparent, #87663a 8%, #87663a 92%, transparent); + opacity: .75; +} + +.string-lights span { + position: relative; + width: clamp(4px, .7vw, 7px); + height: clamp(7px, 1.2vw, 11px); + margin-top: 2px; + border-radius: 45% 45% 50% 50%; + background: radial-gradient(circle at 50% 30%, #fff6c8, #f0c96a 55%, #a36b1e 100%); + box-shadow: 0 0 9px rgba(255, 214, 120, .65), 0 0 22px rgba(255, 196, 70, .22); + animation: twinkle 3.4s ease-in-out infinite alternate; +} + +.string-lights span:nth-child(2n) { + animation-delay: -1.1s; +} + +.string-lights span:nth-child(3n) { + animation-delay: -2.2s; + height: clamp(6px, 1vw, 9px); +} + +.string-lights span:nth-child(5n) { + animation-delay: -.6s; +} + +.shelf-grid { + position: relative; + display: grid; + gap: clamp(14px, 2.6vw, 30px); + padding: clamp(26px, 4vw, 42px) clamp(10px, 2.2vw, 26px) clamp(10px, 2vw, 20px); + border: 1px solid #0c1a13; + border-radius: 8px; + background: + radial-gradient(ellipse at 50% 0%, rgba(240, 201, 106, .07), transparent 60%), + repeating-linear-gradient(90deg, rgba(255, 255, 255, .018) 0 1px, transparent 1px 42px), + linear-gradient(180deg, #163027, #0e2019 60%, #0b1913); + box-shadow: + inset 0 0 60px rgba(0, 0, 0, .55), + inset 0 0 0 4px #241509, + inset 0 0 0 6px #6b4527; + z-index: 2; +} + +.shelf { + position: relative; + display: grid; + grid-template-columns: repeat(4, minmax(0, 1fr)); + gap: clamp(8px, 1.7vw, 22px); + align-items: end; + padding: 0 clamp(2px, 1vw, 12px) clamp(15px, 2.4vw, 24px); +} + +.shelf::before { + content: ""; + position: absolute; + left: 0; + right: 0; + bottom: 0; + height: 30%; + background: linear-gradient(180deg, transparent, rgba(0, 0, 0, .34)); + pointer-events: none; +} + +.shelf::after { + content: ""; + position: absolute; + left: -3%; + right: -3%; + bottom: 0; + height: clamp(9px, 1.4vw, 14px); + border: 1px solid #a06a3d; + border-radius: 3px; + background: linear-gradient(180deg, #9a653b, #6b4326 55%, #3d2413); + box-shadow: 0 6px 10px rgba(0, 0, 0, .5), inset 0 1px 0 rgba(255, 224, 170, .25); + z-index: 2; +} + +.book { + position: relative; + display: block; + width: 100%; + aspect-ratio: 3 / 4.35; + padding: 0; + border: 0; + background: none; + cursor: pointer; + -webkit-tap-highlight-color: transparent; + transform-origin: center bottom; +} + +.book-cover { + position: absolute; + inset: 0; + display: flex; + flex-direction: column; + align-items: center; + padding: clamp(7px, 1.3vw, 14px) clamp(7px, 1.2vw, 13px) clamp(8px, 1.4vw, 14px) calc(clamp(7px, 1.2vw, 12px) + 5px); + border-radius: 3px 6px 6px 3px; + background: + radial-gradient(circle at 28% 18%, rgba(255, 255, 255, .12), transparent 36%), + linear-gradient(150deg, var(--cover, #2e4a30), var(--cover-2, #557c4c)); + color: var(--book-ink, var(--cream)); + box-shadow: + 0 10px 18px rgba(0, 0, 0, .42), + inset 0 0 0 1px rgba(255, 255, 255, .13); + overflow: hidden; + transition: transform .18s ease, box-shadow .2s ease, filter .2s ease; + transform-origin: center bottom; +} + +.book-cover::before { + content: ""; + position: absolute; + inset: 0 auto 0 0; + width: 7%; + border-right: 1px solid rgba(0, 0, 0, .28); + background: linear-gradient(90deg, rgba(0, 0, 0, .55), rgba(255, 255, 255, .09) 62%, rgba(0, 0, 0, .16)); +} + +.book-cover::after { + content: ""; + position: absolute; + top: 2%; + right: 0; + bottom: 2%; + width: 4px; + border-radius: 0 2px 2px 0; + background: repeating-linear-gradient(0deg, #f4ead2 0 2px, #cbbb9b 2px 3px); + opacity: .8; +} + +.book-frame { + position: absolute; + inset: 6% 7% 6% 11%; + border: 1px solid rgba(255, 255, 255, .22); + border-radius: 2px; + box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12); + pointer-events: none; +} + +.book-emblem { + position: relative; + display: grid; + place-items: center; + width: 44%; + aspect-ratio: 1; + margin: 7% 0 6%; + border: 1px solid rgba(255, 255, 255, .3); + border-radius: 50%; + background: rgba(0, 0, 0, .13); + box-shadow: inset 0 0 14px rgba(0, 0, 0, .2); +} + +.book-emblem svg { + width: 62%; + height: 62%; + overflow: visible; +} + +.book-title { + position: relative; + display: -webkit-box; + max-width: 100%; + overflow: hidden; + -webkit-box-orient: vertical; + -webkit-line-clamp: 4; + font-family: var(--serif); + font-size: clamp(.56rem, 1.45vw, .9rem); + font-weight: 700; + line-height: 1.14; + letter-spacing: .015em; + text-align: center; + text-wrap: balance; + text-shadow: 0 1px 2px rgba(0, 0, 0, .4); +} + +.book-author { + position: relative; + max-width: 100%; + margin-top: auto; + padding-top: 6%; + overflow: hidden; + font-size: clamp(.4rem, .95vw, .6rem); + letter-spacing: .08em; + text-align: center; + text-transform: uppercase; + opacity: .72; + text-overflow: ellipsis; + white-space: nowrap; +} + +.book-state { + position: absolute; + right: 8%; + bottom: 6%; + z-index: 3; + display: grid; + place-items: center; + width: 17%; + aspect-ratio: 1; + border-radius: 50%; + background: linear-gradient(180deg, var(--brass-bright), var(--brass)); + color: #2c1c0b; + box-shadow: 0 2px 6px rgba(0, 0, 0, .35); + font-size: clamp(.45rem, 1vw, .7rem); + font-weight: 900; + opacity: 0; + transform: scale(.4); + transition: opacity .22s, transform .24s cubic-bezier(.2, .9, .3, 1.4); +} + +.book-state::before { + content: "\2713"; +} + +.bookmark { + position: absolute; + top: -7px; + right: 13%; + z-index: 4; + width: 12%; + height: 31%; + background: linear-gradient(180deg, var(--brass-bright), var(--brass-dark)); + clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 80%, 0 100%); + box-shadow: 0 4px 8px rgba(0, 0, 0, .35); + opacity: 0; + transform: translateY(-14px) rotate(8deg); + transition: opacity .25s, transform .3s cubic-bezier(.2, .9, .3, 1.3); + pointer-events: none; +} + +.book:hover .book-cover, +.book:focus-visible .book-cover { + transform: translateY(-6px) rotate(-1.2deg); + box-shadow: + 0 18px 26px rgba(0, 0, 0, .5), + 0 0 0 2px rgba(240, 201, 106, .85), + 0 0 24px rgba(240, 201, 106, .18); +} + +.book:nth-child(even):hover .book-cover, +.book:nth-child(even):focus-visible .book-cover { + transform: translateY(-6px) rotate(1deg); +} + +.book:focus-visible { + outline: none; +} + +.book:active .book-cover { + transform: translateY(-2px) scale(.99); +} + +.book.is-solved .book-cover { + box-shadow: + 0 0 0 2px var(--brass), + 0 10px 22px rgba(0, 0, 0, .46), + 0 0 28px rgba(217, 164, 65, .2); +} + +.book.is-solved .book-emblem { + color: var(--brass-bright); + border-color: rgba(240, 201, 106, .62); + background: rgba(0, 0, 0, .22); +} + +.book.is-solved .book-state { + opacity: 1; + transform: scale(1); +} + +.book.is-solved .bookmark { + opacity: 1; + transform: translateY(0) rotate(0); +} + +.book.is-solved .book-author { + opacity: .9; +} + +.bookcase-base { + position: relative; + z-index: 3; + display: flex; + align-items: center; + justify-content: space-between; + gap: clamp(8px, 1.6vw, 18px); + margin-top: clamp(10px, 1.8vw, 18px); + padding: 0 clamp(2px, 1vw, 10px); +} + +.plaque { + flex: none; + padding: 6px 10px; + border: 1px solid rgba(217, 164, 65, .34); + border-radius: 4px; + background: rgba(0, 0, 0, .22); + color: var(--brass-bright); + font-family: var(--serif); + font-size: clamp(.52rem, 1.2vw, .68rem); + font-weight: 700; + letter-spacing: .18em; + text-transform: uppercase; + opacity: .9; +} + +.plaque-right { + text-align: right; +} + +.drawer { + position: relative; + flex: 0 1 360px; + margin: 0 auto; + padding: 0; + border: 0; + background: none; + cursor: pointer; + -webkit-tap-highlight-color: transparent; +} + +.drawer-front { + position: relative; + display: block; + padding: clamp(15px, 2.4vw, 22px) 18px clamp(10px, 1.8vw, 14px); + border: 1px solid #96663a; + border-radius: 6px; + background: + linear-gradient(180deg, rgba(255, 255, 255, .06), transparent 35%), + linear-gradient(180deg, #744a29, #4d2e18 60%, #3a2110); + box-shadow: + inset 0 1px 0 rgba(255, 223, 170, .16), + inset 0 0 18px rgba(0, 0, 0, .25), + 0 7px 14px rgba(0, 0, 0, .42); + transition: box-shadow .25s, border-color .25s; +} + +.drawer-front::before { + content: ""; + position: absolute; + inset: 4px; + border: 1px solid rgba(0, 0, 0, .28); + border-radius: 3px; + pointer-events: none; +} + +.drawer-handle { + position: relative; + display: block; + width: 31%; + height: 7px; + margin: 0 auto 10px; + border-radius: 999px; + background: linear-gradient(180deg, #f0c96a, #a67527 70%, #6d4a17); + box-shadow: 0 2px 3px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255, 246, 200, .5); +} + +.drawer-keyhole { + position: absolute; + top: 38%; + right: 13%; + width: 9px; + height: 13px; + border-radius: 50% 50% 42% 42%; + background: #1f1208; + box-shadow: inset 0 1px 2px rgba(0, 0, 0, .8), 0 0 0 1px rgba(240, 201, 106, .22); +} + +.drawer-keyhole::after { + content: ""; + position: absolute; + left: 50%; + top: 72%; + width: 3px; + height: 7px; + transform: translateX(-50%); + background: #1f1208; +} + +.drawer-label { + display: block; + color: var(--cream); + font-family: var(--serif); + font-size: clamp(.62rem, 1.3vw, .8rem); + font-weight: 700; + letter-spacing: .15em; + text-align: center; + text-transform: uppercase; +} + +.drawer-hint { + display: block; + margin-top: 3px; + color: #d3b98f; + font-size: clamp(.5rem, 1.1vw, .62rem); + font-weight: 700; + letter-spacing: .1em; + text-align: center; + text-transform: uppercase; +} + +.drawer:hover .drawer-front { + border-color: var(--brass); +} + +.drawer:focus-visible { + outline: none; +} + +.drawer:focus-visible .drawer-front { + box-shadow: + 0 0 0 2px var(--brass-bright), + 0 0 22px rgba(240, 201, 106, .3), + 0 7px 14px rgba(0, 0, 0, .42); +} + +.drawer.is-unlocked .drawer-front { + border-color: var(--brass-bright); + box-shadow: + 0 0 0 2px rgba(240, 201, 106, .3), + 0 0 32px rgba(240, 201, 106, .34), + 0 7px 14px rgba(0, 0, 0, .42); + animation: drawer-glow 2.4s ease-in-out infinite alternate; +} + +.drawer.is-unlocked .drawer-handle { + background: linear-gradient(180deg, #fff3bd, #f0c96a 55%, #b8862e); + box-shadow: 0 0 12px rgba(240, 201, 106, .6), 0 2px 3px rgba(0, 0, 0, .4); +} + +.drawer.is-unlocked .drawer-hint { + color: var(--brass-bright); +} + +.drawer.is-locked-shake .drawer-front { + animation: drawer-shake .35s ease; +} + +.secret { + display: flex; + flex-direction: column; + align-items: center; + gap: 9px; + margin-top: 14px; + padding: 13px clamp(12px, 2vw, 20px); + border: 1px solid #3a4a3c; + border-radius: 14px; + background: rgba(9, 17, 12, .62); + box-shadow: inset 0 1px 8px rgba(0, 0, 0, .3); +} + +.secret-label { + margin: 0; + color: var(--muted); + font-size: clamp(.6rem, 1.25vw, .7rem); + font-weight: 800; + letter-spacing: .22em; + text-transform: uppercase; +} + +.slots { + display: flex; + flex-wrap: wrap; + justify-content: center; + gap: clamp(5px, .9vw, 9px); +} + +.slot { + display: grid; + place-items: center; + width: clamp(30px, 4.6vw, 48px); + aspect-ratio: 1 / 1.15; + border: 1px dashed rgba(217, 164, 65, .32); + border-radius: 5px; + background: rgba(0, 0, 0, .2); + color: transparent; + font-family: var(--serif); + font-size: clamp(.95rem, 2.4vw, 1.5rem); + font-weight: 700; + transition: background .2s, border-color .2s, color .2s; +} + +.slot::before { + content: ""; + width: 38%; + height: 2px; + border-radius: 2px; + background: rgba(217, 164, 65, .22); +} + +.slot.filled { + border-style: solid; + border-color: var(--brass); + background: linear-gradient(180deg, #f9efd3, #e3c98a); + color: #2d1f0d; + box-shadow: 0 4px 10px rgba(0, 0, 0, .3); + animation: slot-pop .42s cubic-bezier(.2, .9, .3, 1.25); +} + +.slot.filled::before { + display: none; +} + +.secret.is-complete .slot { + box-shadow: 0 0 18px rgba(240, 201, 106, .38), 0 4px 10px rgba(0, 0, 0, .3); +} + +.secret-hint { + margin: 0; + color: #8d9a8d; + font-size: clamp(.66rem, 1.3vw, .76rem); + text-align: center; +} + +.secret.is-complete .secret-hint { + color: var(--brass-bright); + font-weight: 700; +} + +.underbar { + margin-top: 14px; +} + +.log { + min-height: 3.4em; + margin: 0; + padding: 11px 15px; + border-left: 4px solid var(--brass); + border-radius: 0 10px 10px 0; + background: #0d1812; + color: #e5dccb; + font-size: clamp(.86rem, 1.6vw, .98rem); + line-height: 1.5; +} + +.log.is-warning { + border-left-color: var(--burgundy); + color: #f0c9c1; +} + +.log.is-done { + border-left-color: var(--sage); + color: #e4efd8; +} + +.controls-hint { + margin: 14px 2px 0; + color: #8b998b; + font-size: clamp(.74rem, 1.4vw, .84rem); + line-height: 1.6; +} + +.footer { + display: flex; + justify-content: space-between; + gap: 14px; + margin-top: 22px; + padding: 0 4px; + color: #849183; + font-size: .78rem; + letter-spacing: .04em; +} + +.footer-date { + color: #a8b3a3; + font-weight: 700; + letter-spacing: .12em; + text-transform: uppercase; +} + +#confetti { + position: fixed; + inset: 0; + z-index: 2600; + width: 100%; + height: 100%; + pointer-events: none; +} + +.modal { + position: fixed; + inset: 0; + z-index: 2500; + display: flex; + padding: clamp(12px, 3vw, 30px); + overflow-y: auto; +} + +.modal[hidden] { + display: none; +} + +.modal-backdrop { + position: fixed; + inset: 0; + background: rgba(5, 9, 7, .84); + backdrop-filter: blur(8px); + animation: fade-in .28s ease; +} + +.book-dialog { + position: relative; + z-index: 1; + display: grid; + grid-template-columns: 1fr 1fr; + width: min(960px, 100%); + margin: auto; + border-radius: 10px; + background: var(--paper); + box-shadow: 0 34px 90px rgba(0, 0, 0, .72), 0 0 0 1px rgba(240, 201, 106, .28); + color: #2b2114; + transform: rotate(-.35deg); + animation: book-open .48s cubic-bezier(.2, .9, .3, 1.05); + overflow: hidden; +} + +.book-dialog::before { + content: ""; + position: absolute; + top: 0; + bottom: 0; + left: 50%; + z-index: 2; + width: 30px; + transform: translateX(-50%); + background: linear-gradient(90deg, transparent, rgba(74, 48, 22, .3), rgba(74, 48, 22, .12), transparent); + pointer-events: none; +} + +.page-right.is-shaking { + animation: dialog-shake .34s ease; +} + +@keyframes dialog-shake { + 0%, 100% { transform: translateX(0); } + 25% { transform: translateX(-6px); } + 55% { transform: translateX(5px); } + 80% { transform: translateX(-2px); } +} + +.book-page { + position: relative; + min-height: 470px; + padding: clamp(24px, 4vw, 44px); + background: + radial-gradient(circle at 8% 6%, rgba(255, 255, 255, .9), transparent 30%), + linear-gradient(180deg, #fbf4e4, #efe1c3); +} + +.page-left { + border-right: 1px solid rgba(100, 70, 30, .18); + background: + radial-gradient(circle at 12% 8%, rgba(255, 255, 255, .92), transparent 32%), + radial-gradient(circle at 82% 96%, rgba(154, 107, 35, .1), transparent 40%), + linear-gradient(180deg, #fcf6e8, #f0e2c4); +} + +.page-right { + background: + radial-gradient(circle at 88% 8%, rgba(255, 255, 255, .92), transparent 32%), + radial-gradient(circle at 12% 92%, rgba(154, 107, 35, .1), transparent 40%), + linear-gradient(180deg, #fbf3e1, #eedfbf); +} + +.page-corner { + position: absolute; + top: 0; + left: 0; + width: 42px; + height: 42px; + background: linear-gradient(135deg, #e4d2ad, #f8efd9 55%, transparent 56%); + border-radius: 10px 0 0; + opacity: .8; + pointer-events: none; +} + +.modal-close { + position: absolute; + top: 12px; + right: 12px; + z-index: 6; + display: grid; + place-items: center; + width: 38px; + height: 38px; + padding: 0; + border: 1px solid rgba(120, 88, 38, .45); + border-radius: 50%; + background: rgba(255, 249, 235, .72); + color: #6d5326; + font-size: 1.4rem; + line-height: 1; + cursor: pointer; + transition: background .15s, transform .12s; +} + +.modal-close:hover { + background: #fff9eb; + transform: rotate(90deg); +} + +.modal-close:focus-visible { + outline: 2px solid var(--brass-dark); + outline-offset: 2px; +} + +.book-emblem-large { + display: grid; + place-items: center; + width: clamp(72px, 12vw, 108px); + aspect-ratio: 1; + margin: 0 auto clamp(16px, 2.4vw, 24px); + border: 1px solid rgba(154, 107, 35, .55); + border-radius: 50%; + background: radial-gradient(circle at 34% 28%, #fff8e6, #ead8b4); + color: #8a6226; + box-shadow: inset 0 0 0 4px rgba(255, 255, 255, .38), 0 5px 14px rgba(74, 48, 22, .14); +} + +.book-emblem-large svg { + width: 58%; + height: 58%; + overflow: visible; +} + +.book-kicker, +.task-kicker { + margin: 0 0 7px; + color: #9a742f; + font-size: .66rem; + font-weight: 800; + letter-spacing: .24em; + text-align: center; + text-transform: uppercase; +} + +.task-kicker { + text-align: left; +} + +.book-dialog h2 { + margin: 0; + font-family: var(--serif); + font-size: clamp(1.65rem, 4vw, 2.5rem); + line-height: 1.04; + text-align: center; + text-wrap: balance; +} + +.book-byline { + margin: 8px 0 0; + color: #826a43; + font-size: .78rem; + font-style: italic; + letter-spacing: .04em; + text-align: center; +} + +.page-left > .book-intro { + max-width: 34ch; + margin: clamp(18px, 3vw, 28px) auto 0; + color: #56452c; + font-size: clamp(.94rem, 1.8vw, 1.05rem); + line-height: 1.6; + text-align: center; +} + +.book-quote { + max-width: 32ch; + margin: clamp(20px, 3.4vw, 32px) auto 0; + padding: 10px 0 10px 16px; + border-left: 2px solid rgba(154, 107, 35, .5); + color: #765d36; + font-family: var(--serif); + font-size: clamp(.9rem, 1.7vw, 1.02rem); + font-style: italic; + line-height: 1.55; +} + +.task { + display: flex; + flex-direction: column; + min-height: 100%; +} + +.task h3 { + margin: 0; + color: #332612; + font-family: var(--serif); + font-size: clamp(1.2rem, 2.6vw, 1.55rem); + line-height: 1.3; + text-wrap: balance; +} + +.options { + display: grid; + gap: 8px; + margin: 20px 0 14px; +} + +.option { + display: flex; + align-items: center; + gap: 12px; + width: 100%; + padding: 11px 13px; + border: 1px solid #c8b48a; + border-radius: 9px; + background: rgba(255, 255, 255, .42); + color: #3a2b17; + font-size: clamp(.86rem, 1.7vw, .96rem); + line-height: 1.35; + text-align: left; + cursor: pointer; + transition: border-color .15s, background .15s, transform .12s, opacity .15s; +} + +.option:hover:not(:disabled) { + border-color: #8a6a2f; + background: #fffaf0; + transform: translateX(2px); +} + +.option:focus-visible { + outline: 2px solid var(--brass-dark); + outline-offset: 2px; +} + +.option:disabled { + cursor: default; +} + +.option:disabled:not(.is-correct):not(.is-wrong) { + opacity: .68; +} + +.option-key { + display: grid; + place-items: center; + width: 27px; + height: 27px; + flex: none; + border: 1px solid #b89a5c; + border-radius: 50%; + background: rgba(255, 255, 255, .5); + color: #7a5a22; + font-family: var(--serif); + font-size: .78rem; + font-weight: 700; +} + +.option.is-correct { + border-color: #5f7d4f; + background: #e8f0d9; + box-shadow: inset 0 0 0 1px rgba(95, 125, 79, .25); +} + +.option.is-correct .option-key { + border-color: #5f7d4f; + background: #5f7d4f; + color: #fff; +} + +.option.is-wrong { + border-color: #a34a3d; + background: #f4ddd7; + animation: option-shake .32s ease; +} + +.option.is-wrong .option-key { + border-color: #a34a3d; + background: #a34a3d; + color: #fff; +} + +.feedback { + min-height: 2.7em; + margin: 0; + color: #6a5636; + font-size: clamp(.84rem, 1.6vw, .92rem); + line-height: 1.5; +} + +.feedback.is-correct { + color: #416b3b; + font-weight: 700; +} + +.feedback.is-error { + color: #9a3b2c; + font-weight: 700; +} + +.hint { + margin: 0 0 12px; + padding: 9px 12px; + border-left: 3px solid #b89a5c; + background: rgba(185, 154, 92, .13); + color: #6f5a36; + font-size: clamp(.8rem, 1.5vw, .88rem); + font-style: italic; + line-height: 1.45; +} + +.letter-stamp { + position: relative; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + width: clamp(86px, 13vw, 106px); + aspect-ratio: 1; + margin: 6px auto 16px; + border: 3px solid var(--brass); + border-radius: 50%; + background: radial-gradient(circle at 34% 28%, #a94b43, #7b2d32 60%, #571e24); + color: #f7e8c8; + box-shadow: + 0 8px 20px rgba(0, 0, 0, .3), + inset 0 0 0 2px rgba(255, 255, 255, .13), + inset 0 0 18px rgba(0, 0, 0, .28); + transform: rotate(-6deg); +} + +.letter-stamp.is-visible { + animation: stamp-in .55s cubic-bezier(.2, .9, .3, 1.35); +} + +.stamp-letter { + font-family: var(--serif); + font-size: clamp(2.2rem, 5vw, 3rem); + font-weight: 700; + line-height: 1; + text-shadow: 0 2px 0 rgba(0, 0, 0, .35); +} + +.stamp-caption { + margin-top: 2px; + font-size: .5rem; + letter-spacing: .2em; + text-transform: uppercase; + opacity: .82; +} + +.primary-btn, +.secondary-btn, +.copy-btn { + border: 0; + border-radius: 9px; + cursor: pointer; + font-weight: 800; + transition: transform .12s, box-shadow .15s, background .15s, border-color .15s; +} + +.primary-btn { + align-self: flex-start; + padding: 11px 20px; + background: linear-gradient(180deg, #2f4c36, #1e3426); + color: #f7e9c9; + font-size: clamp(.82rem, 1.6vw, .9rem); + box-shadow: 0 4px 0 #0d1a12, 0 8px 18px rgba(0, 0, 0, .18); +} + +.primary-btn:hover { + background: linear-gradient(180deg, #3b5c42, #27422f); + transform: translateY(-1px); +} + +.primary-btn:active { + transform: translateY(1px); + box-shadow: none; +} + +.secondary-btn { + padding: 10px 18px; + border: 1px solid rgba(45, 31, 13, .32); + background: transparent; + color: #4b3a20; + font-size: clamp(.8rem, 1.6vw, .88rem); +} + +.secondary-btn:hover { + border-color: rgba(45, 31, 13, .6); + background: rgba(255, 255, 255, .32); + transform: translateY(-1px); +} + +.primary-btn:focus-visible, +.secondary-btn:focus-visible, +.copy-btn:focus-visible { + outline: 2px solid var(--brass-dark); + outline-offset: 2px; +} + +.voucher { + position: relative; + z-index: 1; + width: min(590px, 100%); + margin: auto; + padding: clamp(24px, 5vw, 40px); + border: 1px solid #e2c98d; + border-radius: 18px; + background: + radial-gradient(circle at 15% 10%, rgba(255, 255, 255, .82), transparent 32%), + radial-gradient(circle at 88% 94%, rgba(154, 107, 35, .12), transparent 40%), + linear-gradient(145deg, #fff9e9, #eddfbe); + box-shadow: 0 32px 84px rgba(0, 0, 0, .68); + color: #2b2114; + text-align: center; + transform: rotate(-1deg); + animation: voucher-pop .46s cubic-bezier(.2, .9, .3, 1.2); +} + +.voucher::before { + content: ""; + position: absolute; + inset: 10px; + border: 2px dashed rgba(146, 108, 43, .5); + border-radius: 12px; + pointer-events: none; +} + +.voucher-kicker { + margin: 0 0 8px; + color: #9a742f; + font-size: .68rem; + font-weight: 800; + letter-spacing: .22em; + text-transform: uppercase; +} + +.voucher h2 { + margin: 0; + font-family: var(--serif); + font-size: clamp(1.6rem, 4.6vw, 2.35rem); + line-height: 1.05; + text-wrap: balance; +} + +.voucher-lead { + max-width: 42ch; + margin: 13px auto 21px; + color: #5d4a30; + font-size: clamp(.9rem, 2vw, 1rem); + line-height: 1.58; +} + +.voucher-card { + margin: 0 auto; + padding: 17px; + border: 2px dashed #b38a3f; + border-radius: 14px; + background: rgba(255, 255, 255, .46); +} + +.voucher-label { + display: block; + color: #9a742f; + font-size: .66rem; + font-weight: 800; + letter-spacing: .26em; + text-transform: uppercase; +} + +.voucher-recipient { + display: block; + margin: 5px 0 13px; + font-family: var(--serif); + font-size: clamp(1.08rem, 2.6vw, 1.3rem); + font-weight: 700; +} + +.voucher-code-row { + display: flex; + flex-wrap: wrap; + justify-content: center; + gap: 8px; +} + +#voucher-code { + display: inline-block; + max-width: 100%; + padding: 10px 15px; + border-radius: 8px; + background: #22352a; + color: #f0c96a; + font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; + font-size: clamp(1rem, 3.6vw, 1.45rem); + font-weight: 700; + letter-spacing: .07em; + overflow-wrap: anywhere; + box-shadow: inset 0 2px 6px rgba(0, 0, 0, .35); +} + +.copy-btn { + padding: 10px 14px; + background: #22352a; + color: #fff1ca; + font-size: .76rem; +} + +.copy-btn:hover { + background: #2f4a39; + transform: translateY(-1px); +} + +.copy-btn.is-copied { + background: #4f7d4f; +} + +.voucher-foot { + display: block; + margin-top: 12px; + color: #7d6745; + font-size: .68rem; + letter-spacing: .04em; +} + +.voucher-note { + min-height: 1.35em; + margin: 13px 0 0; + color: #7a5d31; + font-size: .82rem; + font-weight: 700; +} + +.modal-actions { + display: flex; + flex-wrap: wrap; + justify-content: center; + gap: 10px; + margin-top: 17px; +} + +@keyframes twinkle { + 0% { opacity: .55; filter: brightness(.85); } + 100% { opacity: 1; filter: brightness(1.18); } +} + +@keyframes drawer-glow { + 0% { box-shadow: 0 0 0 2px rgba(240, 201, 106, .22), 0 0 22px rgba(240, 201, 106, .22), 0 7px 14px rgba(0, 0, 0, .42); } + 100% { box-shadow: 0 0 0 2px rgba(240, 201, 106, .45), 0 0 38px rgba(240, 201, 106, .45), 0 7px 14px rgba(0, 0, 0, .42); } +} + +@keyframes drawer-shake { + 0%, 100% { transform: translateX(0); } + 25% { transform: translateX(-5px) rotate(-.6deg); } + 55% { transform: translateX(5px) rotate(.6deg); } + 78% { transform: translateX(-3px); } +} + +@keyframes slot-pop { + 0% { transform: scale(.6) rotate(-8deg); opacity: .2; } + 60% { transform: scale(1.08) rotate(2deg); opacity: 1; } + 100% { transform: scale(1) rotate(0); opacity: 1; } +} + +@keyframes book-open { + 0% { opacity: 0; transform: rotate(-3deg) scale(.9) translateY(18px); } + 100% { opacity: 1; transform: rotate(-.35deg) scale(1) translateY(0); } +} + +@keyframes stamp-in { + 0% { opacity: 0; transform: rotate(-18deg) scale(1.6); } + 55% { opacity: 1; transform: rotate(-4deg) scale(.94); } + 75% { transform: rotate(-7deg) scale(1.04); } + 100% { transform: rotate(-6deg) scale(1); } +} + +@keyframes option-shake { + 0%, 100% { transform: translateX(0); } + 30% { transform: translateX(-5px); } + 60% { transform: translateX(4px); } + 82% { transform: translateX(-2px); } +} + +@keyframes voucher-pop { + 0% { opacity: 0; transform: rotate(-4deg) scale(.86); } + 100% { opacity: 1; transform: rotate(-1deg) scale(1); } +} + +@keyframes fade-in { + from { opacity: 0; } + to { opacity: 1; } +} + +@media (max-width: 820px) { + .book-dialog { + grid-template-columns: 1fr; + width: min(620px, 100%); + transform: none; + animation-name: book-open-mobile; + } + + .book-dialog::before { + display: none; + } + + .book-page { + min-height: 0; + padding: clamp(22px, 5vw, 36px); + } + + .page-left { + border-right: 0; + border-bottom: 1px solid rgba(100, 70, 30, .18); + } + + .book-emblem-large { + width: 74px; + } + + .page-left > .book-intro, + .book-quote { + max-width: 46ch; + } + + .plaque { + display: none; + } + + .drawer { + flex: 1 1 auto; + max-width: 420px; + } +} + +@keyframes book-open-mobile { + 0% { opacity: 0; transform: scale(.92) translateY(18px); } + 100% { opacity: 1; transform: scale(1) translateY(0); } +} + +@media (max-width: 560px) { + .page { + padding-top: 20px; + } + + .hero { + margin-bottom: 16px; + } + + .hero::after { + margin-top: 14px; + } + + .game-shell { + padding: 10px; + border-radius: 18px; + } + + .hud { + gap: 10px; + margin-bottom: 11px; + } + + .icon-btn { + width: 42px; + height: 42px; + } + + .bookcase { + padding: 11px; + border-radius: 12px; + } + + .shelf-grid { + gap: 12px; + padding: 24px 7px 8px; + } + + .shelf { + gap: 6px; + padding-bottom: 13px; + } + + .book-cover { + padding: 6px 5px 7px 9px; + } + + .book-emblem { + width: 47%; + margin-top: 8%; + } + + .book-title { + font-size: clamp(.5rem, 2.1vw, .7rem); + -webkit-line-clamp: 3; + } + + .book-author { + display: none; + } + + .book-state { + width: 20%; + } + + .drawer-front { + padding: 13px 14px 10px; + } + + .secret { + padding: 11px 10px; + } + + .slot { + width: clamp(28px, 8vw, 38px); + } + + .log { + min-height: 4.4em; + } + + .footer { + flex-direction: column; + align-items: center; + gap: 8px; + } + + .book-dialog, + .voucher { + transform: none; + } + + .task h3 { + font-size: clamp(1.1rem, 4.4vw, 1.35rem); + } + + .option { + padding: 10px 11px; + gap: 10px; + } + + .primary-btn { + align-self: stretch; + text-align: center; + } +} + +@media (max-width: 400px) { + .book-title { + -webkit-line-clamp: 4; + } + + .shelf { + gap: 5px; + } +} + +@media (prefers-reduced-motion: reduce) { + *, + *::before, + *::after { + animation-duration: .01ms !important; + animation-iteration-count: 1 !important; + transition-duration: .01ms !important; + } +} diff --git a/Dockers/mama-boek-game/docker-compose.yml b/Dockers/mama-boek-game/docker-compose.yml new file mode 100644 index 0000000..a8e7e93 --- /dev/null +++ b/Dockers/mama-boek-game/docker-compose.yml @@ -0,0 +1,13 @@ +services: + mama-boek-game: + build: . + image: bramkel/mama-boek-game:latest + container_name: mama-boek-game + ports: + - "8005:8000" + environment: + - TZ=Europe/Brussels + - GIFT_CODE=${GIFT_CODE:-VUL-JE-CADEAUBONCODE-IN} + - RECIPIENT=${RECIPIENT:-Mama} + - EVENT_DATE=${EVENT_DATE:-vandaag} + restart: unless-stopped diff --git a/Dockers/mama-boek-game/version b/Dockers/mama-boek-game/version new file mode 100644 index 0000000..b9bc2fd --- /dev/null +++ b/Dockers/mama-boek-game/version @@ -0,0 +1 @@ +latest \ No newline at end of file