@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}

/* ══════════════════════════════════════
   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:14px;border:none;
  padding:0 14px;font-size:13px;font-weight:800;
  cursor:pointer;display:flex;align-items:center;gap:5px;
  transition:transform .1s,box-shadow .15s;
  box-shadow:0 2px 8px #00000010;position:relative;
}
.hd-btn:hover{transform:translateY(-1px);box-shadow:0 4px 14px #00000018}
.hd-btn:active{transform:scale(.95)}

/* Run button — BIG & rounded */
.hd-btn.run{
  background:linear-gradient(150deg,#66bb6a,#43a047 50%,#2e7d32);
  border:3px solid #1b5e20;border-bottom:5px solid #145216;color:#fff;
  font-size:17px;padding:0 24px;height:46px;
  box-shadow:0 4px 16px #43a04755;border-radius:16px;
}
.hd-btn.run:active{transform:translateY(2px);border-bottom-width:3px}
.hd-btn.run.on{
  background:linear-gradient(150deg,#ef5350,#d32f2f 50%,#b71c1c);
  border-color:#b71c1c;border-bottom-color:#8e1515;box-shadow:0 4px 16px #d32f2f55;
}

/* Secondary buttons */
.hd-btn.save{background:#fff;border:2.5px solid #90caf9;border-bottom:4px solid #64b5f6;color:#1976d2;padding:0 10px;font-size:17px}
.hd-btn.save:hover{background:#e3f2fd}
.hd-btn.load{background:#fff;border:2.5px solid #a5d6a7;border-bottom:4px solid #81c784;color:#388e3c;padding:0 10px;font-size:17px}
.hd-btn.load:hover{background:#e8f5e9}
.hd-btn.rst{background:#fff;border:2.5px solid #e0e0e0;border-bottom:4px solid #bdbdbd;color:#9e9e9e;font-size:17px;padding:0 10px}
.hd-btn.rst:hover{background:#fafafa}
.hd-btn.cfg{background:#fff;border:2.5px solid #e0e0e0;border-bottom:4px solid #bdbdbd;color:#78909c;font-size:19px;padding:0 10px}
.hd-btn.cfg:hover{background:#fafafa}
.hd-btn.save:active,.hd-btn.load:active,.hd-btn.rst:active,.hd-btn.cfg:active{transform:translateY(1px);border-bottom-width:2.5px}

.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
   ══════════════════════════ */
.hd-btn.ai-toggle{
  background:#fff;border:2.5px solid #b0bec5;border-bottom:4px solid #90a4ae;
  color:#607d8b;font-size:17px;padding:0 10px;
}
.hd-btn.ai-toggle:hover{border-color:#7c4dff;background:#ede7f6}
.hd-btn.ai-toggle.on{border-color:#7c4dff;color:#7c4dff;background:#ede7f6;box-shadow:0 0 10px #7c4dff33}

.hd-btn.lang-switch{background:#fff;border:2.5px solid #b0bec5;border-bottom:4px solid #90a4ae;color:#607d8b;font-size:18px;padding:0 10px}
.hd-btn.lang-switch:hover{background:#eceff1}

/* ══════════════════════════
   BLE TOGGLE
   ══════════════════════════ */
.hd-btn.ble-toggle{
  background:#fff;border:2.5px solid #b0bec5;color:#607d8b;gap:6px;font-size:13px;
}
.hd-btn.ble-toggle:hover{border-color:#42a5f5;background:#e3f2fd}
.hd-btn.ble-toggle.has-conn{border-color:#66bb6a;color:#2e7d32;background:#e8f5e9}
.ble-dot{width:9px;height:9px;border-radius:50%;background:#b0bec5;display:inline-block;transition:all .3s}
.ble-dot.on{background:#66bb6a;box-shadow:0 0 8px #66bb6a88;animation:blink 2s infinite}

/* ══════════════════════════════════
   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(150deg,#42a5f5,#1e88e5);
  border:none;border-bottom:3px solid #1565c0;border-radius:12px;
  color:#fff;font-size:13px;font-weight:700;cursor:pointer;
  box-shadow:0 2px 8px #1e88e533;transition:all .08s;
}
.ble-grp-btn:hover{background:linear-gradient(150deg,#64b5f6,#42a5f5)}
.ble-grp-btn:active{transform:translateY(1px);border-bottom-width:1px}
.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(150deg,#42a5f5,#1e88e5);color:#fff;border-bottom:3px solid #1565c0;box-shadow:0 2px 6px #1e88e522}
.ble-card-btn.connect:hover{background:linear-gradient(150deg,#64b5f6,#42a5f5)}
.ble-card-btn.connect:active{transform:translateY(1px);border-bottom-width:1px}
.ble-card-btn.disconnect{background:#fff0f0;color:#e53935;border:1.5px solid #ef9a9a;border-bottom:3px solid #e57373}
.ble-card-btn.disconnect:hover{background:#fce4ec}
.ble-card-btn.disconnect:active{transform:translateY(1px);border-bottom-width:1.5px}
.ble-drawer-foot{padding:14px 18px;border-top:2px solid #e3ecf4;display:flex;gap:8px;background:#f0f6fc;border-radius:0 0 0 24px}
.ble-foot-btn{
  flex:1;height:42px;border-radius:12px;border:2.5px solid #d6e3f0;border-bottom:4px solid #b0cadf;
  background:#fff;color:#78909c;font-size:13px;font-weight:700;cursor:pointer;transition:all .08s;
}
.ble-foot-btn:hover{border-color:#90a4ae;color:#546e7a;background:#f5f5f5}
.ble-foot-btn:active{transform:translateY(1px);border-bottom-width:2.5px}
.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-row label{display:block;font-size:13px;font-weight:700;color:#546e7a;margin-bottom:6px}
.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}

/* ══════════════════════════
   CANVAS — ScratchJr style warm background
   ══════════════════════════ */
.cv{
  flex:1;
  background:
    radial-gradient(circle, #c8dff033 1.5px, transparent 1.5px),
    linear-gradient(170deg,#eaf4ff 0%,#e4f0fb 35%,#f0f4ff 100%);
  background-size: 32px 32px, 100% 100%;
  position:relative;overflow:hidden;cursor:grab;
}
.cv:active{cursor:grabbing}
.cv-s{position:absolute;inset:0;overflow:visible;transform-origin:0 0}
.hint{position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;opacity:.35;pointer-events:none;gap:12px}
.hint em{font-size:60px;font-style:normal;animation:bob 3s ease-in-out infinite}
.hint p{font-size:16px;font-weight:700;color:#607d8b;text-align:center;line-height:1.8}
@keyframes bob{0%,100%{transform:translateY(0)}50%{transform:translateY(-10px)}}

/* ══════════════════════════
   ZOOM CONTROLS
   ══════════════════════════ */
.zoom-ctrl{
  position:absolute;bottom:12px;right:12px;
  display:flex;align-items:center;gap:4px;z-index:160;
  background:#ffffffee;border-radius:16px;
  padding:5px 7px;box-shadow:0 3px 14px #0001;
  backdrop-filter:blur(8px);border:2px solid #e3ecf4;
}
.zoom-btn{
  width:38px;height:38px;border:2.5px solid #e3ecf4;border-bottom:4px solid #c5d5e4;border-radius:12px;
  background:#fff;font-size:18px;font-weight:800;color:#607d8b;
  cursor:pointer;display:flex;align-items:center;justify-content:center;transition:all .08s;
}
.zoom-btn:hover{background:#e3f2fd;border-color:#90caf9;border-bottom-color:#64b5f6}
.zoom-btn:active{transform:translateY(1px);border-bottom-width:2.5px}
.zoom-btn.fit{font-size:12px;font-weight:900;color:#42a5f5}
.zoom-lbl{font-size:12px;font-weight:800;color:#78909c;min-width:40px;text-align:center}

/* ══════════════════════════
   SNAP INDICATOR
   ══════════════════════════ */
#snap{position:absolute;z-index:200;pointer-events:none;display:none;flex-direction:row;align-items:flex-start;opacity:0.4;filter:saturate(0.5)}
#snap.on{display:flex;animation:spulse 1s ease-in-out infinite alternate}
#snap .bk{pointer-events:none;filter:drop-shadow(0 0 6px rgba(50,120,255,0.5))}
@keyframes spulse{from{opacity:0.25}to{opacity:0.5}}

/* ══════════════════════════
   CHAIN — ScratchJr horizontal, NO TAB OVERLAP
   ══════════════════════════ */
.ch{position:absolute;display:flex;align-items:flex-start;z-index:10;cursor:grab;flex-wrap:nowrap;overflow:visible;filter:drop-shadow(0 4px 2px rgba(0,0,0,0.18))}
.ch:active{cursor:grabbing}
.ch .bx{position:relative;display:inline-flex;flex-direction:column;align-items:center;flex-shrink:0;overflow:visible;z-index:2;transition:margin 0.15s ease}

/* ★ No margin — tabs extend beyond div via SVG overflow:visible */
.ch .bx:not(:last-child){margin-right:0px}

/* ══════════════════════════
   BLOCK — ScratchJr Rounded Rectangle
   ══════════════════════════ */
.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 */
.vt{
  margin-top:0;background:#fff;
  border:2.5px solid #d6e3f0;border-radius:10px;
  padding:2px 8px;font-size:14px;font-weight:800;color:#37474f;
  cursor:pointer;z-index:5;box-shadow:0 2px 6px #00000008;
  line-height:22px;min-width:28px;text-align:center;
}
.vt:hover{border-color:#42a5f5;background:#e3f2fd}

/* Block colors (placeholder classes) */
.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:7px;
  overflow-x:auto;height:62px;align-items:center;flex-shrink:0;
}
.hw-bar::-webkit-scrollbar{height:0}
.hwb{
  height:48px;border-radius:16px;border:none;
  display:flex;align-items:center;justify-content:center;gap:5px;
  cursor:pointer;flex-shrink:0;font-size:17px;padding:0 16px;
  position:relative;transition:transform .12s,opacity .15s;
  font-weight:700;color:#fff;border-bottom:4px solid #00000022;
}
.hwb::after{content:'';position:absolute;top:3px;left:12%;right:12%;height:30%;background:linear-gradient(180deg,#fff5,transparent);border-radius:50%}
.hwb:hover{transform:translateY(-2px)}.hwb:active{transform:translateY(1px);border-bottom-width:2px}
.hwb:not(.on){opacity:.50;filter:saturate(.35)}.hwb.on{transform:translateY(-1px);opacity:1}
.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}
}

/* ══════════════════════════
   TRASH
   ══════════════════════════ */
.trash{
  position:absolute;bottom:0;left:0;right:0;height:0;
  background:linear-gradient(0deg,#f4433644,transparent);
  display:flex;align-items:center;justify-content:center;
  font-size:30px;transition:height .2s,opacity .2s;
  opacity:0;z-index:90;pointer-events:none;
}
.trash.on{height:80px;opacity:1}.trash.hot{background:linear-gradient(0deg,#f44336aa,transparent)}

/* ══════════════════════════
   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;left:6px;background:#000a;color:#b388ff;font-size:10px;font-weight:700;padding:3px 8px;border-radius:8px}
.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}

/* ══════════════════════════════════════
   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-val{font-size:13px;font-weight:700;color:#37474f;min-width:30px;text-align:right;font-family:monospace}
.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;
}
