:root {
  --bg: #08080a;
  --bg-soft: #131316;
  --card: #16161a;
  --border: #2b2b31;
  --text: #f4f4f6;
  --muted: #9a9aa6;
  --accent: #e11d2e;
  --accent-2: #ff4d5a;
  --danger: #ff4d5a;
  --radius: 14px;

  /* Динамические размеры: считаются от высоты экрана */
  --pad: 16px;
  --gap: 14px;
  --logo-size: 44px;
  --title-size: 22px;
  --body-size: 14.5px;
  --key-size: 12.5px;
  --btn-size: 15px;
  --card-pad: 16px;
}

/* =========================================================================
   Базовые стили
   ========================================================================= */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100%;
  /* clip вместо hidden: не создаёт вложенный scroll-контейнер,
     который ломает прокрутку в WebView Telegram */
  overflow-x: clip;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;

  /* Прокрутка: явно разрешаем и включаем инерцию */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: auto;

  /* Безопасные зоны (вырез камеры, скругления, складки) */
  padding:
    env(safe-area-inset-top, 0px)
    env(safe-area-inset-right, 0px)
    env(safe-area-inset-bottom, 0px)
    env(safe-area-inset-left, 0px);
}

.backdrop {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 15% 0%, rgba(225, 29, 46, 0.22), transparent 45%),
    radial-gradient(circle at 85% 15%, rgba(255, 77, 90, 0.10), transparent 45%);
  pointer-events: none;
  z-index: 0;
}

/* =========================================================================
   Контейнер: центрируется и занимает удобную ширину
   ========================================================================= */

.app {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: var(--max-app-width, 480px);
  margin: 0 auto;
  padding: var(--pad) var(--pad) calc(var(--pad) + 12px);
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  min-height: 100%;
}

/* =========================================================================
   Шапка
   ========================================================================= */

.header { text-align: center; padding: 4px 0 2px; }

.logo {
  font-size: var(--logo-size);
  line-height: 1;
  filter: drop-shadow(0 6px 18px rgba(59, 130, 246, 0.45));
}

.header h1 {
  margin: 10px 0 4px;
  font-size: var(--title-size);
  letter-spacing: 0.2px;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: var(--body-size);
}

/* =========================================================================
   Карточки
   ========================================================================= */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--card-pad);
  min-width: 0;
  overflow: hidden;
  animation: rise 0.25s ease both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.card-label {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

/* ---------- Ключ ---------- */

.key {
  display: block;
  max-width: 100%;
  padding: 12px;
  border-radius: 10px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--accent-2);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: var(--key-size);
  line-height: 1.5;
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: normal;
  margin-bottom: 12px;
}

/* ---------- Строки подписки ---------- */

.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  font-size: var(--body-size);
}

.row:last-child { border-bottom: none; }
.row span { color: var(--muted); flex-shrink: 0; }
.row b { text-align: right; overflow-wrap: anywhere; }

.muted {
  color: var(--muted);
  font-size: var(--body-size);
  line-height: 1.55;
  margin: 0;
}

/* =========================================================================
   Кнопки
   ========================================================================= */

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 46px;
  padding: 13px 16px;
  border: none;
  border-radius: 11px;
  font-size: var(--btn-size);
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.12s ease, opacity 0.12s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.btn:active { transform: scale(0.975); }

.btn-primary {
  background: linear-gradient(180deg, #e11d2e, #a10d1a);
  color: #fff;
  box-shadow: 0 6px 18px rgba(225, 29, 46, 0.22);
}

.btn-secondary {
  background: var(--bg-soft);
  color: var(--text);
  border: 1px solid var(--border);
  margin-top: 12px;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  font-weight: 500;
}

.btn.copied {
  background: linear-gradient(180deg, #f4f4f6, #d4d4d8);
  color: #08080a;
}

/* =========================================================================
   Загрузка и ошибка
   ========================================================================= */

.spinner {
  width: 26px;
  height: 26px;
  margin: 4px auto 12px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

#loading { text-align: center; color: var(--muted); }

.error-card {
  border-color: rgba(239, 68, 68, 0.45);
  background: rgba(239, 68, 68, 0.08);
}

.error-text {
  margin: 0;
  color: #fca5a5;
  font-size: var(--body-size);
  line-height: 1.5;
}

.footer { margin-top: 4px; }

/* =========================================================================
   Уведомление
   ========================================================================= */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(34px + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 20px);
  background: #1f2b3d;
  color: #fff;
  padding: 11px 18px;
  border-radius: 10px;
  font-size: 14px;
  border: 1px solid var(--border);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
  z-index: 10;
  max-width: min(88vw, 420px);
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.hidden { display: none !important; }

/* =========================================================================
   АДАПТИВНОСТЬ
   ========================================================================= */

/* ---------- Очень маленькие экраны (iPhone SE, старые Android) ---------- */
@media (max-width: 360px) {
  :root {
    --pad: 12px;
    --gap: 10px;
    --logo-size: 36px;
    --title-size: 19px;
    --body-size: 13.5px;
    --key-size: 11.5px;
    --btn-size: 14px;
    --card-pad: 12px;
    --radius: 12px;
  }
}

/* ---------- Большие телефоны ---------- */
@media (min-width: 400px) and (max-width: 599px) {
  :root { --max-app-width: 480px; }
}

/* ---------- Планшеты (портрет): 600–1023px ---------- */
@media (min-width: 600px) and (max-width: 1023px) {
  :root {
    --max-app-width: 560px;
    --pad: 24px;
    --gap: 18px;
    --logo-size: 56px;
    --title-size: 26px;
    --body-size: 16px;
    --key-size: 14px;
    --btn-size: 17px;
    --card-pad: 22px;
    --radius: 18px;
  }

  .btn { min-height: 54px; }
}

/* ---------- Десктоп и планшеты в ландшафте ---------- */
@media (min-width: 1024px) {
  :root {
    --max-app-width: 620px;
    --pad: 32px;
    --gap: 20px;
    --logo-size: 60px;
    --title-size: 28px;
    --body-size: 16px;
    --key-size: 14.5px;
    --btn-size: 17px;
    --card-pad: 26px;
    --radius: 20px;
  }

  .app {
    padding-top: 40px;
    padding-bottom: 48px;
  }

  .btn { min-height: 56px; }
}

/* ---------- Очень широкие мониторы ---------- */
@media (min-width: 1600px) {
  :root { --max-app-width: 680px; }
}

/* =========================================================================
   Низкие экраны (ландшафт телефона, складные в разложенном виде)
   ========================================================================= */

@media (max-height: 520px) and (orientation: landscape) {
  :root {
    --pad: 10px;
    --gap: 8px;
    --logo-size: 28px;
    --title-size: 17px;
    --body-size: 13px;
    --key-size: 11px;
    --btn-size: 13.5px;
    --card-pad: 11px;
    --max-app-width: 760px;
  }

  .header h1 { margin: 6px 0 2px; }
  .app { padding-top: 10px; gap: 8px; }
  .btn { min-height: 40px; padding: 10px 14px; }
  .logo { filter: none; }
}

/* =========================================================================
   Складные смартфоны
   ========================================================================= */

/* ---------- Samsung Fold: внешний экран (узкий, ~344–420px) ---------- */
@media (min-width: 330px) and (max-width: 430px) and (min-height: 700px) {
  :root { --max-app-width: 100%; }
}

/* ---------- Samsung Fold 8: разложенный экран (~673–760px в ширину) ---------- */
@media (min-width: 650px) and (max-width: 800px) and (min-height: 600px) {
  :root {
    --max-app-width: 600px;
    --pad: 22px;
    --logo-size: 50px;
    --title-size: 24px;
    --body-size: 15.5px;
    --btn-size: 16px;
  }
}

/* ---------- iPhone "Duo"/fold-подобные в разложенном виде ----------
   Ширина примерно 1024–1200px при высоте 700–900px */
@media (min-width: 1000px) and (max-width: 1250px) and (max-height: 950px) {
  :root {
    --max-app-width: 580px;
    --pad: 26px;
    --logo-size: 54px;
    --title-size: 26px;
  }
}

/* ---------- Одинаковые колонки для широких раскладок ---------- */
@media (min-width: 900px) and (min-height: 700px) {
  /* Две колонки для карточек на просторных экранах */
  .app {
    display: grid;
    grid-template-columns: 1fr;
    align-content: start;
  }
}

/* =========================================================================
   Печать и предпочтения пользователя
   ========================================================================= */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (prefers-color-scheme: light) {
  /* Оставляем тёмную тему — фирменный стиль, но гасим свечение */
  .backdrop { opacity: 0.7; }
}


/* ============================================================
   Статус подписки
   ============================================================ */

.status-big {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 0.5px;
  margin: 6px 0 2px;
}

.status-ok    { color: #ffffff; }
.status-warn  { color: #ff4d5a; }
.status-off   { color: #9a9aa6; }

.status-sub {
  font-size: 14px;
  color: var(--muted, #94a3b8);
  margin-bottom: 14px;
}

#actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 6px 0 14px;
}

/* ============================================================
   Устройства
   ============================================================ */

#devices-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.device {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.07);
}

.device-info {
  min-width: 0;
}

.device-name {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.device-meta {
  font-size: 12px;
  color: var(--muted, #94a3b8);
  margin-top: 2px;
}

.device-del {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  border: 1px solid rgba(239, 68, 68, 0.35);
  background: rgba(239, 68, 68, 0.12);
  color: #f87171;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.device-del:active {
  transform: scale(0.94);
  background: rgba(239, 68, 68, 0.22);
}

/* ============================================================
   Инструкция
   ============================================================ */

.guide {
  margin: 8px 0 0;
  padding-left: 20px;
  font-size: 14px;
  line-height: 1.65;
  color: #cbd5e1;
}

.guide li { margin-bottom: 8px; }

.guide a {
  color: #60a5fa;
  text-decoration: none;
  border-bottom: 1px dotted rgba(96, 165, 250, 0.45);
}

/* ============================================================
   Кнопка в процессе
   ============================================================ */

.btn.busy {
  opacity: 0.6;
  cursor: progress;
}

.btn:disabled {
  cursor: default;
}



/* ============================================================
   Палитра: чёрный, красный, белый
   ============================================================ */

#status-card {
  border-color: rgba(225, 29, 46, 0.22);
}

/* ---------- Статус: строка с индикатором ---------- */

.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 4px 0 2px;
}

.status-pill {
  flex-shrink: 0;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid var(--border);
  color: var(--muted);
  background: rgba(255, 255, 255, 0.03);
}

.pill-ok {
  color: #ffffff;
  border-color: rgba(225, 29, 46, 0.45);
  background: rgba(225, 29, 46, 0.12);
}

.pill-warn {
  color: #ff8a92;
  border-color: rgba(255, 77, 90, 0.5);
  background: rgba(255, 77, 90, 0.14);
}

.pill-off { color: var(--muted); }

/* ---------- Полоса остатка подписки ---------- */

.progress { margin: 10px 0 12px; }

.progress-bar {
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, #e11d2e, #ff6b76);
  transition: width 0.45s ease;
}

.fill-warn {
  background: linear-gradient(90deg, #ff4d5a, #ff9aa2);
}

/* ---------- Ссылка-подписка ---------- */

.sub-hint {
  margin: 0 0 14px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
}

.sub-hint b { color: #ffffff; }

.link-box {
  padding: 12px;
  border-radius: 12px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  margin-bottom: 14px;
}

.link-host {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 5px;
  overflow-wrap: anywhere;
}

.link-token {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13.5px;
  color: #ffffff;
  overflow-wrap: anywhere;
  word-break: break-all;
}

/* ---------- Список серверов в подписке ---------- */

.servers-preview {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.servers-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 10px;
}

.server-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(255, 255, 255, 0.04);
  margin-bottom: 6px;
}

.server-row:last-child { margin-bottom: 0; }

.server-name {
  font-size: 14px;
  font-weight: 500;
  color: #ffffff;
}

.server-proto {
  flex-shrink: 0;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 10.5px;
  letter-spacing: 0.05em;
  white-space: nowrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.proto-reality {
  background: rgba(225, 29, 46, 0.18);
  color: #ff6b76;
}

.proto-xhttp {
  background: rgba(255, 255, 255, 0.09);
  color: #e4e4e7;
}

.proto-hy2 {
  background: rgba(225, 29, 46, 0.09);
  color: #ff9aa2;
}

/* ---------- Иконки в кнопках ---------- */

.ico {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.logo svg {
  display: block;
  width: 1em;
  height: 1em;
  margin: 0 auto;
}

.btn .ico { opacity: 0.95; }

/* ---------- Меньше пустоты внизу ---------- */

.footer {
  padding-top: 6px;
}

/* ---------- Выбор тарифа ---------- */

.field-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin: 14px 0 8px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  flex: 1 1 auto;
  min-width: 58px;
  padding: 11px 10px;
  border-radius: 10px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.chip:active { transform: scale(0.97); }

.chip-active {
  background: rgba(225, 29, 46, 0.14);
  border-color: rgba(225, 29, 46, 0.55);
  color: #ffffff;
}

.price-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 18px 0 14px;
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
}

.price-caption {
  font-size: 13px;
  color: var(--muted);
}

.price-value {
  font-size: 24px;
  font-weight: 800;
  color: #ffffff;
  letter-spacing: -0.02em;
}

.tariff-note {
  margin-top: 12px;
  font-size: 12px;
  text-align: center;
}

/* ---------- Пошаговый выбор числа устройств ---------- */

.stepper {
  display: flex;
  align-items: center;
  gap: 10px;
}

.step-btn {
  width: 52px;
  height: 52px;
  flex-shrink: 0;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: #ffffff;
  font-size: 24px;
  font-weight: 500;
  line-height: 1;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s ease, opacity 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.step-btn:active { transform: scale(0.96); }

.step-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.step-value {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 6px;
  border-radius: 12px;
  background: rgba(225, 29, 46, 0.10);
  border: 1px solid rgba(225, 29, 46, 0.35);
}

.step-value b {
  font-size: 22px;
  font-weight: 800;
  color: #ffffff;
  line-height: 1.1;
}

.step-value span {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.02em;
}
