/* Het Geheim van de Nachtuil — stijl
   Donker, lantaarnlicht, goud en rood. Groot en goed leesbaar (min. 18px). */
:root {
  --bg: #0a1228;
  --bg2: #13224a;
  --gold: #e6c068;
  --gold-d: #b8913a;
  --red: #b3261e;
  --text: #f6efe0;
  --muted: #b9c0d6;
  --ok: #6fd08c;
  --bad: #ff8a80;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: radial-gradient(ellipse at 30% 10%, #1d2f5e 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font: 20px/1.45 -apple-system, "Helvetica Neue", "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior: none;
}
img, svg { -webkit-user-drag: none; user-drag: none; }
input { -webkit-user-select: text; user-select: text; }
button { font: inherit; color: inherit; touch-action: manipulation; cursor: pointer; }
[hidden] { display: none !important; }

#app {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l);
}

/* ---------------- bovenbalk ---------------- */
#topbar {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 8px 14px 4px; gap: 8px; flex: none;
}
.topbar-side.right { display: flex; justify-content: flex-end; }
#seals { display: flex; gap: clamp(10px, 2.5vmin, 22px); }
.seal {
  width: clamp(56px, 8vmin, 76px); height: clamp(56px, 8vmin, 76px);
  border-radius: 50%; border: none; padding: 0;
  background: radial-gradient(circle at 35% 30%, #e0473c, #8f1410 70%);
  box-shadow: inset 0 0 0 4px #6e0e0a, inset 0 0 0 7px #c33a30, 0 3px 8px #0008;
  display: grid; place-items: center;
  font: 700 clamp(26px, 4vmin, 36px)/1 Georgia, serif; color: #ffd9d2;
  position: relative;
}
.seal.current { animation: sealPulse 2.2s infinite; }
.seal.broken {
  background: radial-gradient(circle at 35% 30%, #f3d98c, #a7802c 75%);
  box-shadow: inset 0 0 0 4px #7a5a1a, 0 0 14px #e6c06888;
  color: #3a2508;
}
.seal.broken::after {
  content: ""; position: absolute; inset: 6px; border-radius: 50%;
  background: linear-gradient(115deg, transparent 46%, #3a250866 47%, transparent 52%);
}
.seal.breaking { animation: sealBreak .9s ease-out; }
@keyframes sealPulse { 50% { box-shadow: inset 0 0 0 4px #6e0e0a, inset 0 0 0 7px #c33a30, 0 0 18px #ff705880; } }
@keyframes sealBreak { 0% { transform: scale(1) rotate(0); } 30% { transform: scale(1.35) rotate(-12deg); } 60% { transform: scale(.9) rotate(8deg); } 100% { transform: scale(1); } }

.icon-btn {
  width: 56px; height: 56px; border-radius: 50%;
  border: 2px solid #ffffff33; background: #ffffff12; font-size: 26px;
}

/* ---------------- schermen ---------------- */
.screen { display: none; flex: 1 1 auto; min-height: 0; flex-direction: column; padding: 8px 18px; }
.screen.active { display: flex; }
.center-col {
  margin: auto; display: flex; flex-direction: column; align-items: center; gap: 18px;
  text-align: center; max-width: 720px; padding: 10px;
}
.title { font: 700 clamp(32px, 6vmin, 54px)/1.15 Georgia, serif; color: var(--gold); margin: 0; text-shadow: 0 2px 12px #000; }
.lead { font-size: clamp(22px, 3vmin, 28px); margin: 0; }
.muted { color: var(--muted); }
.owl-big { font-size: clamp(80px, 16vmin, 140px); filter: drop-shadow(0 0 30px #e6c06855); }

.progress { width: min(520px, 80vw); height: 18px; border-radius: 9px; background: #ffffff1a; overflow: hidden; }
#loadBar { height: 100%; width: 0; background: linear-gradient(90deg, var(--gold-d), var(--gold)); transition: width .2s; }

.btn {
  min-height: 56px; min-width: 56px; padding: 10px 22px; border-radius: 14px;
  border: 2px solid var(--gold); background: linear-gradient(#2a3c70, #1a2a55);
  color: var(--text); font-weight: 600; font-size: 20px;
}
.btn:active { transform: scale(.97); }
.btn-big { font-size: 26px; padding: 16px 34px; min-height: 68px; }
.btn-ghost { border-color: #ffffff40; background: #ffffff10; }
.btn-piet { border-color: var(--ok); background: linear-gradient(#2a6040, #19422b); }
.icon-lg { font-size: 26px; width: 72px; }

.phase-title { font: 700 clamp(24px, 3.6vmin, 34px)/1.2 Georgia, serif; color: var(--gold); text-align: center; margin: 4px 0; flex: none; }
.phase-intro { text-align: center; margin: 2px auto 8px; max-width: 760px; color: var(--muted); flex: none; }
.phase-body { flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; container-type: size; }
.piet-msg {
  flex: none; margin: 8px auto 0; max-width: 760px; padding: 12px 18px; border-radius: 16px;
  background: #fff3d6; color: #2b1b05; font-size: 21px; position: relative;
}
.piet-msg::before { content: "🧑‍🎄 Piet: "; font-weight: 700; }
.piet-msg.good { background: #d9f7e3; }
.phase-after { flex: none; display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; align-items: center; margin: 10px 0 4px; }
.digit-q label { font-size: 22px; font-weight: 600; }
.digit-input {
  width: 84px; height: 64px; text-align: center; font: 700 34px Georgia, serif;
  border-radius: 12px; border: 3px solid var(--gold); background: #0d1938; color: var(--text);
}
.shake { animation: shake .4s; }
@keyframes shake { 20%,60% { transform: translateX(-8px); } 40%,80% { transform: translateX(8px); } }

/* ---------------- werkbalk ---------------- */
#phasebar {
  flex: none; display: flex; flex-wrap: wrap; gap: 10px; justify-content: center;
  padding: 8px 12px 10px; border-top: 1px solid #ffffff1a; background: #0a122899;
}
.hint-btn .owl { display: inline-block; }
.hint-btn.glow { border-color: var(--gold); box-shadow: 0 0 18px #e6c068aa; }
.hint-btn.glow .owl { animation: owlGlow 1.4s infinite; }
@keyframes owlGlow { 50% { transform: scale(1.3); filter: drop-shadow(0 0 10px #ffd76a); } }

/* ---------------- modals ---------------- */
.modal { position: fixed; inset: 0; background: #000b; display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal-card { background: var(--bg2); border: 2px solid var(--gold); border-radius: 18px; padding: 20px 26px; max-width: 640px; width: 100%; }
.modal-card h3 { margin: 0 0 10px; color: var(--gold); font: 700 28px Georgia, serif; }
.modal-card li { margin: 8px 0; font-size: 22px; }
#previewImg { max-width: min(90vw, 90vh); max-height: min(90vw, 90vh); border-radius: 12px; border: 3px solid var(--gold); }

/* ---------------- video ---------------- */
#videoWrap {
  position: relative; flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center;
  background: #000; border-radius: 16px; overflow: hidden; margin: 6px 0;
}
#video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.video-tap {
  position: absolute; inset: 0; border: none; background: #000a;
  font: 700 clamp(26px, 4vmin, 36px)/1.3 Georgia, serif; color: var(--gold);
}
#balloons { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px; padding: 20px; background: radial-gradient(#1d2f5e, #050a18); }
.balloon { background: #fff3d6; color: #2b1b05; border-radius: 22px; padding: 22px 28px; max-width: 720px; font-size: 24px; }
.balloon b { display: block; color: var(--red); margin-bottom: 6px; }
.balloon p { margin: 0; }
.row-btns { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; flex: none; padding-bottom: 6px; }

/* ---------------- memory ---------------- */
#memoryGrid {
  --s: min(100cqw, 100cqh);
  width: var(--s); height: var(--s);
  display: grid; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(3, 1fr); gap: 2%;
}
.mcard { perspective: 800px; border: none; padding: 0; background: none; }
.mcard-in { position: relative; width: 100%; height: 100%; transition: transform .45s; transform-style: preserve-3d; }
.mcard.up .mcard-in, .mcard.done .mcard-in { transform: rotateY(180deg); }
.mface { position: absolute; inset: 0; border-radius: 12px; backface-visibility: hidden; -webkit-backface-visibility: hidden; overflow: hidden; }
.mback {
  background: repeating-linear-gradient(45deg, #7a1510 0 10px, #8f1d16 10px 20px);
  border: 3px solid var(--gold-d); display: grid; place-items: center; font-size: 34px;
}
.mfront { transform: rotateY(180deg); background: #1b2a4a; border: 3px solid var(--gold); }
.mfront img { width: 100%; height: 100%; object-fit: contain; }
.mcard.done .mfront { box-shadow: 0 0 16px #6fd08c; border-color: var(--ok); }

/* ---------------- schuifpuzzel ---------------- */
#slideBoard {
  --s: min(100cqw, 100cqh);
  width: var(--s); height: var(--s); position: relative;
  border: 4px solid var(--gold-d); border-radius: 10px; background: #050a18; touch-action: none;
}
.tile {
  position: absolute; width: 33.333%; height: 33.333%; border: 2px solid #0a1228; border-radius: 6px;
  background-size: 300% 300%; transition: left .18s ease, top .18s ease; touch-action: none;
}
#slideBoard.solved .tile { border-color: transparent; border-radius: 0; }
#slideBoard.solved { border-color: var(--gold); box-shadow: 0 0 26px #e6c06888; }
#slideBoard .glow8 {
  position: absolute; pointer-events: none; color: #fff8e0; opacity: 0;
  font: 700 1px Georgia, serif; transform: translate(-50%, -50%) rotate(-6deg);
}
#slideBoard.solved .glow8 { animation: glow8 2.4s forwards; }
@keyframes glow8 { 0% { opacity: 0; text-shadow: none; } 100% { opacity: 1; text-shadow: 0 0 18px #ffe9a0, 0 0 40px #ffcf4a; } }

/* ---------------- raadsels ---------------- */
#scr-raadsels .phase-body { container-type: normal; display: block; overflow-y: auto; -webkit-overflow-scrolling: touch; }
#riddles { display: flex; flex-direction: column; gap: 14px; max-width: 820px; margin: 0 auto; padding-bottom: 30vh; }
.riddle { background: #f3e6c4; color: #2b1b05; border-radius: 14px; padding: 14px 20px; box-shadow: 0 4px 14px #0007; }
.riddle h4 { margin: 0 0 4px; font: 700 20px Georgia, serif; color: #7a1510; }
.riddle pre { white-space: pre-wrap; font: italic 21px/1.45 Georgia, serif; margin: 0 0 10px; }
.letters { position: relative; display: inline-flex; gap: 6px; }
.letters .box {
  width: 50px; height: 58px; border: 3px solid #7a5a1a; border-radius: 8px; background: #fffaf0;
  display: grid; place-items: center; font: 700 30px Georgia, serif; color: #2b1b05;
}
.letters .box.first { border-color: #b3261e; }
.letters .box.cur { box-shadow: 0 0 0 3px #e6c068; }
.letters input {
  position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0.01; border: none; font-size: 24px;
  color: transparent; background: transparent; caret-color: transparent;
}
.riddle.ok .letters .box { border-color: #2f8f4e; background: #e6f8ec; }
.riddle.ok .letters .box.first { background: #ffd76a; border-color: #b3261e; animation: firstGlow 1.2s 2 alternate; }
@keyframes firstGlow { to { box-shadow: 0 0 18px #ffb300; } }
.riddle .row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.riddle .status { font-weight: 700; color: #2f8f4e; }
.nul { text-align: center; font: 700 44px Georgia, serif; letter-spacing: 18px; color: var(--gold); margin: 8px 0; }

/* ---------------- geheimschrift ---------------- */
.cipher-layout { display: flex; gap: 18px; container-type: normal; }
@media (orientation: portrait) { .cipher-layout { flex-direction: column; } .cipher-layout #logbook { flex: 0 1 auto; } .cipher-layout #wheelBox { flex: 1 1 auto; } }
#logbook {
  background: #d6be8c center/cover; color: #2b1b05;
  border-radius: 12px; padding: 16px 22px; box-shadow: 0 4px 14px #0008; flex: 1 1 0; max-width: 620px;
  display: flex; flex-direction: column; justify-content: center; align-self: stretch; min-height: 0;
}
.cipher-small { font: 18px/1.4 "Courier New", monospace; color: #5a4020; margin: 0 0 10px; letter-spacing: 1px; }
.cipher-live { font: 700 clamp(24px, 3.4vmin, 34px)/1.35 "Courier New", monospace; margin: 0; letter-spacing: 2px; word-break: break-word; }
.cipher-live.readable { color: #0d5a26; }
#wheelBox {
  flex: 1 1 0; min-height: 0; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  container-type: size; align-self: stretch;
}
#wheel { width: min(100cqw, calc(100cqh - 84px)); height: min(100cqw, calc(100cqh - 84px)); touch-action: none; }
.wheel-btns { display: flex; gap: 24px; flex: none; }
#wheel .outer-l { font: 700 31px Georgia, serif; fill: #f6efe0; }
#wheel .inner-l { font: 700 28px Georgia, serif; fill: #2b1b05; }
#wheel .marker { fill: none; stroke: #ffd76a; stroke-width: 3; }

/* ---------------- eindscherm ---------------- */
#scr-einde { position: relative; }
#confetti { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#lock { position: relative; display: flex; flex-direction: column; align-items: center; }
.lock-shackle { width: 160px; height: 110px; border: 22px solid #b0b7c3; border-bottom: none; border-radius: 80px 80px 0 0; margin-bottom: -6px; transition: transform .6s; }
#scr-einde.open .lock-shackle { transform: translateY(-26px); }
.lock-body { display: flex; gap: 14px; padding: 26px 30px; border-radius: 22px; background: linear-gradient(#e6c068, #a07a2a); box-shadow: 0 10px 30px #000a; }
.dial { width: 78px; height: 104px; border-radius: 12px; background: #1a1a1a; display: grid; place-items: center; overflow: hidden; box-shadow: inset 0 0 12px #000; }
.dial span { font: 700 64px Georgia, serif; color: #fff; }
.end-msg { background: #fff3d6; color: #2b1b05; border-radius: 16px; padding: 16px 22px; font-size: 22px; white-space: pre-wrap; max-width: 640px; }

/* ---------------- testmodus ---------------- */
#testbar {
  position: fixed; left: calc(8px + var(--safe-l)); top: calc(8px + var(--safe-t)); z-index: 60; max-width: calc(100vw - 16px);
  background: #000d; border: 2px dashed #ff5; border-radius: 12px; padding: 8px; font-size: 18px;
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
}
#testbar.collapsed > :not(.tb-toggle) { display: none; }
#testbar button { min-height: 44px; min-width: 44px; padding: 4px 10px; border-radius: 8px; border: 1px solid #ff5; background: #333; font-size: 16px; }
#testbar .tb-info { width: 100%; font-size: 16px; color: #ff9; white-space: pre-wrap; -webkit-user-select: text; user-select: text; }
#testbar input { font-size: 18px; width: 90px; }

/* ==========================================================================
   RIJKE OPMAAK — textures, messing, lakzegels (afbeeldingen via --img-* variabelen,
   die app.js na het vooraf laden invult)
   ========================================================================== */
html, body {
  background:
    linear-gradient(180deg, #050a18cc 0%, #0a122899 45%, #050a18e6 100%),
    var(--img-nacht, none) center 70% / cover no-repeat,
    var(--bg);
}
/* gouden titels met sierlijntjes */
.title, .phase-title {
  background: linear-gradient(180deg, #fff2c2 0%, #e6c068 45%, #b8862e 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 2px 6px #000c);
}
.phase-title { display: flex; align-items: center; justify-content: center; gap: 14px; }
.phase-title::before, .phase-title::after {
  content: ""; flex: 0 1 90px; height: 2px;
  background: linear-gradient(90deg, transparent, #e6c068); -webkit-text-fill-color: initial;
}
.phase-title::after { transform: scaleX(-1); }
.phase-intro { color: #d8dcea; text-shadow: 0 1px 3px #000; }

/* messing knoppen */
.btn {
  background: linear-gradient(180deg, #3a4f8a 0%, #22346a 48%, #182654 52%, #1e2f62 100%);
  border: 2px solid #d4ad55;
  box-shadow: inset 0 1px 0 #ffffff40, inset 0 -2px 0 #0006, 0 3px 8px #000a, 0 0 0 1px #6b4f16;
  text-shadow: 0 1px 2px #000;
}
.btn-ghost {
  background: linear-gradient(180deg, #2a1c10cc, #160e06cc);
  border-color: #b8913a;
}
.btn-piet { background: linear-gradient(180deg, #3b8a5a, #1d5534); border-color: #9fe3b5; }
.icon-btn {
  background: radial-gradient(circle at 35% 30%, #4a3a1e, #1c140a);
  border: 2px solid #d4ad55; box-shadow: 0 3px 8px #000a, inset 0 1px 0 #ffffff30;
}

/* lakzegels */
.seal {
  background: var(--img-zegel) center / contain no-repeat;
  box-shadow: none; border-radius: 50%;
  font-size: 0;
}
.seal span { font: 700 clamp(26px, 4vmin, 36px)/1 Georgia, serif; color: transparent; }
.seal.current { animation: sealGlow 2.2s infinite; }
@keyframes sealGlow { 50% { filter: drop-shadow(0 0 12px #ff8a6a); } }
.seal.broken { background: var(--img-zegel-kapot) center / contain no-repeat; box-shadow: none; }
.seal.broken::after { display: none; }
.seal.broken span {
  color: #3a2508; font-size: clamp(30px, 4.6vmin, 42px);
  text-shadow: 0 1px 0 #fff3c4, 0 0 10px #fff3c4;
}

/* perkamenten panelen */
.riddle, .piet-msg, .balloon, .end-msg, .modal-card {
  background: var(--img-perkament, #f3e6c4) center / cover, #f3e6c4;
  color: #2b1b05;
  border: 2px solid #8a6424;
  box-shadow: inset 0 0 30px #7a4f1a55, 0 6px 18px #000b;
}
.modal-card h3 { color: #7a1510; }
.modal-card .btn { color: #fff; }
.modal-card .muted { color: #5a4020; }
.piet-msg.good { background: var(--img-perkament) center / cover; border-color: #2f8f4e; box-shadow: inset 0 0 30px #2f8f4e40, 0 6px 18px #000b; }
.riddle { position: relative; }
.riddle::before, .riddle::after {
  content: ""; position: absolute; width: 34px; height: 34px; background: var(--img-hoek) center / contain no-repeat;
  filter: brightness(.55) sepia(1) saturate(2);
}
.riddle::before { left: 6px; top: 6px; }
.riddle::after { right: 6px; top: 6px; transform: scaleX(-1); }
.riddle h4 { padding-left: 32px; }

/* werkbalk als houten lijst */
#phasebar {
  background: linear-gradient(180deg, #0008, #0004), var(--img-hout, #2a1a0a) center / 600px;
  border-top: 2px solid #b8913a; box-shadow: 0 -4px 14px #000a;
}

/* memory: sierlijke kaartrug, gouden voorkant */
.mback { background: var(--img-kaart-rug) center / 100% 100% no-repeat; border: none; box-shadow: 0 4px 10px #000a; }
.mfront { background: radial-gradient(circle at 50% 40%, #24365e, #0e1830); border: 3px solid #d4ad55; box-shadow: 0 4px 10px #000a; }

/* schuifpuzzel in houten lijst */
#slideBoard {
  --s: calc(min(100cqw, 100cqh) - 44px);
  border: 14px solid transparent;
  border-image: none;
  background: #050a18;
  box-shadow: 0 0 0 3px #d4ad55, 0 0 0 16px #3b2410, 0 0 0 18px #d4ad55, 0 14px 30px #000;
  outline: none;
}
#slideBoard.solved { box-shadow: 0 0 0 3px #ffe08a, 0 0 0 16px #3b2410, 0 0 0 18px #ffe08a, 0 0 40px #e6c068; }

/* logboek */
#logbook { border: 2px solid #6d4a10; box-shadow: inset 0 0 40px #5a3a1088, 0 8px 22px #000c; }

/* slot op het eindscherm: messing met reflectie */
.lock-shackle { border-color: #c9ced8; border-width: 24px; box-shadow: inset 0 0 0 2px #fff6, 0 0 0 2px #6b7280; }
.lock-body {
  background: linear-gradient(160deg, #fff0b8 0%, #e6c068 22%, #a8781e 60%, #6d4a10 100%);
  border: 3px solid #5a3a08; box-shadow: inset 0 2px 0 #fff8, inset 0 -6px 14px #0006, 0 14px 34px #000c;
}
.dial { background: linear-gradient(180deg, #050505, #2a2a2a 45%, #2a2a2a 55%, #050505); border: 2px solid #5a3a08; }

/* video-venster in een gouden lijst */
#videoWrap { box-shadow: 0 0 0 3px #d4ad55, 0 10px 30px #000c; }
.video-tap { background: radial-gradient(circle, #0008, #000c); }
