:root {
  --bg: #0d0a12;
  --panel: #16111e;
  --panel-2: #1e1729;
  --line: #2e2440;
  --text: #f1e7d6;
  --muted: #a397b3;
  --accent: #ff7a2f;
  --accent-2: #ffb347;
  --blood: #d8323c;
  --glass: rgba(13, 10, 18, 0.66);
  /* безопасные зоны: вырез экрана и кнопки Telegram в полноэкранном режиме */
  --safe-top: calc(max(env(safe-area-inset-top), var(--tg-safe-area-inset-top, 0px)) + var(--tg-content-safe-area-inset-top, 0px));
  --safe-bottom: calc(max(env(safe-area-inset-bottom), var(--tg-safe-area-inset-bottom, 0px)) + var(--tg-content-safe-area-inset-bottom, 0px));
  --safe-left: max(env(safe-area-inset-left), var(--tg-safe-area-inset-left, 0px));
  --safe-right: max(env(safe-area-inset-right), var(--tg-safe-area-inset-right, 0px));
  --vh: var(--tg-viewport-stable-height, 100svh);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Rubik, system-ui, -apple-system, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(900px 500px at 15% -10%, rgba(255, 122, 47, 0.12), transparent 60%),
    radial-gradient(800px 500px at 100% 0%, rgba(63, 224, 208, 0.08), transparent 60%),
    var(--bg);
}

button { font: inherit; color: inherit; }

/* ── шапка ── */
.top {
  max-width: 1320px;
  margin: 0 auto;
  padding: 18px 20px 12px;
  display: flex;
  align-items: baseline;
  gap: 18px;
  flex-wrap: wrap;
}
.logo {
  font-family: 'Rubik Wet Paint', Rubik, sans-serif;
  font-size: 38px;
  line-height: 1;
  color: var(--accent);
  text-shadow: 0 0 24px rgba(255, 122, 47, 0.35);
}
.tag { margin: 0; color: var(--muted); font-size: 16px; }

/* ── сетка ── */
.layout {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 20px 40px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 20px;
  align-items: start;
}
.stage-col, .panel { min-width: 0; }

/* ── локации ── */
.locs { display: flex; gap: 6px; margin-bottom: 10px; }
.loc {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-weight: 700;
  font-size: 14px;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.loc:hover { color: var(--text); border-color: #4a3a63; }
.loc.on { background: var(--accent); border-color: var(--accent); color: #1a0d05; }
.loc:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }
body.loc-aquarium .ci, body.loc-circus .aq { display: none !important; }
.hud i { font-style: normal; }

/* ── сцена: камера сама подстраивается под любую форму ── */
.stage {
  position: relative;
  width: 100%;
  height: clamp(520px, calc(100vh - 110px), 920px);
  border-radius: 18px;
  overflow: hidden;
  background: #0d0716;
  box-shadow: 0 0 0 1px var(--line), 0 20px 60px rgba(0, 0, 0, 0.55);
}
.stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.hud {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  background: var(--glass);
  border: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-radius: 10px;
  pointer-events: none;
  font-size: 12.5px;
  color: var(--muted);
}
.hud span { padding: 5px 9px; white-space: nowrap; }
.hud span + span { border-left: 1px solid rgba(255, 255, 255, 0.08); }
.hud b { color: var(--text); font-weight: 700; font-variant-numeric: tabular-nums; }

.hint {
  position: absolute;
  left: 50%;
  bottom: 84px;
  transform: translateX(-50%);
  background: var(--accent);
  color: #1a0d05;
  font-weight: 700;
  font-size: 14px;
  padding: 7px 14px;
  border-radius: 999px;
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(255, 122, 47, 0.35);
  animation: bob 1.6s ease-in-out infinite;
  transition: opacity 0.4s;
  white-space: nowrap;
}
.hint.gone { opacity: 0; }
@keyframes bob { 50% { transform: translate(-50%, -5px); } }

.toasts {
  position: absolute;
  right: 10px;
  top: 46px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  pointer-events: none;
  max-width: calc(100% - 20px);
}
.toast {
  background: rgba(216, 50, 60, 0.92);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  padding: 7px 12px;
  border-radius: 10px;
  animation: pop 0.25s ease-out;
  transition: opacity 0.45s, transform 0.45s;
}
.toast.out { opacity: 0; transform: translateY(-6px); }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(0.96); } }

.chip {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: var(--glass);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: var(--text);
  font-weight: 700;
  font-size: 13px;
  padding: 7px 12px;
  border-radius: 999px;
  cursor: pointer;
}
.recenter { position: absolute; top: 10px; left: 10px; }

/* ── панель управления поверх сцены ── */
.dock {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 8px;
  pointer-events: none;
}
.dock > * { pointer-events: auto; }
.tools, .ctrl {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--glass);
  border: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 16px;
}
.tool {
  appearance: none;
  border: 0;
  background: transparent;
  width: 56px;
  height: 52px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
}
.tool span { font-size: 21px; line-height: 1; }
.tool small { font-size: 10.5px; color: var(--muted); font-weight: 600; }
.tool:hover { background: rgba(255, 255, 255, 0.06); }
.tool.on { background: rgba(255, 122, 47, 0.22); box-shadow: inset 0 0 0 1.5px var(--accent); }
.tool.on small { color: var(--text); }
.tool.zap.cooling { opacity: 0.4; }
.tool:focus-visible, .icon:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 1px; }
.ctrl { align-items: center; }
.ctrl .btn { height: 44px; padding: 0 16px; }
.icon {
  appearance: none;
  border: 0;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: transparent;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.icon:hover { background: rgba(255, 255, 255, 0.06); }
.icon .i-off, .icon.off .i-on { display: none; }
.icon.off .i-off { display: block; }

.keys { color: var(--muted); font-size: 13px; margin: 10px 2px 0; text-align: right; }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel-2);
  padding: 11px 18px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  transition: transform 0.12s, background 0.2s, border-color 0.2s;
}
.btn:hover { border-color: #4a3a63; background: #251c33; }
.btn:active { transform: translateY(1px) scale(0.98); }
.btn:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1a0d05; }
.btn.primary:hover { background: #ff8c4a; }
.btn.link { background: none; border: 0; color: var(--muted); font-weight: 500; font-size: 13px; text-decoration: underline; padding: 8px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn.danger { background: var(--blood); border-color: var(--blood); color: #fff; }

/* ── панель ── */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
}
.panel > section + section:not([hidden]) { margin-top: 22px; }
.step { display: flex; align-items: center; gap: 10px; margin: 18px 0 10px; }
section > .step:first-child { margin-top: 0; }
.step h2 { margin: 0; font-size: 17px; font-weight: 700; }
.step h2 em { font-style: normal; color: var(--muted); font-weight: 500; font-size: 14px; margin-left: 4px; }
.num {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(255, 122, 47, 0.14);
  color: var(--accent);
  font-weight: 900;
  font-size: 14px;
}

.skins { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.skin {
  appearance: none;
  background: var(--panel-2);
  border: 2px solid transparent;
  border-radius: 14px;
  padding: 6px 4px 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: border-color 0.2s, background 0.2s;
}
.skin:hover { background: #251c33; }
.skin.on { border-color: var(--accent); background: #2a1c24; }
.skin canvas { width: 100%; max-width: 120px; aspect-ratio: 120 / 140; }
.skin b { display: block; font-size: 13px; }
.skin small { display: block; font-size: 11px; color: var(--muted); line-height: 1.25; }

.drop {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 2px dashed #4a3a63;
  border-radius: 14px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.drop:hover, .drop.drag { border-color: var(--accent); background: rgba(255, 122, 47, 0.06); }
.drop:focus-within { outline: 2px solid var(--accent-2); outline-offset: 2px; }
.thumb {
  flex: none;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--panel-2) center / cover no-repeat;
  border: 2px solid var(--line);
  position: relative;
}
.drop:not(.has) .thumb::after {
  content: '+';
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 26px;
  color: var(--accent);
}
.drop.has .thumb { border-color: var(--accent); }
.drop-text b { display: block; font-size: 15px; }
.drop-text span { font-size: 13px; color: var(--muted); }

.privacy {
  display: flex;
  gap: 7px;
  align-items: flex-start;
  margin: 10px 2px 0;
  font-size: 12.5px;
  color: #8fd8b5;
  line-height: 1.4;
}
.privacy svg { flex: none; margin-top: 2px; }
.muted { color: var(--muted); font-size: 14px; line-height: 1.5; margin: 0; }
.small { font-size: 13px; }

/* ── загрузка куклы из чата ── */
.loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--glass);
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 12px 18px;
  border-radius: 14px;
  font-weight: 700;
  pointer-events: none;
}
.loading span {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── режимы: сайт / Telegram ── */
.tg-only { display: none; }
body.tg .tg-only { display: revert; }
body.tg .web-only { display: none; }
body.intg .cta { display: none; }
[hidden] { display: none !important; }

/* ── финал: голова на дне ── */
.finale {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: start center;
  padding-top: calc(56px + var(--safe-top-fs, 0px));
  pointer-events: none;
}
.finale-card {
  pointer-events: auto;
  width: min(380px, calc(100% - 24px));
  background: rgba(17, 12, 24, 0.9);
  border: 1px solid var(--line);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 16px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  animation: pop 0.3s ease-out;
}
.finale-card b { font-size: 18px; }
.finale-card p { margin: 0; font-size: 15px; line-height: 1.4; }
.finale-card small { color: var(--muted); font-size: 12.5px; line-height: 1.35; }
.finale-card .row { justify-content: flex-start; flex-wrap: wrap; margin-top: 6px; gap: 8px; }
.finale-card .btn { padding: 9px 14px; font-size: 14px; }

/* ── аквариум чата ── */
.pool-doll { display: flex; align-items: center; gap: 12px; }
.pool-doll b { display: block; font-size: 18px; }
.pool-doll small { color: var(--muted); font-size: 13px; }
.pool-note {
  margin: 12px 0 6px;
  padding: 10px 12px;
  background: var(--panel-2);
  border-radius: 12px;
  font-size: 15px;
  line-height: 1.4;
}
#poolInfo .btn, #sent .btn { margin-top: 10px; }

/* ── поля ── */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field > span { font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; }
.field em { font-style: normal; font-variant-numeric: tabular-nums; }
.field input, .field textarea {
  font: inherit;
  font-size: 16px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  resize: none;
}
.field input:focus, .field textarea:focus { outline: 2px solid var(--accent-2); outline-offset: 1px; border-color: transparent; }
.fine { font-size: 12px; color: var(--muted); line-height: 1.45; margin: 10px 2px 0; }

/* ── стена трофеев ── */
.trophy-wall {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 10px;
  padding: 12px;
  border-radius: 14px;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.025) 0 2px, transparent 2px 28px),
    #22160f;
  box-shadow: inset 0 2px 12px rgba(0, 0, 0, 0.5);
}
.trophy-wall:empty { display: none; }
.trophy {
  appearance: none;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
  transition: transform 0.15s;
  filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.5));
}
.trophy:hover { transform: translateY(-2px) rotate(-1deg); }
.trophy canvas { width: 100%; aspect-ratio: 150 / 180; display: block; }

/* ── карточка головы ── */
.head-card { align-items: center; text-align: center; }
#headCanvas { width: 150px; height: 175px; }
.head-note { margin: 0; font-size: 16px; line-height: 1.45; }
.head-card .row { justify-content: center; flex-wrap: wrap; }
.confirm p { margin: 4px 0 10px; font-size: 14px; }

/* ── диалоги ── */
dialog {
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--panel);
  color: var(--text);
  padding: 0;
  max-width: min(420px, calc(100vw - 32px));
  width: 100%;
}
dialog::backdrop { background: rgba(5, 3, 10, 0.75); backdrop-filter: blur(4px); }
.crop-card { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.crop-card h3 { margin: 0; font-size: 19px; }
#cropCanvas {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 14px;
  touch-action: none;
  cursor: move;
  background: #120d1a;
}
.zoom { display: flex; align-items: center; gap: 12px; font-size: 14px; color: var(--muted); }
.zoom input { flex: 1; accent-color: var(--accent); }
.row { display: flex; justify-content: flex-end; gap: 10px; }

/* ── на весь экран: сцена поверх всего, управление обходит вырезы ── */
body.fs { overflow: hidden; }
body.fs .stage {
  position: fixed;
  inset: 0;
  z-index: 100;
  width: 100%;
  height: 100%;
  border-radius: 0;
  box-shadow: none;
  --safe-top-fs: var(--safe-top);
}
body.fs .hud, body.fs .recenter { top: calc(10px + var(--safe-top)); }
body.fs .hud { right: calc(10px + var(--safe-right)); }
body.fs .recenter { left: calc(10px + var(--safe-left)); }
body.fs .toasts { top: calc(46px + var(--safe-top)); right: calc(10px + var(--safe-right)); }
body.fs .dock {
  left: calc(10px + var(--safe-left));
  right: calc(10px + var(--safe-right));
  bottom: calc(10px + var(--safe-bottom));
}
body.fs .hint { bottom: calc(84px + var(--safe-bottom)); }

/* ── планшеты и телефоны ── */
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 0 12px 28px; gap: 14px; }
  .stage { height: clamp(440px, calc(var(--vh) * 0.74), 900px); border-radius: 16px; }
  .locs { margin-bottom: 8px; }
  .loc { font-size: 13px; padding: 7px 12px; }
  .top { padding: 12px 14px 8px; gap: 4px 14px; }
  .logo { font-size: 30px; }
  .tag { font-size: 14px; }
  .keys { display: none; }
  .toast { font-size: 12.5px; }
}
@media (max-width: 520px) {
  .layout { padding: 0 8px 24px; }
  .stage { border-radius: 14px; }
  .hud { top: 8px; right: 8px; font-size: 10.5px; border-radius: 8px; }
  .hud span { padding: 3px 6px; }
  .recenter { top: 8px; left: 8px; }
  .toasts { top: 36px; right: 8px; }
  .toast { font-size: 11.5px; padding: 5px 9px; }
  .dock { left: 6px; right: 6px; bottom: 6px; gap: 6px; }
  .tools { flex-direction: column; }
  .tool { width: 48px; height: 48px; }
  .tool span { font-size: 19px; }
  .tool small { font-size: 9.5px; }
  .icon { width: 40px; height: 40px; }
  .ctrl .btn { height: 40px; padding: 0 12px; font-size: 14px; }
  .hint { font-size: 12.5px; bottom: 64px; left: calc(50% + 28px); }
  .panel { padding: 14px; border-radius: 16px; }
}
@media (max-width: 370px) {
  .tool small { display: none; }
  .tool { width: 42px; height: 42px; }
  #btnSound { display: none; }
}

/* ── внутри Telegram: компактная шапка; на весь экран — отступ от выреза и кнопок Telegram ── */
body.intg { padding: var(--safe-top) var(--safe-right) 0 var(--safe-left); }
body.tgfs .top { justify-content: center; }
body.tg .top { padding: 8px 14px 6px; }
body.tg .logo { font-size: 24px; }
body.tg .tag { display: none; }
body.tg .layout { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }

@media (prefers-reduced-motion: reduce) {
  .hint { animation: none; }
}
