:root {
  --bg: #12002e;
  --bg-2: #24005a;
  --cyan: #00e1f7;
  --blue: #55a5ff;
  --violet: #a46cf5;
  --pink: #d45fa6;
  --text: #f6f4ff;
  --muted: #b9a9e0;
  --glass: rgba(26, 4, 66, 0.55);
  --glass-strong: rgba(26, 4, 66, 0.82);
  --line: rgba(255, 255, 255, 0.14);
  --grad: linear-gradient(120deg, var(--blue) 0%, var(--violet) 52%, var(--pink) 100%);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  touch-action: manipulation;
  user-select: none; -webkit-user-select: none;
}
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; }
svg { display: block; }
[hidden] { display: none !important; }

.app { position: fixed; inset: 0; overflow: hidden; background: radial-gradient(120% 80% at 50% 0%, #2b0a63 0%, var(--bg) 60%); }

/* ---------- Сцена ---------- */
.stage { position: absolute; inset: 0; }
.view {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; display: block;
  opacity: 0; transition: opacity .35s ease;
}
.app.has-frame .view { opacity: 1; }
.app[data-screen="photo"] .view { object-fit: contain; }
.source-video { position: absolute; width: 2px; height: 2px; opacity: 0; pointer-events: none; }
.flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.flash.on { animation: flash .45s ease-out; }
@keyframes flash { 0% { opacity: .85; } 100% { opacity: 0; } }

.note-guide {
  position: absolute; border-radius: 50%; pointer-events: none;
  box-shadow: 0 0 0 200vmax rgba(18, 0, 46, .5), inset 0 0 0 3px rgba(255,255,255,.9);
  transition: opacity .2s;
}
.note-guide span {
  position: absolute; left: 50%; top: -34px; transform: translateX(-50%); white-space: nowrap;
  padding: 5px 12px; border-radius: 999px; background: var(--glass-strong); font-size: 13px; font-weight: 700;
}
.app[data-recording] .note-guide { box-shadow: 0 0 0 200vmax rgba(18, 0, 46, .5), inset 0 0 0 4px #ff2d55; }
.face-hint {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 18px 22px; border-radius: 22px;
  background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  font-weight: 600; font-size: 15px; text-align: center; pointer-events: none;
  animation: fadeIn .3s ease;
}
.face-hint svg { width: 44px; height: 44px; fill: none; stroke: var(--cyan); stroke-width: 1.6; stroke-linecap: round; }

.busy {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%);
  display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-radius: 18px;
  background: var(--glass-strong); font-weight: 600; font-size: 15px;
}
.busy i { width: 20px; height: 20px; border-radius: 50%; border: 3px solid rgba(255,255,255,.2); border-top-color: var(--cyan); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Верхняя панель ---------- */
.topbar {
  position: absolute; left: 0; right: 0; top: 0;
  padding: calc(var(--safe-t) + 12px) 16px 24px;
  display: flex; align-items: center; justify-content: space-between;
  background: linear-gradient(to bottom, rgba(18,0,46,.7), rgba(18,0,46,0));
  pointer-events: none;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { border-radius: 27%; box-shadow: 0 4px 14px rgba(164,108,245,.45); }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text b { font-size: 16px; letter-spacing: .2px; }
.brand-text small { font-size: 11px; color: var(--muted); }
.in-telegram .brand-text small { display: none; }

.rec-badge {
  display: flex; align-items: center; gap: 8px; padding: 7px 12px; border-radius: 999px;
  background: rgba(230, 30, 60, .92); font-weight: 700; font-variant-numeric: tabular-nums; font-size: 15px;
}
.rec-badge i { width: 9px; height: 9px; border-radius: 50%; background: #fff; animation: blink 1s steps(2) infinite; }
.rec-badge em { font-style: normal; opacity: .75; font-weight: 600; }
@keyframes blink { 50% { opacity: .2; } }

/* ---------- Нижняя панель ---------- */
.dock {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 36px 0 calc(var(--safe-b) + 14px);
  background: linear-gradient(to top, rgba(18,0,46,.92) 0%, rgba(18,0,46,.55) 62%, rgba(18,0,46,0) 100%);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.mask-name {
  font-weight: 800; font-size: 15px; letter-spacing: .3px;
  padding: 6px 14px; border-radius: 999px; background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  min-height: 30px;
}
.strip {
  width: 100%; display: flex; gap: 12px; overflow-x: auto; overflow-y: hidden;
  padding: 6px calc(50% - 32px); scroll-snap-type: x mandatory; scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.strip::-webkit-scrollbar { display: none; }
.mask-btn {
  flex: 0 0 auto; width: 64px; height: 64px; border-radius: 50%; padding: 3px;
  scroll-snap-align: center; position: relative;
  background: rgba(255,255,255,.12);
  transition: transform .2s ease, background .2s ease;
}
.mask-btn img, .mask-btn .ph {
  width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block;
  background: #2a0a63;
}
.mask-btn .ph { display: grid; place-items: center; font-weight: 800; font-size: 20px; color: var(--muted); }
.mask-btn[aria-selected="true"] { background: var(--grad); transform: scale(1.12); }
.mask-btn[aria-selected="true"]::after {
  content: ""; position: absolute; inset: -5px; border-radius: 50%;
  box-shadow: 0 0 18px rgba(164,108,245,.55); pointer-events: none;
}

.modes { display: flex; gap: 6px; padding: 4px; border-radius: 999px; background: var(--glass); }
.modes button {
  padding: 7px 16px; border-radius: 999px; font-weight: 700; font-size: 13px; letter-spacing: .6px; text-transform: uppercase;
  color: var(--muted); transition: background .2s, color .2s;
}
.modes button[aria-selected="true"] { background: rgba(255,255,255,.95); color: var(--bg); }
.app[data-recording] .modes { visibility: hidden; }

.controls { width: 100%; max-width: 420px; display: flex; align-items: center; justify-content: space-between; padding: 2px 28px 0; }
.round-btn {
  width: 52px; height: 52px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  transition: transform .15s ease, opacity .2s;
}
.round-btn:active { transform: scale(.92); }
.round-btn svg { width: 24px; height: 24px; fill: none; stroke: #fff; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.round-btn.invisible { visibility: hidden; }
.app[data-recording] .round-btn { opacity: .3; pointer-events: none; }

.shutter { position: relative; width: 82px; height: 82px; border-radius: 50%; display: grid; place-items: center; }
.shutter .ring { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.shutter .ring circle { fill: none; stroke-width: 6; }
.ring-bg { stroke: rgba(255,255,255,.95); }
.ring-progress { stroke: var(--pink); stroke-dasharray: 289.03; stroke-dashoffset: 289.03; stroke-linecap: round; opacity: 0; }
.app[data-recording] .ring-bg { stroke: rgba(255,255,255,.35); }
.app[data-recording] .ring-progress { opacity: 1; }
.shutter .core {
  width: 64px; height: 64px; border-radius: 50%; background: #fff;
  transition: transform .18s ease, border-radius .2s ease, background .2s ease, width .2s, height .2s;
}
.shutter:active .core { transform: scale(.9); }
.app[data-capture="video"] .shutter .core { background: #ff2d55; width: 58px; height: 58px; }
.app[data-recording] .shutter .core { width: 30px; height: 30px; border-radius: 8px; }
.shutter .save-ico { position: absolute; width: 30px; height: 30px; fill: none; stroke: var(--bg); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; opacity: 0; }
.app[data-screen="photo"] .shutter .core { background: var(--grad); }
.app[data-screen="photo"] .shutter .save-ico { opacity: 1; stroke: #fff; }
.app[data-screen="photo"] .modes { visibility: hidden; }

/* ---------- Экраны ---------- */
.screen {
  position: absolute; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center;
  padding: calc(var(--safe-t) + 24px) 22px calc(var(--safe-b) + 24px);
  background: radial-gradient(120% 70% at 50% 0%, #34107a 0%, var(--bg) 62%);
  overflow: hidden;
}
.app:not([data-screen="intro"]) .intro, .app[data-screen="intro"] .topbar, .app[data-screen="intro"] .dock,
.app[data-screen="denied"] .topbar, .app[data-screen="denied"] .dock { display: none; }
.glow { position: absolute; border-radius: 50%; filter: blur(60px); opacity: .55; pointer-events: none; }
.g1 { width: 320px; height: 320px; background: var(--blue); left: -120px; top: -60px; animation: drift 9s ease-in-out infinite alternate; }
.g2 { width: 300px; height: 300px; background: var(--pink); right: -130px; bottom: 6%; animation: drift 11s ease-in-out infinite alternate-reverse; }
.g3 { width: 220px; height: 220px; background: var(--cyan); right: -40px; top: 18%; opacity: .25; animation: drift 13s ease-in-out infinite alternate; }
@keyframes drift { to { transform: translate(40px, 30px) scale(1.1); } }

.intro-card { position: relative; width: 100%; max-width: 380px; display: flex; flex-direction: column; align-items: center; text-align: center; }
.intro-logo { width: 112px; height: 112px; border-radius: 27%; box-shadow: 0 18px 50px rgba(164,108,245,.45); margin-bottom: 18px; animation: float 4s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-6px); } }
h1 { font-size: 40px; line-height: 1.02; margin: 0 0 12px; font-weight: 900; letter-spacing: -.5px; }
h2 { font-size: 26px; margin: 0 0 10px; font-weight: 800; }
.grad { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.lead { color: var(--muted); font-size: 16px; line-height: 1.4; margin: 0 0 18px; }
.chips { list-style: none; display: flex; gap: 8px; padding: 0; margin: 0 0 24px; flex-wrap: wrap; justify-content: center; }
.chips li { padding: 7px 12px; border-radius: 999px; background: rgba(255,255,255,.08); border: 1px solid var(--line); font-size: 13px; font-weight: 600; }
.chips b { color: var(--cyan); }

.btn {
  width: 100%; height: 54px; border-radius: 16px; font-weight: 800; font-size: 17px;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  transition: transform .15s ease, opacity .2s;
}
.btn:active { transform: scale(.97); }
.btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn.primary { background: var(--grad); color: #fff; box-shadow: 0 10px 30px rgba(164,108,245,.4); }
.btn.ghost { margin-top: 10px; background: rgba(255,255,255,.08); border: 1px solid var(--line); color: var(--text); font-weight: 700; }
.btn.small { height: 46px; font-size: 15px; }

.privacy { display: flex; gap: 8px; align-items: flex-start; text-align: left; color: var(--muted); font-size: 13px; line-height: 1.35; margin: 18px 0 0; }
.privacy svg { flex: 0 0 18px; width: 18px; height: 18px; fill: none; stroke: var(--cyan); stroke-width: 2; margin-top: 1px; }

.loader { width: 100%; margin-top: 18px; display: flex; flex-direction: column; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); transition: opacity .4s; }
.loader .bar { width: 100%; height: 4px; border-radius: 4px; background: rgba(255,255,255,.1); overflow: hidden; }
.loader .bar i { display: block; height: 100%; width: 0; background: var(--grad); border-radius: 4px; transition: width .25s ease; }
.loader.done { opacity: 0; }

.denied-ico { width: 84px; height: 84px; border-radius: 50%; display: grid; place-items: center; background: rgba(255,255,255,.08); margin-bottom: 18px; }
.denied-ico svg { width: 40px; height: 40px; fill: none; stroke: var(--pink); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Лист результата ---------- */
.sheet { position: absolute; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(8, 0, 22, .72); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); animation: fadeIn .2s ease; }
.sheet-body {
  position: relative; width: 100%; max-width: 480px;
  padding: 16px 18px calc(var(--safe-b) + 18px);
  background: linear-gradient(180deg, #2a0a63, #170339);
  border-radius: 26px 26px 0 0; border-top: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 10px;
  animation: up .28s cubic-bezier(.2,.8,.2,1);
  max-height: 100%;
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.preview { border-radius: 18px; overflow: hidden; background: #000; display: grid; place-items: center; max-height: 58vh; }
.preview img, .preview video { display: block; width: 100%; max-height: 58vh; object-fit: contain; }
.preview img { -webkit-touch-callout: default; user-select: auto; -webkit-user-select: auto; pointer-events: auto; }
.sheet-hint { margin: 0; font-size: 13px; color: var(--muted); line-height: 1.35; text-align: center; }
.sheet-hint.ok { color: #7cf5c4; font-size: 15px; font-weight: 700; }
.sheet-hint.err { color: #ff8fa8; font-size: 14px; font-weight: 600; }
.preview.note { background: none; padding: 6px 0; }
.preview.note video { width: min(68vw, 300px); aspect-ratio: 1; border-radius: 50%; object-fit: cover; box-shadow: 0 0 0 4px rgba(255,255,255,.12), 0 16px 40px rgba(0,0,0,.4); }
.sheet-actions { display: flex; gap: 10px; }
.sheet-actions .btn { flex: 1; }
.sheet-actions .btn.ghost { margin-top: 0; }
.sheet > .sheet-body > .btn.ghost { margin-top: 0; }

/* ---------- Тост ---------- */
.toast {
  position: absolute; z-index: 30; left: 50%; top: calc(var(--safe-t) + 70px); transform: translate(-50%, -10px);
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 14px;
  background: var(--glass-strong); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  font-size: 14px; font-weight: 600; text-align: center;
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Тестовый режим (?test) без интерфейса ---------- */
.app.test-clean .topbar, .app.test-clean .dock { display: none; }
.app.test-clean .view { object-fit: contain; }
.test-grid { position: absolute; inset: 0; overflow: auto; padding: 12px; display: grid; align-content: start; align-items: start; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; background: var(--bg); z-index: 5; user-select: auto; }
.test-grid figure { margin: 0; background: #000; border-radius: 12px; overflow: hidden; }
.test-grid img { width: 100%; display: block; }
.test-grid figcaption { padding: 6px 10px; font-size: 13px; font-weight: 700; }

@media (min-width: 700px) {
  .intro-card { max-width: 400px; }
  h1 { font-size: 48px; }
}
@media (max-height: 640px) {
  .intro-logo { width: 84px; height: 84px; margin-bottom: 10px; }
  h1 { font-size: 32px; }
  .lead { font-size: 14px; margin-bottom: 12px; }
  .chips { margin-bottom: 14px; }
  .mask-btn { width: 54px; height: 54px; }
  .strip { padding-left: calc(50% - 27px); padding-right: calc(50% - 27px); }
}
