:root {
  --body: #b8232b;
  --body-dark: #8a1820;
  --gold: #f5c83e;
  --gold-dark: #c68f20;
  --ink: #2b1b14;
  --paper: #fff8e6;
  --font: 'Pixelify Sans', 'Trebuchet MS', system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--body-dark); touch-action: none; overscroll-behavior: none; }
body { font-family: var(--font); color: var(--ink); user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; font-variant-ligatures: none; }
button { font-family: var(--font); font-variant-ligatures: none; cursor: pointer; }
.hidden { display: none !important; }

/* ---------- het apparaat ---------- */
#device {
  position: fixed; inset: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr auto;
  grid-template-areas: "bezel bezel" "left right";
  gap: 10px 8px;
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  background:
    radial-gradient(circle at 20% 10%, rgba(255,255,255,.12), transparent 40%),
    repeating-linear-gradient(45deg, rgba(0,0,0,.03) 0 6px, transparent 6px 12px),
    var(--body);
}
#bezel {
  grid-area: bezel; min-height: 0;
  display: flex; flex-direction: column;
  background: #3a2a24; border-radius: 12px 12px 34px 12px;
  padding: 10px 10px 4px; box-shadow: inset 0 0 0 3px var(--gold-dark), 0 4px 0 rgba(0,0,0,.25);
}
#screen { position: relative; flex: 1; min-height: 0; overflow: hidden; background: #000; border-radius: 4px; container-type: size; }
#canvas { position: absolute; left: 0; top: 0; image-rendering: pixelated; image-rendering: crisp-edges; }
#brand { text-align: center; color: var(--gold); font-weight: 700; letter-spacing: 3px; font-size: 13px; padding-top: 3px; opacity: .9; }
#brand span { color: #fff; }

.pad { display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 10px; }
#left { grid-area: left; }
#right { grid-area: right; }
.pill {
  background: #3a2a24; color: var(--gold); border: 0; border-radius: 20px;
  font-size: 13px; font-weight: 700; letter-spacing: 1px; padding: 7px 14px;
  box-shadow: 0 3px 0 rgba(0,0,0,.35);
}
.pill:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,.35); }

#dpad { display: grid; grid-template-columns: repeat(3, 48px); grid-template-rows: repeat(3, 48px); filter: drop-shadow(0 4px 0 rgba(0,0,0,.35)); }
#dpad .d { background: #2b2b33; border: 0; padding: 0; position: relative; }
#dpad .up { grid-area: 1 / 2; border-radius: 8px 8px 0 0; }
#dpad .left { grid-area: 2 / 1; border-radius: 8px 0 0 8px; }
#dpad .mid { grid-area: 2 / 2; }
#dpad .right { grid-area: 2 / 3; border-radius: 0 8px 8px 0; }
#dpad .down { grid-area: 3 / 2; border-radius: 0 0 8px 8px; }
#dpad button::after { content: ''; position: absolute; left: 50%; top: 50%; border: 8px solid transparent; transform: translate(-50%, -50%); }
#dpad .up::after { border-bottom-color: #55556a; margin-top: -4px; }
#dpad .down::after { border-top-color: #55556a; margin-top: 4px; }
#dpad .left::after { border-right-color: #55556a; margin-left: -4px; }
#dpad .right::after { border-left-color: #55556a; margin-left: 4px; }
#dpad .on { background: #3d3d48; }

#ab { position: relative; width: 150px; height: 120px; }
.round {
  position: absolute; width: 62px; height: 62px; border-radius: 50%; border: 0;
  background: var(--gold); color: #6a3a10; font-size: 24px; font-weight: 700;
  box-shadow: 0 4px 0 var(--gold-dark), 0 6px 0 rgba(0,0,0,.25);
}
.round.on, .round:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--gold-dark); }
#btn-a { right: 4px; top: 4px; }
#btn-b { left: 4px; bottom: 4px; background: #f6f1e7; box-shadow: 0 4px 0 #b9ad98, 0 6px 0 rgba(0,0,0,.25); }

@media (orientation: landscape) {
  #device { grid-template-columns: auto 1fr auto; grid-template-rows: 1fr; grid-template-areas: "left bezel right"; gap: 16px; }
  .pad { justify-content: center; min-width: 160px; }
  #left { flex-direction: column-reverse; }
  #right { flex-direction: column-reverse; }
}
@media (orientation: landscape) and (max-height: 420px) {
  #dpad { grid-template-columns: repeat(3, 42px); grid-template-rows: repeat(3, 42px); }
  .round { width: 54px; height: 54px; }
  #ab { width: 130px; height: 104px; }
  .pad { min-width: 136px; gap: 6px; }
  #brand { display: none; }
}
@media (orientation: portrait) and (max-height: 640px) {
  #dpad { grid-template-columns: repeat(3, 42px); grid-template-rows: repeat(3, 42px); }
  .round { width: 54px; height: 54px; }
  #ab { width: 130px; height: 100px; }
}

/* ---------- in het scherm ---------- */
#hud { position: absolute; left: 6px; top: 6px; right: 6px; display: flex; justify-content: space-between; pointer-events: none; font-size: max(13px, min(3.6cqw, 5cqh)); }
#hud span { background: rgba(43, 27, 20, .78); color: #fff; padding: 2px 8px; border-radius: 10px; font-weight: 600; }
#hud-map:empty { display: none; }

#dialog {
  position: absolute; left: 2%; right: 2%; bottom: 2.5%;
  background: #fbfbf6; border: 4px solid #3b4a62; border-radius: 10px;
  box-shadow: inset 0 0 0 3px #c7d4e8, 0 3px 0 rgba(0,0,0,.35);
  padding: .55em .8em 1.2em; min-height: 4.6em;
  font-size: max(15px, min(4.6cqw, 6.4cqh)); line-height: 1.35; color: #2b2b33;
}
#dlg-name { position: absolute; top: -1.15em; left: .6em; background: var(--body); color: #fff; font-size: .78em; font-weight: 700; padding: .1em .6em; border-radius: 6px; border: 3px solid #3b4a62; }
#dlg-name:empty { display: none; }
#dlg-text { white-space: pre-wrap; }
#dlg-next { position: absolute; right: .6em; bottom: .15em; color: var(--body); animation: bob .7s infinite; }
@keyframes bob { 50% { transform: translateY(3px); } }
#choices {
  position: absolute; right: 2%; bottom: calc(2.5% + 5.4em); min-width: 40%;
  background: #fbfbf6; border: 4px solid #3b4a62; border-radius: 10px; box-shadow: inset 0 0 0 3px #c7d4e8;
  padding: .3em .2em; font-size: max(15px, min(4.4cqw, 6cqh)); display: flex; flex-direction: column;
}
.choice { background: none; border: 0; text-align: left; font-size: 1em; padding: .25em .5em .25em 1.2em; color: #2b2b33; position: relative; }
.choice.sel::before { content: '▶'; position: absolute; left: .2em; color: var(--body); }

#title {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: linear-gradient(rgba(20,10,40,.25), rgba(20,10,5,.65)); text-align: center; padding: 4%;
}
#logo { display: flex; flex-direction: column; line-height: .95; animation: float 3s ease-in-out infinite; }
#logo span { font-weight: 700; color: var(--gold); text-shadow: 0 .06em 0 #5e2f12, .06em 0 0 #5e2f12, -.06em 0 0 #5e2f12, 0 -.06em 0 #5e2f12, .06em .06em 0 #5e2f12, -.06em .06em 0 #5e2f12, 0 .14em 0 rgba(0,0,0,.35); }
#logo .l1 { font-size: min(9cqw, 13cqh); }
#logo .l2 { font-size: min(14cqw, 20cqh); color: #fff; }
#subtitle { color: #fff; margin: 3% 0 5%; font-size: max(14px, min(4.4cqw, 6cqh)); text-shadow: 0 2px 0 #000; }
#title-buttons { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.tbtn { font-size: max(16px, min(5cqw, 7cqh)); padding: .3em 1.2em; min-width: 50%; background: #fbfbf6; color: var(--ink); border: 4px solid #3b4a62; border-radius: 10px; box-shadow: inset 0 0 0 3px #c7d4e8; }
.tbtn.sel { border-color: var(--body); box-shadow: inset 0 0 0 3px var(--gold); }
#title-tip { color: #fff; opacity: .85; margin-top: 4%; font-size: max(12px, min(3.4cqw, 5cqh)); text-shadow: 0 2px 0 #000; }
@keyframes float { 50% { transform: translateY(-6px); } }

#intro { position: absolute; inset: 0; background: radial-gradient(circle at 50% 42%, #3a4a8a, #101028 70%); display: flex; align-items: center; justify-content: center; }
#intro-sint { width: min(34cqw, 50cqh); height: auto; aspect-ratio: 24 / 36; image-rendering: pixelated; margin-bottom: 18cqh; animation: float 3s ease-in-out infinite; }

#fade { position: absolute; inset: 0; background: #000; opacity: 0; pointer-events: none; transition: opacity .3s; display: flex; align-items: center; justify-content: center; color: #fff; text-align: center; padding: 8%; font-size: max(16px, min(5cqw, 7cqh)); line-height: 1.5; white-space: pre-line; }
#fade.on { opacity: 1; pointer-events: auto; }

/* ---------- kaarten en het boekje ---------- */
#overlay { position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom)); background: rgba(20, 8, 6, .62); }
#sheet {
  width: 100%; max-width: 560px; max-height: 100%; overflow: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y;
  background: var(--paper); border-radius: 12px; border: 4px solid var(--gold-dark);
  box-shadow: inset 0 0 0 3px #fff, 0 6px 0 rgba(0,0,0,.35); padding: 18px 18px 14px;
  animation: pop .22s ease-out;
}
@keyframes pop { from { transform: scale(.92); opacity: 0; } to { transform: none; opacity: 1; } }
#sheet h2 { margin: 0 0 4px; text-align: center; font-size: 24px; color: var(--body); }
#sheet .sub { text-align: center; font-size: 15px; opacity: .7; margin-bottom: 12px; }
.poem { font-family: 'Caveat', 'Segoe Script', cursive; font-size: clamp(19px, 5.6vw, 27px); line-height: 1.25; text-align: center; color: #3a2210; padding: 6px 4px; }
.poem + .poem { border-top: 2px dashed #e2cfa4; }
.poem.missing { font-family: var(--font); font-size: 16px; color: #a08a6a; font-style: italic; }
.poem .nr { display: block; font-family: var(--font); font-size: 13px; color: #b08a5a; margin-bottom: 2px; }
.card-hint { margin-top: 12px; padding: 10px 12px; background: #fff0c4; border: 2px solid var(--gold); border-radius: 8px; font-size: 18px; }
.card-hint b { color: var(--body); }
.hints { margin: 6px 0 0; padding-left: 0; list-style: none; font-size: 17px; }
.hints li { padding: 6px 10px; background: #fff0c4; border-radius: 6px; margin-bottom: 6px; }
.section { margin-top: 14px; font-weight: 700; font-size: 18px; color: var(--body); }
.next-up { text-align: center; margin: 10px 0 0; font-size: 16px; background: #eef4ff; border-radius: 8px; padding: 8px; }
.waar { font-size: 22px; text-align: center; padding: 14px; background: #fff0c4; border: 3px dashed var(--body); border-radius: 10px; margin-top: 10px; }
.row-btns { display: flex; gap: 8px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
.btn { font-size: 18px; padding: 8px 18px; border-radius: 10px; border: 3px solid #3b4a62; background: #fbfbf6; color: var(--ink); box-shadow: 0 3px 0 rgba(0,0,0,.25); }
.btn.primary { background: var(--gold); border-color: #8a5a10; }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,.25); }
.keys { font-size: 15px; line-height: 1.7; }
kbd { background: #fff; border: 2px solid #c0a070; border-bottom-width: 3px; border-radius: 4px; padding: 0 5px; font-family: var(--font); font-size: 13px; }
.small { font-size: 13px; opacity: .65; text-align: center; margin-top: 10px; }
.error { background: #fff; color: #9d2727; padding: 16px; font-size: 16px; line-height: 1.5; }

#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 40; }

/* lagen in het scherm */
#hud { z-index: 2; }
#intro { z-index: 3; }
#title { z-index: 4; }
#dialog { z-index: 6; }
#choices { z-index: 7; }
#fade { z-index: 10; }

/* ---------- retro opstartscherm ---------- */
#boot { position: fixed; inset: 0; z-index: 1000; background: #000; color: #33ff55; font-family: 'VT323', 'Courier New', monospace; font-size: clamp(17px, 3.6vw, 26px); line-height: 1.15; overflow: hidden; user-select: text; -webkit-user-select: text; touch-action: manipulation; transition: opacity .45s; }
#boot.out { opacity: 0; }
#boot::after { content: ''; position: absolute; inset: 0; pointer-events: none; background: repeating-linear-gradient(0deg, rgba(0,0,0,.28) 0 1px, transparent 1px 3px); }
#boot .boot-crt { padding: max(14px, env(safe-area-inset-top)) 18px 18px; max-width: 900px; text-shadow: 0 0 6px rgba(51,255,85,.6); }
#boot pre { margin: 0; font: inherit; white-space: pre-wrap; word-break: break-word; }
#boot-form { margin-top: 4px; }
#boot-form label { display: block; margin: 2px 0; white-space: pre; }
#boot-form input { background: transparent; border: 0; outline: 0; color: #33ff55; font: inherit; text-shadow: inherit; caret-color: #33ff55; width: 14em; max-width: 55vw; padding: 0; user-select: text; -webkit-user-select: text; text-transform: none; }
#boot-form input:focus { background: rgba(51,255,85,.12); }
#boot-msg { color: #ffd84a; margin-top: 6px; }
#boot-skip { position: fixed; right: 14px; bottom: 10px; font-size: .7em; opacity: .55; }
#boot-win { position: absolute; inset: 0; background: #008080; display: flex; align-items: center; justify-content: center; text-shadow: none; font-family: 'Pixelify Sans', Arial, sans-serif; }
#boot-win .win-box { width: min(560px, 90vw); background: #c0c0c0; border: 2px solid; border-color: #fff #404040 #404040 #fff; box-shadow: 4px 4px 0 rgba(0,0,0,.45); padding: 28px 24px 16px; text-align: center; color: #000; }
#boot-win .win-logo { font-size: clamp(32px, 8vw, 54px); font-weight: 700; letter-spacing: -1px; color: #000080; text-shadow: 3px 3px 0 #fff; }
#boot-win .win-logo span { font-weight: 400; }
#boot-win .win-sub { font-size: clamp(16px, 4vw, 22px); margin: 2px 0 20px; }
#boot-win .win-bar { height: 22px; border: 2px solid; border-color: #404040 #fff #fff #404040; background: #fff; padding: 2px; }
#boot-win .win-bar i { display: block; height: 100%; width: 0; background: repeating-linear-gradient(90deg, #000080 0 10px, transparent 10px 12px); }
#boot-win .win-copy { font-size: 12px; margin-top: 14px; color: #404040; }
