/* Minimal and flat: one card surface, one accent, hairline dividers — no
   gradients, no decorative shapes, almost no shadows. Colour comes from the
   animated custom emoji (.tge, played by lottie-web) and the faint platform
   tint of file tiles. Light/dark follows Telegram's colorScheme (app.js sets
   data-theme on <html>; without Telegram, prefers-color-scheme decides). */
:root, :root[data-theme="light"] {
  --bg: #f4f5f8;
  --card: #ffffff;
  --card-2: #f1f2f6;
  --text: #16181f;
  --hint: #7d8294;
  --sep: #eceef3;
  --link: #2f6bff;
  --accent: #2f6bff;
  --accent-text: #ffffff;
  --danger: #e5384a;
  --ok: #16a464;
  --shadow: 0 1px 2px rgba(20, 28, 50, .04);
  --tabbar: rgba(255, 255, 255, .92);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #16181f;
  --card: #1f222b;
  --card-2: #2a2e39;
  --text: #f2f3f7;
  --hint: #8e93a4;
  --sep: #2c303b;
  --link: #6f9bff;
  --accent: #4f83ff;
  --accent-text: #ffffff;
  --danger: #ff5c6b;
  --ok: #34c77b;
  --shadow: none;
  --tabbar: rgba(31, 34, 43, .94);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #16181f; --card: #1f222b; --card-2: #2a2e39; --text: #f2f3f7; --hint: #8e93a4; --sep: #2c303b;
    --link: #6f9bff; --accent: #4f83ff; --danger: #ff5c6b; --ok: #34c77b; --shadow: none; --tabbar: rgba(31, 34, 43, .94);
    color-scheme: dark;
  }
}
:root {
  --radius: 18px;
  --tabbar-h: 64px;
  --safe-b: var(--tg-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input { font: inherit; color: inherit; }
svg { display: block; flex: none; }
[hidden] { display: none !important; }

.view {
  padding: 12px 12px calc(var(--tabbar-h) + var(--safe-b) + 28px);
  min-height: 100vh;
  max-width: 640px;
  margin: 0 auto;
}
.view.no-tabbar { padding-bottom: calc(var(--safe-b) + 24px); }

.card {
  background: var(--card);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

/* Animated custom emoji: the plain glyph shows until the Lottie replaces it. */
.tge { width: var(--s, 24px); height: var(--s, 24px); display: inline-grid; place-items: center; flex: none; line-height: 1; }
.tge > * { grid-area: 1 / 1; }
.tge > i { font-style: normal; font-size: calc(var(--s, 24px) * .8); }
.tge > svg { width: 100% !important; height: 100% !important; }

/* ── Header ─────────────────────────────────────────────────────────────── */
.hero-head { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow); }
.profile { display: flex; align-items: center; gap: 14px; }
.avatar {
  width: 48px; height: 48px; border-radius: 50%; flex: none; position: relative; overflow: hidden;
  background: var(--card-2); color: var(--hint);
  display: grid; place-items: center; font-weight: 600; font-size: 20px;
}
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.profile .name { flex: 1; min-width: 0; font-size: 21px; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill-premium {
  flex: none; display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px 4px 6px; border-radius: 999px;
  background: var(--card-2); color: var(--text);
  font-size: 13px; font-weight: 600; white-space: nowrap;
}
.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.quick button { display: flex; align-items: center; gap: 10px; text-align: left; background: var(--card-2); border-radius: 14px; padding: 10px 12px; }
.quick b { display: block; font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
.quick span { font-size: 12px; color: var(--hint); }

/* ── Search ─────────────────────────────────────────────────────────────── */
.searchbar { display: flex; gap: 8px; padding: 12px 12px 6px; }
.search {
  flex: 1; display: flex; align-items: center; gap: 10px;
  background: var(--card-2); border-radius: 12px; padding: 0 12px; height: 44px; color: var(--hint);
}
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font-size: 16px; color: var(--text); }
.search input::placeholder { color: var(--hint); }
.search input::-webkit-search-cancel-button { display: none; }
.search .clear { color: var(--hint); }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--card-2); color: var(--hint); position: relative; }
.icon-btn.active { color: var(--accent); }
.icon-btn .dot { position: absolute; top: 9px; right: 9px; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }

/* ── File list ──────────────────────────────────────────────────────────── */
.group-title { padding: 10px 16px 2px; color: var(--hint); font-size: 13px; font-weight: 600; }
.row { display: flex; align-items: center; gap: 14px; padding: 10px 12px 10px 14px; width: 100%; text-align: left; position: relative; }
.row + .row::before { content: ""; position: absolute; top: 0; left: 78px; right: 14px; border-top: 1px solid var(--sep); }
.row:active { background: var(--card-2); }
.thumb {
  --tint: var(--hint);
  width: 50px; height: 50px; border-radius: 14px; flex: none;
  background: color-mix(in srgb, var(--tint) 10%, var(--card));
  display: grid; place-items: center;
}
.row .body { flex: 1; min-width: 0; }
.row .title { font-weight: 600; font-size: 15.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .meta { margin-top: 3px; color: var(--hint); font-size: 13px; display: flex; align-items: center; gap: 6px; white-space: nowrap; overflow: hidden; }
.row .meta .rest { overflow: hidden; text-overflow: ellipsis; }
.src { display: inline-flex; align-items: center; gap: 3px; color: var(--link); flex: none; max-width: 48%; }
.src span { overflow: hidden; text-overflow: ellipsis; }
.chev { color: var(--hint); opacity: .5; }

.empty { padding: 28px 24px 30px; text-align: center; color: var(--hint); }
.empty .big { margin: 0 auto 12px; width: 64px; height: 64px; display: grid; place-items: center; }
.empty h3 { color: var(--text); margin: 0 0 6px; font-size: 17px; font-weight: 600; }
.empty p { margin: 0 auto; max-width: 300px; }
.more { padding: 14px; text-align: center; color: var(--hint); font-size: 13px; }
.skeleton { height: 70px; margin: 0 12px; border-radius: 14px; background: var(--card-2); animation: pulse 1.2s infinite ease-in-out; }
.skeleton + .skeleton { margin-top: 8px; }
@keyframes pulse { 50% { opacity: .55; } }

/* ── Tab bar ────────────────────────────────────────────────────────────── */
.tabbar {
  position: fixed; left: 12px; right: 12px; bottom: calc(var(--safe-b) + 10px); z-index: 10;
  max-width: 616px; margin: 0 auto;
  display: flex; padding: 5px; gap: 4px; border-radius: 22px;
  background: var(--tabbar); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--sep);
}
.tab {
  flex: 1; height: 52px; border-radius: 17px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--hint); font-size: 11.5px; font-weight: 600; transition: background .15s, color .15s;
}
.tab.active { color: var(--accent); background: var(--card-2); }

/* ── Lists (settings) ───────────────────────────────────────────────────── */
.section-title { padding: 10px 6px 6px; color: var(--hint); font-size: 13px; font-weight: 600; }
.cell { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 11px 14px; min-height: 54px; position: relative; }
.cell + .cell::before { content: ""; position: absolute; top: 0; left: 58px; right: 14px; border-top: 1px solid var(--sep); }
button.cell:active { background: var(--card-2); }
.tile { width: 32px; height: 32px; display: grid; place-items: center; flex: none; }
.cell .label { flex: 1; min-width: 0; }
.cell .label small { display: block; color: var(--hint); font-size: 13px; margin-top: 1px; }
.cell .value { color: var(--hint); white-space: nowrap; }
.cell.danger .label { color: var(--danger); }
.footer-note { text-align: center; color: var(--hint); font-size: 12px; padding: 8px 16px 4px; }

/* ── Premium ────────────────────────────────────────────────────────────── */
.prem-hero { background: var(--card); border-radius: var(--radius); padding: 22px 18px 20px; margin-bottom: 12px; text-align: center; box-shadow: var(--shadow); }
.prem-hero .tge { margin: 0 auto 6px; }
.prem-hero h2 { margin: 0 0 6px; font-size: 21px; font-weight: 700; }
.prem-hero p { margin: 0 auto; max-width: 320px; color: var(--hint); }
.prem-hero .status { display: inline-flex; align-items: center; gap: 6px; margin-top: 14px; padding: 5px 12px 5px 8px; border-radius: 999px; background: var(--card-2); color: var(--ok); font-size: 13px; font-weight: 600; }
.meter { padding: 14px 16px; }
.meter + .meter { border-top: 1px solid var(--sep); }
.meter .top { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.meter .top b { flex: 1; font-size: 15px; font-weight: 600; }
.meter .top span { color: var(--hint); font-size: 14px; font-variant-numeric: tabular-nums; }
.bar { height: 6px; border-radius: 3px; background: var(--card-2); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 3px; background: var(--accent); transition: width .4s ease; }
.bar i.warn { background: #f5a524; }
.bar i.full { background: var(--danger); }
.reset { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--sep); color: var(--hint); font-size: 13px; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.stats .card { margin: 0; padding: 14px; display: flex; align-items: center; gap: 12px; }
.stats b { display: block; font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stats span { color: var(--hint); font-size: 12px; }
.perk { display: flex; gap: 12px; padding: 12px 14px; align-items: center; }
.perk + .perk { border-top: 1px solid var(--sep); }
.perk b { display: block; font-weight: 600; }
.perk span { color: var(--hint); font-size: 13px; }
.notice { padding: 14px; display: flex; gap: 12px; align-items: center; }
.notice span { color: var(--hint); font-size: 14px; }

/* ── Sheets ─────────────────────────────────────────────────────────────── */
.backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(10, 12, 20, .4); opacity: 0; transition: opacity .2s ease; }
.backdrop.open { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51;
  max-width: 640px; margin: 0 auto; max-height: 88vh; overflow-y: auto;
  background: var(--card); border-radius: 22px 22px 0 0;
  padding: 8px 16px calc(var(--safe-b) + 16px);
  transform: translateY(100%); transition: transform .26s cubic-bezier(.2, .8, .2, 1);
}
.sheet.open { transform: none; }
.sheet .grabber { width: 36px; height: 4px; border-radius: 2px; background: var(--sep); margin: 0 auto 14px; }
.sheet h3 { margin: 2px 0 14px; font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.sheet .hero-file { display: flex; gap: 14px; align-items: center; margin-bottom: 16px; }
.sheet .hero-file .thumb { width: 60px; height: 60px; border-radius: 16px; }
.sheet .hero-file .t { font-weight: 700; font-size: 17px; word-break: break-word; }
.sheet .hero-file .a { color: var(--hint); margin-top: 2px; }
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 14px; }
.kv div { padding: 10px 12px; background: var(--card-2); border-radius: 12px; }
.kv span { display: block; color: var(--hint); font-size: 12px; }
.kv b { font-weight: 600; font-variant-numeric: tabular-nums; word-break: break-word; }
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; height: 50px;
  border-radius: 14px; font-weight: 600; font-size: 16px; margin-top: 8px;
  background: var(--card-2); color: var(--text);
}
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); }
.btn:active { opacity: .85; }
.btn:disabled { opacity: .6; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.chip { padding: 7px 14px; border-radius: 999px; background: var(--card-2); font-size: 14px; }
.chip.on { background: var(--text); color: var(--card); }
.sheet .label { color: var(--hint); font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.opt { display: flex; align-items: center; width: 100%; padding: 13px 2px; border-bottom: 1px solid var(--sep); text-align: left; gap: 12px; }
.opt:last-child { border-bottom: 0; }
.opt .check { margin-left: auto; color: var(--accent); }
.plat-tag { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; font-size: 10.5px; font-weight: 700; flex: none; }

/* ── Terms ──────────────────────────────────────────────────────────────── */
.doc-head { background: var(--card); border-radius: var(--radius); padding: 18px; margin-bottom: 12px; box-shadow: var(--shadow); }
.doc-head .top { display: flex; align-items: center; justify-content: space-between; }
.doc-head h1 { font-size: 23px; margin: 10px 0 4px; line-height: 1.2; font-weight: 700; }
.doc-head .updated { color: var(--hint); font-size: 13px; }
.lang-switch { display: inline-flex; background: var(--card-2); border-radius: 10px; padding: 3px; }
.lang-switch button { padding: 5px 12px; border-radius: 8px; font-size: 13px; color: var(--hint); font-weight: 600; }
.lang-switch button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }
.doc .lead { margin: 0; padding: 16px 18px; }
.toc { padding: 4px 0; }
.toc button { display: flex; width: 100%; gap: 12px; padding: 10px 16px; text-align: left; }
.toc button em { color: var(--hint); font-style: normal; min-width: 22px; font-variant-numeric: tabular-nums; }
.doc-section { padding: 18px 18px 6px; scroll-margin-top: 12px; }
.doc-section + .doc-section { border-top: 1px solid var(--sep); }
.doc-section h2 { font-size: 17px; font-weight: 700; margin: 0 0 10px; display: flex; gap: 10px; align-items: baseline; }
.doc-section h2 em { font-style: normal; color: var(--hint); font-weight: 600; }
.doc-section p { margin: 0 0 12px; }
.doc-section ul { margin: 0 0 12px; padding-left: 20px; }
.doc-section li { margin-bottom: 6px; }
.doc a { color: var(--link); text-decoration: none; }
.to-top { position: fixed; right: 16px; bottom: calc(var(--safe-b) + 20px); width: 44px; height: 44px; border-radius: 50%; background: var(--card); color: var(--text); border: 1px solid var(--sep); display: grid; place-items: center; z-index: 5; }

/* ── Toast ──────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 26px); z-index: 60;
  transform: translate(-50%, 16px); opacity: 0; pointer-events: none;
  display: flex; align-items: center; gap: 8px;
  background: var(--text); color: var(--bg); font-weight: 500;
  padding: 9px 16px 9px 10px; border-radius: 14px; font-size: 14px; max-width: calc(100% - 32px);
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.gate { min-height: 80vh; display: grid; place-items: center; text-align: center; padding: 24px; color: var(--hint); }
.gate h2 { color: var(--text); }

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