/* Frace VPN — палитра «ночной маршрут».
   route  — фиолетовый туннель (бренд, главные кнопки)
   signal — мятный «подключено»
   amber  — ожидание, alert — доступ выключен.
   Тема (светлая/тёмная) берётся из Telegram, вне его — из настроек устройства. */
:root {
  --ink: #f3f2fa;
  --panel: #ffffff;
  --text: #15172b;
  --muted: #686c8a;
  --line: rgba(21, 23, 43, 0.1);
  --route: #5b47f0;
  --on-route: #ffffff;
  --signal: #0f9e66;
  --amber: #c27a06;
  --alert: #d64545;
  --display: "Unbounded", "Onest", system-ui, sans-serif;
  --body: "Onest", -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --ink: #0e1020;
  --panel: #171a2e;
  --text: #eef0ff;
  --muted: #8c90b0;
  --line: rgba(238, 240, 255, 0.09);
  --route: #8f7cff;
  --on-route: #0e1020;
  --signal: #5be7a9;
  --amber: #ffb547;
  --alert: #ff6b6b;
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* Атрибут hidden должен побеждать display: grid/flex у блоков ниже. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--ink);
  color: var(--text);
  font: 16px/1.5 var(--body);
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 460px;
  margin: 0 auto;
  padding: 18px 16px calc(28px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.mono { font-family: var(--mono); font-weight: 500; letter-spacing: -0.01em; }

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font: 700 15px/1 var(--display);
  letter-spacing: 0.01em;
}
.brand-mark { width: 20px; height: 20px; fill: var(--route); }

/* ---------- Маршрут туннеля ---------- */
.route {
  background: var(--panel);
  border-radius: 22px;
  padding: 18px 16px 14px;
  --state: var(--muted);
}
.route-map { display: block; width: 100%; height: auto; overflow: visible; }
.route-arc { fill: none; stroke-width: 3; stroke-linecap: round; }
.route-ghost { stroke: var(--line); }
.route-line { stroke: var(--state); transition: stroke .3s; }
.route-node { fill: var(--panel); stroke: var(--state); stroke-width: 3; transition: stroke .3s; }
.packet { fill: var(--signal); }

.route-ends {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 6px;
}
.route-ends div { display: flex; flex-direction: column; gap: 2px; }
.route-ends b { font-weight: 600; font-size: 15px; }
.route-ends .mono { font-size: 11px; color: var(--muted); }
.route-ends-right { text-align: right; }

/* Состояния линии: пунктир — туннеля ещё нет, разрыв — доступ выключен. */
.route[data-state="loading"] .route-line { stroke-dasharray: 2 6; animation: crawl 1s linear infinite; }
.route[data-state="none"] .route-line { stroke-dasharray: 2 6; }
.route[data-state="pending"] { --state: var(--amber); }
.route[data-state="pending"] .route-line { stroke-dasharray: 2 6; animation: crawl 2.4s linear infinite; }
.route[data-state="active"] { --state: var(--signal); }
.route[data-state="active"] .route-line { stroke: url(#tunnel); }
.route[data-state="active"] .route-node { stroke: var(--route); }
.route[data-state="active"] .route-node-end { stroke: var(--signal); }
.route[data-state="off"] { --state: var(--alert); }
.route[data-state="off"] .route-line { stroke-dasharray: 40 20 40; }
@keyframes crawl { to { stroke-dashoffset: -16; } }

/* ---------- Статус ---------- */
.status { display: flex; flex-direction: column; gap: 8px; }
.status-tag {
  align-self: flex-start;
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--tone, var(--muted));
}
.status-tag::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}
.status h1 {
  margin: 0;
  font: 700 27px/1.15 var(--display);
  letter-spacing: -0.02em;
  text-wrap: balance;
}
.status-text { margin: 0; color: var(--muted); text-wrap: pretty; }

/* ---------- Кнопки ---------- */
.actions { display: flex; flex-direction: column; gap: 10px; }
.actions:empty { display: none; }

.btn {
  appearance: none;
  border: 0;
  width: 100%;
  min-height: 54px;
  padding: 14px 18px;
  border-radius: 16px;
  font: 600 16px/1.2 var(--body);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  transition: transform .12s ease-out, opacity .2s, background-color .2s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.98); }
.btn:focus-visible { outline: 3px solid var(--route); outline-offset: 3px; }
.btn[disabled] { opacity: .55; cursor: progress; }
.btn svg { width: 20px; height: 20px; fill: currentColor; flex: none; }
.btn-primary { background: var(--route); color: var(--on-route); }
.btn-secondary {
  background: transparent;
  color: var(--text);
  box-shadow: inset 0 0 0 1.5px var(--line);
}

/* ---------- Цифры ---------- */
.stats {
  margin: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.stats div { padding: 14px 0; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.stats div + div { padding-left: 16px; border-left: 1px solid var(--line); }
.stats dt { font-size: 13px; color: var(--muted); }
.stats dd { margin: 0; font-size: 18px; overflow-wrap: anywhere; }

/* ---------- Шаги: это настоящая последовательность, поэтому с номерами ---------- */
.steps h2 { margin: 0 0 6px; font: 600 15px/1.3 var(--display); }
.steps ol { margin: 0; padding: 0; list-style: none; counter-reset: step; }
.steps li {
  counter-increment: step;
  display: grid;
  grid-template-columns: 30px 1fr;
  column-gap: 10px;
  row-gap: 8px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.steps li:last-child { border-bottom: 0; }
.steps li::before {
  content: counter(step);
  grid-row: span 2;
  font: 500 13px/30px var(--mono);
  width: 30px;
  height: 30px;
  text-align: center;
  border-radius: 50%;
  color: var(--route);
  box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--route) 45%, transparent);
}
.steps li > span:first-of-type { padding-top: 4px; }
.stores { display: flex; flex-wrap: wrap; gap: 8px; }
.stores a {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  padding: 0 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  color: var(--route);
  text-decoration: none;
  background: color-mix(in srgb, var(--route) 12%, transparent);
}
.stores a:focus-visible { outline: 2px solid var(--route); outline-offset: 2px; }

.footnote { margin: 0; text-align: center; font-size: 13px; color: var(--muted); }
.footnote:empty { display: none; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  width: max-content;
  max-width: calc(100% - 32px);
  transform: translate(-50%, 16px);
  padding: 12px 16px;
  border-radius: 14px;
  background: var(--text);
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .25s ease-out;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

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