:root {
  --bg: var(--tg-theme-bg-color, #0f1220);
  --bg-2: var(--tg-theme-secondary-bg-color, #171a2b);
  --text: var(--tg-theme-text-color, #eef1ff);
  --hint: var(--tg-theme-hint-color, #8b91a8);
  --link: var(--tg-theme-link-color, #7c9dff);
  --button: var(--tg-theme-button-color, #7c5cff);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: #ff5d6c;
  --ok: #31d0a5;
  --warn: #ffb020;
  --card: rgba(255, 255, 255, 0.055);
  --card-strong: rgba(255, 255, 255, 0.09);
  --line: rgba(255, 255, 255, 0.09);
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.28);
  --radius: 18px;
  --radius-sm: 12px;
  --accent: linear-gradient(135deg, #7c5cff 0%, #4f8cff 55%, #32d1c0 100%);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

body.light {
  --bg: var(--tg-theme-bg-color, #f6f7fb);
  --bg-2: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #14172a);
  --hint: var(--tg-theme-hint-color, #6d7386);
  --card: rgba(20, 23, 42, 0.055);
  --card-strong: rgba(20, 23, 42, 0.09);
  --line: rgba(20, 23, 42, 0.1);
  --shadow: 0 12px 30px rgba(20, 23, 42, 0.12);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body {
  background-image:
    radial-gradient(900px 380px at 110% -10%, rgba(124, 92, 255, 0.18), transparent 60%),
    radial-gradient(700px 320px at -20% 5%, rgba(50, 209, 192, 0.12), transparent 60%);
  background-attachment: fixed;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--link); }

.app {
  max-width: 760px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: calc(10px + var(--safe-top)) 14px calc(92px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 2px 12px;
}

.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; letter-spacing: -0.02em; }
.brand-mark { font-size: 24px; filter: drop-shadow(0 4px 10px rgba(124, 92, 255, 0.5)); }
.brand-text { font-size: 20px; }

.chip {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 8px 13px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  transition: transform .12s ease, background .2s ease;
}
.chip:active { transform: scale(.97); }
.chip-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 10px var(--ok); }

.view { flex: 1; }

.tabbar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(10px + var(--safe-bottom));
  width: min(732px, calc(100% - 20px));
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 6px;
  border-radius: 20px;
  background: color-mix(in srgb, var(--bg-2) 88%, transparent);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  z-index: 20;
}

.tab {
  border: 0;
  background: transparent;
  color: var(--hint);
  border-radius: 14px;
  padding: 7px 4px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 10.5px;
  font-weight: 600;
  transition: background .18s ease, color .18s ease, transform .12s ease;
}
.tab .tab-icon { font-size: 19px; line-height: 1.1; }
.tab.active { color: var(--text); background: var(--card-strong); }
.tab:active { transform: scale(.97); }

.boot {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 28px;
  text-align: center;
}
.boot-logo { font-size: 56px; filter: drop-shadow(0 10px 26px rgba(124, 92, 255, .5)); animation: float 3s ease-in-out infinite; }
@keyframes float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
.boot-title { font-size: 26px; font-weight: 800; letter-spacing: -0.03em; }
.boot-text { color: var(--hint); font-size: 14px; max-width: 340px; line-height: 1.5; }
.boot-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; width: min(320px, 100%); }

.h1 { font-size: 26px; font-weight: 800; letter-spacing: -0.035em; margin: 4px 0 4px; }
.h2 { font-size: 18px; font-weight: 750; letter-spacing: -0.02em; margin: 0 0 10px; }
.sub { color: var(--hint); font-size: 13.5px; line-height: 1.45; margin: 0 0 16px; }
.section { margin: 18px 0; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.muted { color: var(--hint); }
.small { font-size: 12px; }
.mono { font-variant-numeric: tabular-nums; }
.center { text-align: center; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}
.card + .card { margin-top: 10px; }
.card.tight { padding: 12px; }
.card.glow { background: linear-gradient(160deg, rgba(124,92,255,.16), rgba(50,209,192,.07)); }

.btn {
  border: 1px solid var(--line);
  background: var(--card-strong);
  color: var(--text);
  border-radius: 14px;
  padding: 11px 14px;
  font-weight: 650;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform .12s ease, filter .2s ease, background .2s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.975); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--button); border-color: transparent; color: var(--button-text); box-shadow: 0 10px 24px rgba(124, 92, 255, .28); }
.btn.accent { background: var(--accent); border-color: transparent; color: #fff; box-shadow: 0 10px 26px rgba(80, 120, 255, .32); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: rgba(255, 93, 108, .35); background: rgba(255, 93, 108, .08); }
.btn.small { padding: 7px 10px; font-size: 12.5px; border-radius: 11px; }
.btn.block { width: 100%; }
.btn.icon { width: 38px; height: 38px; padding: 0; border-radius: 12px; }

.input, .textarea, .select {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg-2);
  border-radius: 13px;
  padding: 12px 13px;
  outline: none;
  transition: border-color .2s ease, box-shadow .2s ease;
}
.input:focus, .textarea:focus, .select:focus { border-color: rgba(124, 92, 255, .7); box-shadow: 0 0 0 3px rgba(124, 92, 255, .16); }
.textarea { min-height: 92px; resize: vertical; }

.dropzone {
  border: 1.5px dashed rgba(124, 92, 255, .45);
  border-radius: 22px;
  padding: 34px 18px;
  text-align: center;
  background: linear-gradient(180deg, rgba(124,92,255,.10), rgba(124,92,255,.02));
  transition: background .2s ease, border-color .2s ease, transform .15s ease;
}
.dropzone.drag { background: rgba(124, 92, 255, .2); border-color: var(--link); transform: scale(1.01); }
.dropzone-icon { font-size: 42px; margin-bottom: 10px; }
.dropzone-title { font-weight: 750; font-size: 17px; margin-bottom: 6px; }
.dropzone-note { color: var(--hint); font-size: 12.5px; line-height: 1.45; }

.progress { height: 8px; background: var(--card-strong); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; width: 0%; border-radius: inherit; background: var(--accent); transition: width .35s ease; }
.progress.warm > span { background: linear-gradient(90deg, #ffb020, #ff7a59); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .01em;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--card-strong);
  color: var(--hint);
  white-space: nowrap;
}
.badge.ok { color: var(--ok); background: rgba(49, 208, 165, .12); }
.badge.warn { color: var(--warn); background: rgba(255, 176, 32, .12); }
.badge.danger { color: var(--danger); background: rgba(255, 93, 108, .12); }
.badge.info { color: var(--link); background: rgba(124, 157, 255, .13); }

.book-card { display: flex; flex-direction: column; gap: 10px; }
.book-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.book-title { font-weight: 750; font-size: 15.5px; line-height: 1.3; letter-spacing: -0.01em; }
.book-author { color: var(--hint); font-size: 12.5px; margin-top: 2px; }
.book-meta { display: flex; gap: 10px; flex-wrap: wrap; color: var(--hint); font-size: 12px; }
.book-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 9px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 11px 12px; }
.stat-label { color: var(--hint); font-size: 11px; margin-bottom: 3px; }
.stat-value { font-size: 17px; font-weight: 800; letter-spacing: -0.02em; }
.stat-value small { font-size: 11px; font-weight: 600; color: var(--hint); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.pill {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 7px 12px;
  white-space: nowrap;
  font-size: 12.5px;
  font-weight: 650;
  color: var(--hint);
}
.pill.active { color: #fff; background: var(--button); border-color: transparent; }

.voice-card { display: flex; flex-direction: column; gap: 10px; }
.voice-top { display: flex; gap: 11px; align-items: center; }
.avatar {
  width: 44px; height: 44px; border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 800;
  background: linear-gradient(140deg, rgba(124,92,255,.35), rgba(50,209,192,.22));
  border: 1px solid var(--line);
  flex: 0 0 auto;
}
.voice-name { font-weight: 750; font-size: 14.5px; line-height: 1.25; }
.voice-tags { color: var(--hint); font-size: 11.5px; margin-top: 3px; line-height: 1.35; }
.voice-card.selected { border-color: rgba(124, 92, 255, .65); box-shadow: 0 0 0 1px rgba(124,92,255,.25) inset; }
.voice-actions { display: flex; gap: 7px; flex-wrap: wrap; }

.package-grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
.package { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.package-title { font-weight: 750; font-size: 15px; }
.package-desc { color: var(--hint); font-size: 12px; margin-top: 2px; }
.price { font-weight: 800; font-size: 15px; white-space: nowrap; }

.chapter-list { display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow: auto; }
.chapter {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 8px 10px; border-radius: 10px; background: var(--card);
  font-size: 12.5px;
}
.chapter span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.preview-text {
  max-height: 300px;
  overflow: auto;
  white-space: pre-wrap;
  line-height: 1.6;
  font-size: 13.5px;
  color: var(--text);
  padding: 12px;
  border-radius: 14px;
  background: var(--bg-2);
  border: 1px solid var(--line);
}

.detail-head { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 12px; }
.detail-cover {
  width: 62px; height: 86px; border-radius: 12px;
  background: linear-gradient(160deg, rgba(124,92,255,.5), rgba(50,209,192,.3));
  display: flex; align-items: center; justify-content: center; font-size: 28px;
  flex: 0 0 auto; border: 1px solid var(--line);
}

.slider-row { display: flex; align-items: center; gap: 12px; }
input[type="range"] { -webkit-appearance: none; appearance: none; height: 6px; background: var(--card-strong); border-radius: 999px; flex: 1; outline: none; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 22px; border-radius: 50%; background: var(--button); border: 3px solid var(--bg); box-shadow: 0 2px 8px rgba(0,0,0,.3); }
input[type="range"]::-moz-range-thumb { width: 20px; height: 20px; border: 3px solid var(--bg); border-radius: 50%; background: var(--button); }

.modal-root { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; background: rgba(3, 5, 12, .62); backdrop-filter: blur(4px); }
.modal-root[hidden] { display: none; }
.modal {
  width: min(760px, 100%);
  max-height: 88dvh;
  overflow: auto;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 24px 24px 0 0;
  padding: 18px 16px calc(20px + var(--safe-bottom));
  box-shadow: 0 -20px 50px rgba(0,0,0,.35);
  animation: slideUp .22s ease-out;
}
@keyframes slideUp { from { transform: translateY(24px); opacity: .6; } to { transform: translateY(0); opacity: 1; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }

.toast-root { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(96px + var(--safe-bottom)); z-index: 80; display: flex; flex-direction: column; gap: 8px; width: min(420px, calc(100% - 28px)); pointer-events: none; }
.toast {
  background: rgba(18, 21, 36, .94);
  color: #fff;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 14px;
  padding: 11px 14px;
  font-size: 13px;
  line-height: 1.35;
  box-shadow: var(--shadow);
  animation: toastIn .2s ease-out;
}
.toast.error { background: rgba(120, 24, 38, .96); }
.toast.ok { background: rgba(14, 84, 67, .96); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.empty { text-align: center; padding: 38px 18px; color: var(--hint); }
.empty-icon { font-size: 44px; margin-bottom: 10px; opacity: .9; }
.empty-title { color: var(--text); font-weight: 750; font-size: 17px; margin-bottom: 6px; }
.empty-text { font-size: 13px; line-height: 1.5; max-width: 300px; margin: 0 auto 16px; }

.list { display: flex; flex-direction: column; gap: 9px; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--hint); }
.kv .v { font-weight: 650; text-align: right; }

.audio-wrap { background: var(--bg-2); border: 1px solid var(--line); border-radius: 16px; padding: 10px; }
audio { width: 100%; height: 42px; }

.notice { border-radius: 14px; padding: 11px 12px; font-size: 12.5px; line-height: 1.45; border: 1px solid var(--line); background: var(--card); }
.notice.warn { border-color: rgba(255,176,32,.35); background: rgba(255,176,32,.08); color: var(--text); }
.notice.danger { border-color: rgba(255,93,108,.35); background: rgba(255,93,108,.08); }
.notice.ok { border-color: rgba(49,208,165,.35); background: rgba(49,208,165,.08); }

.spinner { width: 18px; height: 18px; border: 2px solid rgba(255,255,255,.25); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton { background: linear-gradient(90deg, var(--card) 25%, var(--card-strong) 50%, var(--card) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: 12px; }
@keyframes shimmer { to { background-position: -200% 0; } }

.footer-links { margin: 28px 0 10px; display: flex; gap: 14px; justify-content: center; font-size: 11.5px; color: var(--hint); }

@media (min-width: 640px) {
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
  .package-grid { grid-template-columns: repeat(3, 1fr); }
  .package { flex-direction: column; align-items: flex-start; }
  .modal-root { align-items: center; }
  .modal { border-radius: 24px; max-width: 640px; }
}

/* Юридические страницы */
.doc {
  max-width: 720px;
  margin: 0 auto;
  padding: 28px 18px calc(40px + var(--safe-bottom));
  line-height: 1.62;
  font-size: 14.5px;
}
.doc h1 { font-size: 25px; letter-spacing: -0.03em; margin: 0 0 6px; }
.doc h2 { font-size: 17px; letter-spacing: -0.01em; margin: 26px 0 8px; }
.doc p { margin: 0 0 12px; color: var(--text); }
.doc ul { margin: 0 0 12px; padding-left: 20px; }
.doc li { margin-bottom: 6px; }
.doc .doc-date { color: var(--hint); font-size: 12.5px; margin-bottom: 22px; }
.doc .doc-back {
  display: inline-flex; align-items: center; gap: 6px;
  margin-bottom: 18px; font-size: 13px; font-weight: 650;
  text-decoration: none; color: var(--link);
}
.doc .doc-note {
  border: 1px solid var(--line); background: var(--card);
  border-radius: 14px; padding: 12px 14px; margin: 16px 0;
  font-size: 13px; color: var(--hint);
}
.doc code {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 12.5px; background: var(--card-strong);
  border-radius: 6px; padding: 1px 5px;
}
