:root {
  color-scheme: dark;

  /* --- палитра нового лаунчера (App.xaml) --- */
  --background: #08080a;
  --panel-solid: #0f0f12;
  --panel-soft: #16161a;
  --text: #ececef;
  --muted: #77777f;
  --accent: #6d8cff;
  --accent-dim: rgba(109, 140, 255, 0.12);
  --hairline: #1e1e24;
  --hairline-strong: #2a2a32;
  --surface-hover: #1b1b21;
  --success: #6ef0b4;
  --danger: #ff718d;

  /* обратная совместимость со старыми именами */
  --pink: var(--accent);
  --purple: var(--accent);
  --violet: var(--accent);
  --border: var(--hairline);
  --radius: 14px;

  /* --- чёрное стекло, сдержанно --- */
  --glass-bg: rgba(255, 255, 255, 0.03);
  --glass-bg-strong: rgba(255, 255, 255, 0.05);
  --glass-bg-soft: rgba(255, 255, 255, 0.018);
  --glass-blur: blur(22px) saturate(110%);
  --glass-blur-soft: blur(14px) saturate(105%);
  --glass-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);

  font-family: Bahnschrift, "Arial Narrow", "Segoe UI Variable", system-ui, sans-serif;
}

* { box-sizing: border-box; }

.svg-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon, .button-icon, .download-icon {
  width: 1em;
  height: 1em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.button-icon { flex: 0 0 auto; font-size: 17px; }

html { min-height: 100%; background: var(--background); }

body {
  position: relative;
  min-width: 300px;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--text);
  background: var(--background);
}

button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

/* декоративные пятна убраны — строгий плоский фон */
.ambient { display: none; }

.app-shell {
  position: relative;
  z-index: 1;
  width: min(100%, 680px);
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(104px + env(safe-area-inset-bottom));
}

/* ---------- topbar ---------- */
.topbar {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  padding: 0 0 16px;
  border-bottom: 1px solid var(--hairline);
}

.brand-mark {
  width: 36px;
  height: 36px;
  overflow: hidden;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  background: var(--panel-soft);
}

.brand-mark img { width: 100%; height: 100%; object-fit: cover; }
.brand-copy { display: flex; flex-direction: column; gap: 2px; }
.byline { color: var(--muted); font-size: 12px; }

/* ---------- panel ---------- */
.panel {
  position: relative;
  overflow: hidden;
  margin-bottom: 12px;
  padding: 20px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  box-shadow: var(--glass-shadow);
  animation: panel-in .32s cubic-bezier(.2, .8, .2, 1) both;
}

.hero { display: flex; align-items: center; gap: 14px; }
.hero-copy { flex: 1; min-width: 0; }

.avatar {
  display: grid;
  flex: 0 0 auto;
  width: 52px;
  height: 52px;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--hairline);
  border-radius: 10px;
  color: var(--text);
  background: var(--panel-soft);
  background-position: center;
  background-size: cover;
  font-size: 21px;
  font-weight: 700;
}

.connection-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #3a3a44;
}
.connection-dot.online { background: var(--success); }

h1, h2, p { margin: 0; }
h1 { overflow: hidden; font-size: clamp(22px, 7vw, 30px); text-overflow: ellipsis; white-space: nowrap; }
h2 { font-size: 18px; font-weight: 600; }
.eyebrow { color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .16em; }
.muted { margin-top: 5px; color: var(--muted); font-size: 13px; line-height: 1.45; }

.section-heading { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.section-heading .eyebrow { margin-bottom: 3px; }
.icon-box {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid var(--hairline);
  border-radius: 9px;
  color: #9d9da8;
  background: var(--glass-bg-strong);
  font-size: 19px;
}
.icon-box.accent { color: var(--accent); border-color: rgba(109, 140, 255, .26); background: var(--accent-dim); }

/* ---------- plans ---------- */
.plan-list { display: grid; gap: 10px; margin-top: 16px; }
.plan-option {
  padding: 14px;
  border: 1px solid var(--hairline);
  border-radius: 10px;
  background: var(--glass-bg-soft);
  transition: background .18s ease, border-color .18s ease;
}
.plan-option:hover { background: rgba(255, 255, 255, .04); border-color: var(--hairline-strong); }

.app-pages { min-height: calc(100vh - 105px); }
.app-page { animation: page-in .24s cubic-bezier(.2, .8, .2, 1) both; }
.page-heading { margin: 4px 0 20px; padding-bottom: 16px; border-bottom: 1px solid var(--hairline); }
.page-heading h1 {
  margin-top: 6px;
  font-size: clamp(28px, 8vw, 40px);
  font-weight: 700;
  letter-spacing: -.035em;
  line-height: 1.02;
  white-space: normal;
}
.page-heading > .muted { max-width: 440px; margin-top: 10px; font-size: 13px; }

/* ---------- home hero ---------- */
.home-hero {
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 24px 20px;
  border-color: var(--hairline);
  background: var(--glass-bg-strong);
}
.home-hero h1 {
  max-width: 540px;
  margin-top: 10px;
  overflow: visible;
  font-size: clamp(28px, 7.5vw, 44px);
  font-weight: 700;
  letter-spacing: -.04em;
  line-height: 1.04;
  text-overflow: clip;
  white-space: normal;
}
.home-hero h1 span { color: var(--muted); background: none; -webkit-text-fill-color: currentColor; }
.home-copy { max-width: 380px; margin-top: 14px; color: var(--muted); font-size: 13px; }
.home-action { align-self: stretch; margin-top: 20px; }

/* ---------- overview cards ---------- */
.overview-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.overview-card {
  position: relative;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 16px;
  border: 1px solid var(--hairline);
  border-radius: 12px;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
}
.overview-card:first-child { grid-column: 1 / -1; }
.overview-icon {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  margin-bottom: 16px;
  border: 1px solid var(--hairline);
  border-radius: 9px;
  color: #9d9da8;
  background: var(--glass-bg-strong);
  font-size: 17px;
}
.overview-index { position: absolute; top: 15px; right: 16px; color: #46464f; font-size: 10px; letter-spacing: .1em; }
.overview-card small, .balance-label { color: var(--muted); font-size: 9px; font-weight: 700; letter-spacing: .16em; }
.overview-card strong { display: block; margin-top: 5px; overflow: hidden; font-size: 15px; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- balance ---------- */
.balance-card {
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 22px 20px;
  background: var(--glass-bg-strong);
}
.balance-card strong { margin-top: 6px; font-size: clamp(34px, 10vw, 46px); font-weight: 700; letter-spacing: -.04em; line-height: 1; }
.balance-currency { margin-top: 8px; color: var(--muted); font-size: 10px; letter-spacing: .14em; }
.top-up-tools { width: 100%; margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--hairline); }
.top-up-tools + small { display: block; margin-top: 10px; }
.empty-history { display: flex; gap: 14px; align-items: center; }
.empty-history .overview-icon { flex: 0 0 auto; margin: 0; }
.empty-history .muted { margin-top: 3px; }
.balance-history { display: grid; gap: 8px; }
.transaction-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 0;
  padding: 15px 16px;
  border-radius: 10px;
}
.transaction-row > div { display: flex; min-width: 0; flex-direction: column; gap: 4px; }
.transaction-row > div > strong { overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.transaction-row > div > span { color: var(--muted); font-size: 10px; }
.transaction-amount { flex: 0 0 auto; font-size: 14px; }
.transaction-amount.expense { color: #ff8fae; }
.transaction-amount.income { color: var(--success); }
.profile-refresh { margin: 4px 0 0; }

/* ---------- bottom nav: строгая нижняя панель ---------- */
.bottom-nav {
  position: fixed;
  z-index: 18;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  padding: 0 0 env(safe-area-inset-bottom);
  transform: none;
  border: 0;
  border-top: 1px solid var(--hairline);
  border-radius: 0;
  background: rgba(8, 8, 10, .86);
  backdrop-filter: blur(24px) saturate(110%);
  -webkit-backdrop-filter: blur(24px) saturate(110%);
  box-shadow: none;
}
.nav-item {
  position: relative;
  min-width: 0;
  min-height: 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: 0;
  border-radius: 0;
  color: #5f5f68;
  background: transparent;
  cursor: pointer;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .04em;
  transition: color .18s ease, background .18s ease;
}
/* индикатор активной вкладки — линия сверху, без «пилюли» */
.nav-item::before {
  content: "";
  position: absolute;
  top: -1px;
  left: 0;
  right: 0;
  height: 2px;
  background: transparent;
  transition: background .18s ease;
}
.nav-item:hover { color: #9d9da8; background: rgba(255, 255, 255, .022); }
.nav-item:disabled { cursor: default; opacity: .5; }
.nav-item.active { color: var(--text); background: transparent; }
.nav-item.active::before { background: var(--accent); }
.nav-icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.plan-option.lifetime-plan { border-color: rgba(109, 140, 255, .24); background: var(--accent-dim); }
.plan-copy { display: flex; align-items: center; gap: 12px; }
.plan-copy > span:last-child { display: flex; min-width: 0; flex-direction: column; gap: 3px; }
.plan-copy strong { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 15px; }
.plan-copy small { color: var(--muted); font-size: 11px; line-height: 1.4; }
.plan-copy em {
  padding: 3px 6px;
  border: 1px solid rgba(109, 140, 255, .26);
  border-radius: 4px;
  color: #b6c4ff;
  background: var(--accent-dim);
  font-size: 8px;
  font-style: normal;
  letter-spacing: .1em;
}
.plan-icon {
  display: grid;
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--hairline);
  border-radius: 9px;
  color: #9d9da8;
  background: var(--glass-bg-strong);
  font-size: 18px;
}
.plan-icon.lifetime { color: var(--accent); border-color: rgba(109, 140, 255, .26); background: var(--accent-dim); }
.plan-option .wide { margin-top: 12px; }

/* ---------- inputs ---------- */
.code-form { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 16px; }
input {
  min-width: 0;
  padding: 13px 14px;
  border: 1px solid var(--hairline);
  outline: none;
  border-radius: 10px;
  color: var(--text);
  background: rgba(255, 255, 255, .028);
  font-size: 15px;
  letter-spacing: .08em;
  text-transform: uppercase;
  transition: border-color .18s, background .18s;
}
input::placeholder { color: #4e4e57; }
input:focus { border-color: var(--accent); background: rgba(255, 255, 255, .045); }

/* ---------- buttons ---------- */
.button, .download-button {
  position: relative;
  display: inline-flex;
  min-height: 46px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  overflow: hidden;
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--text);
  cursor: pointer;
  font-weight: 600;
  text-decoration: none;
  transition: opacity .18s ease, background .18s ease, border-color .18s ease;
}
.button:active, .download-button:active { opacity: .7; }
.button:disabled, .download-button:disabled { cursor: default; opacity: .28; }

.button-primary { padding: 12px 18px; color: #0a0a0c; background: #ececef; }
.button-primary:hover { background: #ffffff; }

.button-secondary {
  padding: 12px 18px;
  color: #c9c9d2;
  border-color: var(--hairline);
  background: #14141a;
}
.button-secondary:hover { background: var(--surface-hover); }
.wide { width: 100%; margin-top: 16px; }

/* ---------- badges: прямоугольные, без «пилюль» ---------- */
.status-row, .device-state { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.badge {
  display: inline-flex;
  padding: 5px 8px;
  border: 1px solid var(--hairline);
  border-radius: 5px;
  color: #9d9da8;
  background: var(--glass-bg-strong);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .1em;
}
.badge.active { color: var(--success); border-color: rgba(110, 240, 180, .24); background: rgba(110, 240, 180, .08); }
.badge.neutral { color: var(--accent); border-color: rgba(109, 140, 255, .24); background: var(--accent-dim); }

.reset-counter { display: flex; flex: 0 0 auto; align-items: baseline; gap: 3px; color: var(--muted); white-space: nowrap; }
.reset-counter strong { color: var(--text); font-size: 24px; font-weight: 700; }
.privacy-note { margin-top: 12px; color: #5c5c65; font-size: 11px; line-height: 1.4; }

/* ---------- keys ---------- */
.key-card { margin-top: 12px; }
.key-tools { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; margin-top: 16px; }
.key-tools input { min-width: 0; text-transform: uppercase; }
.key-result {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  padding: 12px;
  border: 1px solid rgba(109, 140, 255, .26);
  border-radius: 10px;
  background: var(--accent-dim);
}
.key-result code { overflow-wrap: anywhere; color: #9db0ff; font-size: 14px; font-weight: 700; letter-spacing: .04em; }
@media (max-width: 480px) {
  .key-tools, .key-result { grid-template-columns: 1fr; }
}

/* ---------- download ---------- */
.download-card { display: grid; grid-template-columns: 1fr; gap: 16px; background: var(--glass-bg-strong); }
.download-button { width: 100%; padding: 13px 18px; color: #0a0a0c; background: #ececef; }
.download-button:hover { background: #ffffff; }
.download-icon { font-size: 20px; }

/* ---------- notice ---------- */
.notice {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
  padding: 18px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
}
.notice.error { border-color: rgba(255, 113, 141, .24); background: rgba(255, 113, 141, .06); }
.notice span { color: var(--muted); font-size: 13px; line-height: 1.45; }

/* ---------- loader / toast ---------- */
.loader {
  position: fixed;
  z-index: 20;
  right: 16px;
  bottom: calc(76px + env(safe-area-inset-bottom));
  display: flex;
  gap: 4px;
  padding: 10px 12px;
  border: 1px solid var(--hairline);
  border-radius: 10px;
  background: rgba(12, 12, 15, .9);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
}
.loader span { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); animation: bounce .85s infinite alternate; }
.loader span:nth-child(2) { animation-delay: .15s; }
.loader span:nth-child(3) { animation-delay: .3s; }
.loader.idle { display: none; }

.toast {
  position: fixed;
  z-index: 30;
  left: 50%;
  bottom: calc(78px + env(safe-area-inset-bottom));
  width: min(calc(100% - 32px), 520px);
  padding: 13px 15px;
  transform: translateX(-50%);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  color: var(--text);
  background: rgba(14, 14, 18, .94);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  box-shadow: 0 14px 34px rgba(0, 0, 0, .6);
  font-size: 13px;
  animation: toast-in .2s ease both;
}
.toast.success { border-color: rgba(110, 240, 180, .26); }
.toast.error { border-color: rgba(255, 113, 141, .28); }

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

@keyframes panel-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes page-in { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }
@keyframes bounce { to { transform: translateY(-4px); opacity: .45; } }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 6px); } }

@media (min-width: 560px) {
  .app-shell { padding-left: 22px; padding-right: 22px; }
  .overview-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .overview-card:first-child { grid-column: auto; }
  .download-card { grid-column: 1 / -1; grid-template-columns: 1fr auto; align-items: center; }
  .download-button { width: auto; min-width: 210px; }
  .home-action { align-self: flex-start; }
  .bottom-nav { grid-template-columns: repeat(4, minmax(0, 160px)); justify-content: center; }
}

@media (max-width: 360px) {
  .app-shell { padding-left: 12px; padding-right: 12px; }
  .nav-item { font-size: 8px; }
}

/* фоллбек без backdrop-filter */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .panel, .notice, .toast, .loader, .overview-card { background: var(--panel-solid); }
  .bottom-nav { background: #0a0a0d; }
  .icon-box, .plan-option, .overview-icon, .plan-icon { background: var(--panel-soft); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* --- статистика PvP на вкладке профиля --- */

.pvp-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 14px;
}

.pvp-stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 8px;
  border-radius: 12px;
  background: var(--glass-bg-soft);
  border: 1px solid var(--hairline);
  text-align: center;
}

.pvp-stat span {
  font-size: 10px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.pvp-stat strong {
  font-size: 19px;
  font-weight: 700;
}

.pvp-stat:first-child strong {
  color: var(--accent);
}

/* Столбики тянутся от общей базовой линии, поэтому align-items: flex-end. */
.pvp-chart {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 96px;
  margin-top: 16px;
}

.pvp-bar {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  height: 100%;
}

.pvp-bar-stack {
  display: flex;
  flex: 1;
  flex-direction: column;
  justify-content: flex-end;
  width: 100%;
  border-radius: 4px;
  background: var(--glass-bg-soft);
  overflow: hidden;
}

.pvp-bar-loss {
  display: block;
  background: var(--danger);
}

.pvp-bar-win {
  display: block;
  background: var(--accent);
}

.pvp-bar small {
  font-size: 9px;
  color: var(--muted);
}

.pvp-details {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 16px 0 10px;
}

.pvp-details dt {
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.pvp-details dd {
  margin: 4px 0 0;
  font-size: 14px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

/* ---------- сайт candydlc.fun: поверх стилей мини-аппа ---------- */
.topbar { grid-template-columns: auto 1fr auto; }
.topbar-action { min-height: 36px; padding: 7px 14px; font-size: 13px; }

.landing-hero { padding: 32px 24px; }
.landing-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-top: 24px;
}
/* Виджет Telegram — iframe фиксированной высоты; без min-height кнопки рядом прыгают при загрузке. */
.telegram-login { min-height: 40px; display: flex; align-items: center; }
.landing-features { margin-top: 12px; }
.landing-features .overview-card:first-child { grid-column: auto; }
.landing-features .muted { margin-top: 8px; font-size: 12px; }

@media (min-width: 900px) {
  .app-shell { width: min(100%, 960px); }
  .landing-hero { padding: 48px 40px; }
  .landing-hero h1 { font-size: 56px; }
  .home-copy { max-width: 520px; font-size: 15px; }
  .landing-features { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  /* На десктопе разделы покупок и профиля читаются лучше в две колонки. */
  .app-page[data-page="purchases"]:not([hidden]),
  .app-page[data-page="profile"]:not([hidden]) {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 12px;
    align-items: start;
  }
  .app-page[data-page="purchases"] .page-heading,
  .app-page[data-page="profile"] .page-heading,
  .app-page[data-page="profile"] .hero,
  .app-page[data-page="profile"] .download-card,
  .app-page[data-page="profile"] .profile-refresh { grid-column: 1 / -1; }
}

@media (max-width: 480px) {
  .landing-actions { flex-direction: column; align-items: stretch; }
  .landing-actions .button { width: 100%; }
}
