* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; user-select: none; }
html, body { height: 100%; overflow: hidden; font-family: 'Segoe UI', system-ui, sans-serif; background: #0f172a; }

.screen { position: fixed; inset: 0; display: none; }
.screen.active { display: block; }

button { font-family: inherit; cursor: pointer; border: none; }
input { font-family: inherit; }

.brand-tag {
  position: fixed; left: 50%; bottom: 6px; transform: translateX(-50%); z-index: 999;
  background: rgba(15,23,42,.55); color: #fff; font-weight: 700; font-size: .68em;
  padding: 4px 12px; border-radius: 20px; letter-spacing: .3px; white-space: nowrap;
  pointer-events: none;
}

/* ══════ ОБЛОЖКА ══════ */
#s-cover.active { display: block; }
.cover-bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cover-play {
  position: absolute; top: 58%; left: 50%; transform: translate(-50%,-50%);
  padding: 16px 46px; background: linear-gradient(135deg,#fbbf24,#f59e0b);
  color: #451a03; font-weight: 800; font-size: 1.5em; letter-spacing: .5px;
  border-radius: 40px; border: 3px solid #fff8e1;
  box-shadow: 0 10px 24px rgba(0,0,0,.35), inset 0 2px 0 rgba(255,255,255,.5);
  cursor: pointer; display: flex; align-items: center; gap: 8px;
}
.cover-play-paw { font-size: .8em; }
.cover-play:active { transform: translate(-50%,-50%) scale(.95); }

/* ══════ СТАРТ: меню ══════ */
#s-start.active { display: flex; }
.menu-content {
  position: relative; z-index: 1; width: 100%; height: 100%; overflow-y: auto;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  padding: 22px 16px 34px;
}
.menu-heading { width: min(320px, 78vw); margin-top: 6px; }
.menu-char-row, .menu-letter-row {
  display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; align-items: center;
}
.menu-char-btn, .menu-letter-btn { background: none; padding: 6px; }
.menu-char-btn img { width: min(150px, 34vw); }
.menu-letter-btn img { width: min(72px, 16vw); transition: transform .15s, filter .15s; }
.menu-letter-btn:hover img {
  transform: scale(1.18);
  filter: drop-shadow(0 0 6px #fff) drop-shadow(0 0 14px #fff);
}
.menu-char-btn img, .menu-letter-btn.selected img {
  transition: transform .15s, filter .15s;
}
.menu-char-btn.selected img, .menu-letter-btn.selected img {
  filter: drop-shadow(0 0 8px #fff) drop-shadow(0 0 18px #fff);
  transform: scale(1.1);
}
.menu-observer-btn { background: none; margin-top: 8px; }
.menu-observer-btn img { width: min(300px, 74vw); }
.menu-observer-btn:active img { transform: scale(.96); }

.menu-child-btn {
  margin-top: 10px; padding: 15px 30px; width: min(300px, 74vw);
  background: linear-gradient(135deg,#22c55e,#16a34a); color: #fff;
  font-weight: 800; font-size: 1.05em; border-radius: 40px;
  border: 3px solid #eafff0; box-shadow: 0 8px 20px rgba(22,163,74,.35);
}
.menu-child-btn:active { transform: scale(.96); }

/* ══════ ЛОГОПЕД: панель наблюдателя + настройки игры ══════ */
#s-therapist-setup.active { display: flex; }
.ts-bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.ts-content {
  position: relative; z-index: 1; width: 100%; height: 100%; overflow-y: auto;
  display: flex; flex-direction: column; align-items: center; gap: 26px;
  padding: 30px 16px 40px;
}
.ts-card {
  width: min(440px, 94vw); background: rgba(255,252,245,.95); border-radius: 28px;
  padding: 40px 20px 24px; box-shadow: 0 16px 40px rgba(0,0,0,.3);
  display: flex; flex-direction: column; align-items: center; gap: 14px;
}
.ts-card-observer { width: min(320px, 94vw); align-items: flex-start; gap: 12px; padding: 32px 18px 20px; }
.ts-card-observer .ts-plank { align-self: center; margin-top: -50px; }
.ts-card-observer .ts-hint { text-align: left; }
.ts-card-settings { width: min(640px, 94vw); padding: 46px 26px 28px; gap: 20px; }
.ts-card-settings .ts-block-title { font-size: 1.15em; }
.ts-plank {
  margin-top: -66px; padding: 14px 26px; border-radius: 16px; text-align: center;
  background: linear-gradient(160deg,#8a5a2f,#6b4423); color: #fff6e0;
  font-weight: 900; font-size: 1.05em; letter-spacing: .5px;
  box-shadow: 0 6px 14px rgba(0,0,0,.3), inset 0 2px 0 rgba(255,255,255,.15);
  border: 2px solid rgba(255,255,255,.25);
}
.ts-hint { color: #475569; text-align: center; font-size: .95em; line-height: 1.4; }
.ts-link-field {
  width: 100%; display: flex; align-items: center; gap: 10px;
  background: #f1f5f9; border: 2px solid #e2e8f0; border-radius: 16px; padding: 14px 16px;
}
.ts-link-field .ts-ico { font-size: 1.1em; opacity: .7; }
.ts-link-text { flex: 1; font-weight: 700; color: #1e293b; overflow-x: auto; white-space: nowrap; font-size: .9em; }
.ts-btn-copy {
  width: 100%; padding: 15px; background: linear-gradient(135deg,#22c55e,#16a34a); color: #fff;
  font-weight: 800; font-size: 1.05em; border-radius: 16px; box-shadow: 0 8px 20px rgba(22,163,74,.35);
  display: flex; align-items: center; justify-content: center; gap: 10px;
}
.ts-btn-copy:active { transform: scale(.97); }
.ts-btn-test {
  width: 100%; padding: 14px; background: #eef2ff; color: #4338ca; font-weight: 700;
  border-radius: 16px; border: 2px dashed #c7d2fe; display: flex; align-items: center; justify-content: center; gap: 10px;
}
.ts-btn-test:active { transform: scale(.97); }
.ts-info {
  width: 100%; background: #eff6ff; border: 2px solid #dbeafe; border-radius: 16px; padding: 14px 16px;
  display: flex; gap: 10px; align-items: flex-start; color: #334155; font-size: .88em; line-height: 1.4;
}
.ts-info .ts-ico { font-size: 1.15em; }

.ts-block { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.ts-block-title { font-weight: 800; color: #1e293b; font-size: 1.05em; display: flex; align-items: center; gap: 8px; }

/* Единая система карточек выбора — персонаж / буква / уровни ведут себя одинаково */
.pick-row { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; width: 100%; }
.pick-card {
  background: #f8fafc; border-radius: 20px; border: 3px solid transparent;
  padding: 10px 8px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  box-shadow: 0 4px 10px rgba(0,0,0,.08); cursor: pointer;
  transition: transform .25s ease, box-shadow .25s ease, border-color .25s ease, background-color .25s ease;
}
.pick-card:hover {
  transform: scale(1.13); background: #eefdf3;
  box-shadow: 0 0 0 5px rgba(34,197,94,.18), 0 10px 20px rgba(0,0,0,.15);
}
.pick-card:active { transform: scale(1.05); }
.pick-card.selected {
  border-color: #22c55e; background: #eefdf3; transform: scale(1.13);
  box-shadow: 0 0 0 5px rgba(34,197,94,.32), 0 10px 22px rgba(0,0,0,.2);
}
.pick-card-img { width: 62px; height: 62px; object-fit: contain; }
.pick-card-label { font-weight: 700; font-size: .78em; color: #1e293b; }
.pick-card-letter { padding: 12px; }
.pick-card-letter .pick-card-img { width: 48px; height: 48px; }
.pick-card-level {
  width: 54px; height: 54px; font-size: 1.6em; font-weight: 900; color: #16a34a; padding: 0;
}

.ts-help-btn {
  position: fixed; top: 18px; right: 18px; z-index: 5;
  width: 44px; height: 44px; border-radius: 50%;
  background: linear-gradient(135deg,#ef4444,#b91c1c); color: #fff;
  font-weight: 900; font-size: 1.3em;
  box-shadow: 0 6px 16px rgba(0,0,0,.35), inset 0 2px 0 rgba(255,255,255,.25);
  border: 2px solid rgba(255,255,255,.4);
}
.ts-help-btn:active { transform: scale(.92); }

.ts-open-btn {
  width: 100%; margin-top: 6px; padding: 19px; background: linear-gradient(135deg,#fbbf24,#f59e0b);
  color: #451a03; font-weight: 900; font-size: 1.25em; letter-spacing: .5px; border-radius: 20px;
  box-shadow: 0 14px 30px rgba(0,0,0,.4), inset 0 2px 0 rgba(255,255,255,.5),
              0 0 0 4px rgba(255,255,255,.55), 0 0 26px 8px rgba(255,255,255,.65);
}
.ts-open-btn:active { transform: scale(.97); }

@media (min-width: 760px) {
  .ts-content { flex-direction: row; align-items: flex-start; justify-content: center; flex-wrap: wrap; gap: 48px; }
  .ts-card-observer { margin-top: 46px; margin-right: 12px; }
}

/* ══════ ИНСТРУКЦИЯ ══════ */
#s-instructions.active { display: flex; align-items: center; justify-content: center; }
.instr-bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; filter: blur(14px); transform: scale(1.08); }
.instr-step { display: flex; gap: 14px; margin-bottom: 16px; text-align: left; }
.instr-emoji { font-size: 1.8em; flex-shrink: 0; }
.instr-text { font-size: .95em; color: #1e293b; line-height: 1.5; }

/* ══════ ПАНЕЛИ (настройка / ввод кода / выбор персонажа) ══════ */
.screen.active:not(#s-start):not(#s-child-game):not(#s-end):not(#s-therapist-obs):not(#s-therapist-setup) {
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #1e3a2f 0%, #2f5233 40%, #4a7c3f 100%);
}
.panel {
  position: relative; z-index: 1;
  width: min(420px, 92vw); background: rgba(255,255,255,.96); border-radius: 24px;
  padding: 30px 26px; text-align: center; box-shadow: 0 20px 50px rgba(0,0,0,.35);
}
.panel-wide { width: min(560px, 94vw); }
.panel h2 { color: #1e293b; font-size: 1.4em; margin-bottom: 20px; }
.field { display: block; text-align: left; margin-bottom: 20px; }
.field span { display: block; font-size: .85em; color: #64748b; margin-bottom: 6px; font-weight: 600; }
.field input {
  width: 100%; padding: 12px 14px; border: 2px solid #e2e8f0; border-radius: 12px; font-size: 1.1em;
}
.btn-primary {
  width: 100%; padding: 15px; background: linear-gradient(135deg,#22c55e,#16a34a); color: #fff;
  font-weight: 800; font-size: 1.05em; border-radius: 14px; box-shadow: 0 8px 20px rgba(22,163,74,.35);
}
.btn-primary:active { transform: scale(.97); }
.btn-ghost { width: 100%; padding: 12px; margin-top: 10px; background: transparent; color: #64748b; font-weight: 600; }

.code-input {
  width: 100%; padding: 18px; font-size: 2.2em; text-align: center; letter-spacing: .3em;
  border: 2px solid #e2e8f0; border-radius: 14px; margin-bottom: 18px; color: #1e293b;
}
.join-err { margin-top: 12px; color: #dc2626; font-size: .9em; min-height: 1.2em; }

.char-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px,1fr)); gap: 14px; margin-top: 6px; }
.char-card {
  padding: 22px 10px; border-radius: 20px; background: #f1f5f9; border: 3px solid transparent;
  display: flex; flex-direction: column; align-items: center; gap: 8px; transition: transform .15s;
}
.char-card:active { transform: scale(.94); }
.char-emoji { font-size: 2.8em; }
.char-name { font-weight: 800; color: #1e293b; }
.char-letter { font-size: .8em; color: #64748b; font-weight: 700; }

.load-emoji { font-size: 3em; margin-bottom: 14px; animation: loadBob 1s ease-in-out infinite; }
@keyframes loadBob { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-8px)} }
.load-bar { width: 100%; height: 10px; background: #e2e8f0; border-radius: 6px; overflow: hidden; margin-bottom: 12px; }
.load-bar-fill { height: 100%; width: 0%; background: linear-gradient(90deg,#22c55e,#16a34a); transition: width .3s; }
.load-txt { color: #475569; font-weight: 600; }

/* ══════ ИГРА (ребёнок) ══════ */
#s-child-game { background: #0f172a; }
#child-video { display: none; }
#child-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.child-hud {
  position: absolute; top: 0; left: 0; right: 0; padding: 14px 18px;
  display: flex; flex-direction: column; gap: 6px; z-index: 2;
}
.hud-round { color: #fff; font-weight: 800; font-size: 1.1em; text-shadow: 0 2px 6px rgba(0,0,0,.5); }
.hud-bar-wrap { height: 10px; background: rgba(255,255,255,.25); border-radius: 6px; overflow: hidden; }
.hud-bar { height: 100%; width: 0%; background: linear-gradient(90deg,#fbbf24,#f97316); transition: width .4s; }
.hud-caught { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.hud-caught-icon { width: 30px; height: 30px; object-fit: contain; filter: drop-shadow(0 2px 4px rgba(0,0,0,.5)); animation: caughtPop .35s ease-out; }
@keyframes caughtPop { 0%{transform:scale(0)} 60%{transform:scale(1.25)} 100%{transform:scale(1)} }
.child-fstatus {
  position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%);
  color: #fcd34d; font-weight: 700; text-shadow: 0 2px 6px rgba(0,0,0,.6); z-index: 2; font-size: .95em;
}
/* Летящая в HUD буква при поимке */
.fly-letter {
  position: fixed; width: 60px; height: 60px; object-fit: contain;
  transform: translate(-50%,-50%) scale(1); opacity: 1;
  transition: left .6s cubic-bezier(.2,.8,.3,1), top .6s cubic-bezier(.2,.8,.3,1), transform .6s ease, opacity .6s ease;
  z-index: 50; pointer-events: none; filter: drop-shadow(0 4px 10px rgba(0,0,0,.5));
}

/* Экран «повтори буквы» после последней поимки — камера ещё видна */
.review-overlay {
  position: absolute; inset: 0; z-index: 4; display: none;
  flex-direction: column; align-items: center; justify-content: center; gap: 24px;
  background: rgba(4,20,10,.45); padding: 24px;
}
.review-overlay.show { display: flex; }
.review-title {
  color: #fff; font-weight: 800; font-size: clamp(1.2em, 4.5vw, 1.6em); text-align: center;
  text-shadow: 0 3px 10px rgba(0,0,0,.6); background: rgba(15,23,42,.5); padding: 12px 22px; border-radius: 18px;
}
.review-letters { display: flex; flex-wrap: wrap; gap: 16px; justify-content: center; max-width: 90vw; }
.review-letter-icon {
  width: 76px; height: 76px; object-fit: contain; cursor: pointer;
  transition: transform .25s ease, opacity .25s ease; filter: drop-shadow(0 4px 10px rgba(0,0,0,.5));
}
.review-letter-icon:active { transform: scale(.9); }
.review-letter-icon.popped { transform: scale(0); opacity: 0; }

/* ══════ ФИНАЛ ══════ */
#s-end.active { display: flex; }
.end-celebrate {
  position: relative; width: 100%; height: 100%; background: #0f172a;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  gap: 12px; padding-bottom: 6%; overflow: hidden;
}
.end-bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }

/* ══════ ЛОГОПЕД: НАБЛЮДЕНИЕ ══════ */
#s-therapist-obs.active { display: flex; }
#s-therapist-obs {
  flex-direction: column; background: #0f172a; color: #fff;
}
.obs-top { display: flex; justify-content: space-between; align-items: center; padding: 12px 18px; font-size: .9em; gap: 10px; }
.obs-back {
  background: #1e293b; color: #fff; font-weight: 700; padding: 8px 12px;
  border-radius: 10px; border: 1px solid #334155; flex-shrink: 0;
}
.obs-back:active { transform: scale(.95); }
.obs-instruction {
  margin: 0 18px 8px; padding: 10px 14px; background: #1e293b; color: #cbd5e1;
  border-radius: 12px; font-size: .82em; line-height: 1.4; border: 1px solid #334155;
}
.obs-room b { color: #fbbf24; }
.obs-conn { color: #94a3b8; }
.obs-stage { flex: 1; position: relative; margin: 0 12px; border-radius: 16px; overflow: hidden; background: #1e293b; }
#obs-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#child-cam-view { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.obs-review-overlay {
  position: absolute; inset: 0; z-index: 3; display: none;
  flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  background: rgba(4,20,10,.5); padding: 16px;
}
.obs-review-overlay.show { display: flex; }
.obs-review-title {
  color: #fff; font-weight: 700; font-size: .95em; text-align: center;
  background: rgba(15,23,42,.55); padding: 10px 16px; border-radius: 14px; max-width: 90%;
}
.obs-review-letters { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; max-width: 92%; }
.obs-review-letter-icon {
  width: 56px; height: 56px; object-fit: contain; cursor: pointer;
  transition: transform .2s ease, opacity .2s ease; filter: drop-shadow(0 3px 8px rgba(0,0,0,.5));
}
.obs-review-letter-icon:active { transform: scale(.9); }
.obs-review-letter-icon.popped { transform: scale(0); opacity: 0; }
.obs-info { display: flex; justify-content: space-between; padding: 10px 18px; font-size: .9em; color: #cbd5e1; }
.obs-controls { display: flex; gap: 10px; padding: 12px 18px; }
.obs-controls button {
  flex: 1; padding: 13px; background: #1e293b; color: #fff; border-radius: 12px; font-weight: 700;
  border: 1px solid #334155;
}
.obs-controls button:active { transform: scale(.96); }
.obs-log { max-height: 70px; overflow-y: auto; padding: 0 18px 12px; font-size: .78em; color: #64748b; }
