/* Bip – speelpagina: bord links, blokjes rechts (op een telefoon onder elkaar). */
body.speel {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ---------- bovenbalk ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  background: var(--paper);
  border-bottom: 3px solid var(--world);
}
.world-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.world-icon {
  display: grid;
  place-items: center;
  width: 44px; height: 44px;
  border-radius: 14px;
  background: var(--world-soft);
  font-size: 1.5rem;
}
.world-title strong { display: block; font-size: 1.1rem; line-height: 1.1; white-space: nowrap; }
.world-title small { display: block; color: var(--muted); font-size: .8rem; white-space: nowrap; }

.level-dots {
  flex: 1;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 4px 4px 8px;
  scrollbar-width: thin;
  justify-content: safe center;
}
.dot {
  flex: none;
  display: grid;
  justify-items: center;
  align-content: center;
  width: 44px; height: 48px;
  border: 0;
  border-radius: 14px;
  background: var(--canvas);
  box-shadow: 0 3px 0 #d3cfc6;
  font-weight: 800;
  font-size: .95rem;
  cursor: pointer;
  line-height: 1;
}
.dot i { font-style: normal; font-size: .62rem; color: var(--yellow-dark); height: .7rem; margin-top: 3px; letter-spacing: -1px; }
.dot.done { background: #fff4cc; }
.dot.current { background: var(--world); color: #fff; box-shadow: 0 3px 0 rgba(0,0,0,.25); }
.dot.current i { color: #fff; }
.settings { display: flex; gap: 8px; }

/* ---------- speelveld ---------- */
.play {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(340px, 460px) 1fr;
  gap: 16px;
  padding: 16px;
  min-height: 0;
}
.stage {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.mission { display: flex; gap: 10px; align-items: flex-start; }
.mission-face { width: 72px; height: auto; flex: none; margin-top: 4px; filter: drop-shadow(0 3px 0 rgba(0,0,0,.12)); }
.bubble {
  position: relative;
  flex: 1;
  padding: 12px 16px 12px;
  background: var(--paper);
  border-radius: var(--radius);
  box-shadow: 0 4px 0 #dcd8cf;
}
.bubble::before {
  content: "";
  position: absolute;
  left: -9px; top: 22px;
  border: 10px solid transparent;
  border-right-color: var(--paper);
  border-left: 0;
}
.bubble p { margin: 0; }
.bubble-level { font-size: .78rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin-bottom: 2px !important; }
#mission-text { font-size: 1.08rem; font-weight: 650; }
body[data-groep="3"] #mission-text, body[data-groep="4"] #mission-text { font-size: 1.2rem; }
.bubble-extra {
  margin-top: 10px !important;
  padding: 8px 12px;
  border-radius: 14px;
  background: #fff4cc;
  font-weight: 700;
}
.bubble-extra[data-mood="au"], .bubble-extra[data-mood="sip"], .bubble-extra[data-mood="moe"] { background: #ffe3e0; }
.bubble-extra[data-mood="huh"] { background: #e8f0ff; }
.bubble-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

.map-tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.map-tab {
  min-height: 40px;
  padding: 0 14px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  font-weight: 800;
  cursor: pointer;
}
.map-tab i { font-style: normal; }
.map-tab[aria-selected="true"] { border-color: var(--world); background: var(--world); color: #fff; }

.board-wrap {
  contain: layout paint;
  flex: 1 1 0;
  min-height: 220px;
  display: grid;
  place-items: center;
}
.board {
  width: 100%;
  border: 7px solid var(--world);
  border-radius: 24px;
  box-shadow: 0 5px 0 rgba(0,0,0,.14);
  background: var(--world);
  touch-action: pan-x pan-y pinch-zoom; /* vegen over het bord scrolt gewoon de pagina */
  will-change: transform; /* eigen laag: Bip laten lopen tekent niet de hele pagina opnieuw */
}
body[data-mode="vrij"] .board { cursor: crosshair; touch-action: none; } /* tekenen met je vinger */

.hud { display: flex; gap: 8px; flex-wrap: wrap; min-height: 0; }
.hud:empty { display: none; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--paper);
  font-weight: 800;
  box-shadow: 0 3px 0 #dcd8cf;
}
.pill.good { background: #d9f7e3; }
.pill.bad { background: #ffe3e0; }

.vars {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 16px;
  background: #fff1e3;
  border: 2px solid #ffd1a6;
}
.vars-title { font-size: .78rem; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; color: #b35c00; }
.var { padding: 3px 10px; border-radius: 10px; background: #ff8c1a; color: #fff; font-family: var(--mono); font-size: .95rem; }
.var b { font-weight: 800; }

.controls { display: flex; gap: 12px; }
.controls .btn-go { flex: 1; min-height: 60px; font-size: 1.35rem; }
.controls .btn-go.btn-stop { --bg: var(--red); --edge: var(--red-dark); }
.btn-reset svg { fill: none; }

/* ---------- tekenpalet (vrij spelen) ---------- */
.palette { display: flex; flex-wrap: wrap; gap: 6px; }
.paint {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 4px 10px 4px 6px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  font-weight: 700;
  font-size: .85rem;
  cursor: pointer;
}
.paint.on { border-color: var(--ink); box-shadow: 0 0 0 2px var(--ink); }
.paint i { width: 24px; height: 24px; border-radius: 7px; background: #ccc; }
.paint-pad i { background: var(--world-soft); border: 2px solid #0002; }
.paint-gras i { background: var(--world); }
.paint-plas i { background: #58b7f0; border-radius: 50%; }
.paint-appel i { background: #e63946; border-radius: 50%; }
.paint-munt i { background: #f2b707; border-radius: 50%; border: 3px solid #c98f00; }
.paint-rood i { background: #e63946; }
.paint-blauw i { background: #3a86ff; }
.paint-bip i { background: url(../img/bip-face.webp) center / contain no-repeat; }
.paint-ster i { background: #ffd23f; clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); border-radius: 0; }

/* ---------- editor ---------- */
.editor {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 480px;
  background: var(--paper);
  border-radius: var(--radius);
  box-shadow: 0 5px 0 #dcd8cf;
  overflow: hidden;
}
.editor-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 10px;
  padding: 10px 14px;
  border-bottom: 2px solid var(--canvas);
}
.editor-title { font-weight: 800; margin-right: auto; }
.block-count { font-weight: 700; color: var(--muted); font-size: .92rem; }
.block-count.good { color: var(--go-dark); }
.editor-body { position: relative; flex: 1; display: flex; min-height: 0; }
.blockly { position: relative; flex: 1; min-width: 0; contain: strict; }

.code-panel {
  flex: 0 0 min(40%, 360px);
  contain: strict;
  display: flex;
  flex-direction: column;
  border-left: 2px solid var(--canvas);
  background: #1d1f2b;
  color: #e7e9f5;
  min-width: 0;
}
.code-panel-title { margin: 0; padding: 10px 14px; font-size: .78rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; color: #9aa0c7; }
.code-panel pre { flex: 1; margin: 0; padding: 0 14px 14px; overflow: auto; font-family: var(--mono); font-size: .86rem; line-height: 1.55; }
.code-panel .k, .code-editor .k { color: #ff8cc6; font-weight: 700; }
.code-panel .f { color: #7cc4ff; font-weight: 700; }
.code-panel .s { color: #ffd479; }
.code-panel .n { color: #a8f0a0; }
.code-panel .c { color: #7c82a8; font-style: normal; }

/* code-levels: een simpele editor met regelnummers */
.code-editor {
  flex: 1;
  display: flex;
  min-height: 0;
  background: #1d1f2b;
  --lh: 1.7;
  font-family: var(--mono);
  font-size: 1.05rem;
}
.gutter {
  margin: 0;
  padding: 16px 10px 16px 14px;
  min-width: 3em;
  text-align: right;
  color: #5d6390;
  line-height: var(--lh);
  font: inherit;
  line-height: var(--lh);
  overflow: hidden;
  user-select: none;
  background: #181a24;
}
.code-area { position: relative; flex: 1; min-width: 0; }
.code-area textarea {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 16px;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: #e7e9f5;
  caret-color: #ffc61a;
  font: inherit;
  line-height: var(--lh);
  tab-size: 2;
  white-space: pre;
}
.line-hl {
  position: absolute;
  left: 0; right: 0; top: 16px;
  background: rgba(255, 198, 26, .18);
  border-left: 4px solid var(--yellow);
  pointer-events: none;
}

/* ---------- gewonnen ---------- */
.win {
  width: min(420px, calc(100vw - 32px));
  padding: 26px 24px 22px;
  border: 0;
  border-radius: 28px;
  background: var(--paper);
  text-align: center;
  box-shadow: 0 10px 0 rgba(0,0,0,.15), 0 30px 80px rgba(0,0,0,.25);
}
.win::backdrop { background: rgba(10, 10, 10, .45); }
.win[open] { animation: pop .35s cubic-bezier(.2, 1.4, .4, 1); }
.win h2 { margin: 6px 0 4px; font-size: 1.8rem; }
.win p { margin: 0 0 18px; color: var(--muted); font-weight: 600; }
.win-bip { width: 120px; height: auto; margin: 0 auto; }
.win-stars { display: flex; justify-content: center; gap: 6px; font-size: 3rem; line-height: 1; margin-bottom: 4px; }
.win-stars span { color: #e6e2d9; }
.win-stars span.on { color: #ffc61a; text-shadow: 0 3px 0 #d99e00; animation: pop .5s var(--d) both cubic-bezier(.2, 1.6, .4, 1); }
.win-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
@keyframes pop { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.toast {
  position: fixed;
  left: 50%; bottom: 24px;
  transform: translateX(-50%);
  padding: 12px 18px;
  border-radius: 14px;
  background: var(--ink);
  color: #fff;
  font-weight: 700;
  z-index: 20;
}

.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 30; }
.confetti i {
  position: absolute;
  top: -20px;
  width: 10px; height: 16px;
  border-radius: 3px;
  animation: fall linear forwards;
}
@keyframes fall {
  to { transform: translate(var(--x), 105vh) rotate(var(--r)); }
}

/* ---------- animaties op het bord ---------- */
/* geen eindeloze animaties op het bord: die tekenen elk frame de hele pagina opnieuw en maken slepen stroef */
.bip-star.locked { filter: grayscale(1) opacity(.55); }
.bip-ripple { transform-box: fill-box; transform-origin: center; animation: ripple .9s ease-out forwards; }
@keyframes ripple { from { transform: scale(.4); opacity: 1; } to { transform: scale(4); opacity: 0; } }
.bip-spark { animation: spark 1s ease-out forwards; }
@keyframes spark { from { transform: translateY(0) scale(.4); opacity: 1; } to { transform: translateY(-70px) scale(1.2); opacity: 0; } }

/* Blockly iets kindvriendelijker */
.blocklyZoom > image, .blocklyZoom > svg > image { opacity: .55; }
.blocklyTreeRow, .blocklyToolboxCategory { min-height: 44px; }
.blocklyTreeLabel, .blocklyToolboxCategoryLabel { font-family: var(--font); font-weight: 800; font-size: 1rem; }

/* op een groot scherm past alles precies; alleen de linkerkolom scrolt als het echt niet past */
@media (min-width: 961px) {
  html:has(body.speel) { overflow: clip; }
  body.speel { height: 100vh; height: 100dvh; overflow: clip; }
  .play { overflow: hidden; }
  .stage { overflow-y: auto; padding-bottom: 6px; }
  .editor { min-height: 0; }
}

.level-pick, .mobile-tabs, .level-sheet:not([open]) { display: none; }

/* ---------- smallere schermen ---------- */
@media (max-width: 960px) {
  .play { grid-template-columns: 1fr; }
  .editor { min-height: 70vh; }
  .board-wrap { flex: none; min-height: 0; height: min(52vh, calc((100vw - 24px) / var(--r, 1))); }
  .code-panel { flex-basis: 45%; }
}

/* ---------- telefoon: één scherm tegelijk (bord of blokjes), balk onderin ---------- */
@media (max-width: 760px) {
  html:has(body.speel) { overflow: clip; }
  body.speel { height: 100vh; height: 100dvh; overflow: clip; }
  .topbar { gap: 8px; padding: 8px 12px; }
  .world-title small { display: none; }
  .world-title > div { min-width: 0; }
  .world-title strong { overflow: hidden; text-overflow: ellipsis; font-size: 1rem; }
  .world-icon { width: 40px; height: 40px; font-size: 1.3rem; }
  .level-dots { display: none; }
  .level-pick { display: inline-flex; margin-left: auto; min-height: 44px; padding: 0 14px; font-size: .95rem; white-space: nowrap; }
  .settings { gap: 6px; }
  .settings .btn-icon { width: 44px; min-width: 44px; min-height: 44px; }

  .play { display: flex; flex-direction: column; min-height: 0; padding: 10px 12px calc(84px + env(safe-area-inset-bottom)); gap: 10px; overflow: hidden; }
  body[data-view="bord"] .editor, body[data-view="blokjes"] .stage { display: none; }
  .stage { flex: 1; min-height: 0; overflow-y: auto; gap: 10px; }
  .board-wrap { flex: 1 1 0; height: auto; min-height: 150px; }
  .controls #btn-run { display: none; }
  .controls .btn-reset { flex: 1; }
  .editor { flex: 1; min-height: 0; }
  .editor-bar { padding: 8px 10px; flex-wrap: nowrap; gap: 6px; }
  .editor-bar .chip { min-height: 40px; padding: .3em .7em; font-size: .82rem; white-space: nowrap; }
  .block-count { font-size: .85rem; white-space: nowrap; }
  .editor-title { display: none; }
  .block-count { margin-right: auto; }
  .blockly { min-height: 0; }
  .mission-face { width: 52px; }
  #mission-text { font-size: 1rem; }
  body[data-groep="3"] #mission-text, body[data-groep="4"] #mission-text { font-size: 1.08rem; }

  .mobile-tabs {
    display: grid;
    grid-template-columns: 1fr 1.2fr 1fr;
    gap: 8px;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 10;
    padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
    background: var(--paper);
    border-top: 3px solid var(--world);
  }
  .tab-view {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 56px;
    border: 2px solid var(--line);
    border-radius: 16px;
    background: var(--paper);
    font-weight: 800;
    font-size: 1rem;
    cursor: pointer;
    touch-action: manipulation;
  }
  .tab-view b { font-weight: 800; }
  .tab-view[aria-pressed="true"] { background: var(--world); border-color: var(--world); color: #fff; }
  .mobile-tabs .run-btn { min-height: 56px; font-size: 1.15rem; }
  .mobile-tabs .run-btn.btn-stop { --bg: var(--red); --edge: var(--red-dark); }

  .level-sheet[open] {
    display: block;
    width: 100%;
    max-width: 100%;
    margin: auto 0 0;
    padding: 18px 16px calc(22px + env(safe-area-inset-bottom));
    border: 0;
    border-radius: 26px 26px 0 0;
    background: var(--paper);
    animation: sheet-up .25s ease-out;
  }
  .level-sheet::backdrop { background: rgba(10, 10, 10, .45); }
  .sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
  .sheet-head h2 { margin: 0; font-size: 1.3rem; }
  .level-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
  .level-grid .dot { width: 100%; height: 64px; font-size: 1.2rem; }
  .level-grid .dot i { font-size: .75rem; }

  .editor-body { flex-direction: column; }
  .code-panel { flex-basis: 34%; border-left: 0; border-top: 2px solid var(--canvas); }
  .blocklyTreeRow, .blocklyToolboxCategory { min-height: 40px; }
  .blocklyTreeLabel, .blocklyToolboxCategoryLabel { font-size: .8rem; }
  .blocklyToolboxCategory { padding-right: 6px; }
  .blocklyToolboxCategoryContainer { padding-left: 0; }
  .toast { bottom: calc(96px + env(safe-area-inset-bottom)); }
}
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: none; } }
