@import url('https://fonts.googleapis.com/css2?family=Noto+Sans:wght@500;700;900&family=Noto+Sans+KR:wght@500;700;900&family=Nunito:wght@700;800;900&display=swap');
*{box-sizing:border-box;margin:0;padding:0}
html,body{width:100%;height:100%;overflow:hidden;touch-action:none;font-family:'Nunito','Noto Sans','Noto Sans KR',sans-serif;background:#f0f6ff}
#app{width:100vw;height:100vh;display:flex;flex-direction:column;background:#f0f6ff;overflow:hidden}
#app.hidden{display:none}

/* ══════════════════════════════════════
   INTRO SCREEN — ScratchJr friendly
   ══════════════════════════════════════ */
.intro{
  position:fixed;inset:0;z-index:9999;
  display:flex;align-items:center;justify-content:center;
  background:linear-gradient(150deg,#e8f5e9 0%,#e3f2fd 25%,#fff8e1 50%,#fce4ec 75%,#ede7f6 100%);
  overflow:hidden;
}
.intro.exit{animation:introOut .4s ease-in forwards}
@keyframes introOut{to{opacity:0;transform:scale(1.05)}}
.intro-bg{position:absolute;inset:0;overflow:hidden;pointer-events:none}
.intro-shape{position:absolute;border-radius:50%;opacity:.15;animation:float 8s ease-in-out infinite}
.intro-shape.s1{width:200px;height:200px;background:#ffd600;top:-40px;left:10%}
.intro-shape.s2{width:160px;height:160px;background:#42a5f5;top:60%;right:-30px;animation-delay:1.5s}
.intro-shape.s3{width:120px;height:120px;background:#66bb6a;bottom:-20px;left:30%;animation-delay:3s}
.intro-shape.s4{width:180px;height:180px;background:#ce93d8;top:20%;right:20%;animation-delay:2s}
.intro-shape.s5{width:100px;height:100px;background:#ff7043;bottom:15%;left:-20px;animation-delay:4s}
@keyframes float{0%,100%{transform:translateY(0) scale(1)}50%{transform:translateY(-20px) scale(1.08)}}
.intro-body{position:relative;z-index:2;text-align:center;padding:40px 32px;max-width:440px;width:90%}
.intro-logo{display:flex;align-items:center;justify-content:center;gap:14px;margin-bottom:28px}
.intro-icon{
  width:68px;height:68px;border-radius:20px;
  background:linear-gradient(150deg,#ffe566,#ffd600 40%,#f9a825);
  border:3px solid #e6a800;display:flex;align-items:center;justify-content:center;
  font-size:30px;color:#43a047;
  box-shadow:0 5px 20px #f9a82544,inset 0 2px 6px #fff8;
}
.intro-brand small{font-size:12px;color:#90a4ae;font-weight:700;display:block;line-height:1}
.intro-brand b{font-size:28px;color:#37474f;font-weight:900}
.intro-title{font-size:clamp(24px,5vw,34px);font-weight:900;color:#263238;margin-bottom:6px;line-height:1.2}
.intro-sub{font-size:clamp(13px,2.5vw,16px);color:#607d8b;font-weight:600;margin-bottom:32px}
.intro-lang{display:flex;gap:12px;justify-content:center;margin-bottom:32px;flex-wrap:wrap}
.lang-btn{
  display:flex;flex-direction:column;align-items:center;gap:6px;
  padding:14px 20px;border-radius:18px;background:#fff;border:3px solid #e0e8f0;
  cursor:pointer;transition:all .2s;min-width:90px;box-shadow:0 3px 10px #00000008;
}
.lang-btn:hover{border-color:#90caf9;transform:translateY(-2px);box-shadow:0 5px 18px #42a5f520}
.lang-btn.active{border-color:#42a5f5;background:linear-gradient(180deg,#e3f2fd,#bbdefb40);box-shadow:0 5px 18px #42a5f530;transform:translateY(-2px)}
.lang-flag{font-size:28px;line-height:1}
.lang-name{font-size:12px;font-weight:700;color:#455a64}
.lang-btn.active .lang-name{color:#1565c0}
.intro-start{
  display:inline-flex;align-items:center;justify-content:center;
  padding:16px 52px;border-radius:20px;
  background:linear-gradient(180deg,#66bb6a,#43a047);
  border:3px solid #2e7d32;color:#fff;font-size:20px;font-weight:900;
  cursor:pointer;transition:all .15s;
  box-shadow:0 5px 20px #43a04744,inset 0 2px 4px #ffffff30;letter-spacing:.5px;
}
.intro-start:hover{transform:translateY(-2px);box-shadow:0 7px 28px #43a04755}
.intro-start:active{transform:translateY(1px);box-shadow:0 2px 8px #43a04744}
.intro-footer{margin-top:32px;font-size:11px;color:#90a4ae}

/* ══════════════════════════════════════
   TOAST POPUP — 상단 헤더 아래 중앙
   ══════════════════════════════════════ */
.toast-wrap{
  position:fixed;top:72px;left:50%;
  transform:translateX(-50%);
  z-index:1000;pointer-events:none;
  display:flex;flex-direction:column;gap:8px;
  align-items:center;
}
.toast{
  background:#f44336;color:#fff;
  padding:12px 20px;border-radius:12px;
  font-weight:600;font-size:14px;
  box-shadow:0 4px 16px rgba(0,0,0,.2);
  animation:toastIn .3s ease;
  pointer-events:auto;
  white-space:nowrap;
}
.toast.out{animation:toastOut .3s ease forwards}
@keyframes toastIn{from{opacity:0;transform:translateY(-10px)}to{opacity:1;transform:translateY(0)}}
@keyframes toastOut{to{opacity:0;transform:translateY(-10px)}}

/* ══════════════════════════════════════
   POPUP MODAL — 중앙 알림 (이미지 포함)
   ══════════════════════════════════════ */
.popup-overlay{
  position:fixed;inset:0;background:rgba(0,0,0,.5);
  z-index:1500;display:none;
}
.popup-overlay.on{display:block}
.popup{
  position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);
  background:#fff;border-radius:20px;padding:32px 36px;
  box-shadow:0 8px 32px rgba(0,0,0,.3);
  z-index:1600;display:none;
  text-align:center;max-width:560px;
}
.popup.on{display:block}
.popup img{max-width:480px;width:100%;margin-bottom:16px;border-radius:12px}
.popup-msg{font-size:18px;font-weight:600;color:#333;margin-bottom:20px;line-height:1.5;white-space:pre-line}
.popup-close{
  background:#29A8E0;color:#fff;border:none;
  padding:10px 32px;border-radius:12px;
  font-size:15px;font-weight:700;cursor:pointer;
}
.popup-close:hover{filter:brightness(1.1)}

/* ══════════════════════════════════════
   HEADER — ScratchJr style, rounded & bright
   ══════════════════════════════════════ */
.hd{
  background:linear-gradient(180deg,#fff,#f4f8fc);
  border-bottom:3px solid #dde6f0;
  padding:6px 14px;display:flex;align-items:center;justify-content:space-between;
  height:60px;flex-shrink:0;
  box-shadow:0 3px 12px #00000008;
  position:relative;z-index:50;
}
.hd-l{display:flex;align-items:center;gap:10px}
.logo{display:flex;align-items:center;gap:10px}
.logo-i{
  width:46px;height:46px;border-radius:14px;
  background:linear-gradient(150deg,#ffe566,#ffd600 40%,#f9a825);
  border:2.5px solid #e6a800;display:flex;align-items:center;justify-content:center;
  font-size:22px;color:#43a047;
  box-shadow:0 3px 12px #f9a82544,inset 0 2px 4px #fff8;position:relative;
}
.logo-i::after{content:'';position:absolute;top:3px;left:16%;right:16%;height:36%;background:linear-gradient(180deg,#fff8,transparent);border-radius:50%}
.logo small{font-size:10px;color:#90a4ae;font-weight:700;display:block;line-height:1}
.logo b{font-size:20px;color:#37474f;font-weight:900}

.hd-r{display:flex;gap:5px;align-items:center}
.hd-btn{
  height:42px;border-radius:12px;border:none;
  padding:0 14px;font-size:13px;font-weight:800;
  cursor:pointer;display:flex;align-items:center;gap:5px;
  transition:all .15s ease;
  box-shadow:0 1px 3px #00000012,0 1px 2px #00000008;position:relative;
}
.hd-btn:hover{transform:translateY(-1px);box-shadow:0 3px 8px #00000016}
.hd-btn:active{transform:translateY(0);box-shadow:0 1px 2px #00000010}
.hd-btn svg{flex-shrink:0;display:block}

/* Run button — semi-flat */
.hd-btn.run{
  background:linear-gradient(180deg,#43a047,#2e7d32);
  border:2px solid #1b5e20;color:#fff;
  font-size:13px;padding:0 14px;height:42px;
  box-shadow:0 2px 6px #2e7d3240;border-radius:12px;
  text-shadow:0 1px 2px rgba(0,0,0,0.25);
}
.hd-btn.run:hover{background:linear-gradient(180deg,#4caf50,#388e3c);box-shadow:0 3px 10px #2e7d3250}
.hd-btn.run:active{background:#1b5e20;box-shadow:0 1px 3px #2e7d3230}
.hd-btn.run.on{
  background:linear-gradient(180deg,#d32f2f,#b71c1c);
  border-color:#8e1515;box-shadow:0 2px 6px #b71c1c40;
}

/* Secondary buttons — semi-flat */
.hd-btn.save{background:#f0f7ff;border:1.5px solid #90caf9;color:#1976d2;padding:0 10px}
.hd-btn.save:hover{background:#e3f2fd;border-color:#64b5f6}
.hd-btn.load{background:#f0f9f1;border:1.5px solid #a5d6a7;color:#388e3c;padding:0 10px}
.hd-btn.load:hover{background:#e8f5e9;border-color:#81c784}
.hd-btn.rst{background:#f8f8f8;border:1.5px solid #e0e0e0;color:#9e9e9e;padding:0 10px}
.hd-btn.rst:hover{background:#f0f0f0;border-color:#bdbdbd}
.hd-btn.cfg{background:#f8f8f8;border:1.5px solid #e0e0e0;color:#78909c;padding:0 10px}
.hd-btn.cfg:hover{background:#f0f0f0;border-color:#bdbdbd}
.hd-btn.save:active,.hd-btn.load:active,.hd-btn.rst:active,.hd-btn.cfg:active{transform:translateY(0);box-shadow:inset 0 1px 3px #00000010}

.hd-tip{
  position:absolute;bottom:-22px;left:50%;transform:translateX(-50%);
  font-size:10px;font-weight:700;color:#78909c;white-space:nowrap;
  pointer-events:none;opacity:0;transition:opacity .15s;
}
.hd-btn:hover .hd-tip{opacity:1}

/* ══════════════════════════
   AI TOGGLE — Emphasized
   ══════════════════════════ */
.hd-btn.ai-toggle{
  background:linear-gradient(180deg,#5e35b1,#4527a0);
  border:2px solid #311b92;color:#fff;padding:0 12px;
  box-shadow:0 2px 6px #4527a030;
  text-shadow:0 1px 2px rgba(0,0,0,0.25);
}
.hd-btn.ai-toggle:hover{background:linear-gradient(180deg,#7e57c2,#5e35b1);box-shadow:0 3px 10px #4527a040}
.hd-btn.ai-toggle:active{background:#311b92;box-shadow:0 1px 3px #4527a020}
.hd-btn.ai-toggle.on{background:linear-gradient(180deg,#ab47bc,#8e24aa);border-color:#6a1b9a;box-shadow:0 2px 10px #ab47bc44}
.hd-btn.ai-toggle svg{stroke:#fff;fill:#ede7f633}
.hd-btn.ai-toggle svg circle{fill:#d1c4e9}
.ai-label{font-size:12px;font-weight:800;letter-spacing:.5px}

.hd-btn.lang-switch{background:#f8f8f8;border:1.5px solid #cfd8dc;color:#607d8b;font-size:18px;padding:0 10px}
.hd-btn.lang-switch:hover{background:#eceff1;border-color:#b0bec5}

/* ══════════════════════════
   BLE TOGGLE
   ══════════════════════════ */
.hd-btn.ble-toggle{
  background:linear-gradient(180deg,#1e88e5,#1565c0);border:2px solid #0d47a1;
  color:#fff;gap:6px;font-size:13px;font-weight:700;
  box-shadow:0 2px 6px #0d47a130;
  text-shadow:0 1px 2px rgba(0,0,0,0.25);
}
.hd-btn.ble-toggle:hover{background:linear-gradient(180deg,#42a5f5,#1e88e5);box-shadow:0 3px 10px #0d47a140}
.hd-btn.ble-toggle:active{background:#0d47a1;box-shadow:0 1px 3px #0d47a120}
.hd-btn.ble-toggle.has-conn{background:linear-gradient(180deg,#43a047,#2e7d32);border-color:#1b5e20;box-shadow:0 2px 6px #2e7d3230}

/* ══════════════════════════════════
   BLE DRAWER
   ══════════════════════════════════ */
.ble-overlay{position:fixed;inset:0;background:#00000044;z-index:400;display:none;backdrop-filter:blur(3px)}
.ble-overlay.on{display:block}
.ble-drawer{
  position:fixed;top:0;right:-360px;width:340px;height:100vh;
  background:#f8fbff;border-left:3px solid #dde6f0;
  z-index:410;display:flex;flex-direction:column;
  transition:right .28s cubic-bezier(.4,0,.2,1);
  box-shadow:-8px 0 36px #00000012;border-radius:24px 0 0 24px;
}
.ble-drawer.on{right:0}
.ble-drawer-hd{
  display:flex;justify-content:space-between;align-items:center;
  padding:14px 18px;background:linear-gradient(180deg,#fff,#f0f6fc);
  border-bottom:2px solid #e3ecf4;border-radius:24px 0 0 0;
}
.ble-drawer-hd span{font-size:16px;font-weight:900;color:#37474f}
.ble-drawer-x{background:none;border:none;font-size:22px;color:#90a4ae;cursor:pointer;padding:4px;line-height:1;border-radius:10px}
.ble-drawer-x:hover{color:#546e7a;background:#e3ecf4}
.ble-drawer-grp{padding:10px 18px;border-bottom:2px solid #e3ecf4;background:#f0f6fc}
.ble-drawer-grp label{font-size:12px;font-weight:700;color:#546e7a;display:block;margin-bottom:6px}
.ble-grp-row{display:flex;gap:8px}
.ble-grp-row input{
  flex:1;height:42px;background:#fff;border:2.5px solid #d6e3f0;border-radius:12px;
  color:#37474f;font-size:16px;font-weight:700;padding:0 12px;outline:none;
}
.ble-grp-row input:focus{border-color:#42a5f5;box-shadow:0 0 0 3px #42a5f522}
.ble-grp-btn{
  height:42px;padding:0 18px;background:linear-gradient(180deg,#1e88e5,#1565c0);
  border:2px solid #0d47a1;border-radius:12px;
  color:#fff;font-size:13px;font-weight:700;cursor:pointer;
  box-shadow:0 2px 6px #0d47a130;transition:all .15s ease;
}
.ble-grp-btn:hover{background:linear-gradient(180deg,#42a5f5,#1e88e5);box-shadow:0 3px 8px #0d47a140}
.ble-grp-btn:active{background:#0d47a1;box-shadow:0 1px 2px #0d47a120;transform:translateY(0)}
.ble-drawer-grp small{font-size:11px;color:#90a4ae;margin-top:6px;display:block}
.ble-drawer-list{flex:1;overflow-y:auto;padding:8px 12px}
.ble-drawer-list::-webkit-scrollbar{width:5px}.ble-drawer-list::-webkit-scrollbar-thumb{background:#d6e3f0;border-radius:3px}
.ble-card{
  display:flex;align-items:center;gap:10px;padding:10px 14px;
  background:#fff;border:2.5px solid #e3ecf4;border-radius:16px;
  margin-bottom:6px;transition:all .15s;box-shadow:0 2px 8px #00000006;
}
.ble-card.on{border-color:#66bb6a;background:#f1f8f1;box-shadow:0 3px 12px #66bb6a18}
.ble-card-icon{width:36px;height:36px;border-radius:12px;display:flex;align-items:center;justify-content:center;font-size:18px;flex-shrink:0}
.ble-card-info{flex:1;min-width:0}
.ble-card-name{font-size:13px;font-weight:800;color:#37474f}
.ble-card-status{font-size:10px;font-weight:600;color:#b0bec5;margin-top:1px}
.ble-card-status.on{color:#66bb6a}
.ble-card-btn{
  height:32px;padding:0 14px;border-radius:10px;font-size:11px;font-weight:700;
  cursor:pointer;border:none;transition:all .08s;flex-shrink:0;
}
.ble-card-btn.connect{background:linear-gradient(180deg,#1e88e5,#1565c0);color:#fff;border:2px solid #0d47a1;box-shadow:0 2px 6px #0d47a130}
.ble-card-btn.connect:hover{background:linear-gradient(180deg,#42a5f5,#1e88e5);box-shadow:0 3px 8px #0d47a140}
.ble-card-btn.connect:active{background:#0d47a1;box-shadow:0 1px 2px #0d47a120;transform:translateY(0)}
.ble-card-btn.disconnect{background:#fafafa;color:#e53935;border:1.5px solid #ef9a9a}
.ble-card-btn.disconnect:hover{background:#fce4ec;border-color:#e57373}
.ble-card-btn.disconnect:active{background:#f8bbd0;transform:translateY(0)}
.ble-drawer-foot{padding:14px 18px;border-top:2px solid #e3ecf4;display:flex;gap:8px;background:#f0f6fc;border-radius:0 0 0 24px}
.ble-log{padding:8px 18px;font-size:11px;line-height:1.7;color:#546e7a;background:#f8fbff;border-top:1.5px solid #e3ecf4;min-height:32px;max-height:90px;overflow-y:auto;word-break:break-all}
.ble-foot-btn{
  flex:1;height:42px;border-radius:12px;border:1.5px solid #d6e3f0;
  background:#f8f8f8;color:#78909c;font-size:13px;font-weight:700;cursor:pointer;transition:all .15s ease;
}
.ble-foot-btn:hover{border-color:#90a4ae;color:#546e7a;background:#f0f0f0}
.ble-foot-btn:active{box-shadow:inset 0 1px 3px #00000010;transform:translateY(0)}
.ble-foot-btn.rev.on{background:#fff3e0;color:#e65100;border-color:#ffb74d}
.ble-foot-btn.dis:hover{background:#fce4ec;color:#e53935;border-color:#ef9a9a}

/* ══════════════════════════
   SETTINGS MODAL
   ══════════════════════════ */
.cfg-overlay{position:fixed;inset:0;background:#00000055;z-index:500;display:none;align-items:center;justify-content:center;backdrop-filter:blur(3px)}
.cfg-overlay.on{display:flex}
.cfg-panel{background:#fff;border-radius:24px;padding:24px 28px;width:400px;max-width:92vw;box-shadow:0 16px 48px #0002}
.cfg-hd{display:flex;justify-content:space-between;align-items:center;margin-bottom:18px;font-size:17px;font-weight:900;color:#37474f}
.cfg-x{background:none;border:none;font-size:22px;color:#90a4ae;cursor:pointer;padding:4px}
.cfg-row{margin-bottom:16px}
.cfg-ev-row{padding-bottom:14px;border-bottom:1.5px solid #e8f0f7}
.cfg-ev-line{display:flex;align-items:center;justify-content:space-between;gap:10px}
.cfg-ev-line small{font-size:11px;color:#90a4ae;line-height:1.4;flex:1}
.cfg-ev-toggle{flex-direction:row;padding:2px}
.cfg-ev-toggle:hover{background:none}
.ed-spd-emoji{font-size:16px;flex-shrink:0}

/* ── Confirm modal (pretty replacement for native confirm) ── */
.ask-overlay{position:fixed;inset:0;background:#0006;backdrop-filter:blur(3px);display:none;align-items:center;justify-content:center;z-index:400}
.ask-overlay.on{display:flex}
.ask-panel{background:#fff;border-radius:26px;padding:26px 30px 22px;box-shadow:0 18px 50px #0005;text-align:center;min-width:270px;max-width:80vw;animation:askPop .22s ease}
@keyframes askPop{from{transform:scale(.82);opacity:0}to{transform:scale(1);opacity:1}}
.ask-emoji{font-size:46px;margin-bottom:8px;animation:bob2 2s ease-in-out infinite}
@keyframes bob2{0%,100%{transform:translateY(0)}50%{transform:translateY(-4px)}}
.ask-msg{font-size:17px;font-weight:800;color:#37474f;margin:0 0 18px;line-height:1.5}
.ask-btns{display:flex;gap:10px;justify-content:center}
.ask-btn{border:none;border-radius:16px;padding:12px 26px;font-size:15px;font-weight:800;cursor:pointer;font-family:inherit;transition:transform .1s}
.ask-btn.no{background:#eceff1;color:#78909c}
.ask-btn.yes{background:#ff7043;color:#fff;box-shadow:0 4px 14px #ff704355}
.ask-btn:active{transform:scale(.93)}
.grp-sub{font-size:13px;color:#607d8b;margin:0 0 14px;line-height:1.6;white-space:pre-line;text-align:center}
.grp-input{width:140px;font-size:24px;font-weight:800;text-align:center;color:#1565c0;border:2.5px solid #90caf9;border-radius:14px;padding:8px 10px;margin:0 auto 18px;display:block;outline:none}
.grp-input:focus{border-color:#42a5f5;box-shadow:0 0 0 4px #42a5f522}
.flash{animation:flashShake .5s ease}
@keyframes flashShake{0%,100%{transform:translateX(0)}20%,60%{transform:translateX(-6px)}40%,80%{transform:translateX(6px)}}
.ble-grp-row input.flash{border-color:#ef5350}

/* ── Arabic RTL: text flows right-to-left, but spatial coding areas stay LTR
   so block execution order (left→right) and the condition column (col 0 = left)
   keep their meaning. Arabic glyphs still shape correctly inside LTR containers. ── */
html[dir=rtl] .hd,
html[dir=rtl] .grid-stage,
html[dir=rtl] .grid-cells,
html[dir=rtl] .pal-wrap,
html[dir=rtl] .pal,
html[dir=rtl] .hw-bar{direction:ltr}
.cfg-row label{display:flex;align-items:center;gap:7px;font-size:13px;font-weight:700;color:#546e7a;margin-bottom:6px}
.cfg-row label svg{flex-shrink:0;width:18px;height:18px}
.cfg-row input[type=range]{width:100%;height:8px;-webkit-appearance:none;background:#e3ecf4;border-radius:4px;outline:none}
.cfg-row input[type=range]::-webkit-slider-thumb{-webkit-appearance:none;width:26px;height:26px;border-radius:50%;background:#42a5f5;cursor:pointer;box-shadow:0 2px 10px #0002}
.cfg-val{display:block;text-align:right;font-size:14px;font-weight:800;color:#1e88e5;margin-top:2px}
.cfg-btns{display:flex;gap:8px;justify-content:flex-end;margin-top:20px}
.cfg-btn{padding:10px 22px;border-radius:12px;font-size:14px;font-weight:700;cursor:pointer;border:none;transition:all .08s}
.cfg-btn.ok{background:linear-gradient(150deg,#42a5f5,#1e88e5);color:#fff;box-shadow:0 3px 10px #1e88e522;border-bottom:3px solid #1565c0}
.cfg-btn.ok:hover{background:linear-gradient(150deg,#64b5f6,#42a5f5)}
.cfg-btn.ok:active{transform:translateY(1px);border-bottom-width:1px}
.cfg-btn.reset{background:#f5f5f5;color:#90a4ae;border:2.5px solid #e0e0e0;border-bottom:4px solid #bdbdbd}
.cfg-btn.reset:hover{background:#eee}
.cfg-btn.reset:active{transform:translateY(1px);border-bottom-width:2.5px}

/* ══════════════════════════
   GRID STAGE
   ══════════════════════════ */
.grid-stage{
  flex:1;
  background:linear-gradient(170deg,#cde8fa 0%,#b8dcf5 50%,#c5e4f7 100%);
  position:relative;overflow:hidden;
  display:flex;flex-direction:row;align-items:center;justify-content:center;
  gap:0;
  padding:12px 0;
}

/* ── Grid cells container ── */
.grid-cells{
  display:grid;
  grid-template-columns:repeat(6,1fr);
  gap:10px;
  padding:16px 20px;
  flex-shrink:0;
}

/* ── Individual grid cell ── */
.grid-cell{
  width:80px;height:80px;
  border-radius:20px;
  border:3px solid rgba(255,255,255,0.75);
  background:rgba(255,255,255,0.5);
  display:flex;align-items:center;justify-content:center;
  position:relative;
  transition:border-color .15s, background .15s, transform .12s, box-shadow .15s;
  cursor:default;
  box-shadow:0 2px 8px rgba(0,100,160,0.08), inset 0 1px 3px rgba(255,255,255,0.7);
}
.grid-cell.filled{
  background:rgba(255,255,255,0.65);
  border-color:rgba(255,255,255,0.9);
  box-shadow:0 3px 12px rgba(0,100,160,0.12), inset 0 1px 3px rgba(255,255,255,0.8);
}
.grid-cell.condition-hint{
  border-color:rgba(229,57,53,0.5);
  background:rgba(229,57,53,0.08);
  box-shadow:0 0 0 2px rgba(229,57,53,0.2), inset 0 0 8px rgba(229,57,53,0.1);
  animation:condHint 1.2s ease-in-out infinite alternate;
}
@keyframes condHint{
  from{box-shadow:0 0 0 2px rgba(229,57,53,0.15), inset 0 0 6px rgba(229,57,53,0.08);}
  to{box-shadow:0 0 0 4px rgba(229,57,53,0.35), inset 0 0 12px rgba(229,57,53,0.18);}
}
.grid-cell.condition.condition-hint{
  animation:none; /* already has full condition style */
}
  border-color:rgba(229,57,53,0.7);
  background:rgba(229,57,53,0.15);
  box-shadow:0 0 0 2px rgba(229,57,53,0.25), 0 3px 10px rgba(229,57,53,0.2);
}
.grid-cell.condition.filled{
  background:rgba(229,57,53,0.18);
  border-color:rgba(229,57,53,0.8);
}
  border-color:#42a5f5;
  background:rgba(66,165,245,0.18);
  transform:scale(1.06);
  box-shadow:0 0 0 3px #42a5f544, 0 4px 16px rgba(66,165,245,0.3);
}
.grid-cell.active{
  border-color:#66bb6a;
  background:rgba(102,187,106,0.2);
  box-shadow:0 0 0 3px #66bb6a44, 0 4px 20px rgba(102,187,106,0.4);
  animation:cellPulse .5s ease-in-out infinite alternate;
}
@keyframes cellPulse{
  from{box-shadow:0 0 0 3px #66bb6a44, 0 4px 20px rgba(102,187,106,0.3);}
  to{box-shadow:0 0 0 5px #66bb6a66, 0 6px 28px rgba(102,187,106,0.55);}
}


/* ── Run indicator dot ── */
@keyframes blink{0%,100%{opacity:1}50%{opacity:.3}}
.run-dot{display:inline-block;width:8px;height:8px;border-radius:50%;background:#66bb6a;margin-right:5px;animation:blink 1s infinite}

/* ══════════════════════════
   RUN PANEL — right of grid
   ══════════════════════════ */
.grid-run-panel{
  display:flex;flex-direction:column;align-items:center;gap:10px;
  padding:0 16px 0 8px;
  flex-shrink:0;
}

/* Cycle button — changes repeat count */
.run-cycle-btn{
  width:44px;height:44px;border-radius:50%;
  background:url('../img/number.png') center/cover no-repeat;
  border:none;
  box-shadow:none;
  display:flex;align-items:center;justify-content:center;
  cursor:pointer;transition:transform .18s;
  color:#fff;font-size:20px;
}
.run-cycle-btn:hover{transform:scale(1.1);}
.run-cycle-btn:active{transform:scale(0.92) rotate(90deg)}
.run-cycle-btn.spinning{animation:spinOnce .3s ease-out forwards}
@keyframes spinOnce{from{transform:rotate(0deg)}to{transform:rotate(360deg)}}

/* Run button — yellow circle + SVG green triangle with number */
.grid-run-btn{
  width:92px;height:92px;border-radius:50%;
  background:url('../img/play.png') center/cover no-repeat;
  border:none;
  box-shadow:none;
  display:flex;align-items:center;justify-content:center;
  cursor:pointer;transition:transform .12s;
  position:relative;
}
.grid-run-btn:hover{transform:scale(1.06);}
.grid-run-btn:active{transform:scale(0.94)}
.grid-run-btn.stop{
  background:url('../img/stop.png') center/cover no-repeat;
}
.grid-run-btn.stop:hover{transform:scale(1.06);}

/* SVG triangle container inside run button */
.run-btn-svg{
  width:100%;height:100%;
  position:absolute;top:0;left:0;
  display:flex;align-items:center;justify-content:center;
}
.run-btn-svg svg{display:none;}
.run-btn-stop-icon{display:none;}
.bk{
  width:64px;height:64px;
  display:flex;align-items:center;justify-content:center;
  position:relative;user-select:none;cursor:pointer;flex-shrink:0;
  overflow:visible;background:none;border:none;box-shadow:none;
  transition:transform .1s;
}
.bk .i{position:relative;z-index:2;font-weight:900;line-height:1}
.bk .i.w{color:#fff;text-shadow:0 1px 3px #0005,0 0 1px #0003;font-size:26px}
.bk .i.d{color:#333;text-shadow:0 1px 0 #fff4;font-size:26px}
.bk:active{transform:translateY(1px)}
.bk.glow > svg:first-child{animation:glowBk .4s ease-in-out infinite alternate}
@keyframes glowBk{to{filter:brightness(1.4) drop-shadow(0 0 10px #ff572244)}}

/* Value tag — small badge at bottom-right, tap to cycle */
.vt{
  position:absolute;bottom:3px;right:3px;
  background:#fffffff0;
  border:2px solid #a8d0f0;border-radius:8px;
  padding:1px 6px;font-size:12px;font-weight:900;color:#1565c0;
  cursor:pointer;z-index:10;
  line-height:17px;min-width:20px;text-align:center;
  box-shadow:0 1px 4px #00000018;
  transition:background .1s, transform .08s;
}
.vt:hover{border-color:#42a5f5;background:#e3f2fd;transform:scale(1.12)}
.vt:active{transform:scale(0.9)}

/* Block colors (placeholder classes) */
/* ══════════════════════════
   BLOCK — ScratchJr Rounded Rectangle
   ══════════════════════════ */
.bk.Y,.bk.B,.bk.C,.bk.P,.bk.G,.bk.R,.bk.O,.bk.K,.bk.A,.bk.T,.bk.V,.bk.F1,.bk.F2,.bk.F3{}
.cdot{width:30px;height:30px;border-radius:50%;position:relative;z-index:2;box-shadow:inset 0 1px 2px #fff4,0 2px 4px #0002}

/* ══════════════════════════
   ∏ BRACKET — ScratchJr rounded
   ══════════════════════════ */
.bracket-bg{position:absolute;pointer-events:none;z-index:1}
.glow-bg svg{animation:glowBg .4s ease-in-out infinite alternate}
@keyframes glowBg{to{filter:brightness(1.3) drop-shadow(0 0 14px #ff572266)}}

/* ══════════════════════════════════════════
   HW CATEGORY BAR — ScratchJr rounded tabs
   ══════════════════════════════════════════ */
.hw-bar{
  background:linear-gradient(180deg,#f8fbff,#edf3fa);
  border-top:3px solid #dde6f0;
  padding:6px 14px;display:flex;gap:15px;
  overflow-x:auto;height:80px;align-items:center;flex-shrink:0;
}
.hw-bar::-webkit-scrollbar{height:0}
.hwb{
  height:70px;border-radius:15px;border:none;
  display:flex;align-items:center;justify-content:center;gap:5px;
  cursor:pointer;flex-shrink:0;font-size:17px;padding:0 25px;
  position:relative;transition:transform .12s,opacity .15s;
  font-weight:700;color:#fff;border-bottom:4px solid #00000022;
}
.hwb:hover{transform:translateY(-2px)}.hwb:active{transform:translateY(1px);border-bottom-width:2px}
.hwb:not(.on):not(.hw-active){opacity:.35;filter:saturate(.2);transition:opacity .25s,filter .25s}
.hwb.hw-active:not(.on){opacity:.8;filter:saturate(.8);transition:opacity .25s,filter .25s}
.hwb.on:not(.hw-active){transform:translateY(-1px);opacity:.45;filter:saturate(.25)}
.hwb.on.hw-active{transform:translateY(-1px);opacity:1;filter:none}
.hwb .hw-label{font-size:12px;font-weight:800;color:#fff;text-shadow:0 1px 2px #0003}
.hwb .ph-bold{font-size:20px;color:#fff;text-shadow:0 1px 3px #0004;filter:drop-shadow(0 0 2px #fff3)}

/* ══════════════════════════════
   PALETTE — ScratchJr style
   ══════════════════════════════ */
.pal-wrap{
  display:flex;align-items:stretch;flex-shrink:0;
  background:linear-gradient(180deg,#f8fbff,#edf3f8);
  border-top:2px solid #dde6f0;position:relative;
}
.pal-arrow{
  width:40px;flex-shrink:0;border:none;
  background:linear-gradient(180deg,#f0f6fc,#e3ecf4);
  color:#607d8b;font-size:24px;font-weight:900;
  cursor:pointer;transition:all .08s;
  display:flex;align-items:center;justify-content:center;
  z-index:2;border-bottom:3px solid #c5d5e4;
}
.pal-arrow:hover{background:#dce8f2;color:#37474f}
.pal-arrow:active{transform:translateY(1px);border-bottom-width:1px}
.pal-arrow-l{border-right:2px solid #dde6f0}
.pal-arrow-r{border-left:2px solid #dde6f0}

.pal{
  flex:1;padding:10px 16px 14px;display:flex;gap:26px;
  overflow-x:auto;min-height:108px;align-items:flex-start;
  -webkit-overflow-scrolling:touch;scroll-behavior:smooth;
}
.pal::-webkit-scrollbar{height:4px}.pal::-webkit-scrollbar-thumb{background:#c5d5e4;border-radius:2px}
.pi{flex-shrink:0;display:flex;flex-direction:column;align-items:center;gap:4px;cursor:grab;padding-bottom:2px;min-width:64px;padding-right:10px}
.pi .bk{width:60px;height:60px;transition:transform .08s,box-shadow .08s;filter:drop-shadow(0 3px 2px rgba(0,0,0,0.18))}
.pi .bk:hover{transform:translateY(-3px);box-shadow:0 8px 20px #00000022 !important}
.pi .bk:active{transform:translateY(1px) !important;box-shadow:0 1px 4px #00000018 !important}
.pi span{font-size:11px;font-weight:700;color:#78909c}

/* ══════════════════════════
   Touch targets: larger on tablets
   ══════════════════════════ */
@media (pointer:coarse) {
  .hd-btn{height:46px;padding:0 14px;font-size:15px;min-width:46px}
  .hd-btn.run{height:48px;padding:0 28px;font-size:18px}
  .hwb{height:54px;font-size:18px;padding:0 18px}
  .hwb .hw-label{font-size:13px}
  .hw-bar{height:66px;padding:7px 14px;gap:8px}
  .pi .bk{width:66px;height:66px;filter:drop-shadow(0 3px 2px rgba(0,0,0,0.18))}
  .pal{min-height:116px;padding:12px 16px 18px;gap:28px}
  .pal-arrow{width:46px;font-size:28px}
  .ble-card{padding:14px 16px}
  .ble-card-icon{width:46px;height:46px;font-size:22px}
  .ble-card-name{font-size:15px}
  .ble-card-btn{height:38px;font-size:13px;padding:0 18px}
  .zoom-btn{width:42px;height:42px;font-size:19px}
}

/* ══════════════════════════
   NUMPAD — Rounded ScratchJr
   ══════════════════════════ */
.np{
  position:absolute;background:#fff;border-radius:20px;
  padding:14px;box-shadow:0 10px 36px #0002;
  border:3px solid #42a5f5;z-index:300;width:170px;display:none;
}
.np.on{display:block}
.np-h{display:flex;justify-content:space-between;align-items:center;margin-bottom:8px}
.np-h b{font-size:14px;color:#37474f;font-weight:800}
.np-val{display:inline-block;min-width:28px;text-align:center;font-size:18px;font-weight:900;color:#1565c0;background:#e3f2fd;border-radius:6px;padding:1px 8px;margin-left:6px;vertical-align:middle}
.np-x{border:none;background:none;font-size:16px;color:#90a4ae;cursor:pointer;font-weight:700}
.np-g{display:grid;grid-template-columns:repeat(3,1fr);gap:5px}
.np-b{
  aspect-ratio:1;border:2.5px solid #e3ecf4;border-bottom:4px solid #c5d5e4;border-radius:14px;
  background:linear-gradient(180deg,#fff,#f5f8fc);
  font-size:20px;font-weight:800;color:#37474f;cursor:pointer;transition:transform .06s;
}
.np-b:hover{background:#e3f2fd;border-color:#90caf9;border-bottom-color:#64b5f6;transform:translateY(-1px)}
.np-b:active{transform:translateY(1px);border-bottom-width:2.5px}
.np-b.x{background:#fff0f0;color:#e53935;border-color:#ef9a9a;border-bottom-color:#e57373}

/* ══════════════════════════
   GHOST
   ══════════════════════════ */
.ghost{position:fixed;pointer-events:none;z-index:999;opacity:.85;display:flex;filter:drop-shadow(0 6px 16px #0004)}

/* ══════════════════════════
   STATUS BAR
   ══════════════════════════ */
.st{
  background:linear-gradient(180deg,#edf3fa,#dde8f2);
  border-top:2px solid #d6e3f0;
  padding:3px 16px;display:flex;justify-content:space-between;
  align-items:center;height:30px;flex-shrink:0;
}
.st span{color:#78909c;font-size:12px;font-weight:700}
.st .run-dot{display:inline-block;width:8px;height:8px;border-radius:50%;background:#43a047;animation:blink .8s infinite;margin-right:5px}
@keyframes blink{0%,100%{opacity:1}50%{opacity:.3}}

/* ══════════════════════════
   LOG
   ══════════════════════════ */
.log{
  position:absolute;bottom:8px;left:8px;
  background:#ffffffee;color:#37474f;
  font-size:11px;font-weight:700;
  padding:10px 16px;border-radius:16px;
  max-width:320px;z-index:100;display:none;line-height:1.7;
  backdrop-filter:blur(8px);border:2px solid #dde6f0;
  box-shadow:0 3px 16px #00000010;
}
.log.on{display:block}

/* ══════════════════════════
   AI CAMERA
   ══════════════════════════ */
.ai-cam{
  position:absolute;top:10px;right:10px;width:400px;height:300px;
  border-radius:20px;overflow:hidden;
  border:3px solid #7c4dff;box-shadow:0 8px 30px #0004;
  z-index:150;display:none;background:#000;
}
.ai-cam.on{display:block}
.ai-cam video{width:100%;height:100%;object-fit:cover;transform:scaleX(-1)}
.ai-cam canvas{position:absolute;top:0;left:0;width:100%;height:100%;pointer-events:none}
.ai-badge{position:absolute;bottom:6px;right:6px;background:#000a;color:#b388ff;font-size:10px;font-weight:700;padding:3px 8px;border-radius:8px;display:flex;align-items:center;gap:4px}
.ai-badge img{width:14px;height:14px;display:block}
.ai-badge .dot{display:inline-block;width:11px;height:11px;border-radius:50%;box-shadow:0 0 0 1px #fff5}
.ai-close{position:absolute;top:4px;right:6px;background:none;border:none;color:#fffc;font-size:16px;cursor:pointer;font-weight:700;z-index:2}
.ai-resize{position:absolute;left:0;bottom:0;width:22px;height:22px;cursor:nesw-resize;z-index:3;touch-action:none}
.ai-resize::before{content:'';position:absolute;left:5px;bottom:5px;width:9px;height:9px;border-left:2px solid #fff9;border-bottom:2px solid #fff9;border-radius:0 0 0 3px}

/* ══════════════════════════════════════
   EDITOR MODAL
   ══════════════════════════════════════ */
.editor-overlay{
  position:fixed;inset:0;background:#00000066;z-index:600;display:none;
  align-items:center;justify-content:center;backdrop-filter:blur(4px);
}
.editor-panel{
  background:#fff;border-radius:24px;width:90vw;max-width:500px;max-height:88vh;
  display:flex;flex-direction:column;overflow:hidden;box-shadow:0 20px 56px #0004;
}
.editor-hd{
  display:flex;align-items:center;justify-content:space-between;
  padding:16px 20px;border-bottom:2px solid #e8eff5;
}
.editor-title{font-size:17px;font-weight:800;color:#263238}
.editor-x{background:none;border:none;font-size:20px;color:#90a4ae;cursor:pointer;font-weight:700}
.editor-body{flex:1;overflow-y:auto;padding:18px 20px;min-height:0}
.editor-foot{
  display:flex;justify-content:flex-end;gap:10px;padding:14px 20px;border-top:2px solid #e8eff5;
}
.editor-btn{
  padding:10px 26px;border-radius:14px;font-size:14px;font-weight:700;
  cursor:pointer;border:2.5px solid #d6e3f0;background:#fff;color:#546e7a;transition:all .15s;
}
.editor-btn.save{background:linear-gradient(180deg,#66bb6a,#43a047);border-color:#2e7d32;color:#fff}
.editor-btn.save:hover{transform:translateY(-1px);box-shadow:0 5px 14px #43a04744}
.editor-btn.cancel:hover{background:#f5f5f5}

.ed-sec-label{display:block;font-size:11px;font-weight:700;color:#90a4ae;text-transform:uppercase;letter-spacing:1px;margin:12px 0 6px}

/* ── LED DOT EDITOR ── */
.ed-led-wrap{display:flex;gap:16px;align-items:flex-start;flex-wrap:wrap;justify-content:center}
.ed-led-grid{
  display:grid;grid-template-columns:repeat(8,1fr);gap:3px;
  padding:10px;background:#1e1e2e;border-radius:14px;touch-action:none;user-select:none;
}
.ed-dot{width:30px;height:30px;border-radius:6px;background:#2d2d44;cursor:pointer;transition:background .1s;border:1px solid transparent}
.ed-dot:hover{border-color:#7c4dff66}
.ed-dot.on{background:#a78bfa;box-shadow:0 0 8px #a78bfa88}
.ed-led-acts{display:flex;flex-direction:column;gap:6px}
.ed-led-acts button{
  padding:8px 14px;border:2.5px solid #d6e3f0;border-radius:12px;
  background:#fff;color:#546e7a;font-size:12px;font-weight:700;cursor:pointer;transition:all .15s;
}
.ed-led-acts button:hover{border-color:#7c4dff;color:#7c4dff}
.ed-led-pv-wrap{display:flex;justify-content:center;margin:12px 0}
#edLedPv{border-radius:10px;border:2.5px solid #d6e3f0;image-rendering:pixelated;width:80px;height:80px}
.ed-led-presets{margin-top:8px}
.ed-preset-row{display:flex;flex-wrap:wrap;gap:6px}
.ed-preset-btn{
  width:42px;height:42px;border:2.5px solid #d6e3f0;border-radius:12px;
  background:#fff;font-size:18px;cursor:pointer;transition:all .15s;
  display:flex;align-items:center;justify-content:center;
}
.ed-preset-btn:hover{border-color:#7c4dff;transform:translateY(-1px)}
.ed-preset-btn.mel{width:auto;padding:6px 12px;font-size:12px;font-weight:600}

/* Palette toggle blocks */
/* Toggle switch button (M1↔M2) */
.toggle-btn{flex-shrink:0;display:flex;flex-direction:column;align-items:center;gap:6px;cursor:pointer;padding:6px 10px;border-radius:14px;transition:background .2s}
.toggle-btn:hover{background:rgba(0,0,0,0.04)}
.toggle-btn:active{transform:scale(0.95)}
.toggle-track{width:48px;height:26px;border-radius:13px;background:#c5d5e4;position:relative;transition:background .25s}
.toggle-thumb{position:absolute;top:2px;left:2px;width:22px;height:22px;border-radius:11px;background:#fff;box-shadow:0 1px 4px rgba(0,0,0,0.25);transition:left .25s}
.toggle-btn.on .toggle-track{background:#4a90f5}
.toggle-btn.on .toggle-thumb{left:24px}
.toggle-label{font-size:11px;font-weight:700;color:#78909c}

/* ── FRAME STRIP ── */
.ed-fs-wrap{margin-bottom:12px}
.ed-fs{display:flex;gap:6px;overflow-x:auto;padding:8px;background:#f5f7fa;border-radius:14px;border:2px solid #e8eff5}
.ed-fs-thumb{
  display:flex;flex-direction:column;align-items:center;gap:3px;
  padding:4px;border:2.5px solid transparent;border-radius:10px;cursor:pointer;
  transition:all .15s;min-width:48px;
}
.ed-fs-thumb:hover{border-color:#7c4dff44}
.ed-fs-thumb.active{border-color:#7c4dff;background:#ede7f6}
.ed-fs-thumb canvas{width:32px;height:32px;border-radius:6px;image-rendering:pixelated;border:1px solid #d6e3f0}
.ed-fs-thumb span{font-size:10px;font-weight:700;color:#78909c}

/* ── STEP STRIP ── */
.ed-ss-wrap{margin-bottom:12px}
.ed-ss{display:flex;gap:4px;overflow-x:auto;padding:8px;background:#f5f7fa;border-radius:14px;border:2px solid #e8eff5}
.ed-ss-chip{
  display:flex;align-items:center;justify-content:center;
  padding:6px 10px;border-radius:12px;cursor:pointer;
  font-size:10px;font-weight:700;min-width:48px;
  border:3px solid transparent;transition:all .15s;box-shadow:0 2px 8px #0002;
}
.ed-ss-chip:hover{transform:scale(1.08)}
.ed-ss-chip.active{border-color:#333;box-shadow:0 2px 12px #0003}

/* ── Frame/step controls ── */
.ed-f-ctrls{display:flex;gap:6px;margin:10px 0;flex-wrap:wrap}

/* ── Speed/duration sliders ── */
.ed-spd-row{display:flex;align-items:center;gap:10px;margin:8px 0}
.ed-slider-full{flex:1;height:6px;-webkit-appearance:none;appearance:none;border-radius:3px;outline:none;background:linear-gradient(90deg,#d6e3f0,#7c4dff)}
.ed-slider-full::-webkit-slider-thumb{-webkit-appearance:none;width:20px;height:20px;border-radius:50%;background:#fff;border:3px solid #7c4dff;cursor:pointer;box-shadow:0 2px 6px #0003}
.ed-spd-val{font-size:12px;font-weight:700;color:#37474f;min-width:44px;text-align:right;font-family:monospace}
.ed-step-dur{display:flex;flex-direction:column;gap:4px;flex:1}
.ed-step-dur label{font-size:11px;font-weight:700;color:#78909c}

/* ── MELODY EDITOR ── */
.ed-mel-tl-wrap{margin-bottom:12px}
.ed-mel-tl{
  display:flex;gap:3px;flex-wrap:wrap;padding:10px;
  background:#f5f7fa;border-radius:14px;min-height:48px;border:2px dashed #d6e3f0;
}
.ed-mel-empty{color:#b0bec5;font-size:13px;font-weight:500;padding:6px}
.ed-mel-chip{
  display:flex;align-items:center;justify-content:center;
  padding:4px 8px;background:linear-gradient(180deg,#66bb6a,#43a047);
  color:#fff;font-size:11px;font-weight:700;border-radius:10px;
  cursor:pointer;transition:all .15s;box-shadow:0 2px 6px #43a04733;
}
.ed-mel-chip:hover{transform:scale(1.1);opacity:.8}
.ed-mel-chip.rest{background:linear-gradient(180deg,#90a4ae,#607d8b)}
.ed-mel-dur{margin-bottom:12px}
.ed-dur-btns{display:flex;gap:6px;flex-wrap:wrap}
.ed-dur-btns button{
  padding:6px 14px;border:2.5px solid #d6e3f0;border-radius:12px;
  background:#fff;color:#546e7a;font-size:12px;font-weight:700;cursor:pointer;transition:all .15s;
}
.ed-dur-btns button.on{border-color:#43a047;background:#e8f5e9;color:#2e7d32}
.ed-dur-btns button:hover{border-color:#43a047}

/* Piano */
.ed-piano-wrap{margin-bottom:12px}
.ed-piano{display:flex;gap:2px;overflow-x:auto;padding:10px;background:#263238;border-radius:14px}
.ed-key{
  border:none;border-radius:0 0 8px 8px;cursor:pointer;
  display:flex;align-items:flex-end;justify-content:center;
  padding-bottom:6px;font-weight:700;transition:all .1s;touch-action:none;user-select:none;
}
.ed-key.white{
  width:36px;height:80px;background:linear-gradient(180deg,#f5f5f5,#fff);
  color:#78909c;font-size:9px;box-shadow:0 2px 4px #0002,inset 0 -2px 0 #e0e0e0;
}
.ed-key.white:active{background:#e0e0e0}
.ed-key.black{
  width:26px;height:52px;background:linear-gradient(180deg,#37474f,#263238);
  color:#90a4ae;font-size:8px;margin-left:-13px;margin-right:-13px;z-index:2;
  box-shadow:0 2px 6px #0004;
}
.ed-key.black:active{background:#455a64}
.ed-key span{pointer-events:none}
.ed-mel-ctrls{display:flex;gap:8px;margin-bottom:12px;flex-wrap:wrap}
.ed-ctrl-btn{
  padding:8px 16px;border:2.5px solid #d6e3f0;border-radius:12px;
  background:#fff;color:#546e7a;font-size:12px;font-weight:700;cursor:pointer;transition:all .15s;
}
.ed-ctrl-btn.play{border-color:#43a047;color:#2e7d32}
.ed-ctrl-btn:hover{transform:translateY(-1px);box-shadow:0 2px 8px #0001}
.ed-mel-presets{margin-top:4px}

/* ── RGB EDITOR ── */
.ed-rgb-sliders{display:flex;flex-direction:column;gap:12px;margin-bottom:16px}
.ed-rgb-row{display:flex;align-items:center;gap:10px}
.ed-rgb-row label{font-size:14px;font-weight:800;min-width:18px}
.ed-slider{flex:1;height:6px;-webkit-appearance:none;appearance:none;border-radius:3px;outline:none}
.ed-slider::-webkit-slider-thumb{-webkit-appearance:none;width:22px;height:22px;border-radius:50%;background:#fff;border:3px solid #42a5f5;cursor:pointer;box-shadow:0 2px 8px #0003}
.ed-slider.r{background:linear-gradient(90deg,#eee,#f87171)}
.ed-slider.g{background:linear-gradient(90deg,#eee,#4ade80)}
.ed-slider.b{background:linear-gradient(90deg,#eee,#60a5fa)}
.ed-rgb-pv{display:flex;align-items:center;gap:12px;justify-content:center;margin-bottom:16px}
.ed-swatch{width:80px;height:80px;border-radius:18px;border:3px solid #d6e3f0;box-shadow:0 4px 16px #0002}
.ed-rgb-colors{margin-top:4px}
.ed-color-grid{display:flex;flex-wrap:wrap;gap:6px}
.ed-color-btn{
  width:38px;height:38px;border-radius:10px;border:2.5px solid transparent;
  cursor:pointer;transition:all .15s;box-shadow:0 2px 6px #0002;
}
.ed-color-btn:hover{transform:translateY(-2px);border-color:#fff;box-shadow:0 4px 14px #0003}

/* ── Block canvas indicators ── */
.ed-badge{
  position:absolute;top:-5px;right:-5px;width:26px;height:26px;
  border-radius:8px;background:#fff;color:#7c4dff;
  font-size:14px;line-height:26px;text-align:center;
  box-shadow:0 2px 8px #0004;z-index:5;cursor:pointer;border:2.5px solid #d6e3f0;
  transition:all .15s;
}
.ed-badge:hover{background:#ede7f6;border-color:#7c4dff;transform:scale(1.15)}
.ed-color-dot{
  position:absolute;bottom:4px;left:50%;transform:translateX(-50%);
  width:22px;height:22px;border-radius:50%;border:2px solid #fffc;
  box-shadow:0 2px 6px #0003;z-index:3;pointer-events:none;
}
.ed-led-mini{
  position:absolute;bottom:4px;left:50%;transform:translateX(-50%);
  width:30px;height:30px;border-radius:6px;border:1px solid #fff6;
  image-rendering:pixelated;z-index:3;pointer-events:none;
}
.ed-note-cnt{
  position:absolute;bottom:2px;left:50%;transform:translateX(-50%);
  background:#fff;color:#2e7d32;font-size:10px;font-weight:800;
  padding:1px 6px;border-radius:8px;z-index:3;pointer-events:none;
  box-shadow:0 1px 4px #0002;
}
