*, *::before, *::after { box-sizing: border-box; }

html {
  background: var(--sky-top) var(--sky-gradient);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  position: relative;
  width: min(100%, 480px);
  height: 100vh;
  height: 100dvh;
  margin-inline: auto;
  overflow: hidden;
  background: var(--sky-gradient);
  color: var(--text);
  font: 600 15px/1.4 var(--font);
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

h1, h2, h3, p, ul, ol { margin: 0; padding: 0; }
ul, ol { list-style: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
button:disabled { cursor: default; }
input { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }
a { color: var(--text); }
[hidden] { display: none !important; }

:focus { outline: none; }
:focus-visible { outline: 2px solid rgba(255, 255, 255, 0.8); outline-offset: 2px; border-radius: var(--r-xs); }

/* небо за приложением: мелкий шум и два облака, которые медленно плывут */
.ambient {
  position: absolute; inset: 0; z-index: 0; overflow: hidden; pointer-events: none;
  background: url('../assets/sky/noise.png') 0 0 / 160px repeat;
}
.ambient::before, .ambient::after {
  content: ''; position: absolute; aspect-ratio: 1;
  background: url('../assets/sky/cloud.png') center / contain no-repeat;
  animation: cloud-drift 46s ease-in-out infinite alternate;
}
.ambient::before { width: 440px; left: -200px; top: 56%; opacity: 0.42; }
.ambient::after { width: 480px; right: -250px; top: 4%; opacity: 0.32; animation-duration: 58s; animation-direction: alternate-reverse; }
@keyframes cloud-drift { from { transform: translateX(-18px); } to { transform: translateX(26px); } }

.app {
  position: absolute;
  inset: var(--top) 0 0 0;
  z-index: 1;
}

.icon { width: 24px; height: 24px; flex: none; fill: none; stroke: currentColor; }
.icon use { pointer-events: none; }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* макет «окна Telegram» для запуска в обычном браузере */
.devframe {
  position: absolute;
  inset: 0 0 auto 0;
  height: var(--devframe-h);
  z-index: calc(var(--z-overlay) + 20);
  display: flex;
  align-items: center;
  padding: 0 6px;
  background: rgba(8, 52, 108, 0.92);
  border-bottom: 1px solid var(--line);
}
.devframe__title { flex: 1; font-weight: 600; font-size: 16px; padding-left: 10px; }
.devframe__btn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: var(--r-pill); color: var(--text-2); }
.devframe__btn:hover { background: rgba(255, 255, 255, 0.1); }
.devframe__btn .icon { width: 22px; height: 22px; }
.devframe__btn:first-child[hidden] + .devframe__title { padding-left: 14px; }

/* загрузка */
/* экран загрузки (разметка — в index.html): переписка как в Telegram — сообщение пользователя справа,
   бот «печатает» и отвечает ссылкой на себя и стикерами. Когда приложение готово, плавно растворяется (main.js) */
.boot {
  position: absolute; inset: 0; z-index: 80;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 34px;
  padding: calc(24px + var(--safe-top)) 16px calc(24px + var(--safe-bottom));
  background: var(--sky);
  transition: opacity 480ms var(--ease), visibility 0s linear 480ms;
}
.boot.is-done { opacity: 0; visibility: hidden; pointer-events: none; }
.boot.is-done .bchat { transform: translateY(-10px) scale(0.98); }
.bchat { width: min(100%, 360px); display: grid; gap: 12px; transition: transform 480ms var(--ease); }
.bchat__date {
  justify-self: center; padding: 5px 11px; border-radius: 999px; background: rgba(255, 255, 255, 0.14);
  font: 600 12px/1 var(--font); color: var(--text-2);
  animation: bmsg-in 400ms var(--ease) both;
}
.bmsg { display: flex; align-items: flex-end; gap: 8px; animation: bmsg-in 480ms var(--ease-spring) both; }
.bmsg--out { flex-direction: row-reverse; animation-delay: 150ms; }
.bmsg--in { animation-delay: 650ms; }
.bmsg__ava {
  width: 34px; height: 34px; flex: none; display: grid; place-items: center; overflow: hidden; border-radius: 50%;
  background: linear-gradient(135deg, #7cc4ff, #3b82e8); box-shadow: 0 0 0 1.5px rgba(255, 255, 255, 0.4);
  font: 700 14px/1 var(--font); color: #fff;
}
.bmsg__ava img { width: 100%; height: 100%; object-fit: cover; }
.bmsg__body { display: grid; gap: 4px; max-width: 80%; min-width: 0; }
.bmsg--out .bmsg__body { justify-items: end; }
.bmsg--in .bmsg__body { justify-items: start; }
.bmsg__name { padding: 0 8px; font: 700 12px/1 var(--font); color: rgba(255, 255, 255, 0.78); }
.bmsg__bubble { padding: 9px 13px; border-radius: 18px; font: 600 14.5px/1.38 var(--font); overflow-wrap: anywhere; }
.bmsg--out .bmsg__bubble { background: #fff; color: var(--text-on-accent); border-bottom-right-radius: 6px; box-shadow: 0 6px 22px rgba(255, 255, 255, 0.22); }
.bmsg--in .bmsg__bubble {
  background: rgba(255, 255, 255, 0.16); box-shadow: inset 0 0 0 1px var(--line-strong);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); border-bottom-left-radius: 6px;
}
.bmsg__typing { display: flex; gap: 4px; padding: 14px 15px; }
.bmsg__typing i { width: 7px; height: 7px; border-radius: 50%; background: #fff; opacity: 0.4; animation: bmsg-dot 1.1s ease-in-out infinite; }
.bmsg__typing i:nth-child(2) { animation-delay: 160ms; }
.bmsg__typing i:nth-child(3) { animation-delay: 320ms; }
.bmsg__reply { display: grid; gap: 6px; animation: bmsg-pop 420ms var(--ease-spring) both; }
.bmsg__link { justify-self: start; color: #cdeaff; font-weight: 700; text-decoration: underline; text-decoration-color: rgba(205, 234, 255, 0.45); text-underline-offset: 3px; }
.bmsg__stickers { display: flex; gap: 6px; margin: 2px -2px 0; }
.bmsg__stickers img {
  width: 64px; height: 64px; object-fit: contain; filter: drop-shadow(0 6px 10px rgba(4, 30, 72, 0.35));
  animation: bmsg-sticker 520ms var(--ease-spring) both;
}
.bmsg__stickers img:nth-child(2) { animation-delay: 110ms; }
.bmsg__stickers img:nth-child(3) { animation-delay: 220ms; }
.boot__foot { display: grid; justify-items: center; gap: 12px; }
.boot__hand { font-size: 21px; transform: rotate(-3deg); transform-origin: 50% 100%; }
.boot__bar { width: 120px; height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.2); overflow: hidden; }
.boot__bar i {
  display: block; width: 42%; height: 100%; border-radius: inherit; background: #fff;
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.9);
  animation: boot-bar 1.3s var(--ease) infinite;
}
@keyframes bmsg-in { from { opacity: 0; transform: translateY(14px) scale(0.94); } to { opacity: 1; transform: none; } }
@keyframes bmsg-pop { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: none; } }
@keyframes bmsg-sticker { from { opacity: 0; transform: scale(0.4) rotate(-14deg); } to { opacity: 1; transform: none; } }
@keyframes bmsg-dot { 0%, 60%, 100% { opacity: 0.35; transform: none; } 30% { opacity: 1; transform: translateY(-3px); } }
@keyframes boot-bar { from { transform: translateX(-110%); } to { transform: translateX(250%); } }

.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.28);
  border-top-color: var(--text);
  animation: spin 0.8s linear infinite;
}
.spinner--lg { width: 34px; height: 34px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* уведомления */
.toasts {
  position: absolute;
  left: 0; right: 0;
  bottom: calc(var(--dock-h) + 14px);
  z-index: var(--z-toast);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none;
  padding: 0 var(--gutter);
}
.toast {
  max-width: 100%;
  padding: 12px 18px;
  border-radius: var(--r-md);
  background: var(--glass);
  -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
  box-shadow: inset 0 0 0 1px var(--line-strong), var(--shadow);
  font-size: 14px; font-weight: 600;
  opacity: 0; transform: translateY(10px) scale(0.96);
  transition: opacity var(--t-med) var(--ease), transform var(--t-med) var(--ease-spring);
}
.toast.is-in { opacity: 1; transform: none; }
.toast--warn { color: var(--warn); }
.toast--error { color: var(--danger); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
}
