:root {
  --bg: #0f1117;
  --panel: #171a23;
  --line: #262b38;
  --text: #e8eaf0;
  --muted: #969db0;
  --accent: #4f8cff;
  --accent-2: #7a5cff;
  --ok: #35c48d;
  --warn: #e0a33c;
  --err: #e0574c;
}

* {
  box-sizing: border-box;
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ---------- головна ---------- */

.hero {
  max-width: 620px;
  margin: 0 auto;
  padding: 12vh 24px 48px;
  text-align: center;
}

.logo {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 28px;
}
.logo span { color: var(--accent); }

h1 {
  font-size: clamp(28px, 6vw, 42px);
  line-height: 1.15;
  margin: 0 0 16px;
  letter-spacing: -.02em;
}

.lead { color: var(--muted); margin: 0 auto 36px; max-width: 46ch; }

.btn-primary {
  border: 0;
  border-radius: 12px;
  padding: 15px 34px;
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  cursor: pointer;
  transition: transform .12s ease, box-shadow .2s ease;
  box-shadow: 0 8px 24px -8px rgba(79, 140, 255, .7);
}
.btn-primary:hover { transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }

.join { display: flex; gap: 8px; justify-content: center; margin: 28px 0 0; }
.join input {
  flex: 0 1 260px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 14px;
  color: var(--text);
  font: inherit;
}
.join input:focus { outline: none; border-color: var(--accent); }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 20px;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
.btn-ghost:hover { border-color: var(--accent); }

.notes {
  list-style: none;
  padding: 0;
  margin: 44px 0 0;
  color: var(--muted);
  font-size: 14px;
  text-align: left;
}
.notes li { margin: 10px 0; padding-left: 22px; position: relative; }
.notes li::before { content: "✓"; position: absolute; left: 0; color: var(--ok); }

/* ---------- кімната ---------- */

.room { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.wait { background: var(--warn); animation: pulse 1.4s infinite; }
.dot.live { background: var(--ok); }
.dot.err  { background: var(--err); }
@keyframes pulse { 50% { opacity: .3; } }

/* верхню смугу (лого/статус/копіювати) прибрали, щоб звільнити місце під
   робочу область — лишилась колодочка входу зверху-зліва (плаваюча, видна
   всім, доки не залогінено — це єдиний спосіб зайти) і бренд+статус нагорі
   бічної панелі (тільки в логопеда); щойно залогінились — та сама колодочка
   фізично переїжджає під "LogoPro" (js: lockWrapSlot.appendChild), тож тут
   лишається лише позиція для НЕзалогінованого стану. */
.top-right-cluster {
  position: fixed; top: 8px; left: 8px; z-index: 40;
  display: flex; align-items: center; gap: 8px;
}
.side-rail-wrap { flex: none; width: 64px; display: flex; flex-direction: column; background: var(--panel); border-right: 1px solid var(--line); }
.side-rail-brand {
  width: 100%; padding: 10px 4px 8px; text-align: center;
  border-bottom: 1px solid var(--line);
}
/* колодочка, перенесена сюди після входу — між назвою й крапкою стану */
.side-rail-brand .lock-wrap { display: flex; justify-content: center; margin: 6px 0; }
.side-rail-brand .login-popup { left: 0; right: auto; }
.brand-name {
  font-size: 10px; font-weight: 800; letter-spacing: .04em; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand-name span { color: var(--accent); }
/* лише кружечок — без тексту "підключено/не підключено", який розтягував
   бічну панель; колір/блимання самого кружечка вже й так усе каже */
.brand-status { display: flex; align-items: center; justify-content: center; margin-top: 4px; }
.brand-status #status { display: none; }
.brand-status .dot { width: 10px; height: 10px; }

.body-row { position: relative; flex: 1; display: flex; min-height: 0; }

.side-rail {
  flex: 1;
  min-height: 0;
  width: 64px;
  display: flex;
  flex-direction: column-reverse; /* нові іконки додаються знизу вгору, а
    flex:1 + стандартний justify-content (flex-start у column-reverse
    пакує елементи до низу) притискає всю групу іконок до низу панелі */
  align-items: center;
  gap: 28px;
  padding: 10px 4px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}
.rail-icon {
  width: 56px; height: auto;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #20242f;
  color: var(--text);
  font-size: 18px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  padding: 6px 2px;
  cursor: pointer;
}
.rail-icon.active { border-color: var(--accent); background: #2a3550; }
.rail-icon { touch-action: none; position: relative; }
.rail-icon.rail-dragging {
  z-index: 50; cursor: grabbing;
  border-color: var(--accent);
  box-shadow: 0 8px 20px -4px #000a;
  transition: none;
}
.rail-icon-emoji { font-size: 18px; line-height: 1; }
.rail-label { font-size: 9px; line-height: 1.15; text-align: center; white-space: normal; word-break: break-word; }

.games-menu {
  position: absolute;
  left: 76px;
  /* top виставляє JS — рівно навпроти кнопки, яка відкрила меню (навіть
     якщо ту кнопку потім перетягнули в інше місце бічної панелі) */
  width: min(70vw, 240px);
  max-height: 65vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  z-index: 20;
  box-shadow: 0 12px 30px -8px #000a;
  transform: translateX(0);
  visibility: visible;
  transition: transform .22s ease;
}
/* .hidden лишає display, щоб transform міг анімувати "виїзд" зліва —
   загальне правило .hidden{display:none} тут навмисно перебите вищим
   пріоритетом (два класи) */
.games-menu.hidden {
  display: block;
  /* -115% від власної ширини на вузьких екранах не завжди виносить панель
     повністю за межі екрана (лишався видимий шматок зліва й заступав
     кнопки рейки) — тому їдемо додатково на весь viewport поверх того */
  transform: translateX(calc(-100% - 100vw));
  visibility: hidden;
  pointer-events: none;
}

/* острівець керування фоном — той самий вигляд, що й галерея картинок
   у "Дошці": ряд іконок + мініатюри, що прокручуються, замість колишнього
   вертикального списку текстових пунктів */
.bg-island {
  display: flex; align-items: center; gap: 8px;
  width: min(90vw, 340px); max-height: none;
  /* прокрутка — на самому острівці (не лише на внутрішньому рядку
     мініатюр), щоб кнопки хрестик/фото/білий фон гортались РАЗОМ із
     мініатюрами в один рядок, а не лишались нерухомо зліва */
  overflow-x: auto; overflow-y: hidden;
}
/* .gallery-row усередині острівця фону більше не свій окремий скрол-бокс —
   display:contents прибирає його як обгортку, і його діти (мініатюри)
   стають прямими учасниками того самого flex-рядка й тієї самої прокрутки,
   що й кнопки-іконки зліва від них */
.bg-island > .gallery-row { display: contents; }
/* кнопки-іконки острівця фону — того самого розміру, що й мініатюри
   картинок поряд, щоб рядок виглядав однорідно */
.bg-island > .gallery-icon-btn {
  width: 56px; height: 56px; border-radius: 10px; font-size: 22px;
}
.bg-island > .bg-white-btn {
  background: #fff; color: #1a1d24; font-size: 11px; font-weight: 700;
  line-height: 1.15; border-color: var(--line);
}

.offscreen-video { position: fixed; left: -9999px; top: 0; width: 2px; height: 2px; opacity: 0; }

.games-menu-title {
  font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); padding: 6px 8px;
}
.game-item {
  display: block; width: 100%; text-align: left;
  padding: 11px 10px; border-radius: 8px; border: 0;
  background: transparent; color: var(--text); font: inherit; cursor: pointer;
}
.game-item:hover, .game-item:active { background: #ffffff14; }
.game-item.active { background: var(--accent); color: #fff; }

.stage {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  /* ЄДИНИЙ фон на всю робочу область (гра + камера) — раніше в кожної
     панелі був свій колір (блакитний у гри, темний "за замовчуванням" у
     відео), і межу між ними доводилось "заклеювати" градієнтом-латкою,
     що й давало помітну лінію/смугу. Тепер бридити нема чого: обидві
     панелі прозорі, і крізь них скрізь видно один і той самий фон. */
  background: linear-gradient(180deg, #bfe4ff, #eaf6ff);
  overflow: hidden;
}

.game-frame { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #fff; }

.pane { position: relative; overflow: hidden; min-height: 0; }

.partner-pane { flex: 1; min-height: 0; }

.game-pane { flex: none; }
.game-pane .game-placeholder { position: absolute; inset: 0; overflow: hidden; }
.deco { position: absolute; opacity: .6; }
.deco.circle { border-radius: 50%; }
.deco.diamond { border-radius: 8px; transform: rotate(45deg); }
.c1 { left: 8%;  top: 18%; width: 62px; height: 62px; background: #ffe08a; }
.c2 { left: 72%; top: 12%; width: 42px; height: 42px; background: #ffb3c6; }
.c3 { left: 52%; top: 58%; width: 80px; height: 80px; background: #bdf3e0; }
.d1 { left: 20%; top: 62%; width: 34px; height: 34px; background: #a7d8ff; }
.d2 { left: 85%; top: 50%; width: 26px; height: 26px; background: #ffd6a5; }

.split-grip {
  flex: none;
  height: 72px;
  position: relative;
  background: transparent;
  display: flex; align-items: center; justify-content: center;
  touch-action: none; cursor: ns-resize; z-index: 4;
}
/* тонка чорна лінія на всю ширину — щоб чітко було видно межу поділу */
.split-grip::before {
  content: ""; position: absolute; left: 0; right: 0; top: 50%;
  height: 2px; transform: translateY(-50%); background: #000c;
}
/* сама ручка — грубша, як кнопка, щоб легше було в неї попадати */
.split-grip::after { content: ""; position: relative; width: 64px; height: 14px; border-radius: 7px; background: #1e3a8a; }
body:not(.is-admin) .split-grip { display: none; }

#remote {
  /* Розмір виставляється точно через JS (syncRemoteVideoSize): висота
     завжди дорівнює висоті .partner-pane (головний параметр масштабу),
     ширина — похідна від реального співвідношення сторін камери й може
     виходити за межі екрана (тоді overflow:hidden у .pane просто обрізає
     зайве, без чорних/білих смуг). Рамка елемента точно збігається з
     рамкою видимого зображення (жодних внутрішніх полів), тому маска
     нижче гасне рівно на межі фото, а не в порожньому просторі навколо. */
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  border-radius: 24px;
  mask-image:
    linear-gradient(to bottom, transparent, #000 20px, #000 calc(100% - 20px), transparent),
    linear-gradient(to right, transparent, #000 20px, #000 calc(100% - 20px), transparent);
  mask-composite: intersect;
  -webkit-mask-image:
    linear-gradient(to bottom, transparent, #000 20px, #000 calc(100% - 20px), transparent),
    linear-gradient(to right, transparent, #000 20px, #000 calc(100% - 20px), transparent);
  -webkit-mask-composite: source-in;
}

/* Велике "я на себе дивлюсь" — суто візуальний шар поверх відео логопеда.
   Звук навмисно й далі йде з #remote, який ніхто не займає — щоб дитина
   чула терапевта, навіть коли дивиться на власне зображення. */
.big-self-view {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; background: #000;
}
.big-self-view.hidden { display: none; }

#local {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}

.placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 10px;
  color: var(--muted);
  padding: 24px;
}
.placeholder.hidden { display: none; }
.placeholder-icon { font-size: 38px; opacity: .5; }
/* у логопеда замість іконки камери — кнопка "Копіювати посилання" */
body.is-admin .guest-only-icon { display: none; }

.controls {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 14px;
  border-top: 1px solid var(--line);
  background: #ffffff;
}
.controls-row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
}
/* панель керування (мікрофон/камера/дзвінок) тепер на білому тлі — кнопки
   теж білі з рамкою, а не темні, як в іншому інтерфейсі */
.ctrl {
  width: 52px; height: 52px;
  border-radius: 50%;
  border: 1px solid #c9ced9;
  background: #ffffff;
  color: #1a1d27;
  font-size: 20px;
  cursor: pointer;
  display: grid;
  place-content: center;
  flex: none;
}
.ctrl:hover { border-color: var(--accent); }
.ctrl.off { background: #e0574c2e; border-color: var(--err); }
.ctrl.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.ctrl.hangup { background: var(--err); border-color: var(--err); color: #fff; }
.ctrl.go { background: var(--ok); border-color: var(--ok); color: #fff; }

/* доріжка для протягування дзвінка — щоб не завершити/не приєднатись
   випадковим дотиком, треба протягнути повзунок праворуч до кінця */
.call-track {
  position: relative;
  flex: 1;
  min-width: 140px;
  height: 52px;
  background: #ffffff;
  border: 1px solid #c9ced9;
  border-radius: 26px;
  overflow: hidden;
}
.call-track-fill {
  position: absolute; left: 0; top: 0; bottom: 0; width: 0;
  background: var(--ok);
  opacity: .28;
  pointer-events: none;
}
.call-track.hangup .call-track-fill { background: var(--err); }
.call-track-label {
  position: absolute; left: 62px; right: 12px; top: 0; bottom: 0;
  display: flex; align-items: center;
  color: #1a1d27; font-size: 12px; font-weight: 700;
  pointer-events: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.call-handle {
  position: absolute; left: 0; top: 0;
  touch-action: none;
  z-index: 2;
}

.copy {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  border-radius: 8px;
  padding: 7px 13px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.copy:hover { border-color: var(--accent); }
.copy.done { border-color: var(--ok); color: var(--ok); }

.copy-link {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  padding: 8px 15px;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.copy-link:hover { background: #3f78e0; }
.copy-link.done { background: var(--ok); border-color: var(--ok); }

/* колодочка входу/виходу логопеда — видна ВСІМ (і не залогіненим теж),
   бо саме через неї й відбувається вхід */
.lock-wrap { position: relative; flex: none; }
.lock-btn {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  border-radius: 8px;
  width: 38px; height: 38px;
  font-size: 17px;
  cursor: pointer;
}
.lock-btn:hover { border-color: var(--accent); }
.login-popup {
  position: absolute; top: 100%; right: 0; margin-top: 8px;
  width: 240px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px; box-shadow: 0 12px 30px -8px #000c;
  z-index: 50;
}
.login-popup.hidden { display: none; }
.login-title { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.login-popup input {
  width: 100%; background: #20242f; border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 11px; color: var(--text); font: inherit; margin-bottom: 8px;
}
.login-submit {
  width: 100%; border: 0; border-radius: 8px;
  background: var(--accent); color: #fff; font: inherit; font-weight: 700;
  padding: 9px 0; cursor: pointer;
}
.login-submit.logout { background: var(--err); }
.login-err { color: var(--err); font-size: 12px; min-height: 16px; margin-top: 6px; }

.enable-media {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 5;
  border: 1px solid var(--accent);
  background: #171a23dd;
  color: var(--text);
  border-radius: 12px;
  padding: 14px 22px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.enable-media.hidden { display: none; }

.debug-panel {
  position: absolute;
  left: 8px;
  bottom: 8px;
  max-width: min(90vw, 480px);
  max-height: 40vh;
  overflow: auto;
  margin: 0;
  padding: 10px 12px;
  background: #05060acc;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #9de7b8;
  font: 11px/1.5 ui-monospace, Consolas, monospace;
  white-space: pre-wrap;
  z-index: 6;
}
.debug-panel.hidden { display: none; }

/* ---------- сцена: відео/гра на весь екран + плаваюча бульбашка ---------- */

.pointer-overlay {
  position: absolute; inset: 0; z-index: 5; pointer-events: none; touch-action: none;
  -webkit-touch-callout: none; -webkit-user-select: none; user-select: none;
}

/* малювання поверх БУДЬ-ЯКОЇ поточної гри (не власна гра) — вмикається/
   вимикається лише через режим "олівець", працює незалежно від того,
   що зараз відкрито в game-frame */
.draw-canvas {
  /* left/top/width/height рахує JS (resizeDrawCanvas) — на "Дошці" це
     коробка самої дошки, а не все ігрове поле; тут лише дефолт про всяк. */
  position: absolute; left: 0; top: 0; width: 100%; height: 100%; z-index: 4;
  pointer-events: none; touch-action: none;
}
.draw-color-strip {
  position: absolute; top: 50%; right: 10px; z-index: 8;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  background: #ffffff66; border-radius: 18px; padding: 10px 7px;
  transform: translate(140%, -50%);
  transition: transform .28s ease;
  pointer-events: none;
}
.draw-color-strip.show { transform: translate(0, -50%); pointer-events: auto; }
.draw-color-strip.preview { pointer-events: none; opacity: .55; }
.draw-swatch {
  width: 28px; height: 28px; flex: none; border-radius: 50%;
  border: 2px solid #ffffffcc; box-shadow: 0 1px 5px rgba(0,0,0,.35);
  padding: 0; cursor: pointer;
}
.draw-swatch.selected { border-color: #2a4d6e; box-shadow: 0 0 0 2px #2a4d6e; }

.lock-badge {
  position: absolute; top: 10px; right: 10px;
  background: #000a; border-radius: 8px; padding: 6px 9px; font-size: 16px; z-index: 7;
  display: none;
}
.game-pane.locked .lock-badge { display: block; }

.remote-pointer {
  position: absolute; width: 34px; height: 34px; margin: -17px 0 0 -17px;
  border-radius: 50%; background: #ff3b3b; box-shadow: 0 0 0 6px #ff3b3b40;
  display: flex; align-items: center; justify-content: center; font-size: 15px;
  pointer-events: none; z-index: 6;
}
.remote-pointer.hidden { display: none; }

/* плаваюча бульбашка з власною камерою — вільно тягається по всьому екрану */
.self-bubble {
  position: fixed;
  width: 104px; height: 104px;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid #ffffffaa;
  box-shadow: 0 8px 24px -6px #000c;
  background: #000;
  touch-action: none;
  cursor: grab;
  z-index: 8;
}
.self-bubble.dragging { cursor: grabbing; border-color: var(--accent); }
.self-bubble.hidden { display: none; }
.self-bubble.enlarged { width: 208px; height: 208px; }

/* мінімальний вигляд для дитини: жодних кнопок логопеда */
body:not(.is-admin) .admin-only { display: none !important; }

.admin-toolbar {
  position: relative;
  display: flex; align-items: flex-start; justify-content: flex-start; gap: 10px;
  /* зліва невеликий відступ (орієнтир — ширина бічної панелі зверху), але
     менший за неї, щоб обидва блоки (мій і дитини) влазили в один рядок
     тепер, коли в моєму зʼявилась стирачка/мітла (5 колонок) */
  padding: 10px 8px 10px 48px;
  background: var(--panel); border-top: 1px solid var(--line);
  font-size: 14px; flex-wrap: wrap;
}
/* блок "Дитина" — праворуч, окремо від мого блоку керування, а не впритул */
.admin-toolbar.hidden { display: none; }

/* "додати зображення" на слайд дошки — окрема плаваюча кнопка в
   лівому нижньому куті робочої області (протилежний кут від панелі
   керування дитиною), видно лише коли відкрита "Дошка" */
.add-image-overlay-btn {
  position: absolute; left: 10px; bottom: 10px; z-index: 9;
  width: 44px; height: 44px; border-radius: 10px;
  border: 1px solid var(--line); background: #171a23aa; color: var(--text);
  font-size: 18px; cursor: pointer; display: grid; place-content: center;
}
.add-image-overlay-btn.hidden { display: none; }

/* панель керування дитиною тепер прямо в робочій зоні, справа внизу —
   яка саме (повна для малювання, чи проста для решти ігор) вирішує JS */
.game-overlay-panel {
  position: absolute; right: 10px; bottom: 10px; z-index: 9;
}
.game-overlay-panel.hidden { display: none; }

/* острівець галереї картинок для дошки — над усіма шарами гри, тому
   клікабельний завжди, незалежно від того, який зараз режим обрано */
.gallery-island {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  z-index: 15;
  max-width: calc(100% - 20px);
  display: flex; align-items: center; gap: 8px;
  background: #171a23aa; border: 1px solid var(--line); border-radius: 12px;
  padding: 8px 10px;
  box-shadow: 0 8px 22px -6px #000a;
}
.gallery-island.hidden { display: none; }
/* острівець слайдів — притиснутий до ЛІВОГО краю (не по центру) і до
   самого верху; ширина адаптивна — росте разом із кількістю слайдів, але
   не більш ніж приблизно під 4 мініатюри, далі внутрішній рядок сам
   прокручується (замість острівця, що розпухає на весь екран) */
.slides-island {
  left: 10px; top: 2px; transform: none;
  max-width: min(77vw, 290px);
  /* верх/низ навмисно 0 тут — внутрішній .gallery-row нижче й так додає
     свій власний відступ (7/2px), і те й те разом давало подвійний,
     завеликий відступ */
  padding: 0 10px;
}
/* 7px зверху / 2px знизу — рівно стільки, скільки лишає місця для
   червоного кільця-таймера видалення (виступає на 6px), і не більше */
.slides-island .gallery-row { padding: 7px 8px 2px 2px; }
/* поява нового слайду — коротка анімація "виринання", а не миттєва поява */
@keyframes slideItemIn {
  from { opacity: 0; transform: scale(.5); }
  to { opacity: 1; transform: scale(1); }
}
.slide-item-enter { animation: slideItemIn .25s ease-out; }
.gallery-icon-btn {
  flex: none;
  width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid var(--line);
  background: #20242f; color: var(--text); font-size: 16px;
  cursor: pointer; display: grid; place-content: center;
}
/* padding зверху й справа — щоб хрестик, що виступає за межі мініатюри
   (top:-6px;right:-6px), не обрізався прокруткою рядка */
.gallery-row { display: flex; gap: 10px; overflow-x: auto; max-width: 100%; flex: 1; min-width: 0; padding: 8px 8px 4px 2px; }
.gallery-item { position: relative; flex: none; width: 56px; height: 56px; }
.gallery-thumb {
  display: block; width: 56px; height: 56px; border-radius: 10px;
  border: 2px solid var(--line);
  background-size: cover; background-position: center;
  cursor: pointer; padding: 0;
}
.gallery-thumb.selected { border-color: var(--accent); }
.gallery-item.armed .gallery-thumb { border-color: var(--err); }
.thumb-ring {
  position: absolute; inset: -6px; pointer-events: none; z-index: 2;
  transform: rotate(-90deg);
}
.thumb-ring-fg {
  fill: none; stroke: var(--err); stroke-width: 3; stroke-linecap: round;
  stroke-dasharray: 169.6; stroke-dashoffset: 169.6;
}
.gallery-del {
  position: absolute; top: -6px; right: -6px; z-index: 3;
  width: 18px; height: 18px; border-radius: 50%;
  border: 0; background: var(--err); color: #fff;
  font-size: 10px; line-height: 1; cursor: pointer;
  display: grid; place-content: center;
}

/* слайди дошки — трохи вищі за звичайні мініатюри (3:4, як і сама дошка) */
.slides-island .gallery-item { width: 48px; height: 51px; }
.slide-thumb {
  width: 48px; height: 51px;
  background-color: #fff;
}
.slide-thumb.slide-thumb-empty { background-image: none !important; }
.slide-add-btn {
  flex: none; width: 48px; height: 51px; border-radius: 10px;
  border: 2px dashed var(--line); background: transparent; color: var(--muted);
  font-size: 22px; cursor: pointer; display: grid; place-content: center;
}

.tool-switch { display: flex; gap: 13px; }
.tool-switch button {
  border: 1px solid var(--line); border-radius: 10px;
  background: transparent; color: var(--text); font-size: 18px;
  padding: 11px 0; cursor: pointer;
}
.tool-switch button.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.permission-toggle { display: flex; align-items: center; gap: 8px; color: var(--text); cursor: pointer; }
.permission-toggle input { width: 18px; height: 18px; }

.mode-group { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }

/* фіксована ширина колонки — однакова у верхньому ряді (кнопки режимів) і
   в другому ряді (підказки/×1/колір), щоб вони строго співпадали одна під
   одною (той самий gap теж); другий ряд може мати на одну колонку більше
   (для "сама"), яка просто продовжується праворуч за межі верхнього ряду */
.tool-switch button, .tool-subcell { width: 38px; flex: none; }

/* другий ряд під перемикачем — по колонці на кожну кнопку зверху, завжди
   на видноті (не залежить від того, який режим зараз обрано); підпис
   "я"/"дитина" ховається сюди ж (під "рукою"), щоб не займати окремий
   рядок зверху */
.tool-subrow { display: flex; gap: 13px; align-items: stretch; min-height: 30px; }
.tool-subcell { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 2px; }
.tool-subcell:first-child { align-items: flex-start; justify-content: flex-end; }
.mode-tag { font-size: 10px; color: var(--muted); padding-left: 4px; line-height: 1; }

/* блок "Дитина" — окремий, у світло-блакитному тлі, щоб чітко відрізнявся
   від мого власного блоку керування */
.child-panel {
  background: #cfe8ffcc;
  border-radius: 14px;
  padding: 6px 10px 8px;
}
/* на дошці (рука/олівець/колір) — без напівпрозорого блакитного тла; і без
   власного відступу (він же .child-panel padding), інакше кнопки в ній
   висіли б вище, ніж кнопка "кадр" зліва, хоч обидві на bottom:10px */
#drawChildPanel { background: transparent; padding: 0; }
.child-panel .mode-tag { color: #2a4d6e; }
.child-panel .tool-switch button { color: #2a4d6e; border-color: #9cc7ea; }
/* активна кнопка тут не синя (злилась би з голубим тлом), а жовта */
.child-panel .tool-switch button.active { background: #ffe066; color: #4a3c00; border-color: #e0c34a; }
.child-panel .x1-btn { border-color: #9cc7ea; color: #2a4d6e; background: #ffffffa0; }
.child-panel .x1-btn.active { background: #ffe066; color: #4a3c00; border-color: #e0c34a; }
.child-panel .color-dot { border-color: #9cc7ea; }

/* кружечок кольору дитини сидить прямо в перемикачі режимів (справа від
   олівця) — власний слот з position:relative, щоб над ним точно
   прикріпилось спливаюче вікно */
.color-slot { width: 38px; flex: none; position: relative; display: flex; align-items: center; justify-content: center; }

/* кнопка-перемикач "сама обирає колір" — тепер живе у шапці спливаючого
   вікна з кольорами, поруч із кількістю кольорів. Обидві кнопки шапки
   лежать глибоко всередині .tool-switch (через .color-slot), тому без
   .color-popup-header у селекторі їхній стиль забивало б .tool-switch
   button — тут навмисно вищий пріоритет. */
.color-popup-header .child-picks-btn, .color-popup-header .count-btn {
  width: auto; height: auto; padding: 8px 12px; font-size: 12px; font-weight: 700;
  border: 1px solid #9cc7ea; border-radius: 8px;
  background: #ffffffa0; color: #2a4d6e;
  cursor: pointer; white-space: nowrap;
}
.child-picks-btn.on { border-color: var(--err); box-shadow: 0 0 0 2px var(--err); }

.color-dot {
  width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid var(--line); padding: 0; cursor: pointer;
}
.tool-switch .color-dot { width: 28px; height: 28px; border-radius: 50%; }
.color-popup {
  /* right:0 замість центрування — кружечок кольору часто сидить біля
     самого правого краю екрана (панель дошки притиснута справа знизу),
     і центрований попап там вилазив за межі екрана */
  position: absolute; bottom: 100%; right: 0;
  margin-bottom: 10px;
  display: flex; flex-direction: column; gap: 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 16px; box-shadow: 0 10px 28px -6px #000a;
  z-index: 30;
  min-width: 220px;
  max-width: calc(100vw - 24px);
}
.color-popup.hidden { display: none; }
.color-popup-header { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.color-popup-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.color-popup-grid.disabled { opacity: .35; pointer-events: none; }
.color-swatch {
  width: 38px; height: 38px; border-radius: 50%;
  border: 2px solid var(--line); padding: 0; cursor: pointer;
}
.color-swatch.selected { border-color: #fff; box-shadow: 0 0 0 3px var(--accent); }

.x1-btn {
  border: 1px solid var(--line); border-radius: 10px;
  background: transparent; color: var(--text);
  font-weight: 800; font-size: 13px;
  padding: 6px 12px; cursor: pointer;
}
.x1-btn:active { background: var(--accent); color: #fff; }

.clear-all-wrap { position: relative; display: flex; align-items: center; justify-content: center; width: 44px; height: 44px; }
.clear-confirm-label {
  position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%);
  margin-bottom: 6px;
  background: var(--panel); border: 1px solid var(--ok); border-radius: 8px;
  color: var(--ok); font-size: 10px; font-weight: 800; text-align: center; line-height: 1.25;
  padding: 4px 7px; white-space: nowrap;
  z-index: 20;
}
.clear-confirm-label.hidden { display: none; }
.clear-all-btn {
  width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid var(--line);
  background: transparent; color: var(--text);
  font-size: 19px; padding: 0; cursor: pointer;
  display: grid; place-content: center;
}
.clear-all-btn.armed { border-color: var(--ok); color: var(--ok); }
.clear-ring {
  position: absolute; inset: 0; pointer-events: none;
  transform: rotate(-90deg);
}
.clear-ring-fg {
  fill: none; stroke: var(--ok); stroke-width: 3; stroke-linecap: round;
  stroke-dasharray: 119.4; stroke-dashoffset: 119.4;
}

.selfview-ctrl {
  width: auto; height: 52px; border-radius: 12px; padding: 4px 12px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  font-size: 10px; font-weight: 700; line-height: 1.15; white-space: nowrap;
}
.selfview-ctrl span { display: block; }
.selfview-ctrl.on { animation: selfviewBlink 1s step-start infinite; color: #fff; }
@keyframes selfviewBlink {
  0%, 49% { background: #ff3b3b; border-color: #ff3b3b; }
  50%, 100% { background: #2ecc71; border-color: #2ecc71; }
}
