/*
 * Global styles shared across every page: design tokens, reset, background,
 * header, footer, buttons and layout helpers.
 *
 * Page-specific styles live in their own files (e.g. home.css) and are linked
 * per page via `content_for :stylesheets`. Keep this file free of one-off,
 * page-only rules so it stays a small shared foundation.
 */

:root {
  --bg: #05060f;
  --bg-soft: #0b0d1f;
  --panel: rgba(255, 255, 255, 0.04);
  --panel-border: rgba(255, 255, 255, 0.09);
  --text: #eef0ff;
  --muted: #9aa0c3;
  --accent: #7c6cff;
  --accent-2: #33e6b8;
  --accent-glow: rgba(124, 108, 255, 0.55);
  /* Цвета облаков туманности (см. html::before), собранные в одну заливку. */
  --nebula-gradient: linear-gradient(100deg, #33e6b8, #7c6cff 52%, #c456ff);
  --danger: #ff6b6b;
  --max: 1120px;
}

* {
  box-sizing: border-box;
}

/* Базовый цвет держит <html>, а не <body>: тогда фон страницы не пропагируется
   на канву и не закрывает слои звёзд, которые лежат ниже контента (z-index < 0). */
html {
  scroll-behavior: smooth;
  background: var(--bg);
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: transparent;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/*
 * Космический фон — три фиксированных слоя за контентом:
 *   html::before  — туманность (цветные облака, медленно «дышат»);
 *   body::before  — мелкая звёздная пыль;
 *   body::after   — крупные яркие звёзды, мерцают.
 *
 * Звёздные слои — повторяющиеся плитки (background-size), поэтому сдвиг ровно
 * на высоту плитки замыкается бесшовно. Двигаем transform'ом (композитится на
 * GPU), а не background-position; запас по вертикали (inset) закрывает края.
 * Фиксированные слои не участвуют в overflow страницы — прокрутку не создают.
 */
html::before {
  content: "";
  position: fixed;
  inset: -10%;
  z-index: -3;
  background:
    radial-gradient(58% 42% at 78% -2%, rgba(124, 108, 255, 0.34), transparent 70%),
    radial-gradient(52% 38% at 6% 14%, rgba(51, 230, 184, 0.16), transparent 66%),
    radial-gradient(46% 36% at 24% 78%, rgba(196, 86, 255, 0.18), transparent 70%),
    radial-gradient(50% 40% at 98% 62%, rgba(64, 120, 255, 0.17), transparent 70%),
    radial-gradient(34% 28% at 52% 42%, rgba(255, 120, 180, 0.09), transparent 72%),
    linear-gradient(180deg, var(--bg-soft), var(--bg) 58%);
  animation: nebula-drift 80s ease-in-out infinite alternate;
  will-change: transform;
}

body::before {
  content: "";
  position: fixed;
  inset: -300px 0;
  z-index: -2;
  background-image:
    radial-gradient(1px 1px at 24px 38px, #ffffff, transparent),
    radial-gradient(1px 1px at 137px 91px, #cfd3ff, transparent),
    radial-gradient(1px 1px at 62px 173px, #ffffff, transparent),
    radial-gradient(1px 1px at 199px 24px, #b9c0ff, transparent),
    radial-gradient(1px 1px at 231px 148px, #ffffff, transparent),
    radial-gradient(1px 1px at 105px 236px, #cfd3ff, transparent),
    radial-gradient(1px 1px at 176px 205px, #ffffff, transparent),
    radial-gradient(1px 1px at 12px 118px, #b9c0ff, transparent);
  background-size: 260px 260px;
  opacity: 0.55;
  animation: star-drift-near 150s linear infinite;
  will-change: transform;
}

body::after {
  content: "";
  position: fixed;
  inset: -560px 0;
  z-index: -1;
  background-image:
    radial-gradient(1.7px 1.7px at 78px 64px, #ffffff, transparent),
    radial-gradient(1.5px 1.5px at 386px 142px, #d8f7ff, transparent),
    radial-gradient(2px 2px at 214px 331px, #ffffff, transparent),
    radial-gradient(1.5px 1.5px at 451px 428px, #cfd3ff, transparent),
    radial-gradient(1.8px 1.8px at 47px 396px, #ffeede, transparent),
    radial-gradient(1.4px 1.4px at 302px 231px, #ffffff, transparent);
  background-size: 520px 520px;
  opacity: 0.75;
  animation:
    star-drift-far 260s linear infinite,
    twinkle 7s ease-in-out infinite alternate;
  will-change: transform, opacity;
}

@keyframes nebula-drift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to { transform: translate3d(-2%, 1.5%, 0) scale(1.06); }
}

@keyframes star-drift-near {
  from { transform: translate3d(0, 0, 0); }
  to { transform: translate3d(0, 260px, 0); }
}

@keyframes star-drift-far {
  from { transform: translate3d(0, 0, 0); }
  to { transform: translate3d(0, 520px, 0); }
}

@keyframes twinkle {
  from { opacity: 0.45; }
  to { opacity: 0.9; }
}

@media (prefers-reduced-motion: reduce) {
  html::before,
  body::before,
  body::after {
    animation: none;
  }
}

/* Shared floating animation, used by the logo and the hero mascot */
@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

a {
  color: inherit;
  text-decoration: none;
}

.wrap {
  width: 100%;
  max-width: var(--max);
  margin: 0 auto;
  padding: 0 24px;
}

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

/* Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(12px);
  background: rgba(5, 6, 15, 0.55);
  border-bottom: 1px solid var(--panel-border);
}

/* min-height, не height: на узком экране содержимое не должно вылезать за
   пределы шапки, если строка всё-таки окажется выше. */
.site-header .wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 68px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.2px;
}

.brand .logo {
  font-size: 26px;
  filter: drop-shadow(0 0 10px var(--accent-glow));
  animation: bob 3.5s ease-in-out infinite;
}

/* Название залито градиентом туманности целиком. Заливка обрезается по тексту
   всего элемента, включая вложенный <b>, — тому свой фон не нужен. */
.brand-name {
  white-space: nowrap;
  background: var(--nebula-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  /* Свечение по контуру букв: text-shadow при прозрачной заливке не виден. */
  filter: drop-shadow(0 0 12px rgba(124, 108, 255, 0.45));
}

/* Фолбэк для браузеров без background-clip: text — там надпись останется
   прежней: белое «Space» и бирюзовое «VPN». С поддержкой оба цвета перекрыты
   унаследованным text-fill-color. */
.brand b {
  color: var(--accent-2);
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 26px;
  font-size: 15px;
  color: var(--muted);
}

.nav-links a:hover {
  color: var(--text);
}

/* Кнопка-«бургер»: есть в разметке всегда, показывается только за
   брейкпоинтом (см. медиазапрос в конце файла). */
.nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

.nav-toggle-bars {
  display: block;
  width: 20px;
}

.nav-toggle-bars span {
  display: block;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  transition: transform 0.18s ease, opacity 0.18s ease;
}

.nav-toggle-bars span + span {
  margin-top: 5px;
}

/* Открытое меню — «бургер» превращается в крестик. */
.nav-toggle[aria-expanded="true"] .nav-toggle-bars span:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.nav-toggle[aria-expanded="true"] .nav-toggle-bars span:nth-child(2) {
  opacity: 0;
}

.nav-toggle[aria-expanded="true"] .nav-toggle-bars span:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

@media (prefers-reduced-motion: reduce) {
  .nav-toggle-bars span {
    transition: none;
  }
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.12s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  color: #0a0713;
  background: linear-gradient(135deg, var(--accent-2), #6cf0ff);
  box-shadow: 0 8px 30px rgba(51, 230, 184, 0.28);
}

.btn-primary:hover {
  box-shadow: 0 10px 40px rgba(51, 230, 184, 0.45);
}

.btn-ghost {
  color: var(--text);
  background: var(--panel);
  border-color: var(--panel-border);
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.09);
}

.btn-lg {
  padding: 15px 30px;
  font-size: 17px;
  border-radius: 14px;
}

/*
 * Modal shell, shared by every page that uses the `modal` Stimulus controller
 * (checkout on the dashboard, the outbound-call warning on sign-in).
 * Plain div + [hidden] instead of <dialog>, which Safari 15.0–15.3 lacks.
 */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
}

/* Must out-specify the rule above, or `hidden` would not hide anything. */
.modal[hidden] {
  display: none;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3, 4, 12, 0.72);
}

.modal-box {
  position: relative;
  width: 100%;
  max-width: 520px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  padding: 26px;
  border-radius: 18px;
  border: 1px solid var(--panel-border);
  background: linear-gradient(180deg, var(--bg-soft), var(--bg));
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
  text-align: left;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.modal-head h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
}

.modal-close {
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--muted);
  border-radius: 10px;
  width: 34px;
  height: 34px;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  font-family: inherit;
}

.modal-close:hover {
  color: var(--text);
}

.modal-text {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
}

.modal-text-free {
  color: var(--accent-2);
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
}

/* Set while the modal is open so the page behind it does not scroll away. */
body.modal-open {
  overflow: hidden;
}

/* Footer */
.site-footer {
  border-top: 1px solid var(--panel-border);
  padding: 30px 0;
  color: var(--muted);
  font-size: 14px;
}

.site-footer .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

/*
 * Узкий экран: ссылки и кнопки шапки уезжают в выпадающее меню под ней.
 * В строку они не помещаются — подписи вроде «Личный кабинет» переносятся
 * внутри кнопки, и шапка вырастает на пол-экрана. Открытием управляет
 * site_nav_controller: класс .is-open плюс aria-expanded на «бургере».
 */
@media (max-width: 820px) {
  .nav-toggle {
    display: inline-flex;
  }

  .nav-links {
    position: absolute;
    top: calc(100% + 8px);
    right: 12px;
    left: 12px;
    z-index: 20;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    max-height: calc(100vh - 96px);
    overflow-y: auto;
    padding: 10px;
    border-radius: 16px;
    border: 1px solid var(--panel-border);
    /* Непрозрачный фон: панель висит поверх страницы, и просвечивающий сквозь
       неё текст читать невозможно. */
    background: var(--bg-soft);
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.65);

    /* visibility, а не display: закрытое меню недоступно с клавиатуры и при
       этом остаётся анимируемым. */
    visibility: hidden;
    opacity: 0;
    transform: translateY(-8px);
    transition: opacity 0.16s ease, transform 0.16s ease, visibility 0.16s;
  }

  .nav-links.is-open {
    visibility: visible;
    opacity: 1;
    transform: translateY(0);
  }

  /* В столбце ссылкам нужна та же кликабельная высота, что и кнопкам. */
  .nav-links a:not(.btn) {
    padding: 11px 14px;
    border-radius: 12px;
  }

  .nav-links a:not(.btn):hover {
    background: var(--panel);
  }

  .nav-links .btn {
    width: 100%;
  }
}

@media (max-width: 820px) and (prefers-reduced-motion: reduce) {
  .nav-links {
    transition: none;
  }
}

/* Телефон: 24px полей с каждой стороны съедают заметную долю ширины. */
@media (max-width: 560px) {
  .wrap {
    padding: 0 16px;
  }

  .site-header .wrap {
    min-height: 60px;
  }

  .nav-links {
    top: calc(100% + 6px);
    right: 8px;
    left: 8px;
  }

  .btn-lg {
    padding: 14px 22px;
    font-size: 16px;
  }

  .modal {
    padding: 12px;
  }

  .modal-box {
    padding: 20px 18px;
    max-height: calc(100vh - 24px);
  }
}
