/* Мини-приложение Пранкоинатора — оформление один в один по прототипу docs/design/miniapp.html.
   Цвета, скругления и размеры — переменные ниже: одна правка меняет всё приложение
   (docs/SPEC_MINIAPP.md, «Как строить»). Значения — как прототип показывает на экране (с его
   последним блоком «плитки без границ и полупрозрачные»). */

/* Шрифт SF Compact Rounded отдаёт наш сервер (/fonts/); файлов нет — swap сразу показывает
   запасной: на iPhone — скруглённый системный (ui-rounded), на остальных — обычный системный. */
@font-face {
  font-family: "SF Compact Rounded";
  src: url("/fonts/SF-Compact-Rounded-Regular.otf") format("opentype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "SF Compact Rounded";
  src: url("/fonts/SF-Compact-Rounded-Medium.otf") format("opentype");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "SF Compact Rounded";
  src: url("/fonts/SF-Compact-Rounded-Semibold.otf") format("opentype");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "SF Compact Rounded";
  src: url("/fonts/SF-Compact-Rounded-Bold.otf") format("opentype");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "SF Compact Rounded";
  src: url("/fonts/SF-Compact-Rounded-Heavy.otf") format("opentype");
  font-weight: 800;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Чёрное небо с мерцающими звёздами, полупрозрачные плитки, белые главные кнопки. Фиолетовый
     — только в логотипе и фокусе. Одна колонка до 480px, нижнее меню из трёх вкладок. */
  --bg: #000000;
  --text: #ffffff;
  --text-2: #8e8e95;
  --text-3: #5d5d64;
  --accent: #a568ee;
  --gold: #f5a524;
  --surface: rgba(255, 255, 255, 0.085); /* карточки */
  --surface-2: rgba(255, 255, 255, 0.09); /* плитки баланса */
  --surface-3: rgba(255, 255, 255, 0.1); /* баланс в шапке, выбранная вкладка */
  --surface-btn: rgba(255, 255, 255, 0.11); /* тёмная кнопка */
  --icon-tile: #26262a; /* значок в плитке баланса */
  --big-icon: #1b1b1e; /* большой значок в пустом состоянии */
  --separator: rgba(255, 255, 255, 0.14);
  --tabbar: rgba(10, 10, 12, 0.8);
  --tab-icon: #6b6b72;
  --header-fade: rgba(0, 0, 0, 0.94);
  --avatar-from: #3a3a40;
  --avatar-to: #151517;
  --primary: #ffffff;
  --on-primary: #000000;
  --primary-glow: rgba(255, 255, 255, 0.35);
  --disabled: #222225;
  --on-disabled: #6b6b72;

  --radius-card: 22px;
  --radius-tile: 16px;
  --radius-button: 14px;
  --radius-icon: 10px;
  --radius-pill: 19px;

  --app-width: 480px;
  --gutter: 16px;
  --tabbar-height: 58px;
  --button-height: 52px;

  --font: "SF Compact Rounded", ui-rounded, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    sans-serif;
  --font-logo: var(--font);

  /* Безопасные зоны: вырез и полоска «домой» на iPhone (env) и то, что сообщает Telegram
     (--tg-…, Bot API 8.0: системные зоны и свои кнопки Telegram в полноэкранном режиме). */
  --safe-top: max(
    env(safe-area-inset-top, 0px),
    calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px))
  );
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));

  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); overscroll-behavior: none; }
body { font-family: var(--font); font-size: 16px; line-height: 1.4; -webkit-font-smoothing: antialiased; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
a { color: inherit; }
svg { display: block; }
[hidden] { display: none !important; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#sky { position: fixed; left: 0; top: 0; width: 100%; height: 100%; z-index: 0; pointer-events: none; }
.app { position: relative; z-index: 1; max-width: var(--app-width); margin: 0 auto; padding: 0 var(--gutter) calc(104px + var(--safe-bottom)); }

/* шапка */
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: calc(var(--safe-top) + 64px); margin: 0 calc(var(--gutter) * -1); padding: calc(var(--safe-top) + 12px) var(--gutter) 14px; background: linear-gradient(to bottom, var(--header-fade) 55%, rgba(0, 0, 0, 0)); }
.logo { display: flex; align-items: center; gap: 7px; font-family: var(--font-logo); font-weight: 800; font-size: 20px; letter-spacing: -0.01em; }
.logo-av { width: 24px; height: 24px; border-radius: 50%; object-fit: cover; display: block; flex: none; }
.balance { display: inline-flex; align-items: center; gap: 7px; height: 38px; padding: 0 4px 0 12px; border-radius: var(--radius-pill); background: var(--surface-3); font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.balance .ic { width: 16px; height: 16px; color: var(--text-2); }
.balance .sep { width: 1px; height: 14px; margin: 0 2px; background: var(--separator); }
.balance .plus { width: 30px; height: 30px; margin-left: 3px; border-radius: 50%; background: var(--primary); color: var(--on-primary); display: grid; place-items: center; }
.balance .plus svg { width: 16px; height: 16px; }

/* экраны */
.view { display: none; }
.view.active { display: block; animation: rise .28s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.view-head { padding: 6px 0 18px; }
.view-head h1 { margin: 0; font-size: 28px; line-height: 1.15; font-weight: 700; letter-spacing: -0.025em; text-wrap: balance; }
.view-head p { margin: 6px 0 0; font-size: 15px; color: var(--text-2); }

.card { background: var(--surface); border-radius: var(--radius-card); padding: 16px; }
.stack { display: flex; flex-direction: column; gap: 10px; }

/* «скоро здесь» — вкладки, которых пока нет (как пустой выбор фото в прототипе) */
.soon { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 32px 16px; text-align: center; font-size: 13px; color: var(--text-2); }
.big-ic { width: 52px; height: 52px; margin-bottom: 6px; border-radius: var(--radius-tile); background: var(--big-icon); color: var(--text); display: grid; place-items: center; }
.big-ic svg { width: 24px; height: 24px; }
.soon strong { color: var(--text); font-size: 16px; font-weight: 600; }

/* профиль */
.user { display: flex; align-items: center; gap: 14px; }
.avatar { width: 52px; height: 52px; flex: none; border-radius: 50%; display: grid; place-items: center; font-size: 20px; font-weight: 600; background: linear-gradient(145deg, var(--avatar-from), var(--avatar-to)); }
.user b { display: block; font-size: 18px; font-weight: 600; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.user span { font-size: 14px; color: var(--text-2); }
.bal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.bal { display: flex; flex-direction: column; gap: 10px; padding: 14px; border-radius: var(--radius-tile); background: var(--surface-2); }
.bal .bi { width: 32px; height: 32px; border-radius: var(--radius-icon); background: var(--icon-tile); color: var(--text); display: grid; place-items: center; }
.bal .bi svg { width: 17px; height: 17px; }
.bal .n { font-size: 30px; line-height: 1; font-weight: 700; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.bal .l { margin-top: -4px; font-size: 13px; color: var(--text-2); }

/* кнопки */
.btn { position: relative; display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; height: var(--button-height); padding: 0 18px; border-radius: var(--radius-button); font-size: 16px; font-weight: 600; text-decoration: none; overflow: hidden; transition: transform .12s ease, background-color .2s, color .2s; }
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn svg { position: relative; width: 19px; height: 19px; flex: none; }
.btn-primary { background: var(--primary); color: var(--on-primary); box-shadow: 0 10px 30px -12px var(--primary-glow); }
.btn-primary:disabled { background: var(--disabled); color: var(--on-disabled); box-shadow: none; cursor: default; }
.btn-dark { background: var(--surface-btn); color: var(--text); }

/* нижнее меню */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; padding-bottom: var(--safe-bottom); background: var(--tabbar); -webkit-backdrop-filter: blur(20px) saturate(140%); backdrop-filter: blur(20px) saturate(140%); }
.tabbar-inner { max-width: var(--app-width); margin: 0 auto; display: grid; grid-template-columns: repeat(3, 1fr); height: var(--tabbar-height); }
.tab-btn { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--tab-icon); font-size: 11px; font-weight: 600; transition: color .2s; }
.tab-btn .ti { width: 60px; height: 38px; border-radius: var(--radius-pill); display: grid; place-items: center; transition: background-color .2s; }
.tab-btn svg { width: 25px; height: 25px; }
.tab-btn[aria-selected="true"] { color: var(--text); }
.tab-btn[aria-selected="true"] .ti { background: var(--surface-3); }

/* Загрузка, «Скоро», «Доступ ограничен», «Нет связи» и другие экраны во весь экран — в том же
   стиле: логотип, заголовок как у экранов, белая кнопка. */
.state { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0; min-height: calc(100vh - 160px - var(--safe-top) - var(--safe-bottom)); padding: 8px 8px 48px; text-align: center; animation: rise .28s ease both; }
.state-logo { width: 72px; height: 72px; border-radius: 50%; object-fit: cover; margin-bottom: 18px; box-shadow: 0 0 40px rgba(165, 104, 238, 0.25); }
.state h1 { margin: 0; font-size: 28px; line-height: 1.15; font-weight: 700; letter-spacing: -0.025em; text-wrap: balance; }
.state p { max-width: 320px; margin: 8px 0 0; font-size: 15px; color: var(--text-2); text-wrap: balance; }
.state .btn { max-width: 320px; margin-top: 26px; }
.loader { width: 26px; height: 26px; color: var(--text); animation: twinkle 1.6s ease-in-out infinite; }
.state.loading .state-logo { display: none; }
@keyframes twinkle { 0%, 100% { opacity: .35; transform: scale(.85); } 50% { opacity: 1; transform: none; } }

/* Узкие экраны (до 359px, например iPhone SE первого поколения): шапка прототипа там не
   помещается по ширине — чуть меньше логотип и промежутки. На остальных — как в прототипе. */
@media (max-width: 359px) {
  .top { gap: 8px; }
  .logo { gap: 6px; font-size: 17px; }
  .balance { gap: 5px; padding-left: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
