/* Klosskod – the editor. Everything is laid out in ONE 1024 x 700 box (design px) that klosskod.js scales to the
   screen with --k (like the original scales its 1024 x 768 iPad layout by the window's height). Colours of the blocks are the
   original's category colours (blocks.js); the frame round them is the site's dark "godis" look (css/bv-app.css buttons). */

.bb-page { overflow-x: hidden; }
.bb-main { padding: 4px 0 1rem; }
.bb-wrap {
  position: relative; margin: 0 auto; padding: 0;
  width: calc(1024px * var(--k, 1)); height: calc(700px * var(--k, 1));
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.bb-app {
  position: absolute; left: 0; top: 0; width: 1024px; height: 700px; transform: scale(var(--k, 1)); transform-origin: 0 0;
  background: #120a2c; border-radius: 14px; overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
.bb-app .bv-btn { width: 48px; height: 48px; border-radius: 13px; }
.bb-app .bv-ico { width: 26px; height: 26px; }

/* ---------- The three columns on top ---------- */
.bb-left { position: absolute; left: 0; top: 0; width: 168px; height: 432px; display: flex; flex-direction: column; gap: 8px; padding: 8px; }
.bb-left-top { display: flex; gap: 6px; }
.bb-sprites { flex: 1; overflow: hidden; display: flex; flex-direction: column; gap: 6px; padding-right: 2px; position: relative; }
.bb-add { width: 100% !important; height: 50px !important; flex: none; }

.bb-thumb {
  position: relative; flex: none; height: 64px; display: grid; grid-template-columns: 62px 1fr; align-items: center; gap: 6px; padding: 4px 6px;
  color: #e9e4ff; background: #22174d; border: 3px solid #3a2c72; border-radius: 12px; cursor: pointer;
}
.bb-thumb canvas { width: 46px; height: 46px; justify-self: end; image-rendering: pixelated; }   /* room for the lock on its left */
.bb-thumb-name { font-size: 13px; font-weight: 800; line-height: 1.1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bb-thumb.is-selected { border-color: var(--yellow); background: #2f2163; box-shadow: 0 0 10px #ffe94d55; }
.bb-thumb.is-target { border-color: var(--cyan); box-shadow: 0 0 16px var(--cyan); }
.bb-thumb.is-flash { animation: bb-flash 0.3s; }
/* The lock: the card's top left corner (owner, 2026-11-10: "vänstra översta hörnet utan att täcka figuren"), never on the name */
.bb-lock {
  position: absolute; left: 2px; top: 2px; width: 24px; height: 24px; padding: 4px; display: none; place-items: center;
  color: #e9e4ff; background: #3a2c72; border: 0; border-radius: 8px; cursor: pointer;
}
.bb-thumb.is-selected .bb-lock, .bb-lock.is-on { display: grid; }
.bb-lock.is-on { color: #1b1040; background: var(--yellow); }
.bb-lock svg { width: 100%; height: 100%; fill: currentColor; }
.bb-thumb.is-shaking .bb-lock { display: none; }   /* the delete cross takes that corner */
.bb-x {
  position: absolute; left: -6px; top: -8px; width: 30px; height: 30px; display: grid; place-items: center; padding: 5px;
  color: #fff; background: #d62222; border: 2px solid #fff; border-radius: 50%; cursor: pointer; z-index: 2;
}
.bb-x svg { width: 100%; height: 100%; fill: currentColor; }
.is-shaking { animation: bb-shake 0.3s infinite; }
@keyframes bb-shake { 25% { transform: rotate(-3deg); } 75% { transform: rotate(3deg); } }
/* The long press shows itself: red rises from the bottom while the finger stays (HOLD_MS 0.5 s; a quick tap shows nothing) */
.is-holding::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; z-index: 1;
  background: linear-gradient(to top, #d62222cc, #d6222244); transform-origin: bottom; transform: scaleY(0);
  animation: bb-hold 0.38s 0.12s linear forwards;
}
@keyframes bb-hold { to { transform: scaleY(1); } }
@keyframes bb-flash { 50% { background: var(--cyan); } }

.bb-center { position: absolute; left: 168px; top: 0; width: 720px; height: 432px; }
.bb-topbar { position: absolute; left: 120px; right: 120px; top: 6px; height: 50px; display: flex; gap: 8px; align-items: center; }
.bb-stage-frame { position: absolute; left: 117px; top: 62px; width: 486px; height: 366px; border: 3px solid #3a2c72; border-radius: 6px; background: #000; }
.bb-stage { display: block; width: 480px; height: 360px; touch-action: none; image-rendering: auto; }
.bb-go { width: 64px !important; }
.bb-go svg { width: 34px; height: 34px; }
.bb-go .bb-stop, .bb-go.is-running .bb-flag { display: none; }
.bb-go.is-running .bb-stop { display: block; }
.bb-go.is-running { border-color: #ff8a8a; }
#grid[aria-pressed="true"] { color: #1b1040; background: var(--cyan); }

.bb-right { position: absolute; left: 888px; top: 0; width: 136px; height: 432px; display: flex; flex-direction: column; gap: 8px; padding: 8px; }
.bb-pages { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.bb-page-thumb {
  position: relative; width: 112px; height: 84px; padding: 0; border: 3px solid #3a2c72; border-radius: 8px; background: #000; cursor: pointer; flex: none;
}
.bb-page-thumb canvas { display: block; width: 100%; height: 100%; border-radius: 5px; }
.bb-page-thumb.is-current { border-color: var(--yellow); box-shadow: 0 0 10px #ffe94d55; }
.bb-page-num {
  position: absolute; right: 4px; bottom: 4px; min-width: 22px; height: 22px; display: grid; place-items: center;
  font-size: 14px; font-weight: 900; color: #1b1040; background: #fff; border-radius: 11px;
}
.bb-add-page { width: 112px !important; height: 50px !important; align-self: center; }
.bb-full { margin-top: auto; align-self: center; }

/* ---------- The whole editor in fullscreen (#full, F) ----------
   Real fullscreen of <main> where the browser has it, else (iPhone/iPad) <main> just covers the window. Either way
   klosskod.js fitApp scales the box to the whole screen and centres it (--ox, --oy); the stage's own show mode,
   the dialogs and the pop-ups are inside <main>, so they still show. */
.bb-main.is-full {
  position: fixed; inset: 0; z-index: 1000; width: 100vw; height: 100vh; height: 100dvh; margin: 0; padding: 0;
  background: #0b0620; overflow: hidden;
}
.bb-main.is-full > .bb-how-to { display: none; }
.bb-main.is-full .bb-wrap { position: absolute; left: var(--ox, 0px); top: var(--oy, 0px); margin: 0; }
body.bb-covering { overflow: hidden; }

/* ---------- The block bar: the six category tabs and the palette ---------- */
.bb-blockbar {
  position: absolute; left: 0; top: 432px; width: 1024px; height: 76px; display: flex; align-items: center; gap: 10px;
  padding: 0 10px; background: var(--cat, #FFE75A); box-shadow: inset 0 -4px 0 rgba(0,0,0,0.18); transition: background 0.15s;
}
.bb-cats { display: flex; gap: 4px; flex: none; }
.bb-cat {
  width: 50px; height: 56px; display: grid; place-items: center; padding: 0; cursor: pointer;
  background: var(--c); border: 3px solid rgba(0,0,0,0.25); border-radius: 12px; opacity: 0.55;
  box-shadow: 0 3px 0 rgba(0,0,0,0.3);
}
.bb-cat svg { width: 32px; height: 32px; }
.bb-cat[aria-selected="true"] { opacity: 1; border-color: #fff; transform: translateY(-2px); }
.bb-palette { position: relative; flex: 1; height: 64px; overflow: hidden; }
.bb-palette .bb-block { cursor: grab; }

/* ---------- Blocks ---------- */
.bb-block { position: absolute; left: 0; top: 0; }
.bb-shape { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
.bb-icon { position: absolute; left: 50%; top: 5px; width: 42px; height: 42px; transform: translateX(-50%); pointer-events: none; }
.bb-start .bb-icon { left: calc(50% + 4px); }
.bb-icon svg { width: 100%; height: 100%; overflow: visible; }
.bb-icon-repeat { left: auto; right: 12px; top: 50%; transform: translateY(-80%); }
.bb-endlong .bb-icon { top: 8px; }
/* A block with no number/text/menu under its icon (Gå hem, Göm, Visa, Stopp, the start blocks in the palette …): the icon in the middle */
.bb-no-arg > .bb-icon { top: 50%; transform: translate(-50%, -50%); }
.bb-no-arg > .bb-page-number { top: 24px; }
.bb-page-number { position: absolute; left: 0; right: 0; top: 17px; text-align: center; font-size: 16px; font-weight: 900; color: #D62222; pointer-events: none; }
.bb-arg {
  position: absolute; left: 50%; bottom: 5px; transform: translateX(-50%); min-width: 30px; height: 20px; padding: 0 6px;
  font: 800 15px/20px system-ui, sans-serif; text-align: center; color: #1b2a34; background: #fff; border-radius: 10px;
  white-space: nowrap; overflow: hidden; max-width: 66px;
}
.bb-repeat > .bb-arg { left: auto; right: 14px; transform: none; bottom: 10px; }
.bb-arg-t { max-width: 64px; text-overflow: ellipsis; font-size: 13px; }
.bb-arg-sound { font-size: 11px; max-width: 64px; }
.bb-arg.is-editing { color: #fff; background: #28A5DA; }
.bb-menu-button {
  position: absolute; left: 50%; bottom: 4px; width: 28px; height: 14px; transform: translateX(-50%);
  background: #fff; border-radius: 7px; box-shadow: inset 0 -3px 0 rgba(0,0,0,0.15);
}
.bb-menu-button::after { content: ""; position: absolute; left: 9px; top: 4px; border: 5px solid transparent; border-top-color: #555; }
.bb-block.is-lit { filter: drop-shadow(0 0 6px #fff) drop-shadow(0 0 10px #fff) brightness(1.15); }
.bb-script.is-dragging, .bb-drag-layer .bb-script { filter: drop-shadow(0 6px 6px rgba(0,0,0,0.45)); }

/* ---------- The script area ---------- */
.bb-scripts { position: absolute; left: 0; top: 508px; width: 1024px; height: 192px; overflow: hidden; background: #fbfaff; touch-action: none; }
.bb-scripts-canvas { position: absolute; left: 0; top: 0; width: 1px; height: 1px; }
.bb-script { position: absolute; }
.bb-ghost { position: absolute; left: 0; top: 0; pointer-events: none; opacity: 0.45; }
.bb-ghost svg { overflow: visible; }
.bb-drag-layer { position: absolute; inset: 0; pointer-events: none; z-index: 30; }

/* ---------- Help bubble, keypad, menus ---------- */
.bb-help {
  position: absolute; z-index: 40; max-width: 260px; padding: 8px 12px; font-size: 16px; font-weight: 800; color: #fff;
  background: #4682B5; border-radius: 12px; pointer-events: none; box-shadow: 0 4px 10px rgba(0,0,0,0.35);
}
.bb-help::after { content: ""; position: absolute; left: var(--tip, 30px); bottom: -10px; border: 6px solid transparent; border-top: 6px solid #4682B5; border-width: 10px 8px 0; }
.bb-keypad {
  position: absolute; right: 10px; bottom: 10px; z-index: 40; width: 210px; padding: 8px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
  background: #22174d; border: 3px solid var(--cyan); border-radius: 14px; box-shadow: 0 8px 20px rgba(0,0,0,0.5);
}
.bb-key {
  height: 48px; font: 900 24px/1 system-ui, sans-serif; color: #fff; background: #3a2c72; border: 0; border-radius: 10px; cursor: pointer;
  box-shadow: 0 3px 0 #120a2c;
}
.bb-key:active { transform: translateY(2px); box-shadow: 0 1px 0 #120a2c; }
.bb-key[hidden] { visibility: hidden; display: block; }
.bb-key svg { width: 26px; height: 26px; fill: currentColor; }
.bb-pop {
  position: absolute; z-index: 40; padding: 8px; display: grid; grid-template-columns: repeat(3, 50px); gap: 6px;
  background: #fff; border: 3px solid var(--pop-edge, #FFE75A); border-radius: 14px; box-shadow: 0 8px 20px rgba(0,0,0,0.4);
}
.bb-pop button { width: 50px; height: 50px; padding: 4px; background: #f2eefc; border: 2px solid transparent; border-radius: 10px; cursor: pointer; }
.bb-pop button.is-chosen { border-color: #1b2a34; }
.bb-pop svg { width: 100%; height: 100%; color: #1b2a34; }
.bb-say-field {
  position: absolute; z-index: 40; width: 220px; height: 40px; padding: 0 10px; font: 800 18px system-ui, sans-serif; color: #1b2a34;
  background: #fff; border: 3px solid #28A5DA; border-radius: 10px; outline: 0; user-select: text; -webkit-user-select: text;
}

/* ---------- Dialogs (the library, the backgrounds, the projects) ---------- */
.bb-dialog { width: min(760px, 94vw); max-height: 86vh; padding: 12px 16px 18px; color: #e9e4ff; background: #1b1040; border: 3px solid var(--cyan); border-radius: 18px; }
.bb-dialog::backdrop { background: rgba(5, 2, 20, 0.7); }
.bb-dialog-head { display: flex; justify-content: flex-end; margin-bottom: 6px; }
.bb-dialog-head .bv-btn { width: 48px; height: 48px; }
.bb-library { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
.bb-lib-group { grid-column: 1 / -1; margin: 6px 0 0; font-size: 1rem; color: var(--yellow); }
.bb-lib-item {
  position: relative;
  display: grid; justify-items: center; gap: 4px; padding: 8px 4px; font: inherit; font-size: 0.85rem; font-weight: 800; color: #e9e4ff; cursor: pointer;
  background: #2a1d5c; border: 3px solid #3a2c72; border-radius: 14px;
}
.bb-lib-item:hover, .bb-lib-item:focus-visible { border-color: var(--cyan); }
.bb-lib-item canvas { width: 72px; height: 72px; image-rendering: pixelated; }
.bb-bg-list .bb-lib-item canvas { width: 120px; height: 90px; border-radius: 6px; image-rendering: auto; }
.bb-project-cards .bb-lib-item canvas { width: 120px; height: 90px; border-radius: 6px; image-rendering: auto; }
.bb-bg-list, .bb-project-cards { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }   /* room for a 120 px picture */
.bb-lib-item.is-current { border-color: var(--yellow); }
.bb-card-wrap { position: relative; }
.bb-card-wrap .bb-lib-item { width: 100%; }
.bb-examples-title { margin: 16px 0 8px; font-size: 1rem; color: var(--yellow); }
.bb-new-card { color: var(--yellow); }
.bb-new-card .bv-ico { width: 48px; height: 48px; }

/* ---------- The show mode (the original's full screen) ---------- */
.bb-show {
  position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; background: #000; touch-action: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.bb-show[hidden] { display: none; }
.bb-show .bb-stage { width: var(--show-w, 480px); height: var(--show-h, 360px); }
.bb-show .bv-btn { position: absolute; width: 60px; height: 60px; }
.bb-show-exit { left: 14px; top: 14px; }
.bb-show-go { right: 14px; top: 14px; }
.bb-show-page { top: 50%; transform: translateY(-50%); }
.bb-show-prev { left: 14px; }
.bb-show-next { right: 14px; }
.bb-show-page[hidden] { display: none; }

.bb-how-to { margin-top: 1rem; }

@media (prefers-reduced-motion: reduce) {
  .is-shaking { animation: none; outline: 3px dashed #ff7a7a; }
  .is-holding::after { animation: none; transform: none; opacity: 0.5; }
}

/* ---------- Ritprogrammet (paint.js): the original's places in our 1024 x 700 box ---------- */
.bp {
  position: absolute; inset: 0; z-index: 30; background: #1b1040;
  --pen-colour: #1c1c1c;
}
.bp[hidden] { display: none; }
.bp .bv-btn { width: 56px; height: 56px; border-radius: 14px; padding: 10px; }
.bp .bv-btn svg { width: 100%; height: 100%; fill: currentColor; }
.bp-top { position: absolute; left: 0; right: 0; top: 0; height: 58px; }
.bp-undo { position: absolute; left: 15px; top: 4px; }
.bp-redo { position: absolute; left: 92px; top: 4px; }
.bp-name {
  position: absolute; left: calc(50% - 120px); top: 9px; width: 240px; height: 40px; padding: 0 12px;
  font: inherit; font-size: 19px; font-weight: 800; text-align: center; color: #1b2a34; background: #fff;
  border: 1px solid #808080; border-radius: 20px; user-select: text; -webkit-user-select: text;
}
.bp-name[hidden] { display: none; }
.bp-done { position: absolute; right: 8px; top: 2px; width: 60px !important; height: 56px !important; color: #fff; background: #2fb84a; border-color: #1d6b2b; }
.bp-done:hover, .bp-done:focus-visible { border-color: #fff; }

.bp-left { position: absolute; left: 20px; top: 76px; width: 80px; }
.bp-tools { display: grid; gap: 7px; justify-items: center; }
.bp-right { position: absolute; right: 20px; top: 124px; width: 80px; display: grid; gap: 22px; justify-items: center; }
.bp-group { display: grid; gap: 7px; }
.bp-tool.is-on { color: #1b1040; background: var(--yellow); border-color: #fff; }
.bp-outline svg { fill: none !important; stroke: currentColor; stroke-width: 18px; }   /* the shape tools draw outlines */

.bp-pens { margin-top: 26px; display: grid; gap: 3px; }
.bp-pen {
  width: 80px; height: 40px; display: grid; place-items: center; padding: 0; background: #22174d;
  border: 3px solid #3a2c72; border-radius: 10px; cursor: pointer;
}
.bp-pen span { display: block; width: 54px; border-radius: 9px; background: var(--pen-colour); box-shadow: 0 0 0 1px #ffffff55; }
.bp-pen.is-on { border-color: var(--yellow); background: #2f2163; }

.bp-area {
  position: absolute; left: 113px; top: 62px; width: 799px; height: 524px; display: grid; place-items: center;
  background: #fff; border: 1px solid #b0b1b1; border-radius: 6px; box-shadow: inset 0 0 12px #0003; overflow: hidden;
}
.bp-canvas { display: block; touch-action: none; cursor: crosshair; }

.bp-colours {
  position: absolute; left: 12px; top: 596px; width: 1000px; height: 100px;
  display: grid; grid-template-columns: repeat(20, 50px); grid-auto-rows: 50px;
}
.bp-colour {
  position: relative; width: 50px; height: 50px; padding: 0; background: none; border: 0; cursor: pointer;
}
.bp-colour::before {
  content: ""; position: absolute; left: 7px; top: 7px; width: 36px; height: 36px; border-radius: 50%;
  background: var(--c); box-shadow: 0 0 0 2px #3a2c72;
}
.bp-colour.is-on::before { left: 2px; top: 2px; width: 46px; height: 46px; box-shadow: 0 0 0 3px #fff, 0 0 10px 3px var(--c); }

/* The brush on the selected figure (opens the drawing program), and on the current background in its library */
.bb-brush {
  position: absolute; right: 2px; bottom: 2px; width: 28px; height: 28px; padding: 5px; display: grid; place-items: center;
  color: #1b1040; background: var(--yellow); border: 0; border-radius: 9px; cursor: pointer; z-index: 2;
}
.bb-brush svg { width: 100%; height: 100%; fill: currentColor; }
.bb-thumb.is-shaking .bb-brush { display: none; }
.bb-thumb.is-selected .bb-thumb-name { padding-right: 24px; }
.bb-card-wrap > .bb-brush { right: 6px; bottom: 30px; width: 34px; height: 34px; padding: 6px; }
.bb-draw-new { color: var(--yellow); }
