:root {
  --ink: #1e2a33;
  --panel: #2b3a45;
  --panel-hi: #3a4d5b;
  --cream: #f4f1e8;
  --orange: #e8662a;
  --orange-d: #b84a1c;
  --blue: #2e6fb5;
  --green: #5c9a3a;
  --red: #c4432f;
  --muted: #9fb0b8;
  --font: ui-monospace, 'SF Mono', 'Cascadia Mono', Menlo, Consolas, monospace;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--ink); color: var(--cream); font-family: var(--font); overflow: hidden; overscroll-behavior: none; }
button { font-family: inherit; color: inherit; cursor: pointer; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
[hidden] { display: none !important; }

#app {
  position: fixed; inset: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: 'hud' 'stage' 'bar';
}
#hud, #bar, #stage, #skills, #controls { min-width: 0; }
#stage { grid-area: stage; position: relative; overflow: hidden; touch-action: none; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; image-rendering: pixelated; }

/* ---------- HUD ---------- */
#hud {
  grid-area: hud; display: flex; align-items: center; gap: 6px;
  padding: calc(var(--sat) + 6px) calc(var(--sar) + 6px) 6px calc(var(--sal) + 6px);
  background: var(--ink); border-bottom: 3px solid #121a20;
}
.hud-main { flex: 1; min-width: 0; }
#hud-name { font-weight: 700; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.hud-stats { display: flex; gap: 12px; font-size: 15px; font-weight: 700; }
.hud-stats > span { display: inline-flex; align-items: center; gap: 4px; }
.hud-stats .bad { color: #ff9a7a; }
.hud-stats .good { color: #a6e07a; }
#hud-meter { font-size: 12px; line-height: 1.25; color: #8fc0ec; min-height: 15px; }
#hud-meter .warn { color: #ffb36b; font-weight: 700; }
.hud-btn {
  width: 40px; height: 40px; flex: none; font-size: 18px; font-weight: 700;
  background: var(--panel); border: 2px solid #121a20; border-radius: 4px;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.35), inset 0 2px 0 rgba(255,255,255,.08);
}
.hud-btn:active { transform: translateY(1px); box-shadow: inset 0 -1px 0 rgba(0,0,0,.35); }
b[class^="ico-"] { display: inline-block; width: 12px; height: 12px; image-rendering: pixelated; background-size: 12px 12px; }
.ico-home { background: linear-gradient(#b23a2a 0 40%, #efe9dc 40%); clip-path: polygon(50% 0, 100% 45%, 100% 100%, 0 100%, 0 45%); }
.ico-man { background: linear-gradient(#e8662a 0 25%, #f2c39a 25% 45%, #f4f1e8 45% 70%, #2f5fa7 70%); clip-path: polygon(30% 0,70% 0,70% 100%,30% 100%); }
.ico-clock { border-radius: 50%; background: radial-gradient(circle, var(--cream) 0 55%, var(--muted) 56%); }

/* ---------- vaardighedenbalk ---------- */
#bar {
  grid-area: bar; display: flex; flex-direction: column; gap: 6px;
  padding: 6px calc(var(--sar) + 6px) calc(var(--sab) + 6px) calc(var(--sal) + 6px);
  background: var(--ink); border-top: 3px solid #121a20;
}
#skills { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
#skills::-webkit-scrollbar { display: none; }
.skill {
  position: relative; flex: 1 0 58px; max-width: 96px; height: 64px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: var(--panel); border: 2px solid #121a20; border-radius: 4px; padding: 4px 2px;
  box-shadow: inset 0 -4px 0 rgba(0,0,0,.35), inset 0 2px 0 rgba(255,255,255,.08);
}
.skill img { width: 32px; height: 32px; image-rendering: pixelated; }
.skill .lbl { font-size: 11px; font-weight: 700; }
.skill .cnt {
  position: absolute; top: -2px; right: -2px; min-width: 22px; height: 20px; padding: 0 4px;
  background: var(--cream); color: var(--ink); font-weight: 800; font-size: 13px; line-height: 20px;
  border: 2px solid #121a20; border-radius: 3px;
}
.skill.sel { background: var(--orange); box-shadow: inset 0 -4px 0 var(--orange-d), 0 0 0 2px var(--cream); }
.skill.empty { opacity: .35; }
#controls { display: flex; gap: 6px; }
.ctl {
  flex: 1; height: 46px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--panel-hi); border: 2px solid #121a20; border-radius: 4px;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.35);
}
.ctl-ico { font-size: 17px; font-weight: 800; line-height: 1; }
.ctl-lbl { font-size: 10px; color: var(--muted); }
.ctl.on { background: var(--blue); }
.ctl.armed { background: var(--red); animation: pulse .5s infinite alternate; }
.ctl.danger .ctl-ico { color: #ffb36b; }
@keyframes pulse { to { filter: brightness(1.3); } }

/* ---------- landschap: balk rechts ---------- */
@media (orientation: landscape) and (max-height: 620px) {
  #app { grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto minmax(0, 1fr); grid-template-areas: 'hud bar' 'stage bar'; }
  #bar { flex-direction: column; width: calc(var(--sar) + 168px); border-top: 0; border-left: 3px solid #121a20; padding-top: calc(var(--sat) + 6px); overflow-y: auto; }
  #skills { flex-wrap: wrap; overflow: visible; }
  .skill { flex: 0 0 calc(50% - 3px); max-width: none; height: 56px; }
  .skill img { width: 26px; height: 26px; }
  #controls { flex-wrap: wrap; margin-top: auto; }
  .ctl { flex: 0 0 calc(50% - 3px); height: 42px; }
  #hud { padding-top: calc(var(--sat) + 4px); padding-bottom: 4px; }
}

/* ---------- schermen ---------- */
.screen {
  position: absolute; inset: 0; z-index: 10; overflow-y: auto;
  padding: calc(var(--sat) + 16px) calc(var(--sar) + 16px) calc(var(--sab) + 16px) calc(var(--sal) + 16px);
  background:
    linear-gradient(transparent 70%, rgba(46,111,181,.35) 70% 72%, transparent 72%),
    linear-gradient(#26343e, #1e2a33);
  display: flex; flex-direction: column; align-items: center;
}
#screen-menu { justify-content: center; gap: 28px; }
.logo { text-align: center; }
#logo-art { width: 192px; height: 80px; image-rendering: pixelated; }
h1 {
  margin: 8px 0 4px; font-size: 44px; line-height: .95; letter-spacing: 2px; text-transform: uppercase;
  color: var(--cream); text-shadow: 3px 3px 0 var(--blue), 6px 6px 0 #121a20;
}
.tag { margin: 10px 0 0; color: var(--muted); font-size: 13px; }
.menu-buttons { display: flex; flex-direction: column; gap: 12px; width: min(320px, 100%); }
.big {
  height: 56px; font-size: 18px; font-weight: 800; letter-spacing: 1px;
  background: var(--orange); border: 3px solid #121a20; border-radius: 5px;
  box-shadow: inset 0 -5px 0 var(--orange-d), 0 4px 0 #121a20;
}
.big:active { transform: translateY(3px); box-shadow: inset 0 -2px 0 var(--orange-d), 0 1px 0 #121a20; }
.big.alt { background: var(--panel-hi); box-shadow: inset 0 -5px 0 rgba(0,0,0,.35), 0 4px 0 #121a20; }
.danger-text { color: #ffb36b; }
.foot { color: #6f8590; font-size: 11px; text-align: center; }
.screen-head { display: flex; align-items: center; gap: 12px; width: min(560px, 100%); }
.screen-head h2 { margin: 0; font-size: 24px; text-transform: uppercase; letter-spacing: 1px; }
.back { width: 44px; height: 44px; font-size: 20px; background: var(--panel); border: 2px solid #121a20; border-radius: 4px; }
.sub { color: var(--muted); font-size: 13px; width: min(560px, 100%); }

#level-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; width: min(560px, 100%); margin-top: 16px; }
.lvl {
  text-align: left; padding: 10px; min-height: 92px; display: flex; flex-direction: column; gap: 4px;
  background: var(--panel); border: 2px solid #121a20; border-radius: 5px; box-shadow: inset 0 -4px 0 rgba(0,0,0,.35);
}
.lvl .n { font-size: 22px; font-weight: 800; color: var(--orange); }
.lvl .t { font-size: 13px; font-weight: 700; }
.lvl .s { font-size: 11px; color: var(--muted); margin-top: auto; }
.lvl.done { background: #2f4a33; }
.lvl.done .s { color: #a6e07a; }
.lvl.locked { opacity: .45; }

#feature-list { width: min(560px, 100%); display: flex; flex-direction: column; gap: 8px; margin: 8px 0 20px; }
.feat { display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: var(--panel); border: 2px solid #121a20; border-radius: 5px; }
.feat .txt { flex: 1; }
.feat .txt b { display: block; font-size: 14px; }
.feat .txt small { color: var(--muted); font-size: 12px; }
.switch { position: relative; width: 52px; height: 30px; flex: none; background: #121a20; border-radius: 4px; border: 2px solid #121a20; }
.switch::after { content: ''; position: absolute; top: 2px; left: 2px; width: 22px; height: 22px; background: var(--muted); border-radius: 2px; transition: left .12s; }
.switch.on { background: var(--green); }
.switch.on::after { left: 24px; background: var(--cream); }

/* ---------- modal ---------- */
.modal { position: absolute; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(18,26,32,.6); }
.card {
  width: min(420px, 100%); max-height: 100%; overflow-y: auto; padding: 18px;
  background: var(--cream); color: var(--ink); border: 3px solid #121a20; border-radius: 6px;
  box-shadow: 6px 6px 0 rgba(0,0,0,.45);
}
.card h3 { margin: 0 0 4px; font-size: 13px; color: var(--blue); text-transform: uppercase; letter-spacing: 1px; }
.card h2 { margin: 0 0 10px; font-size: 24px; }
.card p { margin: 0 0 12px; font-size: 14px; line-height: 1.45; }
.card .goal { font-weight: 800; background: #e5dfcf; padding: 8px 10px; border-radius: 4px; }
.card .chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px 3px 4px; background: #fff; border: 2px solid var(--ink); border-radius: 4px; font-size: 12px; font-weight: 700; }
.chip img { width: 20px; height: 20px; image-rendering: pixelated; }
.chip.new { background: #ffe1c9; border-color: var(--orange); }
.card .row { display: flex; gap: 8px; }
.card .row .big { flex: 1; height: 48px; font-size: 16px; color: var(--cream); }
.card .big.alt { color: var(--cream); }
.result-num { font-size: 40px; font-weight: 800; margin: 4px 0 8px; }
.result-num.win { color: var(--green); }
.result-num.lose { color: var(--red); }

#toast {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%) translateY(20px);
  max-width: 90%; padding: 8px 12px; background: rgba(18,26,32,.92); color: var(--cream);
  border: 2px solid #121a20; border-radius: 4px; font-size: 13px; font-weight: 700; text-align: center;
  opacity: 0; transition: opacity .15s, transform .15s; pointer-events: none;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#stage.paused::after {
  content: 'PAUZE'; position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  padding: 4px 10px; background: rgba(18,26,32,.8); border-radius: 3px; font-weight: 800; letter-spacing: 3px; font-size: 13px; pointer-events: none;
}
#stage.paused.explore::after { content: 'RONDKIJKEN'; background: rgba(46,111,181,.9); }
