:root {
  color-scheme: dark;

  /* Тема зафиксирована на тёмную намеренно — не берём цвета из
     var(--tg-theme-*), чтобы оформление не менялось у пользователей
     со светской темой в Telegram. */
  --bg: #0b0c0b;
  --surface: #1a1c1a;
  --surface-2: #232622;
  --text: #f3f5f1;
  --text-dim: #8b928c;
  --accent: #52AA52;
  --accent-ink: #0b0c0b;
  --danger: #ff6b6b;
  --track: rgba(255, 255, 255, 0.1);

  --r-lg: 24px;
  --r-md: 16px;
  --r-sm: 12px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding: 14px 14px 96px;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.screen {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.page {
  /* Каждая страница — свой flex-контейнер с тем же вертикальным ритмом,
     что раньше был у #screen-main целиком (когда всё шло одним списком) */
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: opacity 0.18s ease, transform 0.18s ease;
  transform: translateX(0);
}

.page.page-shift {
  opacity: 0;
  transform: translateX(calc(var(--slide-mult, 1) * 18px));
}

#loading {
  align-items: center;
  justify-content: center;
  height: 60vh;
  color: var(--text-dim);
  font-size: 15px;
  text-align: center;
  padding: 0 24px;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 2px 6px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}

.brand-mark {
  color: var(--text);
  flex-shrink: 0;
}

.discount-chip {
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 800;
  padding: 5px 10px;
  border-radius: 999px;
}

/* ---------- generic card ---------- */

.card {
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: 16px;
}

.card-title {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

/* ---------- hero: balance + subscription ring ---------- */

.hero-grid {
  display: grid;
  grid-template-columns: 1fr 1.15fr;
  gap: 10px;
  align-items: stretch;
}

.hero-side {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mini-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px;
}

.mini-label {
  font-size: 12px;
  color: var(--text-dim);
}

.mini-value {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.mini-btn {
  margin-top: auto;
  align-self: flex-start;
  background: none;
  border: none;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  padding: 0;
  cursor: pointer;
}

.mini-btn.ghost {
  color: var(--text-dim);
}

.sub-card {
  background: var(--accent);
  color: var(--accent-ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 18px 14px 16px;
}

.ring-wrap {
  position: relative;
  width: 112px;
  height: 112px;
  margin-bottom: 8px;
}

.ring-svg {
  width: 100%;
  height: 100%;
  transform: rotate(0deg);
}

.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.ring-number {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.ring-label {
  font-size: 11px;
  font-weight: 600;
  opacity: 0.65;
  margin-top: 2px;
}

.sub-plan-name {
  font-size: 14px;
  font-weight: 700;
}

.sub-plan-date {
  font-size: 12px;
  opacity: 0.65;
  margin-top: 2px;
  margin-bottom: 12px;
}

.btn-manage {
  width: 100%;
  border: none;
  border-radius: 999px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 700;
  background: var(--accent-ink);
  color: var(--accent);
  cursor: pointer;
}

.btn-manage:active {
  opacity: 0.85;
}

/* ---------- auto-renew strip ---------- */

.autorenew-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
}

.autorenew-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
}

.autorenew-dot.on {
  background: var(--accent);
}

.autorenew-dot.off {
  background: var(--text-dim);
}

.autorenew-text {
  flex: 1;
  min-width: 0;
}

.autorenew-title {
  font-size: 14px;
  font-weight: 700;
}

.autorenew-sub {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 1px;
}

.autorenew-toggle-btn {
  border: none;
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 12px;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
}

.autorenew-toggle-btn.is-on {
  background: var(--accent);
  color: var(--accent-ink);
}

/* ---------- subscription url ---------- */

.sub-url {
  word-break: break-all;
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--accent);
  margin-bottom: 10px;
}

/* ---------- app selector (шаг выбора приложения) ---------- */

.connect-app-select {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.app-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  border-radius: var(--r-sm);
  border: 1px solid var(--surface-2);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}

.app-option.active {
  border-color: var(--accent);
  background: rgba(163, 232, 63, 0.14);
}

.app-option-badge {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent-ink);
  background: var(--accent);
  padding: 3px 8px;
  border-radius: 999px;
}

/* ---------- connect steps (установка / добавление подписки / подключение) ---------- */

.connect-steps {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.connect-step {
  display: flex;
  gap: 12px;
}

.connect-step-icon {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}

.connect-step-body {
  flex: 1;
  min-width: 0;
}

.connect-step-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 4px;
}

.connect-step-desc {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.4;
  margin-bottom: 10px;
}

.connect-step-btn {
  width: auto;
  padding: 9px 16px;
  font-size: 13px;
}

#connect-other-device-btn {
  margin: 10px 0;
}

#connect-platform-chips {
  margin-bottom: 10px;
}

#connect-no-sub {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.4;
}

/* ---------- sections ---------- */

.section-title {
  font-size: 13px;
  font-weight: 700;
  margin-top: 6px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.plan-card {
  background: var(--surface);
  border-radius: var(--r-md);
  padding: 14px 16px;
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  cursor: pointer;
}

.plan-title {
  font-size: 16px;
  font-weight: 700;
}

.plan-price {
  font-size: 13px;
  color: var(--text-dim);
}

.plan-price .old {
  text-decoration: line-through;
  opacity: 0.6;
  margin-right: 6px;
}

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

.btn {
  border: none;
  border-radius: var(--r-sm);
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 700;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  flex: 1;
}

.btn:active {
  opacity: 0.85;
}

.btn-standalone {
  /* Для одиночной кнопки/ссылки вне .row — без flex:1 от .btn (иначе внутри
     вертикального flex-контейнера, напр. #loading, она растягивается на
     всю высоту родителя вместо нормального размера по контенту). */
  flex: none;
  align-self: center;
  display: inline-block;
  text-decoration: none;
  text-align: center;
}

.btn.secondary {
  background: var(--surface-2);
  color: var(--text);
}

.btn:disabled {
  opacity: 0.4;
  cursor: default;
}

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

.chip {
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--surface);
  font-size: 14px;
  cursor: pointer;
  border: none;
  color: var(--text);
}

.chip.active {
  background: var(--accent);
  color: var(--accent-ink);
}

.row {
  display: flex;
  gap: 8px;
}

input {
  flex: 1;
  border-radius: var(--r-sm);
  border: 1px solid var(--surface-2);
  background: var(--surface);
  color: var(--text);
  padding: 10px 12px;
  font-size: 14px;
}

input:focus {
  outline: none;
  border-color: var(--accent);
}

#devices-text {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.4;
}

/* ---------- about card ---------- */

.about-name {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 6px;
}

.about-desc {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.4;
  margin-bottom: 8px;
}

.about-support {
  font-size: 13px;
  color: var(--accent);
  font-weight: 600;
}

/* ---------- legal links (account page) ---------- */

.legal-card {
  display: flex;
  flex-direction: column;
}

.legal-link {
  display: block;
  padding: 10px 0;
  font-size: 14px;
  color: var(--text);
  text-decoration: none;
}

.legal-link:active {
  color: var(--accent);
}

.legal-link + .legal-link {
  border-top: 1px solid rgba(255, 255, 255, 0.07);
}

/* ---------- account page ---------- */

.account-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 14px;
}

.account-row + .account-row {
  border-top: 1px solid rgba(255, 255, 255, 0.07);
}

.account-row-label {
  color: var(--text-dim);
}

.account-row-value {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  word-break: break-all;
  text-align: right;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%);
  background: var(--surface-2);
  color: var(--text);
  padding: 10px 16px;
  border-radius: var(--r-sm);
  font-size: 13px;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  z-index: 100;
}

/* ---------- модалка подтверждения оплаты (товар-цена-кнопка «Оплатить») ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
}

.modal-card {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border-radius: var(--r-md) var(--r-md) 0 0;
  padding: 20px 18px max(20px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.modal-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 10px;
}

.modal-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 8px 0;
  border-bottom: 1px solid var(--track);
  font-size: 14px;
}

.modal-row:last-of-type {
  border-bottom: none;
}

.modal-row-label {
  color: var(--text-dim);
}

.modal-row-value {
  font-weight: 700;
  text-align: right;
}

.modal-row-value .old {
  text-decoration: line-through;
  opacity: 0.6;
  margin-right: 6px;
  font-weight: 400;
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

/* ---------- ось выбора количества доп. устройств (модалка тарифа) ---------- */

.device-selector {
  padding: 10px 0 4px;
}

.device-selector-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 22px;
}

.device-selector-label span:last-child {
  color: var(--text);
  font-weight: 700;
}

.device-track {
  position: relative;
  height: 24px;
  margin: 0 12px;
}

.device-track-line {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--track);
  border-radius: 2px;
  transform: translateY(-50%);
}

.device-track-fill {
  position: absolute;
  top: 50%;
  left: 0;
  height: 2px;
  background: var(--accent);
  border-radius: 2px;
  transform: translateY(-50%);
  transition: width 0.18s ease;
}

.device-dot {
  position: absolute;
  top: 50%;
  width: 24px;
  height: 24px;
  margin-left: -12px;
  margin-top: -12px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 2px solid var(--track);
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.device-dot:active {
  transform: scale(0.94);
}

.device-dot.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  transform: scale(1.1);
}

/* ---------- bottom nav ---------- */

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(20, 22, 19, 0.82);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  padding: 6px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  z-index: 50;
  isolation: isolate; /* .nav-indicator позиционируется абсолютно внутри этого блока */
}

/* ---------- скользящий индикатор активного пункта ---------- */

.nav-indicator {
  position: absolute;
  top: 6px;
  left: 0;
  width: 46px;
  height: 46px;
  border-radius: 999px;
  background: var(--accent);
  pointer-events: none;
  z-index: 0;
  will-change: transform;
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.nav-indicator.no-anim {
  transition: none;
}

.nav-item {
  position: relative;
  z-index: 1;
  width: 46px;
  height: 46px;
  flex-shrink: 0;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.nav-item svg {
  width: 20px;
  height: 20px;
  transition: transform 0.24s cubic-bezier(0.22, 1, 0.36, 1);
}

.nav-item.active {
  color: var(--accent-ink);
}

.nav-item.active svg {
  transform: scale(1.05);
}

.nav-item:active svg {
  transform: scale(0.88);
}

@media (prefers-reduced-motion: reduce) {
  .nav-indicator,
  .nav-item,
  .nav-item svg {
    transition: none !important;
  }
}

/* ---------- small screens ---------- */

@media (max-width: 340px) {
  .ring-wrap {
    width: 96px;
    height: 96px;
  }
  .ring-number {
    font-size: 26px;
  }
}

/* ---------- desktop / wide viewports ---------- */
/* На узких экранах (телефон, Telegram WebView) вёрстка не меняется.
   На широких — контент собирается в «карточку» шириной с телефон,
   отцентрированную на странице, плюс добавляются hover-состояния для мыши. */

@media (min-width: 720px) {
  html,
  body {
    min-height: 100%;
  }

  body {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 56px 24px;
    background:
      radial-gradient(900px 480px at 50% -8%, rgba(163, 232, 63, 0.07), transparent 62%),
      var(--bg);
  }

  #app {
    width: 100%;
    max-width: 460px;
  }

  #screen-main {
    background: var(--surface);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 32px;
    padding: 22px 22px 112px;
    box-shadow: 0 40px 100px rgba(0, 0, 0, 0.55), 0 1px 0 rgba(255, 255, 255, 0.03) inset;
  }

  #loading {
    min-height: 70vh;
  }

  .toast {
    left: 50%;
  }

  .ring-wrap {
    width: 120px;
    height: 120px;
  }

  .ring-number {
    font-size: 32px;
  }
}

/* ---------- hover-состояния для устройств с мышью ---------- */

@media (hover: hover) and (pointer: fine) {
  .mini-btn:hover {
    opacity: 0.8;
  }

  .btn:not(:disabled):hover {
    filter: brightness(1.08);
  }

  .btn.secondary:hover {
    background: #2a2e27;
  }

  .btn-manage:hover {
    filter: brightness(1.1);
  }

  .chip:hover {
    background: var(--surface-2);
  }

  .chip.active:hover {
    filter: brightness(1.08);
  }

  .autorenew-toggle-btn:hover {
    filter: brightness(1.1);
  }

  .nav-item:not(.active):hover {
    color: var(--text);
  }

  .nav-item:hover svg {
    transform: scale(1.06);
  }

  .plan-card {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
  }

  .plan-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.35);
  }

  input:hover {
    border-color: rgba(255, 255, 255, 0.2);
  }
}
