/* ===== Скретч для начинающих — стили ===== */
/*
 * Блоки нарисованы средствами CSS, без картинок и без библиотек: форма
 * стакового блока (шип снизу, паз сверху) задана `clip-path: polygon()`
 * со смешанными единицами — проценты по ширине, пиксели по высоте.
 * Так блок остаётся резиновым: текст внутри может быть любой длины,
 * а шип всегда одного размера и всегда садится в паз соседа.
 */

:root{
  --ink:#2E2A4F;
  --card:#FFFFFF;
  --line:#E3DEF6;
  --accent:#FF7A59;
  --ok:#3BC97D;
  --bad:#FF5A6E;
  --shadow:0 6px 18px rgba(46,42,79,.16);

  /* цвета ящиков — как в оригинале, ребёнок узнаёт их по цвету раньше, чем по названию */
  --c-motion:#4C97FF;   --c-motion-d:#3373CC;
  --c-looks:#9966FF;    --c-looks-d:#774DCB;
  --c-sound:#CF63CF;    --c-sound-d:#BD42BD;
  --c-events:#FFBF00;   --c-events-d:#CC9900;
  --c-control:#FFAB19;  --c-control-d:#CF8B17;
  --c-sensing:#5CB1D6;  --c-sensing-d:#2E8EB8;
  --c-operators:#59C059; --c-operators-d:#389438;
  --c-data:#FF8C1A;     --c-data-d:#DB6E00;
  --c-list:#FF661A;     --c-list-d:#E64D00;
  --c-my:#FF6680;       --c-my-d:#FF3355;
  --c-pen:#0FBD8C;      --c-pen-d:#0B8E69;

  --z:1;                /* масштаб холста скриптов */
}

*{ box-sizing:border-box; }
html,body{ margin:0; padding:0; height:100%; }

body{
  font-family: "Naukino Emoji", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size:18px;
  color:var(--ink);
  background:linear-gradient(160deg,#EAF2FF,#F1E9FF 55%,#FFF1E6);
  background-attachment:fixed;
  -webkit-text-size-adjust:100%;
  overflow:hidden;
}

.hidden{ display:none !important; }
.hidden-file{ position:absolute; width:1px; height:1px; opacity:0; pointer-events:none; }

.app{ height:100%; }

/* ---------- экраны ---------- */
.screen{
  height:100%;
  overflow:auto;
  display:flex; flex-direction:column; gap:12px;
  max-width:820px; margin:0 auto; padding:60px 12px 28px;
  animation:fadeIn .3s ease;
}
.screen--full{ max-width:none; padding:0; overflow:hidden; gap:0; }
@keyframes fadeIn{ from{ opacity:0; transform:translateY(8px);} to{ opacity:1; transform:none;} }

.title{ margin:6px 0 0; text-align:center; font-size:clamp(26px,6vw,40px); line-height:1.15; text-shadow:0 2px 0 #fff; }
.title-sm{ font-size:clamp(22px,5vw,30px); }
.rules{ margin:0; text-align:center; font-size:17px; opacity:.88; line-height:1.5; }
.best-line{ margin:0; text-align:center; font-size:16px; opacity:.75; min-height:22px; }

.big-btn{
  border:none; border-radius:18px; padding:14px 22px;
  background:linear-gradient(180deg,#6FA8FF,#4C97FF); color:#fff;
  font:inherit; font-weight:800; font-size:19px; cursor:pointer;
  box-shadow:0 4px 0 #3373CC;
}
.big-btn:active{ transform:translateY(3px); box-shadow:0 1px 0 #3373CC; }
.big-btn.secondary{ background:#fff; color:var(--ink); box-shadow:0 4px 0 rgba(46,42,79,.14); }
.big-btn.secondary:active{ box-shadow:0 1px 0 rgba(46,42,79,.14); }
.big-btn[disabled]{ opacity:.5; cursor:default; }

.mini-btn{
  border:none; border-radius:12px; padding:8px 12px;
  background:#fff; color:var(--ink);
  font:inherit; font-size:15px; font-weight:700; cursor:pointer;
  box-shadow:0 2px 0 rgba(46,42,79,.12); white-space:nowrap;
}
.mini-btn:active{ transform:translateY(2px); box-shadow:none; }
.icon-btn{
  border:none; border-radius:12px; width:40px; height:40px;
  background:#fff; font-size:20px; line-height:1; cursor:pointer;
  box-shadow:0 2px 0 rgba(46,42,79,.12);
}
.add-btn{
  border:none; border-radius:14px; padding:10px 12px; margin-top:6px;
  background:#fff; color:var(--ink); font:inherit; font-size:15px; font-weight:700;
  cursor:pointer; box-shadow:0 2px 0 rgba(46,42,79,.12); width:100%;
}
.add-mini{
  border:none; border-radius:10px; padding:5px 8px; margin-top:4px;
  background:#fff; font:inherit; font-size:13px; font-weight:700; cursor:pointer;
  box-shadow:0 2px 0 rgba(46,42,79,.12);
}

.start-btns{ display:flex; gap:12px; justify-content:center; flex-wrap:wrap; }

/* ---------- совёнок ---------- */
.hero-row{ display:flex; align-items:center; gap:10px; }
.hero-art{ font-size:clamp(34px,7vw,48px); line-height:1; flex:0 0 auto; }
.bubble{
  position:relative; background:#fff; border-radius:16px; padding:10px 14px;
  font-size:16px; line-height:1.4; box-shadow:var(--shadow);
}
.bubble::before{
  content:""; position:absolute; left:-8px; top:50%; margin-top:-7px;
  border:7px solid transparent; border-right-color:#fff;
}
.start-hero{ margin-top:auto; }

/* ---------- карта глав ---------- */
.map-top{ display:flex; align-items:center; justify-content:space-between; gap:10px; }
.map-sub{ margin:0; text-align:center; font-size:16px; opacity:.8; }
.chapters{ display:grid; grid-template-columns:repeat(auto-fill,minmax(240px,1fr)); gap:12px; }
.chapter{
  border:none; border-radius:18px; padding:14px; text-align:left;
  background:#fff; box-shadow:var(--shadow); cursor:pointer; font:inherit;
  display:flex; flex-direction:column; gap:6px; border-left:10px solid var(--ch,#4C97FF);
}
.chapter[disabled]{ opacity:.55; cursor:default; }
.chapter-name{ font-weight:800; font-size:19px; }
.chapter-sub{ font-size:15px; opacity:.8; }
.chapter-stars{ font-size:16px; letter-spacing:2px; }

/* ---------- редактор: верхняя панель ---------- */
/* Место под «Выйти» вынесено в переменную не для красоты: рядом с этой
   кнопкой встаёт «Во весь экран», и её ширину прибавляет сам
   games-static/common/fullscreen.js — до числа в padding он не дотянулся
   бы, и значок накрывал кнопку «Меню». */
:root{ --exit-space:128px; }        /* 10 + 104 + отступ */

.ed-top{
  display:flex; align-items:center; gap:10px;
  padding:8px 10px 8px var(--exit-space);
  background:rgba(255,255,255,.86); backdrop-filter:blur(6px);
  border-bottom:1px solid var(--line);
  flex:none;
}
.run-btns{ display:flex; gap:6px; }
.flag-btn{
  border:none; border-radius:12px; padding:8px 14px;
  background:linear-gradient(180deg,#4FD08A,#3BC97D); color:#fff;
  font:inherit; font-weight:800; font-size:15px; cursor:pointer;
  box-shadow:0 2px 0 #2A9D62; display:inline-flex; align-items:center; gap:6px;
}
.flag-btn:active{ transform:translateY(2px); box-shadow:none; }
.flag-ico{ font-size:18px; }
.stop-btn{
  border:none; border-radius:12px; padding:8px 12px;
  background:#fff; color:var(--bad); font-size:18px; cursor:pointer;
  box-shadow:0 2px 0 rgba(46,42,79,.12);
}
.ed-tabs{ display:flex; gap:4px; background:#EFEBFB; border-radius:14px; padding:3px; }
.tab-btn{
  border:none; border-radius:11px; padding:7px 14px; background:transparent;
  font:inherit; font-size:15px; font-weight:700; color:var(--ink); cursor:pointer;
}
.tab-btn.is-on{ background:#fff; box-shadow:0 2px 6px rgba(46,42,79,.14); }
.ed-tools{ margin-left:auto; display:flex; gap:6px; align-items:center; }

/* ---------- полоса урока ---------- */
.lesson-bar{
  display:flex; gap:14px; align-items:flex-start; position:relative;
  padding:10px 44px 10px 12px; background:#fff; border-bottom:1px solid var(--line);
  flex:none; max-height:34vh; overflow:auto;
}
.lesson-bar.is-folded .lesson-teach,
.lesson-bar.is-folded .lesson-side{ display:none; }
.lesson-main{ flex:1 1 auto; min-width:0; }
.lesson-head{ display:flex; align-items:baseline; gap:8px; }
.lesson-num{ font-size:14px; font-weight:800; opacity:.6; white-space:nowrap; }
.lesson-title{ margin:0; font-size:19px; }
.lesson-teach{ margin-top:4px; font-size:16px; line-height:1.45; }
.lesson-teach p{ margin:.35em 0; }
.lesson-teach b{ color:#3373CC; }
.lesson-goal{
  margin-top:6px; font-size:16px; font-weight:700;
  background:#FFF6E0; border-radius:12px; padding:7px 10px; display:inline-block;
}
.lesson-goal.is-done{ background:#DFF6E8; }
.lesson-side{ flex:0 0 auto; display:flex; flex-direction:column; gap:8px; align-items:flex-end; max-width:340px; }
.lesson-hero .bubble{ font-size:15px; box-shadow:0 3px 10px rgba(46,42,79,.12); }
.lesson-btns{ display:flex; gap:6px; flex-wrap:wrap; justify-content:flex-end; }
.fold-btn{
  position:absolute; top:8px; right:8px; border:none; background:#F2EFFF;
  border-radius:10px; width:30px; height:30px; cursor:pointer; font-size:13px;
}

/* ---------- тело редактора ---------- */
.ed-body{ flex:1 1 auto; display:flex; min-height:0; }
.pal-col{ flex:0 0 404px; display:flex; min-width:0; background:#fff; border-right:1px solid var(--line); }
/* Ширина колонки — по самому длинному имени ящика («Управление»,
   «Переменные»): в 58 px оно не помещалось и разрывалось посреди слова. */
.cat-col{
  flex:0 0 76px; overflow:auto; padding:6px 0;
  display:flex; flex-direction:column; align-items:center; gap:2px;
  background:#FAF8FF; border-right:1px solid var(--line);
}
.cat-btn{
  border:none; background:transparent; cursor:pointer; font:inherit;
  width:72px; padding:5px 2px; border-radius:10px;
  display:flex; flex-direction:column; align-items:center; gap:2px;
  font-size:10px; font-weight:700; color:var(--ink); line-height:1.1; text-align:center;
}
.cat-dot{ width:20px; height:20px; border-radius:50%; background:var(--cc); }
.cat-btn.is-on{ background:#EFEBFB; }
.pal-list{ flex:1 1 auto; overflow:auto; padding:10px 10px 60px; }
.pal-head{ margin:10px 0 6px; font-size:14px; font-weight:800; opacity:.6; }
.pal-head:first-child{ margin-top:0; }

.mid-col{ flex:1 1 auto; min-width:0; display:flex; }
.pane{ flex:1 1 auto; min-width:0; display:flex; }

/* ---------- холст скриптов ---------- */
#paneCode{ flex-direction:column; }
.ws-wrap{
  position:relative; flex:1 1 auto; overflow:auto; touch-action:pan-x pan-y;
  background:
    radial-gradient(circle, rgba(46,42,79,.12) 1px, transparent 1.4px) 0 0/22px 22px,
    #F6F4FF;
}
.ws{ position:relative; width:2600px; height:2000px; transform:scale(var(--z)); transform-origin:0 0; }
.ws-hint{
  position:absolute; left:20px; top:16px; max-width:280px;
  font-size:15px; opacity:.55; pointer-events:none;
}
.ws-caret{
  position:absolute; height:6px; border-radius:3px; background:#FFBF00;
  box-shadow:0 0 0 3px rgba(255,191,0,.3); pointer-events:none; z-index:5;
}
.ws-tools{
  flex:none; display:flex; gap:6px; padding:6px 8px;
  background:#fff; border-top:1px solid var(--line);
}
.drag-layer{ position:fixed; left:0; top:0; z-index:90; pointer-events:none; }

/* ---------- блоки ---------- */
.script{ position:absolute; }
.blk{
  position:relative; font-size:14px; font-weight:700; color:#fff;
  line-height:1.15; user-select:none; -webkit-user-select:none;
  touch-action:none; cursor:grab;
}
.blk-row{
  display:flex; align-items:center; flex-wrap:wrap; gap:6px;
  padding:8px 12px 13px; min-height:36px;
}
/* стаковый блок: паз сверху, шип снизу */
.blk--stack > .blk-row, .blk--c > .c-head{
  clip-path:polygon(
    0 0, 14px 0, 19px 5px, 31px 5px, 36px 0, 100% 0,
    100% calc(100% - 5px),
    36px calc(100% - 5px), 31px 100%, 19px 100%, 14px calc(100% - 5px),
    0 calc(100% - 5px));
}
.blk--stack{ margin-bottom:-5px; }
.blk--hat > .blk-row{
  padding-top:22px; border-radius:18px 18px 0 0;
  clip-path:polygon(
    0 14px, 6px 6px, 18px 1px, 34px 0, 100% 0,
    100% calc(100% - 5px),
    36px calc(100% - 5px), 31px 100%, 19px 100%, 14px calc(100% - 5px),
    0 calc(100% - 5px));
}
.blk--hat{ margin-bottom:-5px; }
.blk--cap > .blk-row{
  clip-path:polygon(0 0, 14px 0, 19px 5px, 31px 5px, 36px 0, 100% 0, 100% 100%, 0 100%);
  padding-bottom:8px; border-radius:0 0 8px 8px;
}
/* C-блок */
.blk--c{ margin-bottom:-5px; }
.blk--c > .c-body{ display:flex; }
.blk--c > .c-body{ background:transparent; }
.blk--c > .c-body > .c-spine{ flex:0 0 15px; }
.blk--c > .c-body > .blk-sub{ flex:1 1 auto; min-height:26px; min-width:60px; padding-bottom:5px; }
.blk--c > .c-foot{
  height:19px;
  clip-path:polygon(
    0 0, 100% 0, 100% calc(100% - 5px),
    36px calc(100% - 5px), 31px 100%, 19px 100%, 14px calc(100% - 5px),
    0 calc(100% - 5px));
}
.blk--c.is-cap > .c-foot{ clip-path:none; height:14px; border-radius:0 0 8px 8px; }

/* Цвета ящиков.
   Цвет задаётся переменной, а красится не сам блок, а его полосы:
   фон целого блока не обрезается `clip-path`, и шип с пазом были бы
   закрашены прямоугольником — блоки выглядели бы плитками, а не
   деталями, которые сцепляются. У C-блока рот обязан быть дыркой:
   сквозь него виден холст, и сразу понятно, что блок внутри лежит. */
.blk-row, .c-mid, .c-foot, .c-spine{ background:var(--blk,#4C97FF); }
.fld{ color:var(--blk-d,#3373CC); }
.cat-motion{ --blk:var(--c-motion); --blk-d:var(--c-motion-d); }
.cat-looks{ --blk:var(--c-looks); --blk-d:var(--c-looks-d); }
.cat-sound{ --blk:var(--c-sound); --blk-d:var(--c-sound-d); }
.cat-events{ --blk:var(--c-events); --blk-d:var(--c-events-d); }
.cat-control{ --blk:var(--c-control); --blk-d:var(--c-control-d); }
.cat-sensing{ --blk:var(--c-sensing); --blk-d:var(--c-sensing-d); }
.cat-operators{ --blk:var(--c-operators); --blk-d:var(--c-operators-d); }
.cat-data{ --blk:var(--c-data); --blk-d:var(--c-data-d); }
.cat-list{ --blk:var(--c-list); --blk-d:var(--c-list-d); }
.cat-my{ --blk:var(--c-my); --blk-d:var(--c-my-d); }
.cat-pen{ --blk:var(--c-pen); --blk-d:var(--c-pen-d); }

/* репортёры и условия */
.blk--rep > .blk-row{ padding:5px 12px; min-height:28px; border-radius:999px; }
.blk--bool > .blk-row{
  padding:5px 14px; min-height:28px;
  clip-path:polygon(12px 0, calc(100% - 12px) 0, 100% 50%, calc(100% - 12px) 100%, 12px 100%, 0 50%);
}
.blk--rep, .blk--bool{ display:inline-block; vertical-align:middle; }

/* окошки внутри блока */
.slot{ display:inline-flex; align-items:center; min-height:22px; }
.fld{
  border:none; border-radius:999px; padding:3px 9px; min-width:34px; width:44px;
  background:#fff; font:inherit; font-size:13px; font-weight:700; text-align:center;
  outline:none;
}
.fld--str{ width:92px; text-align:left; border-radius:12px; }
.fld--wide{ width:130px; }
.fld--menu{
  appearance:none; -webkit-appearance:none; cursor:pointer;
  background:rgba(0,0,0,.16); color:#fff; border-radius:999px;
  padding:4px 20px 4px 10px; width:auto; min-width:0; max-width:170px;
  text-align:left; text-overflow:ellipsis;
}
.slot--menu{ position:relative; }
.slot--menu::after{ content:"▾"; position:absolute; right:7px; top:50%; transform:translateY(-50%); font-size:10px; color:#fff; pointer-events:none; }
.slot--bool{
  min-width:38px; height:24px; background:rgba(0,0,0,.15);
  clip-path:polygon(10px 0, calc(100% - 10px) 0, 100% 50%, calc(100% - 10px) 100%, 10px 100%, 0 50%);
}
.slot--drop{ box-shadow:0 0 0 3px #FFBF00; }
.blk-t{ white-space:nowrap; }
.blk-ico{ font-size:15px; }

/* блок в палитре */
.pal-item{ margin-bottom:12px; }
.pal-item .blk{ cursor:pointer; }
/* Окошки внутри блока палитры не ловят нажатие: палец целится в блок,
   а попадал в поле ввода — и блок не брался вовсе. */
.is-pal .fld, .is-pal .slot--bool{ pointer-events:none; }
/* Самые длинные блоки («заменить элемент … списка … на …») шире колонки
   при любой разумной её ширине. Раньше они торчали наружу и палитру
   приходилось листать вбок; теперь надпись переносится на вторую строку,
   а вбок палитра не ездит вовсе. На холсте блок по-прежнему в одну строку. */
.pal-list .blk{ width:max-content; max-width:100%; }
.pal-list .blk-row{ flex-wrap:wrap; row-gap:2px; }
.pal-btn{
  display:block; width:100%; margin:0 0 10px; border:none; border-radius:14px;
  padding:9px 12px; background:#fff; color:var(--ink); font:inherit; font-size:14px;
  font-weight:700; cursor:pointer; text-align:left; box-shadow:0 2px 0 rgba(46,42,79,.12);
}
.blk.is-ghost{ opacity:.45; }
.blk.is-glow > .blk-row, .blk.is-glow > .c-head{ box-shadow:0 0 0 3px #FFD84D; }
@keyframes blkRun{ 50%{ filter:brightness(1.22); } }
.blk.is-run > .blk-row, .blk.is-run > .c-head{ outline:3px solid #FFD84D; outline-offset:-1px; }

/* ---------- сцена ---------- */
.stage-col{
  flex:0 0 400px; display:flex; flex-direction:column; gap:8px;
  padding:8px; background:#fff; border-left:1px solid var(--line); overflow:auto;
}
.stage-box{ flex:none; }
.stage-wrap{
  position:relative; width:100%; aspect-ratio:4/3; border-radius:14px; overflow:hidden;
  background:#fff; box-shadow:0 3px 12px rgba(46,42,79,.16);
}
#stage{ width:100%; height:100%; display:block; touch-action:none; }
.bubbles, .monitors{ position:absolute; inset:0; pointer-events:none; }
.say{
  position:absolute; max-width:min(60%, 190px); background:#fff; border:1px solid #D8D2EE;
  border-radius:12px; padding:5px 9px; font-size:13px; font-weight:600; color:var(--ink);
}
.say::after{ content:""; position:absolute; left:var(--tail,14px); bottom:-7px; border:6px solid transparent; border-top-color:#fff; }
.say--think{ border-radius:16px; }
.mon{
  position:absolute; display:flex; align-items:center; gap:5px;
  background:rgba(255,255,255,.92); border:1px solid #D8D2EE; border-radius:6px;
  padding:2px 5px; font-size:11px; font-weight:700; color:var(--ink);
  pointer-events:auto; cursor:grab; touch-action:none; user-select:none;
}
.mon--drag{ cursor:grabbing; box-shadow:0 4px 12px rgba(46,42,79,.28); }
.mon-val{ background:var(--c-data); color:#fff; border-radius:4px; padding:1px 6px; min-width:22px; text-align:center; }
/* Список листают пальцем, поэтому тянут его только за шапку. */
.mon-list{ flex-direction:column; align-items:stretch; max-height:120px; overflow:auto; touch-action:pan-y; cursor:default; }
.mon-list .mon-head{ cursor:grab; touch-action:none; }
.mon-list .mon-row{ display:flex; gap:4px; }
.mon-foot{ position:sticky; bottom:-2px; margin-top:2px; padding-top:2px; border-top:1px solid var(--line);
  background:#fff; font-size:10px; font-weight:600; color:#6B6790; }
.ask-row{
  position:absolute; left:6px; right:6px; bottom:6px; display:flex; gap:6px;
  pointer-events:auto;
}
.ask-input{ flex:1 1 auto; border:2px solid var(--c-sensing); border-radius:999px; padding:6px 12px; font:inherit; font-size:14px; }
.ask-ok{ border:none; border-radius:50%; width:34px; height:34px; background:var(--c-sensing); color:#fff; font-size:16px; cursor:pointer; }

/* ---------- спрайты ---------- */
.sprite-panel{ flex:1 1 auto; display:flex; flex-direction:column; gap:6px; min-height:0; overflow:auto; }
.sprite-info{ display:flex; flex-wrap:wrap; gap:6px; align-items:center; font-size:13px; }
.sprite-info label{ display:flex; align-items:center; gap:3px; background:#F6F4FF; border-radius:10px; padding:3px 7px; }
.sprite-info input{ border:none; background:#fff; border-radius:8px; padding:3px 5px; width:56px; font:inherit; font-size:13px; text-align:center; }
.sprite-info input.wide{ width:110px; text-align:left; }
/* Ряд со спрайтами и ячейкой фона не ужимается ниже своего содержимого:
   иначе кнопка «＋ Фон» съезжала под «＋ Спрайт» и нажать её было нельзя —
   клик попадал в добавление спрайта, а фон не менялся. Панель при нехватке
   места прокручивается. */
.sprite-lists{ display:flex; gap:8px; align-items:flex-start; min-height:0; flex:0 0 auto; }
.sprite-list{
  flex:1 1 auto; display:grid; grid-template-columns:repeat(auto-fill,minmax(62px,1fr));
  gap:6px; overflow:auto; padding:2px;
}
.sprite-cell{
  position:relative; border:2px solid transparent; border-radius:12px; background:#F6F4FF;
  padding:4px 2px; text-align:center; cursor:pointer; font:inherit; font-size:11px; font-weight:700;
}
.sprite-cell.is-on{ border-color:var(--c-motion); background:#fff; }
.sprite-cell canvas{ width:44px; height:34px; display:block; margin:0 auto; object-fit:contain; }
.sprite-cell .kill{
  position:absolute; top:-6px; right:-6px; width:20px; height:20px; border:none; border-radius:50%;
  background:var(--bad); color:#fff; font-size:11px; line-height:1; cursor:pointer;
}
.backdrop-cell{ flex:0 0 88px; text-align:center; font-size:11px; font-weight:700; }
.backdrop-thumb{ width:84px; height:63px; border-radius:10px; overflow:hidden; background:#EFEBFB; }
.backdrop-thumb canvas{ width:100%; height:100%; display:block; }

/* ---------- костюмы и звуки ---------- */
#paneCostumes, #paneSounds{ background:#F6F4FF; }
.asset-col{
  flex:0 0 120px; padding:8px; overflow:auto; background:#fff; border-right:1px solid var(--line);
}
.asset-list{ display:flex; flex-direction:column; gap:6px; }
.asset-cell{
  position:relative; border:2px solid transparent; border-radius:12px; background:#F6F4FF;
  padding:5px; text-align:center; cursor:pointer; font:inherit; font-size:11px; font-weight:700;
}
.asset-cell.is-on{ border-color:var(--c-looks); background:#fff; }
.asset-cell canvas{ width:70px; height:52px; display:block; margin:0 auto; object-fit:contain; }
.asset-cell .kill{
  position:absolute; top:-6px; right:-6px; width:20px; height:20px; border:none; border-radius:50%;
  background:var(--bad); color:#fff; font-size:11px; line-height:1; cursor:pointer;
}
.paint-wrap{ flex:1 1 auto; display:flex; flex-direction:column; min-width:0; padding:8px; gap:8px; }
.paint-tools{ display:flex; gap:5px; align-items:center; flex-wrap:wrap; }
.ptool{
  border:none; border-radius:10px; width:38px; height:38px; background:#fff;
  font-size:17px; cursor:pointer; box-shadow:0 2px 0 rgba(46,42,79,.12);
}
.ptool.is-on{ background:var(--c-looks); color:#fff; }
.ptool-gap{ width:8px; }
.pcolor{ width:44px; height:38px; border:none; border-radius:10px; background:#fff; cursor:pointer; padding:3px; }
.psize{ width:110px; }
.paint-box{
  flex:1 1 auto; display:flex; align-items:center; justify-content:center; min-height:0;
  background:#F4F2FA; border-radius:14px;
}
/* Клетка живёт на самом холсте, а не на подложке: раньше клетчатым было всё
   поле, а рисовал только маленький холст в его середине — ребёнок водил
   пальцем по «бумаге», на которой ничего не появлялось. Холст растянут на
   всё поле с сохранением пропорций костюма (везде 4:3). */
#paintCanvas{
  width:100%; height:auto; max-height:100%; aspect-ratio:4/3;
  touch-action:none; cursor:crosshair;
  border-radius:12px; box-shadow:inset 0 0 0 1px var(--line);
  background:
    linear-gradient(45deg,#EDEAF7 25%,transparent 25%,transparent 75%,#EDEAF7 75%) 0 0/16px 16px,
    linear-gradient(45deg,#EDEAF7 25%,transparent 25%,transparent 75%,#EDEAF7 75%) 8px 8px/16px 16px,
    #fff;
}
.paint-foot{ display:flex; gap:12px; align-items:center; flex-wrap:wrap; font-size:14px; }
.name-row{ display:flex; align-items:center; gap:6px; font-weight:700; }
.name-input{ border:2px solid var(--line); border-radius:10px; padding:6px 10px; font:inherit; font-size:15px; }
.name-input--big{ width:100%; font-size:17px; }
.paint-tip{ opacity:.7; }
.sound-wrap{ flex:1 1 auto; padding:12px; display:flex; flex-direction:column; gap:10px; overflow:auto; }
.snd-card{ background:#fff; border-radius:14px; padding:12px; box-shadow:var(--shadow); display:flex; gap:10px; align-items:center; }
.snd-wave{ flex:1 1 auto; height:44px; }

/* ---------- нижняя панель телефона ---------- */
.phone-bar{ display:none; }

/* ---------- окна ---------- */
.modal{
  position:fixed; inset:0; z-index:80; display:flex; align-items:center; justify-content:center;
  background:rgba(46,42,79,.45); padding:12px;
}
.modal-card{
  background:#fff; border-radius:20px; padding:18px; max-width:420px; width:100%;
  box-shadow:0 18px 50px rgba(46,42,79,.3); max-height:90vh; overflow:auto;
}
.modal-card--wide{ max-width:720px; }
.modal-top{ display:flex; align-items:center; justify-content:space-between; gap:10px; }
.modal-title{ margin:0 0 6px; font-size:21px; }
.modal-text{ margin:0 0 10px; font-size:16px; line-height:1.4; }
.modal-btns{ display:flex; gap:8px; justify-content:flex-end; flex-wrap:wrap; margin-top:12px; }
.pick-grid{ display:grid; grid-template-columns:repeat(auto-fill,minmax(96px,1fr)); gap:8px; margin-top:10px; }
.pick-cell{
  border:2px solid transparent; border-radius:14px; background:#F6F4FF; padding:6px;
  cursor:pointer; font:inherit; font-size:12px; font-weight:700; text-align:center;
}
.pick-cell:hover{ border-color:var(--c-motion); }
.pick-cell canvas{ width:100%; height:58px; display:block; object-fit:contain; }
.pick-row{
  display:flex; align-items:center; gap:10px; width:100%; text-align:left;
  border:none; border-radius:14px; background:#F6F4FF; padding:10px 12px; margin-bottom:8px;
  font:inherit; font-size:15px; font-weight:700; cursor:pointer;
}
.pick-row .sub{ font-weight:500; opacity:.7; font-size:13px; }
.pick-row .kill{ margin-left:auto; border:none; background:var(--bad); color:#fff; border-radius:10px; padding:5px 9px; cursor:pointer; font-size:13px; }
.proto-preview{ margin:8px 0; min-height:44px; }
.proto-adds{ display:flex; gap:6px; flex-wrap:wrap; margin:10px 0; }
.warp-row{ display:flex; align-items:center; gap:8px; font-size:14px; }

.ctx{
  position:fixed; z-index:95; background:#fff; border-radius:12px; padding:5px;
  box-shadow:0 10px 30px rgba(46,42,79,.3); min-width:170px;
}
.ctx button{
  display:block; width:100%; border:none; background:transparent; text-align:left;
  padding:9px 10px; border-radius:9px; font:inherit; font-size:15px; cursor:pointer;
}
.ctx button:hover{ background:#F2EFFF; }

/* ---------- звёзды и итог ---------- */
.stars{ text-align:center; font-size:34px; letter-spacing:6px; min-height:44px; }
.result-score{ margin:0; text-align:center; font-size:17px; }
.result-btns{ display:flex; gap:10px; justify-content:center; flex-wrap:wrap; }
.parents{ background:#fff; border-radius:16px; padding:12px 14px; box-shadow:var(--shadow); font-size:15px; line-height:1.5; }
.parents summary{ cursor:pointer; font-weight:800; }
.parents p{ margin:.5em 0; }

/* ---------- кнопка «Выйти» ---------- */
.exit-btn{
  display:inline-flex; align-items:center; gap:6px;
  height:46px; padding:0 16px; flex:none;
  border:none; border-radius:16px;
  background:#fff; color:#3D3455;
  font:inherit; font-size:16px; font-weight:800; line-height:1;
  white-space:nowrap; cursor:pointer;
  box-shadow:0 3px 0 rgba(61,52,85,.12);
}
.exit-btn:hover{ background:#F2EFFF; }
.exit-btn:active{ transform:translateY(2px); box-shadow:0 1px 0 rgba(61,52,85,.12); }
.exit-btn--float{ position:fixed; top:10px; left:10px; z-index:60; }
@media (max-width:480px){
  .exit-btn{ height:40px; padding:0 12px; font-size:14px; }
  .exit-btn--float{ top:6px; left:6px; }
}

/* =========================================================
   ПЛАНШЕТ И ТЕЛЕФОН
   Три колонки в 360 px не помещаются никак, поэтому на узком
   экране сцена уезжает наверх, палитра становится выдвижным
   ящиком снизу, а блок кладётся нажатием: тащить блок внутрь
   цикла пальцем на такой ширине тяжело даже взрослому.
   ========================================================= */
@media (max-width:1100px){
  .stage-col{ flex:0 0 320px; }
  .pal-col{ flex:0 0 294px; }
}

@media (max-width:900px){
  body{ font-size:17px; }
  .ed-top{ padding-left:10px; flex-wrap:wrap; gap:6px; }
  .exit-btn--float{ position:static; height:36px; padding:0 10px; font-size:14px; box-shadow:0 2px 0 rgba(61,52,85,.12); }
  .flag-word{ display:none; }
  .flag-btn{ padding:8px 12px; }
  .ed-tools .mini-btn{ padding:8px 9px; font-size:14px; }

  .lesson-bar{ flex-direction:column; gap:8px; max-height:42vh; padding:8px 40px 8px 10px; }
  .lesson-side{ max-width:none; width:100%; align-items:stretch; }
  .lesson-btns{ justify-content:flex-start; }

  /* Нижняя панель обязана остаться на экране: если тело редактора
     перерастёт окно, кнопки «Блоки» и «Сцена» уедут за нижний край,
     и палитру на телефоне будет нечем открыть. */
  .ed-body{ flex-direction:column; position:relative; overflow:hidden; min-height:0; }

  .stage-col{
    flex:0 0 auto; order:-1; flex-direction:row; gap:8px; align-items:flex-start;
    border-left:none; border-bottom:1px solid var(--line); padding:6px; overflow:hidden;
    max-height:44vh;
  }
  /* Ширина сцены ограничена так, чтобы её высота (три четверти ширины)
     не съедала больше трети экрана. */
  .stage-box{ flex:0 0 auto; width:min(58%, 46vh); }
  .sprite-panel{ flex:1 1 auto; min-height:0; overflow:auto; }
  .sprite-list{ grid-template-columns:repeat(auto-fill,minmax(54px,1fr)); max-height:120px; }
  .backdrop-cell{ flex:0 0 64px; }
  .backdrop-thumb{ width:60px; height:45px; }
  body.stage-big .stage-box{ width:min(100%, 62vh); }
  body.stage-big .sprite-panel{ display:none; }

  .mid-col{ flex:1 1 auto; min-height:0; }
  .pane{ min-height:0; }

  /* палитра — выдвижной ящик снизу */
  .pal-col{
    position:absolute; left:0; right:0; bottom:0; z-index:30; flex:none;
    height:46%; border-right:none; border-top:1px solid var(--line);
    border-radius:18px 18px 0 0; box-shadow:0 -10px 30px rgba(46,42,79,.18);
    transform:translateY(102%); transition:transform .22s ease;
  }
  body.pal-open .pal-col{ transform:none; }
  .cat-btn{ font-size:9.5px; }

  .phone-bar{
    display:flex; gap:8px; flex:none; padding:6px 8px;
    background:#fff; border-top:1px solid var(--line);
  }
  .phone-tab{
    flex:1 1 0; border:none; border-radius:14px; padding:11px 8px;
    background:#F2EFFF; font:inherit; font-size:15px; font-weight:800; cursor:pointer;
  }
  .phone-tab.is-on{ background:var(--c-motion); color:#fff; }

  .asset-col{ flex:0 0 96px; }
  .asset-cell canvas{ width:56px; height:42px; }
  .paint-tools .ptool{ width:34px; height:34px; font-size:15px; }
  .psize{ width:78px; }
  .ws-tools{ padding:5px 6px; }

  /* блоки крупнее: палец должен попадать по окошку с числом */
  .blk{ font-size:15px; }
  .blk-row{ min-height:40px; padding:9px 12px 14px; }
  .fld{ padding:5px 10px; font-size:14px; }
}

@media (max-width:520px){
  .stage-box{ flex:0 0 62%; }
  .sprite-info{ font-size:12px; }
  .sprite-info input{ width:44px; }
  .ed-tabs .tab-btn{ padding:7px 10px; font-size:14px; }
  .lesson-title{ font-size:17px; }
  .lesson-teach{ font-size:15px; }
  .pick-grid{ grid-template-columns:repeat(auto-fill,minmax(84px,1fr)); }
}

@media (prefers-reduced-motion: reduce){
  .screen{ animation:none; }
  .pal-col{ transition:none; }
}

/* всплывающая подсказка редактора */
.toast{
  position:fixed; left:50%; bottom:18px; transform:translate(-50%,20px);
  background:#2E2A4F; color:#fff; border-radius:14px; padding:10px 16px;
  font-size:15px; font-weight:700; max-width:min(520px,92vw); text-align:center;
  opacity:0; pointer-events:none; transition:opacity .2s ease, transform .2s ease; z-index:99;
}
.toast.is-on{ opacity:1; transform:translate(-50%,0); }
.pick-rows{ margin-top:10px; }
.c-mid{ padding:7px 12px 7px 14px; min-height:26px; }
.fld--col{ width:34px; height:24px; padding:2px; border-radius:8px; }
@media (prefers-reduced-motion: reduce){ .toast{ transition:none; } }

/* На окне ноутбука правой колонке не хватает трёх десятков пикселей, и
   «＋ Спрайт» оказывается ниже её края. Ужимаем миниатюру сцены и отступы. */
@media (max-height: 800px) {
  .backdrop-thumb { width: 60px; height: 45px; }
  .backdrop-cell { flex: 0 0 64px; }
  .sprite-info { gap: 4px; font-size: 12px; }
  .sprite-info label { padding: 2px 6px; }
  .add-btn { padding: 7px 10px; margin-top: 4px; }
  .sprite-panel { gap: 4px; }
}
