:root {
  --bg: #0a0a0a;
  --card: rgba(0, 0, 0, 0.78);
  --border: rgba(255, 255, 255, 0.22);
  --border-soft: rgba(255, 255, 255, 0.1);
  --text: #ffffff;
  --muted: rgba(255, 255, 255, 0.65);
  --dim: rgba(255, 255, 255, 0.4);
  --radius: 14px;
  --font-display: "Cinzel", serif;
  --font-body: "Manrope", system-ui, sans-serif;
  --stroke: #000000;
  --hero-bar-h: 78px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

/* фон: замок + лёгкая зернистость */
.bg-medieval {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(ellipse 90% 60% at 50% 100%, rgba(255, 255, 255, 0.04), transparent 55%),
    linear-gradient(180deg, rgba(0, 0, 0, 0.3) 0%, rgba(0, 0, 0, 0.75) 42%, rgba(0, 0, 0, 0.95) 100%),
    url("/static/img/castle-bg.svg") center bottom / min(100%, 720px) auto no-repeat,
    #0d0d0d;
}

.bg-grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.35;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.5'/%3E%3C/svg%3E");
  mix-blend-mode: overlay;
}

.app {
  position: relative;
  z-index: 1;
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px 40px;
}

#content {
  padding-top: 12px;
}

/* фиксированная шапка — всегда видна в Telegram WebView */
.hero-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  min-height: var(--hero-bar-h);
  text-align: left;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top, 0px));
  background: rgba(8, 8, 8, 0.94);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-soft);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.45);
}

.hero-bar-inner {
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
}

.hero-bar-text {
  min-width: 0;
  padding: 2px 0;
}

.hero-avatar {
  position: relative;
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  border-radius: 50%;
  overflow: hidden;
  background: #ffffff;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}

.hero-avatar-img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  object-position: center;
}

/* legacy emblem styles (large hero) */
.hero-emblem-sm {
  display: none;
}

.title-stroke-sm {
  margin: 0;
  font-size: 1.05rem;
  letter-spacing: 0.04em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hero-sub-sm {
  margin: 2px 0 0;
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  text-align: left;
}

body {
  padding-top: calc(var(--hero-bar-h) + env(safe-area-inset-top, 0px) + 8px);
}

body.channel-gate-mode {
  padding-top: 0;
}

body.channel-gate-mode #content {
  padding-top: 16px;
}

/* legacy hero (unused) */
.hero {
  text-align: center;
  padding: 6px 0 18px;
}

.hero-emblem {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 108px;
  height: 108px;
  margin-bottom: 10px;
}

.hero-emblem::before {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 50%;
}

.hero-emblem::after {
  content: "";
  position: absolute;
  inset: 5px;
  border: 1px dashed rgba(255, 255, 255, 0.12);
  border-radius: 50%;
}

.hero-logo {
  display: block;
  width: 88px;
  height: auto;
  filter: drop-shadow(0 2px 10px rgba(0, 0, 0, 0.55));
}

.title-stroke {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: #fff;
  text-shadow:
    -1px -1px 0 var(--stroke),
    1px -1px 0 var(--stroke),
    -1px 1px 0 var(--stroke),
    1px 1px 0 var(--stroke);
}

.hero-sub {
  margin: 6px 0 0;
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

.hero-ornament {
  width: 140px;
  height: 8px;
  margin: 14px auto 0;
  background: url("/static/img/ornament.svg") center / contain no-repeat;
  opacity: 0.85;
}

.title-stroke-sub {
  color: var(--muted);
}

/* разделитель между блоками */
.section-divider {
  height: 1px;
  margin: 4px 24px 12px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
}

/* карточки с уголками */
.card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 15px 16px;
  margin-bottom: 10px;
  backdrop-filter: blur(14px);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
}

.card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 16px;
  right: 16px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.35), transparent);
}

.card-corner {
  position: absolute;
  width: 10px;
  height: 10px;
  border-color: rgba(255, 255, 255, 0.3);
  border-style: solid;
  pointer-events: none;
}

.card-corner-tl { top: 6px; left: 6px; border-width: 1px 0 0 1px; }
.card-corner-tr { top: 6px; right: 6px; border-width: 1px 1px 0 0; }
.card-corner-bl { bottom: 6px; left: 6px; border-width: 0 0 1px 1px; }
.card-corner-br { bottom: 6px; right: 6px; border-width: 0 1px 1px 0; }

.card-compact {
  padding: 13px 14px;
}

.card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.card-head.no-margin {
  margin-bottom: 0;
}

.card-head h2 {
  margin: 0;
  flex: 1;
}

.card-head-line {
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.25), transparent);
}

.card h2 {
  font-family: var(--font-display);
  font-size: 0.92rem;
  font-weight: 600;
  color: #fff;
  letter-spacing: 0.05em;
  text-shadow:
    -1px -1px 0 var(--stroke),
    1px -1px 0 var(--stroke),
    -1px 1px 0 var(--stroke),
    1px 1px 0 var(--stroke);
}

.card-icon {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
}

/* статус подписки */
.status-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-soft);
  font-size: 0.88rem;
}

.status-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.status-row span:first-child {
  color: var(--muted);
  font-size: 0.82rem;
  letter-spacing: 0.02em;
}

.status-row span:last-child {
  font-weight: 600;
  text-align: right;
}

.status-badge {
  font-weight: 600;
}

.status-active,
.status-expiring_soon,
.status-expired,
.status-none {
  color: #fff;
}

/* кнопки */
.btn {
  border: none;
  border-radius: 10px;
  padding: 12px 16px;
  font-family: var(--font-body);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s ease, opacity 0.1s ease, background 0.15s ease;
}

.btn:active {
  transform: scale(0.98);
  opacity: 0.88;
}

.btn-primary {
  width: 100%;
  color: #000;
  background: #fff;
  border: 1px solid #fff;
  box-shadow: 0 2px 12px rgba(255, 255, 255, 0.12);
}

.btn-secondary {
  width: 100%;
  color: #fff;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.08);
}

.btn-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-inline {
  width: auto;
  flex-shrink: 0;
  padding: 11px 16px;
  white-space: nowrap;
}

.btn-danger {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.22);
  padding: 6px 10px;
  font-size: 0.78rem;
  width: auto;
  border-radius: 8px;
}

.pay-methods {
  margin-top: 10px;
}

.pay-methods-hint {
  margin-bottom: 8px;
}

  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.btn-row-2 {
  grid-template-columns: 1fr 1fr;
}

/* тарифы */
.period-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.period-btn {
  padding: 11px 10px;
  border-radius: 10px;
  border: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.03);
  color: #fff;
  font: inherit;
  font-size: 0.88rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.period-btn.selected {
  border-color: rgba(255, 255, 255, 0.65);
  background: rgba(255, 255, 255, 0.1);
}

.tariff-grid {
  display: grid;
  gap: 7px;
}

.tariff-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
  color: #fff;
  transition: border-color 0.15s, background 0.15s;
}

.tariff-item.selected {
  border-color: rgba(255, 255, 255, 0.65);
  background: rgba(255, 255, 255, 0.1);
}

.tariff-item strong {
  font-size: 1rem;
  letter-spacing: 0.02em;
}

/* поля ввода */
.input {
  flex: 1;
  min-width: 0;
  padding: 11px 13px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font: inherit;
  font-size: 0.9rem;
}

.input::placeholder {
  color: var(--dim);
}

.input:focus {
  outline: none;
  border-color: rgba(255, 255, 255, 0.55);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.08);
}

.promo-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
  margin-top: 10px;
}

.trial-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.trial-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  color: #fff;
  text-shadow:
    -1px -1px 0 var(--stroke),
    1px -1px 0 var(--stroke),
    -1px 1px 0 var(--stroke),
    1px 1px 0 var(--stroke);
}

.trial-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  font-size: 0.8rem;
  background: rgba(255, 255, 255, 0.05);
}

.trial-row .btn-primary {
  width: auto;
  padding: 10px 18px;
}

/* устройства */
.device-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-soft);
  font-size: 0.86rem;
}

.device-item:last-child {
  border-bottom: none;
}

.link-box {
  word-break: break-all;
  font-size: 0.76rem;
  line-height: 1.5;
  color: var(--muted);
  padding: 10px 11px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-soft);
  margin-top: 10px;
}

.loader {
  text-align: center;
  padding: 40px 16px;
  color: var(--muted);
  font-size: 0.9rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  max-width: 90%;
  padding: 11px 18px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.94);
  border: 1px solid var(--border);
  color: #fff;
  font-size: 0.84rem;
  z-index: 100;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.hidden {
  display: none !important;
}

.referral-link {
  font-size: 0.8rem;
  line-height: 1.45;
  word-break: break-all;
  color: #fff;
  padding: 11px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  margin: 8px 0;
}

.hint {
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0 0 6px;
  line-height: 1.5;
}

.hint:last-child {
  margin-bottom: 0;
}

.back-bar {
  margin-bottom: 12px;
}

.back-bar .btn-secondary {
  width: auto;
  display: inline-flex;
  padding: 9px 14px;
}

.referral-stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  margin: 4px 0;
}

.referral-stat {
  padding: 11px 6px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-soft);
  text-align: center;
}

.referral-stat span {
  display: block;
  font-size: 0.66rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 5px;
}

.referral-stat strong {
  font-size: 1.05rem;
  color: #fff;
}

.nav-actions {
  margin-top: 6px;
  padding-top: 4px;
  display: grid;
  gap: 8px;
}

.nav-actions .btn-secondary {
  letter-spacing: 0.02em;
}

.status-card-linked {
  color: #fff;
}

.status-card-unlinked {
  color: var(--muted);
  font-weight: 500;
}

.card-autopay {
  border-color: rgba(212, 175, 55, 0.28);
  background:
    linear-gradient(145deg, rgba(212, 175, 55, 0.08), transparent 55%),
    var(--card-bg, rgba(18, 16, 14, 0.92));
}

.autopay-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 2px 0 10px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #f3e6b8;
  background: rgba(212, 175, 55, 0.12);
  border: 1px solid rgba(212, 175, 55, 0.28);
}

.autopay-status-off {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.1);
}

.autopay-status-off .autopay-dot {
  background: #6b6b6b;
  box-shadow: none;
}

.btn-unlink:disabled {
  opacity: 0.55;
  cursor: default;
}

.autopay-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #d4af37;
  box-shadow: 0 0 8px rgba(212, 175, 55, 0.7);
}

.autopay-warn {
  margin: 8px 0 12px !important;
  color: #f0c27a !important;
}

.btn-unlink {
  margin-top: 12px;
  width: 100%;
  border-color: rgba(212, 175, 55, 0.35) !important;
  color: #f3e6b8 !important;
}

.btn-danger {
  background: linear-gradient(180deg, #8b3a3a, #6b2828);
  border: 1px solid rgba(220, 140, 120, 0.35);
  color: #fff;
}

.btn-danger:disabled {
  opacity: 0.55;
}

@media (max-width: 360px) {
  .referral-stat-grid {
    grid-template-columns: 1fr;
  }

  .trial-row {
    flex-wrap: wrap;
  }

  .trial-row .btn-primary {
    width: 100%;
  }
}
