/* SOMA — экран входа веб-версии и iOS (web/webauth.js). Опирается на токены и классы styles.css (.btn, .input, .field, .soma). */
.bbw {
  --bbw-hero: radial-gradient(120% 80% at 50% 38%, #FFEE8A 0%, #FFDE00 55%, #FFD000 100%);
  --bbw-hero-ink: #1C1B17;
  --bbw-hero-muted: rgba(28, 27, 23, .72);
  --bbw-sun-fill: #FFFFFF;
  --bbw-hz: #1C1B17;
  --bbw-glow: radial-gradient(closest-side, rgba(255, 255, 255, .6), rgba(255, 255, 255, .18) 50%, transparent 72%);
  --bbw-err: #A4251C;
  --bbw-err-bg: #FDECEA;
  --bbw-apple-bg: #000000;
  --bbw-apple-ink: #FFFFFF;
  --bbw-tg: #2AABEE;
  position: fixed; inset: 0; z-index: 150;
  overflow-x: hidden; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  display: flex; flex-direction: column;
  background: var(--bg); color: var(--ink); font-family: var(--font-body);
  transition: opacity .35s ease, transform .35s ease;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .bbw {
    --bbw-hero: radial-gradient(90% 70% at 50% 40%, #3A320E 0%, #211E14 55%, #141310 100%);
    --bbw-hero-ink: #FFDE00;
    --bbw-hero-muted: rgba(246, 242, 230, .72);
    --bbw-sun-fill: #FFDE00;
    --bbw-hz: #1A1812;
    --bbw-glow: radial-gradient(closest-side, rgba(255, 222, 0, .16), rgba(255, 222, 0, .05) 55%, transparent 72%);
    --bbw-err: #FFB4A9;
    --bbw-err-bg: #3A1A16;
    --bbw-apple-bg: #FFFFFF;
    --bbw-apple-ink: #000000;
  }
}
:root[data-theme="dark"] .bbw {
  --bbw-hero: radial-gradient(90% 70% at 50% 40%, #3A320E 0%, #211E14 55%, #141310 100%);
  --bbw-hero-ink: #FFDE00; --bbw-hero-muted: rgba(246, 242, 230, .72); --bbw-sun-fill: #FFDE00; --bbw-hz: #1A1812;
  --bbw-glow: radial-gradient(closest-side, rgba(255, 222, 0, .16), rgba(255, 222, 0, .05) 55%, transparent 72%);
  --bbw-err: #FFB4A9; --bbw-err-bg: #3A1A16; --bbw-apple-bg: #FFFFFF; --bbw-apple-ink: #000000;
}
.bbw.bbw-out { opacity: 0; transform: scale(1.015); pointer-events: none; }
.bbw [hidden] { display: none !important; }

/* ---------- верх с логотипом ---------- */
.bbw-hero {
  position: relative; flex: none; overflow: hidden; isolation: isolate;
  background: var(--bbw-hero); color: var(--bbw-hero-ink);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  padding: calc(env(safe-area-inset-top, 0px) + 44px) 24px 64px;
  min-height: min(38vh, 330px);
}
.bbw-glow {
  position: absolute; z-index: -1; left: 50%; top: 46%; width: 520px; height: 520px; margin: -260px 0 0 -260px; border-radius: 50%;
  background: var(--bbw-glow);
  pointer-events: none;
}
.bbw-logo { width: min(210px, 56vw); }
.bbw-hero .soma .so-s, .bbw-hero .soma .so-o, .bbw-hero .soma .so-m, .bbw-hero .soma .so-a { stroke: var(--bbw-hero-ink); }
.bbw-hero .soma .so-sun { fill: var(--bbw-sun-fill); }
.bbw-hero .soma .so-hz { stroke: var(--bbw-hz); }
.bbw-tag { margin: 0; font-size: 12px; font-weight: 800; letter-spacing: .3em; text-transform: uppercase; color: var(--bbw-hero-muted); }
.bbw-points { display: none; }

/* ---------- форма ---------- */
.bbw-panel {
  position: relative; z-index: 1; flex: 1 0 auto;
  margin-top: -30px; border-radius: 32px 32px 0 0; background: var(--bg);
  padding: 30px 20px calc(env(safe-area-inset-bottom, 0px) + 28px);
  display: flex; flex-direction: column; align-items: center; gap: 18px;
}
.bbw-card { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 14px; }
.bbw-title { margin: 0; font-family: var(--font-display); font-weight: 600; font-size: 32px; line-height: 1.05; letter-spacing: .01em; text-transform: uppercase; }
.bbw-sub { margin: -6px 0 4px; color: var(--muted); font-size: 15px; }
.bbw-step { display: flex; flex-direction: column; gap: 14px; }
.bbw-form { display: flex; flex-direction: column; gap: 12px; }
.bbw-form .input { min-height: 54px; font-size: 17px; border-radius: 16px; }
.bbw-hint { margin: -2px 0 0; font-size: 13px; color: var(--muted); text-align: center; }
.bbw-hint a { color: inherit; font-weight: 800; }

.bbw-err {
  background: var(--bbw-err-bg); color: var(--bbw-err); border-radius: 16px; padding: 12px 14px;
  font-size: 14px; font-weight: 600; line-height: 1.4;
}

.bbw-or { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; font-weight: 700; margin: 2px 0; }
.bbw-or::before, .bbw-or::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* Apple (только iOS-приложение) */
.bbw-apple {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 54px;
  border: 0; border-radius: 16px; background: var(--bbw-apple-bg); color: var(--bbw-apple-ink);
  font-size: 17px; font-weight: 700; letter-spacing: -.01em; transition: transform .12s ease, opacity .12s;
}
.bbw-apple svg { width: 20px; height: 20px; margin-top: -2px; }
.bbw-apple:active { transform: scale(.98); }
.bbw-apple[disabled] { opacity: .5; }

/* Telegram */
.bbw-tg { border: 1.5px solid var(--line); background: var(--surface); border-radius: 20px; padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 12px; }
.bbw-tg-head { display: flex; align-items: center; gap: 12px; }
.bbw-tg-head > svg { flex: none; width: 36px; height: 36px; padding: 8px 9px 8px 7px; border-radius: 50%; background: var(--bbw-tg); color: #fff; }
.bbw-tg-head b { display: block; font-size: 15px; font-weight: 800; }
.bbw-tg-head span { display: block; font-size: 13px; color: var(--muted); line-height: 1.35; }
.bbw-tg-slot { min-height: 42px; display: flex; align-items: center; justify-content: center; }
.bbw-tg-slot iframe { max-width: 100%; }
.bbw-tg-wait { width: 100%; min-height: 42px; border-radius: 14px; background: var(--surface-2); color: var(--muted); font-size: 13px; font-weight: 600; display: flex; align-items: center; justify-content: center; padding: 8px 12px; text-align: center; }
.bbw-tg-wait:not(.is-error) { animation: bbwPulse 1.4s ease-in-out infinite; }

/* Шаг «код» */
.bbw-back { align-self: flex-start; display: inline-flex; align-items: center; gap: 4px; border: 0; background: none; padding: 6px 8px 6px 0; color: var(--muted); font-weight: 700; font-size: 14px; min-height: 40px; }
.bbw-back svg { width: 18px; height: 18px; }
.bbw-sent { margin: 0; font-size: 15px; }
.bbw-sent b { font-weight: 800; word-break: break-all; }
.bbw-code { border: 0; margin: 4px 0 14px; padding: 0; min-width: 0; display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; }
.bbw-digit {
  width: 100%; min-width: 0; height: 62px; border: 1.5px solid var(--line); border-radius: 16px; background: var(--surface);
  text-align: center; font-family: var(--font-display); font-weight: 600; font-size: 28px; line-height: 1; padding: 0;
  caret-color: var(--ink); transition: border-color .15s, box-shadow .15s, background .15s;
}
.bbw-digit:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 4px var(--sun-soft); }
.bbw-digit.is-filled { border-color: var(--ink); background: var(--card-soft); }
.bbw-code.is-wrong .bbw-digit { border-color: var(--bbw-err); }
.bbw-code.is-wrong { animation: bbwShake .36s ease; }
.bbw-link { align-self: center; border: 0; background: none; color: var(--ink); font-weight: 800; font-size: 14px; padding: 8px; min-height: 40px; text-decoration: underline; text-underline-offset: 3px; }
.bbw-link[disabled] { color: var(--muted); text-decoration: none; cursor: default; font-weight: 600; }
.bbw-dev { margin: 0; text-align: center; font-size: 13px; font-weight: 700; color: var(--warn); background: var(--warn-soft); border-radius: 12px; padding: 8px 12px; }

.bbw-legal { margin: 0; max-width: 420px; text-align: center; font-size: 12px; line-height: 1.5; color: var(--muted); }
.bbw-legal a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }

/* загрузка кнопки */
.bbw .btn.is-loading { color: transparent !important; position: relative; }
.bbw .btn.is-loading::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 22px; height: 22px; margin: -11px 0 0 -11px; border-radius: 50%;
  border: 2.5px solid rgba(28, 27, 23, .25); border-top-color: #1C1B17; animation: bbwSpin .7s linear infinite;
}
.bbw.is-busy .bbw-tg-slot { opacity: .5; pointer-events: none; }

/* начальная загрузка и нет сети */
.bbw-loading, .bbw-offline { flex: 1 0 auto; grid-row: 1 / -1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 24px; text-align: center; }
.bbw-loading .soma { width: 140px; opacity: .35; animation: bbwPulse 1.4s ease-in-out infinite; }
.bbw-loading .soma .so-s, .bbw-loading .soma .so-o, .bbw-loading .soma .so-m, .bbw-loading .soma .so-a, .bbw-loading .soma .so-hz,
.bbw-offline .soma .so-s, .bbw-offline .soma .so-o, .bbw-offline .soma .so-m, .bbw-offline .soma .so-a, .bbw-offline .soma .so-hz { stroke: var(--ink); }
.bbw-loading .soma .so-sun, .bbw-offline .soma .so-sun { fill: var(--sun); }
.bbw-offline .bbw-logo { width: 150px; }
.bbw-offline p { margin: 0; max-width: 320px; color: var(--muted); font-weight: 600; }

@keyframes bbwSpin { to { transform: rotate(360deg); } }
@keyframes bbwPulse { 50% { opacity: .55; } }
@keyframes bbwShake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

/* ---------- маленькие телефоны ---------- */
@media (max-width: 374px) {
  .bbw-panel { padding-left: 16px; padding-right: 16px; }
  .bbw-code { gap: 6px; }
  .bbw-digit { height: 54px; font-size: 24px; border-radius: 14px; }
  .bbw-title { font-size: 28px; }
}
@media (max-height: 700px) and (max-width: 899px) {
  .bbw-hero { min-height: 0; padding-top: calc(env(safe-area-inset-top, 0px) + 28px); padding-bottom: 52px; }
  .bbw-logo { width: min(170px, 48vw); }
}

/* ---------- планшеты ---------- */
@media (min-width: 600px) and (max-width: 899px) {
  .bbw-panel { padding-top: 36px; }
  .bbw-card { background: var(--surface); border-radius: 30px; padding: 30px 28px; box-shadow: var(--shadow); max-width: 460px; }
}

/* ---------- компьютер: две колонки ---------- */
@media (min-width: 900px) {
  .bbw { display: grid; grid-template-rows: minmax(100%, auto); grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); }
  .bbw-hero { min-height: 100%; align-items: flex-start; justify-content: center; gap: 22px; padding: 64px clamp(48px, 7vw, 120px); }
  .bbw-glow { left: 38%; top: 42%; width: 760px; height: 760px; margin: -380px 0 0 -380px; }
  .bbw-logo { width: clamp(260px, 26vw, 380px); }
  .bbw-tag { font-size: 14px; margin-left: 2px; }
  .bbw-points { display: flex; flex-direction: column; gap: 12px; list-style: none; margin: 26px 0 0; padding: 0; max-width: 420px; }
  .bbw-points li { display: flex; align-items: baseline; gap: 14px; font-size: 17px; font-weight: 700; line-height: 1.35; color: var(--bbw-hero-ink); }
  .bbw-points i { flex: none; font-style: normal; font-family: var(--font-display); font-weight: 600; font-size: 14px; letter-spacing: .08em; color: var(--bbw-hero-muted); }
  .bbw-panel { margin: 0; border-radius: 0; justify-content: center; padding: 48px clamp(32px, 5vw, 80px); min-height: 100%; }
  .bbw-card { background: var(--surface); border-radius: 34px; padding: 40px 40px 36px; box-shadow: var(--shadow); max-width: 440px; }
  .bbw-title { font-size: 38px; }
}
@media (max-width: 899px) and (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .bbw-panel { box-shadow: 0 -1px 0 var(--line); }
}
:root[data-theme="dark"] .bbw-panel { box-shadow: 0 -1px 0 var(--line); }
@media (min-width: 900px) { :root[data-theme="dark"] .bbw-panel { box-shadow: none; } }
@media (min-width: 900px) and (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .bbw-points li { color: var(--ink); }
}

@media (prefers-reduced-motion: reduce) {
  .bbw, .bbw * { animation: none !important; transition: none !important; }
}
