/* ============================================================
   Knight of the Keyboard - styles
   ============================================================ */

:root{
  --bg:#0d1020;
  --panel:#171c33;
  --panel-2:#212949;
  --ink:#eef2ff;
  --muted:#9aa4c8;
  --gold:#ffcc33;
  --green:#57d16b;
  --red:#e05252;
  --blue:#4a8cf7;

  /* finger colours */
  --f-lp:#ff6b6b;
  --f-lr:#ffa94d;
  --f-lm:#ffe066;
  --f-li:#8ce99a;
  --f-ri:#66d9e8;
  --f-rm:#91a7ff;
  --f-rr:#e599f7;
  --f-rp:#f783ac;
  --f-th:#cbd3e6;
}

*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  background:
    radial-gradient(1200px 600px at 50% -10%, #1d2545 0%, transparent 60%),
    var(--bg);
  color:var(--ink);
  font-family:"Trebuchet MS","Segoe UI",system-ui,sans-serif;
  display:flex;
  align-items:center;
  justify-content:center;
  overflow:hidden;
  user-select:none;
  -webkit-user-select:none;
}

#app{
  width:min(100vw, calc(100vh * 0.98));
  max-width:1000px;
  padding:10px;
  display:flex;
  flex-direction:column;
  gap:8px;
}

/* ---------------- level banner ---------------- */
#topbar{
  display:flex;align-items:center;justify-content:center;
  padding:5px 16px;border-radius:10px;
  background:linear-gradient(rgba(42,51,96,.85),rgba(23,28,51,.85));
  border:1px solid #3d4a86;
  box-shadow:0 4px 14px rgba(0,0,0,.35);
}
#topbar[hidden]{display:none}
#topbar-text{
  font-size:clamp(11px,1.7vw,15px);font-weight:bold;
  letter-spacing:1.2px;color:var(--gold);
  text-shadow:0 2px 0 rgba(0,0,0,.45);
  white-space:nowrap;overflow:hidden;text-overflow:ellipsis;
}
#topbar-text .num{color:var(--muted);font-weight:normal;letter-spacing:1.6px}

/* ---------------- stage ---------------- */
#stage{
  position:relative;
  width:100%;
  aspect-ratio:16/9;
  border-radius:14px;
  overflow:hidden;
  box-shadow:0 18px 50px rgba(0,0,0,.6), 0 0 0 3px #2c3560, 0 0 0 6px #10142a;
  background:#0a0d1c;
}
#game{width:100%;height:100%;display:block;image-rendering:pixelated}

/* ---------------- screens ---------------- */
.screen{
  position:absolute; inset:0;
  display:flex; flex-direction:column;
  align-items:center;
  /* justify-content:center would clip the TOP once content overflows and
     make it unreachable; auto margins centre the same way but collapse to
     0 when there isn't room, so the screen just scrolls instead */
  justify-content:flex-start;
  gap:12px;
  text-align:center;
  padding:18px;
  overflow-y:auto;
  overscroll-behavior:contain;
  background:
    radial-gradient(900px 500px at 50% 40%, rgba(30,40,80,.92), rgba(8,10,22,.97));
  backdrop-filter:blur(2px);
  animation:fade .18s ease-out;
}
.screen > *:first-child{margin-top:auto}
.screen > *:last-child{margin-bottom:auto}
.screen.dim{background:rgba(8,10,22,.82)}
/* a class rule beats the UA [hidden] rule, so restate it */
.screen[hidden]{display:none}
@keyframes fade{from{opacity:0}to{opacity:1}}

h1{
  margin:0; font-size:clamp(24px,4.6vw,46px); letter-spacing:1px;
  color:var(--gold);
  text-shadow:0 3px 0 #7a5a00, 0 6px 18px rgba(255,204,51,.35);
}
h2{margin:0;font-size:clamp(19px,3.2vw,32px);color:var(--gold);text-shadow:0 3px 0 #7a5a00}
.subtitle{margin:0;color:var(--muted);font-size:clamp(12px,1.9vw,17px);max-width:80%}
.hint{margin:0;color:var(--muted);font-size:clamp(11px,1.7vw,15px);max-width:78%}

.title-art{line-height:0}
#title-canvas{width:min(420px,64%);height:auto;image-rendering:pixelated}

/* ---------------- buttons ---------------- */
.btn{
  font-family:inherit; font-weight:bold;
  font-size:clamp(11px,1.6vw,15px);
  color:#12162b;
  background:linear-gradient(#ffe27a,#ffbe28);
  border:none; border-radius:9px;
  padding:.5em 1.1em;
  cursor:pointer;
  box-shadow:0 4px 0 #b07d00, 0 8px 16px rgba(0,0,0,.35);
  transition:transform .07s, box-shadow .07s, filter .12s;
}
.btn:hover{filter:brightness(1.08)}
.btn:active{transform:translateY(3px); box-shadow:0 1px 0 #b07d00}
#screen-brief .btn-row{margin-top:2px}
.btn.big{font-size:clamp(13px,2vw,18px); padding:.55em 1.4em}
.btn.small{font-size:clamp(11px,1.6vw,14px); padding:.45em .9em}
.btn.danger{background:linear-gradient(#ff9a9a,#e05252); box-shadow:0 4px 0 #8c2222}
.btn-row{display:flex;gap:12px;flex-wrap:wrap;justify-content:center}

.lang-row{display:flex;gap:8px;margin-top:2px}
.lang-btn{
  font-family:inherit;font-size:12px;cursor:pointer;
  background:transparent;border:2px solid #3a4576;color:var(--muted);
  border-radius:8px;padding:.35em .8em;
}
.lang-btn.on{border-color:var(--gold);color:var(--gold)}

/* ---------------- level map ---------------- */
/* The title and the footer are pinned; only the grid of levels scrolls, so
   "Kies je avontuur" and the Back button never leave the screen. */
#screen-map{overflow:hidden}
#screen-map > *:first-child{margin-top:0}
#screen-map > *:last-child{margin-bottom:0}
#level-grid{
  display:grid;
  grid-template-columns:repeat(4,1fr);
  gap:6px;
  width:min(840px,96%);
  flex:1 1 auto;
  min-height:0;
  overflow-y:auto;
  align-content:center;      /* centred while it fits, scrolls when it doesn't */
  padding:2px 4px;
  scrollbar-width:thin;
  scrollbar-color:#3d4a86 transparent;
}
#level-grid::-webkit-scrollbar{width:8px}
#level-grid::-webkit-scrollbar-thumb{background:#3d4a86;border-radius:4px}
#level-grid::-webkit-scrollbar-track{background:transparent}
.lvl{
  position:relative;
  background:linear-gradient(#2a3360,#1a2144);
  border:2px solid #3d4a86;
  border-radius:10px;
  padding:5px 5px 6px;
  cursor:pointer;
  transition:transform .1s, border-color .1s;
}
.lvl:hover{transform:translateY(-3px);border-color:var(--gold)}

/* ---------------- keyboard navigation ---------------- */
*:focus{outline:none}
.kbfocus{
  outline:3px solid var(--gold)!important;
  outline-offset:3px;
  box-shadow:0 0 22px rgba(255,204,51,.55);
}
.lvl.kbfocus{transform:translateY(-3px);border-color:var(--gold)}
.nav-hint{
  font-size:clamp(10px,1.5vw,13px);color:var(--muted);
  display:flex;gap:6px;align-items:center;opacity:.75;
}
.nav-hint kbd{
  font-family:inherit;font-size:.92em;background:#2c3563;border:1px solid #46528f;
  border-bottom-width:2px;border-radius:5px;padding:1px 6px;color:#dfe6ff;
}
.lvl.locked{opacity:.42;cursor:not-allowed;filter:grayscale(.7)}
.lvl.locked:hover{transform:none;border-color:#3d4a86}
.lvl .num{font-size:10px;color:var(--muted);letter-spacing:1px;line-height:1.2}
.lvl .nm{font-size:clamp(9px,1.3vw,12px);font-weight:bold;margin:1px 0 3px;
  line-height:1.1;overflow-wrap:anywhere;hyphens:auto;
  /* two lines' worth on every card so the rows line up */
  min-height:2.2em;display:flex;align-items:center;justify-content:center}
.lvl .keys{
  font-family:"Courier New",monospace;font-size:11px;color:var(--gold);
  background:#11162c;border-radius:5px;padding:1px 0;letter-spacing:2px;
}
.lvl .st{font-size:11px;margin-top:3px;letter-spacing:1px;line-height:1}
.lvl .lock{position:absolute;top:4px;right:6px;font-size:16px}
.map-foot{display:flex;gap:16px;align-items:center;font-size:14px;color:var(--gold);flex:none}

/* ---------------- versus ---------------- */
.party-pick{display:flex;gap:8px;justify-content:center}
.party-btn{
  font-family:inherit;font-size:clamp(11px,1.8vw,15px);font-weight:bold;cursor:pointer;
  background:transparent;border:2px solid #3d4a86;color:var(--muted);
  border-radius:9px;padding:.45em 1em;
}
.party-btn.on{background:var(--gold);border-color:var(--gold);color:#12162b}
.vs-split{display:flex;align-items:center;gap:clamp(10px,3vw,32px);flex-wrap:wrap;justify-content:center}
.vs-side{
  display:flex;flex-direction:column;align-items:center;gap:5px;
  background:rgba(0,0,0,.28);border-radius:12px;padding:10px 14px;
  border:2px solid #3d4a86;min-width:min(280px,38vw);
}
#vs-side-1{border-color:#66d9e8}
#vs-side-2{border-color:#ffa94d}
.vs-tag{font-size:clamp(12px,2vw,17px);font-weight:bold}
#vs-side-1 .vs-tag{color:#66d9e8}
#vs-side-2 .vs-tag{color:#ffa94d}
.vs-hand{font-size:clamp(10px,1.6vw,13px);color:var(--muted)}
/* a miniature of the real keyboard: rows stay in order and step right */
.vs-keys{display:flex;flex-direction:column;gap:4px;align-items:flex-start}
.vs-krow{display:flex;gap:4px}
.vs-key{
  width:26px;height:26px;border-radius:5px;color:#12162b;
  font-size:13px;font-weight:bold;line-height:26px;text-align:center;
  box-shadow:0 2px 0 rgba(0,0,0,.35);
}
.vs-vs{font-size:clamp(16px,3vw,26px);font-weight:bold;color:var(--gold)}
.vs-diff-label{font-size:10px;color:var(--muted);margin-top:4px;letter-spacing:.5px}
.vs-diff{display:flex;gap:4px}
.diff-btn{
  font-family:inherit;font-size:11px;font-weight:bold;cursor:pointer;
  background:transparent;border:2px solid #3d4a86;color:var(--muted);
  border-radius:7px;padding:.3em .7em;
}
.diff-btn.on{background:var(--gold);border-color:var(--gold);color:#12162b}
#vs-side-1 .diff-btn.on{background:#66d9e8;border-color:#66d9e8}
#vs-side-2 .diff-btn.on{background:#ffa94d;border-color:#ffa94d}
.stat-grid em{font-style:normal;color:var(--muted);font-size:.85em}

/* ---------------- story ---------------- */
.story{
  margin:0;max-width:78%;
  font-size:clamp(11px,1.75vw,15px);line-height:1.5;
  color:#cfd8f5;font-style:italic;
  border-left:3px solid var(--gold);padding-left:12px;text-align:left;
}
.story.big{
  max-width:70%;font-size:clamp(13px,2.1vw,19px);line-height:1.6;
  border-left:none;border-top:2px solid rgba(255,204,51,.35);
  border-bottom:2px solid rgba(255,204,51,.35);
  padding:16px 0;text-align:center;
}

/* ---------------- briefing ---------------- */
#screen-brief{gap:clamp(10px,2.2vh,20px)}
#screen-brief .story{max-width:min(620px,86%)}

/* two cards of equal height, so the keys and the weapon read as two slots
   rather than one long stack of loose things */
.brief-cols{
  display:flex;gap:clamp(10px,2.4vw,24px);
  align-items:stretch;justify-content:center;flex-wrap:wrap;
}
.brief-col{
  display:flex;flex-direction:column;align-items:center;gap:9px;
  background:rgba(0,0,0,.26);
  border:2px solid #333d69;border-radius:14px;
  padding:11px clamp(12px,2vw,20px) 14px;
}
.col-head{
  margin:0;font-size:clamp(9px,1.3vw,11px);font-weight:bold;
  letter-spacing:1.5px;text-transform:uppercase;color:var(--muted);
  white-space:nowrap;
}
#brief-weapon-col{justify-content:space-between;min-width:clamp(120px,16vw,168px)}
#screen-brief .hint{
  margin:2px 0 0;max-width:min(330px,42vw);
  font-size:clamp(10px,1.45vw,13px);line-height:1.35;
}

#brief-keys{display:flex;gap:10px;flex-wrap:wrap;justify-content:center}
/* the finale's "you know them all" board */
#brief-keys.mini-keys{flex-direction:column;flex-wrap:nowrap;gap:4px;align-items:flex-start}
.mini-krow{display:flex;gap:4px}
.mini-key{
  width:24px;height:24px;border-radius:5px;color:#12162b;
  font-size:12px;font-weight:bold;line-height:24px;text-align:center;
  box-shadow:0 2px 0 rgba(0,0,0,.35);
}
#brief-weapon{display:flex;flex-direction:column;align-items:center;gap:7px;flex:1;justify-content:center}
#brief-weapon canvas{
  height:clamp(58px,11vh,92px);width:auto;image-rendering:pixelated;
  filter:drop-shadow(0 4px 10px rgba(0,0,0,.5));
  animation:pop .35s ease-out backwards .1s;
}
.weapon-name{
  font-size:clamp(10px,1.5vw,13px);font-weight:bold;color:var(--gold);
  text-align:center;line-height:1.2;
}

/* the party choice is its own decision, so give it its own row */
.party-row{
  display:flex;align-items:center;gap:11px;
  padding:7px 14px;border-radius:11px;
  background:rgba(0,0,0,.22);border:1px solid #2c3563;
}
.party-pick{display:flex;gap:7px}
.party-btn{
  font-family:inherit;font-size:clamp(11px,1.6vw,14px);font-weight:bold;cursor:pointer;
  background:transparent;border:2px solid #3d4a86;color:var(--muted);
  border-radius:9px;padding:.38em 1em;
}
.party-btn.on{background:var(--gold);border-color:var(--gold);color:#12162b}

.bigkey{
  min-width:74px;max-width:100px;min-height:70px;
  padding:8px 7px;border-radius:12px;
  display:flex;flex-direction:column;align-items:center;justify-content:center;
  font-size:25px;font-weight:bold;color:#12162b;
  box-shadow:0 5px 0 rgba(0,0,0,.35);
  animation:pop .3s ease-out backwards;
}
.bigkey small{
  font-size:9px;font-weight:normal;opacity:.85;margin-top:3px;
  line-height:1.15;text-align:center;
}
@keyframes pop{from{transform:scale(.3) rotate(-12deg);opacity:0}}

/* ---------------- results ---------------- */
.stars{font-size:clamp(30px,6vw,54px);letter-spacing:8px}
.star-off{opacity:.22}
.star-on{animation:starpop .4s ease-out backwards;text-shadow:0 0 22px var(--gold)}
@keyframes starpop{from{transform:scale(0) rotate(180deg)}}
.stat-grid{
  display:grid;grid-template-columns:repeat(2,auto);
  gap:6px 26px;font-size:clamp(12px,2vw,17px);
  background:rgba(0,0,0,.28);padding:12px 22px;border-radius:12px;
}
.stat-grid b{color:var(--gold)}

/* ---------------- howto / settings ---------------- */
.howto-body{
  max-width:640px;text-align:left;display:flex;flex-direction:column;gap:8px;
  font-size:clamp(11px,1.8vw,15px);color:#d6ddf5;line-height:1.4;
}
.howto-body .row{display:flex;gap:10px;align-items:flex-start}
.howto-body .ico{font-size:20px;width:28px;text-align:center;flex:none}
.settings-body{display:flex;flex-direction:column;gap:12px;align-items:flex-start}
.toggle{display:flex;gap:10px;align-items:center;font-size:clamp(12px,2vw,16px);cursor:pointer}
.toggle input{width:20px;height:20px;accent-color:var(--gold);cursor:pointer}
.speed-row{display:flex;gap:12px;align-items:center;font-size:clamp(12px,2vw,16px)}
.seg{display:flex;border:2px solid #3d4a86;border-radius:8px;overflow:hidden}
.seg button{
  font-family:inherit;font-size:12px;padding:.4em .8em;cursor:pointer;
  background:transparent;border:none;color:var(--muted);
}
.seg button.on{background:var(--gold);color:#12162b;font-weight:bold}

/* ---------------- pause btn ---------------- */
#btn-pause{
  position:absolute;top:10px;right:10px;
  width:34px;height:34px;border-radius:9px;
  background:rgba(20,26,50,.75);border:2px solid #46528f;color:#cdd6f5;
  font-weight:bold;font-family:inherit;cursor:pointer;letter-spacing:1px;
  z-index:5;
}
#btn-pause:hover{border-color:var(--gold);color:var(--gold)}

/* ============================================================
   Keyboard guide
   ============================================================ */
#guide{
  display:flex;flex-direction:column;align-items:center;gap:5px;
}
#guide.hidden{display:none}

#keyboard{display:flex;flex-direction:column;gap:4px;align-items:center;width:100%}
.krow{display:flex;gap:4px;justify-content:center;width:100%}
.key{
  position:relative;
  flex:1 1 0;
  max-width:52px;
  aspect-ratio:1/.86;
  border-radius:7px;
  background:#232b4d;
  border:1px solid #333d69;
  border-bottom:3px solid #161c36;
  display:flex;align-items:center;justify-content:center;
  font-size:clamp(9px,1.5vw,14px);
  font-weight:bold;
  color:#59648f;
  text-transform:uppercase;
  transition:transform .06s, background .1s, color .1s, box-shadow .1s;
}
/* --fc is the colour of the finger that presses this key (set from JS).
   The underline is the always-on legend; the ::after wash is the loud
   version, only worn on the briefing screen. */
.key::after{
  content:"";position:absolute;inset:0;border-radius:6px;
  background:var(--fc,transparent);opacity:0;
  transition:opacity .25s;pointer-events:none;
}
.key > span{position:relative;z-index:1}
.key.spacer{background:transparent;border:none;box-shadow:none;max-width:26px}
.key.space{max-width:260px;flex:4 1 0;aspect-ratio:auto;height:clamp(16px,2.6vw,26px)}
.key.learned{color:#c9d2f0;background:#2c3563;border-bottom-color:var(--fc,#161c36)}
/* briefing: wash every key of this level in its finger colour, and let the
   brand-new keys burn brighter than the ones already known */
#keyboard.brief .key.learned::after{opacity:.30}
#keyboard.brief .key.newkey::after{opacity:1}
#keyboard.brief .key.newkey{color:#12162b;transform:translateY(-3px)}
#keyboard.brief .key.newkey::after{animation:keypulse 1.1s ease-in-out infinite}
.key.next{
  color:#12162b;
  transform:translateY(-3px) scale(1.06);
  box-shadow:0 0 0 2px #fff6, 0 6px 16px rgba(0,0,0,.5);
  animation:keypulse .8s ease-in-out infinite;
}
@keyframes keypulse{0%,100%{filter:brightness(1)}50%{filter:brightness(1.22)}}
.key.hit{background:var(--green)!important;color:#0b2b12!important;transform:translateY(2px) scale(.96)}
.key.miss{background:var(--red)!important;color:#fff!important;animation:shakekey .25s}
@keyframes shakekey{25%{transform:translateX(-4px)}75%{transform:translateX(4px)}}

/* hands */
#hands{display:flex;gap:clamp(16px,5vw,64px);align-items:flex-end}
.handwrap{display:flex;flex-direction:column;align-items:center}
.hand{display:flex;gap:4px;align-items:flex-end}
.hand.right{flex-direction:row}
.fing{
  width:clamp(9px,1.6vw,14px);
  border-radius:6px 6px 3px 3px;
  background:#28315a;
  transition:height .14s ease-out, background .14s, box-shadow .14s;
}
.fing.on{box-shadow:0 0 14px currentColor}
/* fingers this level asks for — lit on the briefing screen */
.fing.lvl{box-shadow:0 0 10px currentColor}
.fing.fresh{animation:fingpulse 1.1s ease-in-out infinite}
@keyframes fingpulse{
  0%,100%{transform:translateY(0);filter:brightness(1)}
  50%{transform:translateY(-5px);filter:brightness(1.35)}
}
/* The thumbs sit lower and splay outward, or they read as stubby pinkies
   and the whole hand looks mirrored. Left thumb is the hand's rightmost
   digit, right thumb its leftmost — so the two face each other. */
.fing[data-f="thL"],.fing[data-f="thR"]{
  width:clamp(11px,2vw,17px);
  border-radius:8px;
  margin-bottom:-7px;
}
.fing[data-f="thL"]{transform-origin:bottom left;transform:rotate(30deg);margin-left:4px}
.fing[data-f="thR"]{transform-origin:bottom right;transform:rotate(-30deg);margin-right:4px}

.palm{
  width:clamp(34px,6.4vw,60px);height:13px;border-radius:0 0 9px 9px;background:#28315a;
}
#finger-label{
  font-size:clamp(11px,1.8vw,15px);
  color:var(--muted);height:1.3em;font-weight:bold;letter-spacing:.5px;
}

/* small screens: shrink guide */
@media (max-height:620px){
  #hands{display:none}
  #finger-label{display:none}
}
