:root {
  --ink: #1b2a3a; --muted: #5a6a7c; --line: #dfe5ee; --card: #ffffff; --paper: #f6f3ec;
  --go: #19a463; --go-dark: #0f7f4b; --accent: #2b89c9; --warn: #e2504b; --gold: #f5b81c;
  --move: #1f6ae0; --turn: #3f4fd3; --wait: #5c6b80; --act: #c2510a; --loop: #7444d4; --forever: #a8329a; --cond: #0a856a;
  --sky1: #bfe6ff; --sky2: #fff4dd;
  --nav: 56px; --r: 16px;
  --font: "Fredoka", "Trebuchet MS", system-ui, -apple-system, "Segoe UI", sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 17px/1.45 var(--font); }
button { font: inherit; color: inherit; touch-action: manipulation; cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 3px solid #ffb703; outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 12px; top: 12px; z-index: 99; background: #fff; color: #000; padding: 8px 12px; border-radius: 8px; }
.i { display: inline-flex; width: 1.25em; height: 1.25em; flex: none; }
.i svg, .tile svg, .blk svg, .c-title svg, .ci svg, .tb-label svg, .branch-label svg, .check-badge svg { width: 100%; height: 100%; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .45em; min-height: 46px; padding: 0 18px; border: 0; border-radius: 999px; font-weight: 600; font-size: 1rem; background: #fff; color: var(--ink); box-shadow: 0 2px 0 rgba(20,40,70,.18), 0 6px 14px rgba(20,40,70,.08); transition: transform .12s, box-shadow .12s, background .15s; user-select: none; -webkit-user-select: none; }
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 0 0 rgba(20,40,70,.18); }
.btn:disabled { opacity: .45; }
.btn-go { background: var(--go); color: #fff; box-shadow: 0 4px 0 var(--go-dark), 0 8px 18px rgba(25,164,99,.3); }
.btn-go:active:not(:disabled) { box-shadow: 0 1px 0 var(--go-dark); transform: translateY(3px); }
.btn-soft { background: #fff; }
.btn-ghost { background: rgba(255,255,255,.75); backdrop-filter: blur(6px); }
.btn-xl { min-height: 64px; font-size: 1.35rem; padding: 0 34px; }
.btn-sm { min-height: 40px; padding: 0 14px; font-size: .92rem; }
.btn-round { width: 46px; padding: 0; flex: none; }
.btn-icon { width: 44px; min-height: 44px; padding: 0; box-shadow: none; background: transparent; }
.btn-icon:hover:not(:disabled) { background: rgba(31,106,224,.08); }
.btn-hint { color: #b07800; }
.btn-hint.pulse { animation: pulse 1.2s ease-in-out infinite; background: #fff6d6; }
@keyframes pulse { 50% { transform: scale(1.12); box-shadow: 0 0 0 8px rgba(245,184,28,.25); } }
.chip-btn { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 12px; border: 0; border-radius: 999px; background: rgba(255,255,255,.85); font-weight: 600; font-size: .85rem; box-shadow: 0 2px 8px rgba(0,0,0,.12); }

/* ---------- app shell ---------- */
.app { position: relative; min-height: calc(100dvh - var(--nav)); overflow: hidden; }
.screen { min-height: calc(100dvh - var(--nav)); }
.about { max-width: 760px; margin: 0 auto; padding: 40px 20px 60px; color: #334455; font-size: 16px; }
.about h2, .about h3 { font-weight: 600; }
body:not(.on-home) .about { display: none; }

/* ---------- landing ---------- */
.home { position: relative; display: grid; place-items: center; background: radial-gradient(120% 90% at 70% 30%, #fff8e6 0%, #cdeeff 55%, #9fd6ff 100%); overflow: hidden; }
.home-stage { position: absolute; inset: 0 0 0 34%; }
.home-stage canvas, .stage-canvas canvas { display: block; width: 100%; height: 100%; touch-action: pan-y pinch-zoom; }
.home-card { position: relative; z-index: 2; margin-right: auto; margin-left: max(24px, 6vw); max-width: 520px; padding: 30px 32px; border-radius: 28px; background: rgba(255,255,255,.78); backdrop-filter: blur(10px); box-shadow: 0 20px 50px rgba(20,60,110,.18); }
.kicker { margin: 0 0 4px; font-weight: 600; color: var(--accent); text-transform: uppercase; letter-spacing: .08em; font-size: .78rem; }
.home h1 { margin: 0; font-size: clamp(2rem, 4vw, 3rem); line-height: .95; font-weight: 700; letter-spacing: -.01em; }
.home h1 span:first-child { color: #1f6ae0; }
.home h1 span:last-child { color: #ff8a1f; }
.tagline { font-size: 1.2rem; margin: 14px 0 22px; color: #2b3d50; }
.home-actions { display: flex; flex-wrap: wrap; gap: 12px; }
.facts { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 20px 0 0; color: var(--muted); font-size: .9rem; }
.facts span::before { content: "●"; color: #8bd3ff; margin-right: 6px; font-size: .7em; vertical-align: 2px; }
.home-corner { position: absolute; z-index: 2; right: max(16px, var(--safe-r)); bottom: calc(16px + var(--safe-b)); display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 760px) {
  .home h1 { font-size: 36px; }
  .home-stage { inset: 40% 0 5% 0; }
  .home { align-items: start; }
  .home-card { margin: 16px 12px 84px; padding: 22px 20px; text-align: center; }
  .home-actions, .facts { justify-content: center; }
  .home-corner { left: 12px; right: 12px; justify-content: center; }
}

/* ---------- world map & level grid ---------- */
.worlds, .levels { background: linear-gradient(180deg, #d9f0ff 0%, #fff5e4 100%); padding: 0 max(16px, var(--safe-r)) calc(28px + var(--safe-b)) max(16px, var(--safe-l)); }
.screen-head { display: flex; align-items: center; gap: 14px; max-width: 1180px; margin: 0 auto; padding: 18px 0 12px; }
.screen-head > div { flex: 1; min-width: 0; }
.screen-head h2 { margin: 0; font-size: clamp(1.6rem, 3.5vw, 2.3rem); line-height: 1.05; }
.rec-line { margin: 4px 0 0; color: var(--muted); }
.rec-line button { display: inline-flex; align-items: center; min-height: 44px; margin: 4px 0; padding: 0 16px; border: 0; border-radius: 999px; background: var(--gold); color: #3a2a00; font-weight: 700; box-shadow: 0 2px 0 rgba(0,0,0,.15); }
.world-grid { list-style: none; margin: 0 auto; padding: 0; max-width: 1180px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; counter-reset: w; }
.world-card { position: relative; display: flex; flex-direction: column; width: 100%; height: 100%; padding: 0; border: 0; border-radius: 24px; overflow: hidden; background: #fff; text-align: left; box-shadow: 0 3px 0 rgba(20,40,70,.12), 0 12px 28px rgba(20,40,70,.12); transition: transform .15s; }
.world-card:hover:not(:disabled) { transform: translateY(-3px); }
.world-card .art { position: relative; aspect-ratio: 16 / 10; background: var(--wbg, #bfe6ff); }
.world-card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.world-card .num { position: absolute; left: 12px; top: 12px; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: #fff; font-weight: 700; font-size: 1.2rem; box-shadow: 0 2px 6px rgba(0,0,0,.18); }
.world-card .body { padding: 12px 16px 16px; }
.world-card h3 { margin: 0; font-size: 1.3rem; }
.world-card p { margin: 2px 0 10px; color: var(--muted); font-size: .95rem; }
.meter { height: 12px; border-radius: 99px; background: #e8edf4; overflow: hidden; }
.meter i { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, #19a463, #5fd38f); }
.world-card .stats { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; font-size: .9rem; color: var(--muted); font-weight: 500; }
.badge-row { display: inline-flex; gap: 8px; align-items: center; }
.badge-row span { display: inline-flex; align-items: center; gap: 3px; }
.badge-row .i { width: 1.05em; height: 1.05em; }
.locked .art::after { content: ""; position: absolute; inset: 0; background: rgba(40,50,70,.55); }
.lock-tag { position: absolute; z-index: 2; inset: 0; display: grid; place-items: center; color: #fff; font-weight: 600; text-align: center; padding: 10px; }
.lock-tag .i { width: 34px; height: 34px; display: block; margin: 0 auto 4px; }
.next-flag { position: absolute; right: 12px; top: 12px; z-index: 3; padding: 4px 12px; border-radius: 999px; background: var(--gold); color: #3a2a00; font-weight: 700; font-size: .85rem; box-shadow: 0 2px 6px rgba(0,0,0,.2); }
@media (max-width: 980px) { .world-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .world-grid { grid-template-columns: 1fr; gap: 14px; } .world-card { flex-direction: row; } .world-card .art { width: 42%; aspect-ratio: auto; min-height: 120px; } .world-card .body { flex: 1; padding: 10px 12px; } .world-card h3 { font-size: 1.1rem; } .world-card p { display: none; } }

.level-grid { list-style: none; margin: 0 auto; padding: 0; max-width: 1180px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.level-card { position: relative; width: 100%; padding: 0; border: 0; border-radius: 20px; overflow: hidden; background: #fff; text-align: left; box-shadow: 0 3px 0 rgba(20,40,70,.12), 0 10px 22px rgba(20,40,70,.1); transition: transform .15s; }
.level-card:hover:not(:disabled) { transform: translateY(-3px); }
.level-card .art { position: relative; aspect-ratio: 4 / 3; background: var(--wbg, #e6f3ff); }
.level-card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.level-card .n { position: absolute; left: 10px; top: 10px; min-width: 38px; height: 38px; padding: 0 8px; border-radius: 19px; display: grid; place-items: center; background: #fff; font-weight: 700; box-shadow: 0 2px 6px rgba(0,0,0,.18); }
.level-card .done-tag { position: absolute; right: 10px; top: 10px; width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: var(--go); color: #fff; padding: 8px; box-shadow: 0 2px 6px rgba(0,0,0,.2); }
.level-card .body { padding: 10px 14px 12px; }
.level-card h3 { margin: 0; font-size: 1.08rem; line-height: 1.2; }
.level-card .tags { display: flex; gap: 6px; margin-top: 6px; min-height: 26px; flex-wrap: wrap; }
.mini { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; background: #eef3f9; font-size: .78rem; font-weight: 600; color: #3a4b60; }
.mini .i { width: 14px; height: 14px; }
.mini.got { background: #fff2c2; color: #7a5500; }
@media (max-width: 900px) { .level-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 600px) { .level-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; } .level-card h3 { font-size: 1rem; } }

/* ---------- gameplay ---------- */
.game { display: flex; flex-direction: column; height: calc(100dvh - var(--nav)); background: linear-gradient(180deg, var(--sky1), var(--sky2)); }
.g-top { display: flex; align-items: center; gap: 10px; padding: 8px max(12px, var(--safe-r)) 8px max(12px, var(--safe-l)); }
.g-title { flex: 1; min-width: 0; }
.g-title p { margin: 0; font-size: .78rem; font-weight: 600; color: rgba(27,42,58,.7); text-transform: uppercase; letter-spacing: .06em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.g-title h2 { margin: 0; font-size: 1.35rem; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.goals { display: flex; gap: 6px; }
.goal { display: inline-flex; align-items: center; gap: 4px; height: 38px; padding: 0 12px 0 8px; border-radius: 999px; background: rgba(255,255,255,.85); font-weight: 700; font-size: .95rem; box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.goal .i { width: 24px; height: 24px; }
.goal.energy .i { color: #7cc314; }
.goal.lamp .i { color: #e7a500; }
.goal.home .i { color: #2fb6e8; }
.goal.met { background: #dff7e9; }
.goal.met::after { content: "✓"; color: var(--go); margin-left: 2px; }
.g-main { position: relative; flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, 36%); gap: 12px; padding: 0 max(12px, var(--safe-r)) calc(12px + var(--safe-b)) max(12px, var(--safe-l)); }
.stage { position: relative; min-height: 0; border-radius: 26px; overflow: hidden; background: radial-gradient(120% 100% at 50% 20%, rgba(255,255,255,.55), rgba(255,255,255,0) 70%); }
.stage-canvas { position: absolute; inset: 0; }
.stage-tools { position: absolute; right: 10px; top: 10px; display: flex; gap: 8px; z-index: 3; }
.code { min-height: 0; display: flex; flex-direction: column; background: rgba(255,255,255,.9); border-radius: 26px; box-shadow: 0 10px 30px rgba(20,40,70,.12); padding: 10px 12px 12px; }
.code-head { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.code-head h3 { margin: 0 0 0 4px; font-size: 1.05rem; }
.budget { padding: 3px 10px; border-radius: 999px; background: #eef1ff; color: #3b3fa0; font-weight: 700; font-size: .85rem; white-space: nowrap; }
.budget:empty { display: none; }
.budget.full { background: #ffe7d6; color: #9a3d00; }
.code-tools { margin-left: auto; display: flex; }
.program { position: relative; flex: 1; min-height: 90px; overflow-y: auto; overflow-x: hidden; padding: 10px 8px 14px; margin: 4px 0 8px; border-radius: 18px; background: repeating-linear-gradient(0deg, #f4f7fb 0 1px, transparent 1px 30px), #fbfcfe; border: 2px dashed #d6dfeb; touch-action: pan-y; overscroll-behavior: contain; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.program.running { border-style: solid; border-color: #9fd1ff; background: #f3f9ff; }
.palette-label { font-size: .8rem; font-weight: 600; color: var(--muted); margin: 0 4px 6px; }
.palette { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; padding: 4px; border-radius: 18px; transition: background .15s; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.palette.running { opacity: .55; }
.palette.trash-hover { background: #ffe1e1; outline: 3px dashed var(--warn); }
.palette.trash-hover::after { content: "Drop here to remove"; grid-column: 1 / -1; text-align: center; font-weight: 600; color: var(--warn); }
.palette.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
.runbar { display: grid; grid-template-columns: 1.6fr 1fr 1fr 1fr; gap: 8px; margin-top: 10px; }
.runbar .btn { min-height: 54px; padding: 0 10px; font-size: .98rem; }
.runbar .run { font-size: 1.2rem; }
.runbar .run.is-pause { background: #f5a524; box-shadow: 0 4px 0 #b9760a; }
.runbar .i { width: 1.35em; height: 1.35em; }

/* command tiles & blocks */
.tile, .blk { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border: 0; color: #fff; font-weight: 600; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.tile { min-height: 70px; padding: 8px 4px 6px; border-radius: 16px; font-size: .82rem; line-height: 1.1; box-shadow: inset 0 -5px 0 rgba(0,0,0,.18), 0 3px 8px rgba(20,40,70,.15); transition: transform .1s; }
.tile svg { width: 32px; height: 32px; }
.tile:active { transform: scale(.94); }
.tile em { position: absolute; top: -7px; right: -4px; padding: 1px 7px; border-radius: 99px; background: var(--gold); color: #3a2a00; font-style: normal; font-size: .7rem; font-weight: 700; box-shadow: 0 2px 4px rgba(0,0,0,.2); animation: bob 1.4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-3px); } }
.tile.is-new { box-shadow: inset 0 -5px 0 rgba(0,0,0,.18), 0 0 0 3px var(--gold), 0 3px 8px rgba(20,40,70,.15); }
.blk-move { background: var(--move); } .blk-turn { background: var(--turn); } .blk-wait { background: var(--wait); }
.blk-act { background: var(--act); } .blk-loop { --c: var(--loop); background: var(--loop); } .blk-forever { --c: var(--forever); background: var(--forever); } .blk-cond { --c: var(--cond); background: var(--cond); }
.slot { display: flex; flex-wrap: wrap; align-content: flex-start; align-items: center; gap: 8px; min-height: 58px; }
.slot-root { min-height: 100%; }
.blk { width: 76px; height: 66px; padding: 6px 2px 4px; border-radius: 14px; font-size: .72rem; line-height: 1.05; text-align: center; box-shadow: inset 0 -4px 0 rgba(0,0,0,.2), 0 2px 5px rgba(20,40,70,.18); }
.blk svg { width: 28px; height: 28px; }
.blk.selected, .cblk.selected > .c-head { outline: 4px solid #ffb703; outline-offset: 2px; }
.blk.pop, .cblk.pop { animation: pop .25s ease-out; }
@keyframes pop { 0% { transform: scale(.6); } 70% { transform: scale(1.08); } 100% { transform: scale(1); } }
.blk.now, .cblk.now > .c-head { box-shadow: 0 0 0 4px #fff, 0 0 0 8px #ffcf3a, 0 6px 16px rgba(0,0,0,.25); transform: scale(1.08); z-index: 2; transition: transform .12s; }
.blk.was { opacity: .55; }
.blk.fail, .cblk.fail > .c-head { box-shadow: 0 0 0 4px #fff, 0 0 0 8px var(--warn); animation: shake .35s; }
.cblk { flex: 1 1 100%; border-radius: 16px; background: color-mix(in srgb, var(--c) 14%, #fff); border: 3px solid var(--c); overflow: hidden; }
.c-head { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; min-height: 52px; padding: 6px 10px; background: var(--c); color: #fff; font-weight: 600; cursor: pointer; touch-action: none; user-select: none; -webkit-user-select: none; }
.c-title { display: inline-flex; align-items: center; gap: 6px; font-size: .95rem; }
.c-title svg { width: 26px; height: 26px; }
.stepper { display: inline-flex; align-items: center; gap: 4px; }
.step-btn { width: 40px; height: 40px; border: 0; border-radius: 50%; background: rgba(255,255,255,.95); color: var(--c); font-size: 1.5rem; font-weight: 700; line-height: 1; touch-action: manipulation; }
.step-btn:disabled { opacity: .4; }
.count { min-width: 30px; text-align: center; font-size: 1.35rem; }
.times { font-size: .85rem; opacity: .9; }
.cond-chip { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 10px 0 6px; border: 0; border-radius: 12px; background: #fff; color: var(--ink); font-weight: 600; font-size: .9rem; touch-action: manipulation; }
.cond-chip svg { width: 26px; height: 26px; }
.cond-chip .ci { display: inline-flex; width: 26px; height: 26px; color: #2d3a4a; }
.cond-chip i { font-style: normal; color: var(--muted); font-size: .8rem; }
.loop-badge, .check-badge { margin-left: auto; }
.loop-badge.on { padding: 2px 10px; border-radius: 99px; background: #fff; color: var(--c); font-weight: 700; }
.check-badge.yes, .check-badge.no { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px 2px 6px; border-radius: 99px; background: #fff; font-weight: 700; }
.check-badge.yes { color: var(--go); } .check-badge.no { color: var(--warn); }
.check-badge svg { width: 18px; height: 18px; }
.c-body { padding: 8px 8px 4px 18px; border-left: 10px solid var(--c); margin-left: 0; }
.c-body > .slot { padding: 4px; border-radius: 12px; transition: opacity .2s; }
.c-body > .slot.branch-dim { opacity: .35; }
.branch-label { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px 3px 6px; border-radius: 99px; font-size: .8rem; font-weight: 700; background: #fff; flex: 0 0 auto; }
.branch-label svg { width: 16px; height: 16px; }
.branch-label.yes { color: var(--go); } .branch-label.no { color: var(--warn); }
.else-bar { display: flex; align-items: center; margin: 4px 0 2px; padding-top: 6px; border-top: 3px dashed color-mix(in srgb, var(--c) 45%, #fff); }
.c-foot { display: flex; justify-content: flex-end; padding: 0 8px 8px; }
.exit-btn { min-height: 36px; padding: 0 12px; border: 2px solid color-mix(in srgb, var(--c) 40%, #fff); border-radius: 99px; background: #fff; color: var(--c); font-weight: 600; font-size: .8rem; }
.program.running .exit-btn, .program.running .c-foot { display: none; }
.slot-empty { display: inline-flex; align-items: center; min-height: 52px; padding: 0 14px; border: 2px dashed #b9c6d6; border-radius: 12px; color: var(--muted); font-size: .85rem; font-weight: 500; }
.slot-empty.here { border-color: #ffb703; color: #8a5a00; background: #fff8e0; }
.root-empty { width: 100%; justify-content: center; border: 0; font-size: 1rem; }
.caret { display: inline-block; width: 6px; height: 56px; border-radius: 4px; background: #ffb703; box-shadow: 0 0 0 3px rgba(255,183,3,.25); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .35; } }
.drop-caret { display: inline-block; width: 8px; height: 58px; border-radius: 4px; background: var(--go); box-shadow: 0 0 0 4px rgba(25,164,99,.25); }
.cblk.dragging, .blk.dragging { opacity: .3; }
.drag-ghost { position: fixed; left: 0; top: 0; z-index: 100; pointer-events: none; opacity: .92; box-shadow: 0 14px 30px rgba(0,0,0,.3) !important; }
.drag-ghost.cblk { max-height: 120px; }
body.is-dragging, body.is-dragging * { cursor: grabbing !important; }
.block-toolbar { display: flex; align-items: center; gap: 6px; padding: 6px; margin: 4px 0 0; border-radius: 16px; background: #1d2b3a; color: #fff; }
.block-toolbar button { width: 44px; height: 44px; border: 0; border-radius: 12px; background: rgba(255,255,255,.12); color: #fff; padding: 9px; }
.block-toolbar button:disabled { opacity: .3; }
.block-toolbar button.danger { background: #e2504b; }
.block-toolbar .flip svg { transform: scaleX(-1); }
.block-toolbar button[data-tool="up"] svg, .block-toolbar button[data-tool="down"] svg { transform: rotate(90deg); }
.block-toolbar button[data-tool="down"] svg { transform: rotate(-90deg); }
.tb-label { display: inline-flex; align-items: center; gap: 6px; margin: 0 auto 0 6px; font-weight: 600; font-size: .9rem; }
.tb-label svg { width: 22px; height: 22px; }

.cond-menu { position: fixed; z-index: 120; display: grid; gap: 6px; padding: 10px; border-radius: 18px; background: #fff; box-shadow: 0 18px 40px rgba(0,0,0,.25); }
.cond-menu p { margin: 0 4px 2px; font-weight: 600; color: var(--muted); font-size: .85rem; }
.cond-menu button { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 0 12px; border: 2px solid transparent; border-radius: 12px; background: #f3f6fa; font-weight: 600; text-align: left; }
.cond-menu button.on { border-color: var(--cond); background: #e3f6ef; }
.cond-menu svg { width: 28px; height: 28px; }
.cond-menu .ci { display: inline-flex; width: 28px; height: 28px; }

/* overlays on the stage */
.toast { position: absolute; z-index: 4; left: 50%; top: 12px; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; max-width: min(92%, 520px); padding: 10px 16px 10px 12px; border-radius: 18px; background: #fff; box-shadow: 0 10px 30px rgba(0,0,0,.18); font-weight: 600; animation: drop .25s ease-out; }
.toast .i { width: 28px; height: 28px; }
.toast.fail { border: 3px solid #ffb3b0; } .toast.fail .i { color: var(--warn); }
.toast.almost { border: 3px solid #ffe08a; } .toast.almost .i { color: #c78a00; }
.toast.info .i { color: var(--move); }
@keyframes drop { from { transform: translate(-50%, -10px); opacity: 0; } }
.hint-card { position: absolute; z-index: 5; left: 12px; right: 12px; bottom: 12px; max-width: 560px; margin: 0 auto; padding: 12px 14px; border-radius: 20px; background: #fffbea; border: 3px solid #ffd86b; box-shadow: 0 12px 30px rgba(0,0,0,.18); animation: rise .25s ease-out; }
@keyframes rise { from { transform: translateY(12px); opacity: 0; } }
.hint-top { display: flex; align-items: center; gap: 8px; color: #8a5a00; }
.hint-top .i { width: 26px; height: 26px; }
.hint-steps { display: inline-flex; gap: 4px; }
.hint-steps i { width: 10px; height: 10px; border-radius: 50%; background: #f1d68a; }
.hint-steps i.on { background: #e09b00; }
.hint-card p { margin: 6px 0 8px; font-size: 1.05rem; }
.hint-actions { display: flex; gap: 8px; justify-content: flex-end; }
.x { margin-left: auto; width: 40px; height: 40px; border: 0; border-radius: 50%; background: transparent; padding: 8px; }
.intro-card { position: absolute; z-index: 6; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(92%, 420px); padding: 20px; border-radius: 24px; background: #fff; text-align: center; box-shadow: 0 20px 50px rgba(0,0,0,.25); animation: popin .3s ease-out; }
@keyframes popin { from { transform: translate(-50%, -46%) scale(.94); opacity: 0; } }
.intro-card .new { display: inline-block; padding: 2px 12px; border-radius: 99px; background: var(--gold); color: #3a2a00; font-weight: 700; font-size: .8rem; }
.intro-card h3 { margin: 8px 0 4px; font-size: 1.5rem; }
.intro-card p { margin: 0 0 14px; font-size: 1.08rem; }
.intro-card .demo { display: flex; justify-content: center; gap: 10px; margin: 10px 0 12px; }
.intro-card .demo .blk, .intro-card .demo .tile { width: 88px; height: 76px; pointer-events: none; }
.intro-card .demo-pic { display: inline-flex; width: 76px; height: 76px; padding: 10px; border-radius: 18px; background: #f1f5fa; }
.trace { position: absolute; z-index: 4; left: 12px; right: 12px; bottom: 12px; max-height: 45%; overflow: auto; padding: 10px 12px; border-radius: 18px; background: rgba(255,255,255,.95); box-shadow: 0 10px 30px rgba(0,0,0,.18); }
.trace-head { display: flex; align-items: center; }
.trace ol { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.trace li { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px 3px 4px; border-radius: 10px; background: #eef3f9; font-size: .8rem; font-weight: 600; }
.trace li .i { width: 22px; height: 22px; padding: 2px; border-radius: 6px; color: #fff; }
.trace li.fail { background: #ffe3e1; }
.trace li small { color: var(--muted); font-weight: 500; }
.hand { position: fixed; z-index: 90; width: 56px; height: 56px; pointer-events: none; filter: drop-shadow(0 4px 6px rgba(0,0,0,.3)); animation: tap 1.1s ease-in-out infinite; }
@keyframes tap { 0%, 100% { transform: translate(0, 0); } 45% { transform: translate(-4px, -10px); } 60% { transform: translate(0, 0) scale(.92); } }

/* completion */
.complete { position: absolute; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px; background: rgba(20,35,55,.35); backdrop-filter: blur(3px); animation: fade .25s; }
@keyframes fade { from { opacity: 0; } }
.win-card { width: min(100%, 460px); padding: 22px 22px 18px; border-radius: 28px; background: #fff; text-align: center; box-shadow: 0 30px 60px rgba(0,0,0,.3); animation: popwin .4s cubic-bezier(.2,1.4,.4,1); }
@keyframes popwin { from { transform: scale(.85); opacity: 0; } }
.win-card h2 { margin: 0; font-size: 2rem; color: var(--go-dark); }
.win-card .sub { margin: 2px 0 14px; color: var(--muted); }
.awards { display: grid; gap: 8px; margin: 0 0 16px; text-align: left; }
.award { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 14px; background: #f3f6fa; }
.award .i { width: 30px; height: 30px; padding: 4px; border-radius: 50%; background: #dfe6ef; color: #7d8ea3; }
.award.got { background: #fff6d6; } .award.got .i { background: var(--gold); color: #fff; }
.award b { display: block; font-size: 1rem; } .award small { color: var(--muted); font-size: .85rem; }
.win-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.win-actions .btn-go { grid-column: 1 / -1; min-height: 58px; font-size: 1.2rem; }
.unlock-note { margin: -6px 0 14px; padding: 8px 12px; border-radius: 14px; background: #e8f3ff; font-weight: 600; color: #1f4f8a; }

/* sheets (dialogs) */
.sheet { width: min(96vw, 560px); max-height: min(92dvh, 820px); padding: 0; border: 0; border-radius: 26px; background: #fff; color: var(--ink); box-shadow: 0 30px 80px rgba(0,0,0,.35); }
.sheet.wide { width: min(96vw, 860px); }
.sheet.small { width: min(92vw, 400px); padding: 22px; }
.sheet::backdrop { background: rgba(20,35,55,.45); }
.sheet-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 10px; padding: 14px 16px 10px 22px; background: #fff; border-bottom: 1px solid var(--line); }
.sheet-head h2 { margin: 0; flex: 1; font-size: 1.4rem; }
.sheet-body { padding: 14px 22px 22px; }
.sheet h3 { margin: 16px 0 8px; font-size: 1.05rem; }
.sheet h3:first-child { margin-top: 0; }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { width: 48px; height: 48px; border-radius: 50%; border: 4px solid #fff; box-shadow: 0 0 0 2px var(--line); }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 3px var(--ink); }
.opts { display: flex; flex-wrap: wrap; gap: 8px; }
.opt { min-height: 44px; padding: 0 14px; border: 2px solid var(--line); border-radius: 999px; background: #fff; font-weight: 600; font-size: .92rem; display: inline-flex; align-items: center; gap: 6px; }
.opt[aria-pressed="true"] { border-color: var(--move); background: #e9f1ff; color: #13438f; }
.opt:disabled { opacity: .55; }
.opt .i { width: 18px; height: 18px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; border-bottom: 1px solid #eef2f6; }
.row label { font-weight: 500; }
.switch { position: relative; width: 58px; height: 34px; flex: none; border: 0; border-radius: 99px; background: #cfd8e3; transition: background .15s; }
.switch::after { content: ""; position: absolute; left: 4px; top: 4px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .15s; }
.switch[aria-checked="true"] { background: var(--go); }
.switch[aria-checked="true"]::after { transform: translateX(24px); }
input[type=range] { width: 180px; accent-color: var(--move); }
select { min-height: 44px; padding: 0 10px; border: 2px solid var(--line); border-radius: 12px; font: inherit; background: #fff; }
.modes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.mode { padding: 10px 12px; border: 2px solid var(--line); border-radius: 16px; background: #fff; text-align: left; }
.mode b { display: block; } .mode small { color: var(--muted); font-size: .85rem; line-height: 1.3; display: block; }
.mode[aria-pressed="true"] { border-color: var(--move); background: #eef4ff; }
.tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.gate { text-align: center; padding: 10px 0 6px; }
.hold { position: relative; width: 170px; height: 170px; border-radius: 50%; border: 0; background: conic-gradient(var(--move) calc(var(--p, 0) * 1turn), #e6edf6 0); display: grid; place-items: center; margin: 14px auto; touch-action: none; user-select: none; -webkit-user-select: none; }
.hold span { width: 140px; height: 140px; border-radius: 50%; background: #fff; display: grid; place-items: center; font-weight: 600; padding: 12px; line-height: 1.2; }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.stat { padding: 12px; border-radius: 16px; background: #f3f6fa; }
.stat b { display: block; font-size: 1.6rem; line-height: 1.1; }
.stat small { color: var(--muted); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 6px 8px; border-bottom: 1px solid #eef2f6; text-align: left; white-space: nowrap; }
th { font-weight: 600; color: var(--muted); }
.note { color: var(--muted); font-size: .88rem; }
.danger-zone { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.btn-danger { background: #fff0ef; color: #b3261e; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.sheet.small h2 { margin: 0 0 6px; }
.lock-mini { font-size: .75rem; color: var(--muted); }
.webgl-note { position: fixed; left: 12px; right: 12px; bottom: calc(12px + var(--safe-b)); z-index: 50; padding: 10px 14px; border-radius: 14px; background: #fff3cd; box-shadow: 0 6px 20px rgba(0,0,0,.15); font-size: .9rem; }
.noscript { padding: 24px; text-align: center; }

/* ---------- responsive game layouts ---------- */
@media (max-width: 899px), (max-aspect-ratio: 1/1) {
  .g-main { grid-template-columns: 1fr; grid-template-rows: minmax(210px, 42%) minmax(0, 1fr); gap: 8px; }
  .code { padding: 8px 10px 10px; border-radius: 22px; }
  .stage { border-radius: 22px; }
}
@media (max-width: 999px) and (min-aspect-ratio: 1/1) and (max-height: 520px) {
  /* phone landscape: board left, program right, everything compact */
  .g-main { grid-template-columns: minmax(0, 1fr) minmax(340px, 50%); grid-template-rows: none; gap: 8px; }
  .g-top { padding-top: 4px; padding-bottom: 4px; }
  .g-title p { display: none; }
  .g-title h2 { font-size: 1.05rem; }
  .btn-round { width: 44px; min-height: 44px; }
  .goal { height: 32px; }
  .code { padding: 6px 8px 8px; }
  .code-head { min-height: 40px; }
  .code-head h3, .palette-label { display: none; }
  .program { margin: 2px 0 6px; padding: 6px; min-height: 64px; }
  .palette { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; padding: 0; }
  .tile { min-height: 44px; padding: 3px 2px; font-size: .58rem; border-radius: 11px; gap: 0; }
  .tile svg { width: 20px; height: 20px; }
  .runbar { margin-top: 6px; gap: 6px; }
  .runbar .btn { min-height: 44px; font-size: .85rem; }
  .blk { width: 58px; height: 52px; font-size: .6rem; }
  .blk svg { width: 22px; height: 22px; }
  .toast { font-size: .82rem; max-width: 92%; }
}
@media (max-width: 600px) {
  .g-title .long { display: none; }
  .toast { top: auto; bottom: 8px; }
  .g-top { gap: 6px; padding-top: 6px; padding-bottom: 6px; }
  .g-main { grid-template-rows: minmax(170px, 36%) minmax(0, 1fr); }
  .code-head h3 { display: none; }
  .code-head { min-height: 40px; }
  .program { margin: 2px 0 6px; padding: 8px 6px 10px; }
  .g-title h2 { font-size: 1.1rem; }
  .g-title p { font-size: .68rem; }
  .goal { height: 32px; padding: 0 8px 0 5px; font-size: .82rem; }
  .goal .i { width: 20px; height: 20px; }
  .btn-round { width: 44px; min-height: 44px; }
  .palette { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 5px; padding: 2px; }
  .tile { min-height: 54px; padding: 6px 2px 4px; font-size: .62rem; border-radius: 13px; }
  .tile svg { width: 24px; height: 24px; }
  .tile em { font-size: .6rem; top: -6px; }
  .toast { font-size: .9rem; padding: 8px 12px 8px 10px; top: 8px; }
  .toast .i { width: 22px; height: 22px; }
  .runbar { margin-top: 8px; }
  .blk { width: 62px; height: 58px; font-size: .64rem; }
  .blk svg { width: 24px; height: 24px; }
  .slot { gap: 6px; min-height: 52px; }
  .runbar .btn { min-height: 50px; font-size: .9rem; gap: 4px; padding: 0 6px; }
  .runbar .run { font-size: 1.1rem; }
  .code-head h3 { font-size: .95rem; }
  .palette-label { display: none; }
  .c-head { min-height: 48px; padding: 4px 8px; }
  .c-body { padding: 6px 6px 4px 10px; border-left-width: 8px; }
  .stage-tools .chip-btn span:not(.i) { display: none; }
  .modes { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .win-card h2 { font-size: 1.7rem; }
}
@media (max-width: 380px) {
  .runbar { grid-template-columns: 1.4fr 1fr 1fr 1fr; }
  .runbar .btn span:not(.i) { font-size: .82rem; }
  .goal { padding: 0 6px 0 4px; }
}
@media (max-height: 760px) { body.in-game random-express-nav { display: none; } body.in-game { --nav: 0px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; } }
body.reduced *, body.reduced *::before, body.reduced *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
