:root {
  --bg: #FFF7E6;
  --panel: #FFFFFF;
  --ink: #2B2B2B;
  --start: #FFBF1F;
  --looks: #A65CE0;
  --robot: #2F8CE6;
  --red: #E63946;
  --green: #2DB84D;
  --block: 84px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); overscroll-behavior: none; }
body { -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
input, textarea { -webkit-user-select: text; user-select: text; }
button { font: inherit; border: none; cursor: pointer; background: none; color: inherit; padding: 0; }

#app { display: grid; grid-template-rows: 96px 1fr 156px 48px; height: 100dvh; }
#topbar { display: flex; align-items: center; gap: 12px; padding: 0 16px; }
.spacer { flex: 1; }
.sym { width: 100%; height: 100%; display: block; }
.spin { transform-origin: 32px 32px; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.icon-btn { width: 64px; height: 64px; border-radius: 50%; background: var(--panel); padding: 12px;
  box-shadow: 0 3px 0 rgba(0,0,0,.15); color: #555; }
.icon-btn.small { width: 36px; height: 36px; padding: 6px; }
.icon-btn:active { transform: translateY(2px); box-shadow: none; }

.main-btn { width: 150px; height: 84px; border-radius: 24px; padding: 14px 40px; color: #fff;
  box-shadow: 0 5px 0 rgba(0,0,0,.25); transition: background-color .2s; }
.main-btn.red { background: var(--red); }
.main-btn.green { background: var(--green); }
.main-btn.grey { background: #9A9A9A; }
.main-btn.blink { animation: blink 1s ease-in-out infinite; }
.main-btn.shake { animation: shake .5s; }
@keyframes blink { 50% { background: #FFD60A; color: #2B2B2B; transform: scale(1.08); } }
@keyframes shake { 20%, 60% { transform: translateX(-10px); } 40%, 80% { transform: translateX(10px); } }

#work { display: flex; min-height: 0; }
#workspace-wrap { position: relative; flex: 1; min-width: 0; }
#workspace { position: absolute; inset: 0; overflow: auto; touch-action: pan-x pan-y;
  background-image: radial-gradient(#E8DCC4 1.5px, transparent 1.5px); background-size: 28px 28px; }
#scripts { position: relative; width: 2400px; height: 1600px; }
.trash { position: absolute; right: 32px; bottom: 32px; width: 88px; height: 88px; border-radius: 22px;
  background: #fff; color: #888; padding: 16px; box-shadow: 0 3px 0 rgba(0,0,0,.15); transition: transform .15s; }
.trash.hot { transform: scale(1.25); color: var(--red); }

.script { position: absolute; display: flex; align-items: center; }
.script.loose .block { filter: grayscale(1); opacity: .55; }
.block { position: relative; width: var(--block); height: var(--block); margin-right: -6px; border-radius: 14px;
  background: var(--c); color: #fff; padding: 12px; box-shadow: inset 0 -5px 0 rgba(0,0,0,.18);
  touch-action: none; flex: none; }
.block::after { content: ""; position: absolute; right: -10px; top: 30px; width: 16px; height: 24px;
  border-radius: 0 12px 12px 0; background: var(--c); z-index: 1; }
.block.trigger { border-radius: 40px 14px 14px 40px; }
.block.active { outline: 5px solid #FFD60A; outline-offset: 2px; }
.block .badge { position: absolute; right: 6px; bottom: 4px; min-width: 26px; padding: 0 5px; border-radius: 10px;
  background: #fff; color: var(--ink); font-weight: 800; font-size: 16px; text-align: center; z-index: 2; }
.block .word { position: absolute; left: 4px; right: 4px; bottom: 6px; background: #fff; color: var(--ink);
  border-radius: 8px; font-size: 13px; font-weight: 800; text-align: center; overflow: hidden; white-space: nowrap; }
.block .grid { background: #222; border-radius: 8px; }

/* Repeat (ScratchJr style). Widths are set inline from blockSpan(): head 40 px (REPEAT_HEAD), body slots of
   STEP, tail 48 px (REPEAT_TAIL). The rim sticks out above and below the row; the mouth is 6 px larger than its blocks. */
.block.repeat { --rim: 14px; height: calc(var(--block) + 2 * var(--rim)); margin-top: calc(-1 * var(--rim));
  margin-bottom: calc(-1 * var(--rim)); padding: 0; border-radius: 24px; }
.block.repeat::after { top: calc(30px + var(--rim)); }
#blockbar .block.repeat { --rim: 8px; }
.rep-mouth { position: absolute; left: 34px; top: calc(var(--rim) - 6px); height: calc(var(--block) + 12px); padding: 6px;
  display: flex; border-radius: 18px; background: color-mix(in srgb, var(--c) 28%, white);
  box-shadow: inset 0 4px 0 rgba(0,0,0,.12); }
.rep-mouth > .block { margin-right: -6px; }
.rep-mouth > .block:last-child::after { display: none; }
.rep-slot { width: var(--block); height: var(--block); border-radius: 14px; border: 4px dashed color-mix(in srgb, var(--c) 75%, white); }
.rep-tail { position: absolute; right: 0; top: 0; bottom: 0; width: 42px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px; padding-right: 2px; }
.rep-tail .sym { width: 34px; height: 34px; flex: none; }
.count { min-width: 34px; height: 34px; padding: 0 4px; border-radius: 17px; background: #fff; color: var(--ink);
  font-weight: 900; font-size: 22px; line-height: 34px; text-align: center; box-shadow: 0 2px 0 rgba(0,0,0,.2); }
.script.loose .block .block { filter: none; opacity: 1; }
.tile .count { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  height: auto; min-width: 0; padding: 0; background: none; box-shadow: none; color: #fff; font-size: 52px; }
.ghost { position: fixed; z-index: 50; pointer-events: none; opacity: .9; display: flex; transform: scale(1.06); }

#palette { background: var(--panel); border-top: 4px solid #F0E3C8; display: flex; flex-direction: column; }
#tabs { display: flex; gap: 8px; padding: 8px 12px 0; }
.tab { width: 64px; height: 40px; border-radius: 12px 12px 0 0; background: var(--c); opacity: .45; padding: 6px; color: #fff; }
.tab.active { opacity: 1; }
#blockbar { flex: 1; display: flex; align-items: center; gap: 18px; padding: 0 16px; overflow-x: auto;
  background: color-mix(in srgb, var(--c) 15%, white); }
#blockbar .block.used { filter: grayscale(1); opacity: .35; cursor: not-allowed; }

#sim { width: 300px; background: var(--panel); border-left: 4px solid #F0E3C8; display: flex; flex-direction: column;
  align-items: center; gap: 10px; padding: 10px; }
body.sim-hidden #sim { display: none; }
.sim-floor { width: 280px; height: 280px; border-radius: 16px; background: #F4EBD8; }
.sim-mb { width: 220px; }
.sim-row { display: flex; gap: 12px; }
.wheel .tread { stroke-dasharray: 4 4; }
.wheel.spin-fwd .tread { animation: tread .3s linear infinite; }
.wheel.spin-back .tread { animation: tread .3s linear infinite reverse; }
@keyframes tread { to { stroke-dashoffset: -8; } }

#footer { display: flex; align-items: center; justify-content: center; gap: 12px; font-size: 15px; position: relative; }
#privacy-btn { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); width: 34px; height: 34px; }
#intro-btn { position: absolute; right: 16px; top: 50%; transform: translateY(-50%); width: 34px; height: 34px; color: inherit; }

.share-dot { width: 16px; height: 16px; border-radius: 50%; }
.share-dot.off { background: transparent; }
.share-dot.on { background: var(--green); }
.share-dot.wait { background: #FFB000; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 100; display: flex;
  align-items: center; justify-content: center; padding: 16px; }
.modal { position: relative; background: var(--bg); border-radius: 28px; padding: 28px; max-width: 960px;
  width: 100%; max-height: 100%; overflow: auto; }
.modal-close { position: absolute; top: 12px; right: 12px; }
.tile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 14px; margin-top: 56px; }
.tile { aspect-ratio: 1; border-radius: 20px; background: var(--c, #fff); color: #fff; padding: 14px;
  box-shadow: 0 4px 0 rgba(0,0,0,.18); font-size: 34px; font-weight: 900; }
.tile.selected { outline: 6px solid #FFD60A; }
.draw-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; width: min(70vh, 90%); margin: 40px auto 20px;
  background: #222; padding: 18px; border-radius: 22px; }
.draw-cell { aspect-ratio: 1; border-radius: 50%; background: #555; }
.draw-cell.on { background: #FF3B30; box-shadow: 0 0 18px #FF3B30; }
.text-input { display: block; width: 100%; margin: 60px 0 20px; font-size: 48px; font-weight: 900; text-align: center;
  border-radius: 20px; border: 4px solid #ddd; padding: 12px; text-transform: none; }
.confirm-btn { display: block; margin: 0 auto; width: 120px; height: 90px; border-radius: 24px; background: var(--green);
  color: #fff; padding: 14px; box-shadow: 0 5px 0 rgba(0,0,0,.25); }

.confirm-btn.danger { background: var(--red); }
.clear-confirm { text-align: center; }
.clear-icon { width: 140px; height: 140px; margin: 24px auto 28px; color: var(--red); }

.teacher h3 { margin: 0 0 8px; }
.teacher-section { background: #fff; border-radius: 20px; padding: 16px; margin-top: 16px; }
.teacher-section > .row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.toggle-tile { width: 72px; height: 72px; border-radius: 16px; background: var(--c); color: #fff; padding: 10px; }
.toggle-tile.off { filter: grayscale(1); opacity: .35; }
.class-slots { display: flex; gap: 12px; justify-content: center; margin: 12px 0; }
.slot { width: 80px; height: 80px; border-radius: 18px; background: #fff; border: 4px dashed #ccc; padding: 10px; }
.slot.filled { border-style: solid; border-color: #ddd; }
.class-choices { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.class-choices button { width: 80px; height: 80px; border-radius: 18px; background: #fff; padding: 10px; box-shadow: 0 3px 0 rgba(0,0,0,.15); }
.hold-ring { position: absolute; inset: -6px; border-radius: 50%; border: 6px solid var(--green);
  clip-path: inset(0 100% 0 0); transition: clip-path 3s linear; pointer-events: none; }
.holding .hold-ring { clip-path: inset(0 0 0 0); }
#gear { position: relative; touch-action: none; -webkit-touch-callout: none; }
.privacy { max-width: 640px; font-size: 18px; line-height: 1.5; user-select: text; }
.privacy .wipe { margin-top: 16px; padding: 12px 18px; border-radius: 14px; background: #eee; font-weight: 700; }
.privacy .wipe.armed { background: var(--red); color: #fff; }

@media (max-width: 900px) {
  #sim { width: 230px; }
  .sim-floor { width: 210px; height: 210px; }
  .sim-mb { width: 180px; }
}
@media (prefers-reduced-motion: reduce) {
  .main-btn.blink { animation-duration: 2s; }
}
.flash-section > .row { justify-content: center; }
.flash-btn { width: 150px; height: 96px; border-radius: 24px; padding: 12px 40px; background: var(--robot); color: #fff;
  box-shadow: 0 5px 0 rgba(0,0,0,.25); transition: background-color .2s; }
.flash-btn:active { transform: translateY(2px); box-shadow: none; }
.flash-btn:disabled { cursor: default; }
.flash-btn.done { background: var(--green); }
.flash-btn.failed { background: var(--red); }
.icon-btn.unsupported { background: #9A9A9A; opacity: .5; cursor: not-allowed; }
.flash-btn.unsupported { background: #9A9A9A; opacity: .5; }
.flash-bar { height: 28px; margin-top: 14px; border-radius: 14px; background: #E6E6E6; overflow: hidden; }
.flash-bar[hidden] { display: none; }
.flash-bar > div { height: 100%; width: 0; background: var(--green); border-radius: 14px; transition: width .2s; }
.icon-btn.teacher-on { background: var(--green); color: #fff; }
.toggle-tile .badge, .toggle-tile .word { display: none; }

.share-dot.taken { background: var(--red); }

/* teacher menu: tooltips and tour */
.tour-btn { font-size: 22px; font-weight: 800; color: var(--ink); }
.tip-bubble { position: fixed; z-index: 300; max-width: 260px; padding: 8px 12px; border-radius: 12px;
  background: #222; color: #fff; font-size: 15px; line-height: 1.3; pointer-events: none; box-shadow: 0 3px 10px rgba(0,0,0,.3); }
.tip-bubble[hidden] { display: none; }
.driver-popover { font-size: 16px; }
.driver-popover-title { font-size: 20px; }
.driver-popover-description { font-size: 16px; }
.driver-popover-footer-btn { font-size: 20px; padding: 6px 14px; }
a.icon-btn { display: inline-flex; color: #555; text-decoration: none; }
#unplug-btn[hidden] { display: none; }
#unplug-btn { color: #888; }
.teacher-error { background: #FDECEE; border-radius: 14px; padding: 10px 14px; margin-top: 12px; font-size: 16px; }
#volume-wrap { position: relative; }
#volume-pop { position: absolute; top: 74px; left: 50%; transform: translateX(-50%); z-index: 60; background: #fff;
  border-radius: 20px; padding: 18px 22px; box-shadow: 0 6px 20px rgba(0,0,0,.18); }
#volume-pop[hidden] { display: none; }
#volume-slider { width: 220px; height: 44px; accent-color: var(--robot); touch-action: none; }
.sim-mb.shaking { animation: mbshake .45s; }
@keyframes mbshake { 20%, 60% { transform: translateX(-8px) rotate(-4deg); } 40%, 80% { transform: translateX(8px) rotate(4deg); } }
