:root {
  --bg: #0c0a0a;
  --surface: #1c1616;
  --surface-2: #2a2121;
  --nav: #141010;
  --line: #2a2121;
  --line-2: #3a2e2e;
  --hair: #231b1b;
  --dash: #5a4646;
  --track: #2e2424;
  --text: #f6f1ef;
  --soft: #d4cac5;
  --muted: #a39892;
  --dim: #8f8480;
  --accent: #e5413b;
  --accent-soft: #ff7a75;
  --danger: #ff6b66;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px 'Onest', system-ui, -apple-system, 'Segoe UI', sans-serif; min-height: 100vh; overflow-x: hidden; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; cursor: pointer; }
svg { flex-shrink: 0; }
.hidden { display: none !important; }

/* ---------- раскладка ---------- */
.screen { display: flex; flex-direction: column; gap: 22px; padding: 16px; max-width: 640px; margin: 0 auto; }
.screen.g20 { gap: 20px; }
.screen.g18 { gap: 18px; }
.screen.g16 { gap: 16px; }
.screen.admin-home { gap: 24px; padding-top: 20px; }
.screen.with-tabbar { padding-bottom: calc(84px + var(--safe-bottom)); }
.screen.with-cta { padding-bottom: calc(120px + var(--safe-bottom)); }
.screen.empty { min-height: 80vh; align-items: center; justify-content: center; text-align: center; gap: 14px; }
.screen.empty .btn { width: 100%; max-width: 320px; }
.row { display: flex; align-items: center; }
.col { display: flex; flex-direction: column; min-width: 0; }
.between { justify-content: space-between; }
.base { align-items: baseline; }
.top { align-items: flex-start; }
.wrap { flex-wrap: wrap; }
.grow { flex-grow: 1; min-width: 0; }
.jc { justify-content: center; }
.je { justify-content: flex-end; }
.center { align-items: center; text-align: center; }
.gap1 { gap: 1px; } .gap2 { gap: 2px; } .gap4 { gap: 4px; } .gap6 { gap: 6px; } .gap8 { gap: 8px; }
.gap10 { gap: 10px; } .gap12 { gap: 12px; } .gap14 { gap: 14px; }
section { display: flex; flex-direction: column; }

/* ---------- текст ---------- */
.h1 { font-family: 'Unbounded', 'Onest', sans-serif; font-weight: 700; font-size: 20px; }
.h2 { font-family: 'Unbounded', 'Onest', sans-serif; font-weight: 700; font-size: 19px; line-height: 1.2; }
.t14 { font-size: 14px; } .t15 { font-size: 15px; } .t17 { font-size: 17px; }
.b { font-weight: 700; } .sb { font-weight: 600; }
.sm { font-size: 13px; } .xs { font-size: 12px; }
.muted { color: var(--muted); }
.clip { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.eyebrow { font-size: 12px; color: var(--accent); font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.caps { font-size: 13px; color: var(--muted); font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.label { font-size: 13px; color: var(--muted); font-weight: 600; display: flex; align-items: baseline; gap: 8px; }
.desc { font-size: 14px; line-height: 1.5; color: var(--soft); white-space: pre-line; }

/* ---------- кнопки ---------- */
.btn {
  height: 52px; padding: 0 18px; border: 0; border-radius: 14px; background: var(--surface); color: var(--text);
  font-size: 15px; font-weight: 700; display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
}
.btn svg { width: 18px; height: 18px; }
.btn.accent { background: var(--accent); color: #fff; }
.btn.dark { background: var(--surface-2); font-weight: 600; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.sm { height: 44px; border-radius: 12px; font-size: 14px; }
.btn.square { width: 52px; padding: 0; color: var(--muted); }
.btn.square[aria-pressed="true"] { color: var(--accent); }
.btn.square svg { width: 22px; height: 22px; }
.btn:disabled { opacity: .45; cursor: default; }
.btn:not(:disabled):active { transform: scale(.98); }
.danger-text { color: var(--danger) !important; }
.icon-btn { width: 44px; height: 44px; border: 0; background: transparent; color: var(--text); display: flex; align-items: center; justify-content: center; border-radius: 12px; }
.icon-btn.round { border-radius: 22px; background: var(--surface); }
.icon-btn.round svg { width: 20px; height: 20px; }
.icon-btn.danger { color: var(--dim); }
.link-btn { border: 0; background: none; padding: 4px 0; color: var(--accent-soft); font-size: 13px; font-weight: 600; }
.link-btn.muted { color: var(--muted); font-weight: 400; }
.add-link { height: 36px; border: 0; background: none; padding: 0; display: flex; align-items: center; color: var(--accent-soft); font-size: 14px; font-weight: 600; }
.cta-row { display: grid; grid-template-columns: minmax(0, 1fr) 52px; gap: 8px; }
.chev { width: 18px; height: 18px; color: var(--muted); }

/* ---------- обложки и карточки ---------- */
.cover { border-radius: 12px; background: #3a3030 center / cover no-repeat; flex-shrink: 0; }
.cover.big { width: 120px; height: 170px; }
.cover.thumb { width: 36px; height: 50px; border-radius: 6px; }
.cover.mini { width: 26px; height: 36px; border-radius: 4px; }
.continue { display: flex; gap: 14px; padding: 12px; border-radius: 16px; background: var(--surface); }
.continue .cover { width: 84px; height: 118px; border-radius: 10px; }
.bar { height: 6px; border-radius: 3px; background: var(--track); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); transition: width .2s; }
.continue .bar i { border-radius: 3px; }
.bar.w70 { width: 70px; height: 5px; }
.hscroll { display: flex; gap: 10px; overflow-x: auto; margin: 0 -16px; padding: 0 16px; scrollbar-width: none; }
.hscroll::-webkit-scrollbar { display: none; }
.tcard { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.tcard .cover { height: 150px; display: flex; flex-direction: column; align-items: flex-start; padding: 6px; }
.tcard.w112 { width: 112px; flex-shrink: 0; }
.grid3 .tcard.w112 { width: auto; }
.tname { font-size: 13px; font-weight: 600; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.badge { padding: 3px 7px; border-radius: 6px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.span3 { grid-column: 1 / -1; padding: 8px 0; }
.pill { padding: 4px 9px; border-radius: 8px; background: var(--surface); font-size: 12px; font-weight: 600; }
.tag { padding: 3px 8px; border-radius: 6px; border: 1px solid var(--accent); color: var(--accent); font-size: 12px; font-weight: 700; }
.ch-row { min-height: 54px; border-radius: 12px; background: var(--surface); padding: 8px 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.ch-row.read { color: var(--dim); }
.ch-row svg { width: 14px; height: 14px; }

/* ---------- заглушки: прозрачные места под будущие тайтлы, видны только админу ---------- */
.ghost .cover { background: rgba(246, 241, 239, .03); border: 1.5px dashed var(--dash); }
.tcard.ghost .cover { align-items: center; justify-content: center; font-size: 22px; color: var(--dim); }
.ghost .tname, .ghost .t17 { color: var(--dim); }
.continue.ghost { background: transparent; border: 1.5px dashed var(--line-2); }
.tcard.ghost:active .cover { border-color: var(--accent); color: var(--accent); }

/* ---------- чипсы и поля ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; gap: 6px; }
.chip { height: 34px; padding: 0 14px; border-radius: 17px; border: 1px solid var(--line-2); background: transparent; font-size: 13px; font-weight: 600; white-space: nowrap; flex-shrink: 0; }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip.g { padding: 0 12px; }
.chip.g.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.chip.add { width: 34px; padding: 0; border-style: dashed; border-color: var(--dash); font-size: 16px; }
.chip-input { height: 34px; width: 110px; padding: 0 12px; border-radius: 17px; border: 1px solid var(--accent); background: transparent; font-size: 13px; outline: none; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); min-width: 0; }
.input { width: 100%; height: 46px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line-2); background: var(--surface); color: var(--text); font-size: 15px; font-weight: 400; outline: none; }
.input.sb { font-weight: 600; }
.input::placeholder { color: var(--dim); }
.input:focus { border-color: var(--accent); }
textarea.input { height: 84px; padding: 12px; resize: none; }
.tform .input { padding: 0 12px; }
.tform textarea.input { padding: 12px; }
.picker { position: relative; height: 50px; padding: 0 12px 0 8px; border-radius: 12px; border: 1px solid var(--line-2); background: var(--surface); color: var(--text); display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 600; }
.picker select { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; appearance: none; border: 0; font-size: 16px; }
.num-grid { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 8px; }
.search-input { height: 48px; }
.seg { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; padding: 3px; border-radius: 12px; background: var(--surface); }
.seg button { height: 38px; padding: 0; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-size: 14px; font-weight: 600; }
.seg button.on { background: var(--line-2); color: var(--text); }

/* ---------- списки и переключатели ---------- */
.list-card { display: flex; flex-direction: column; border-radius: 16px; background: var(--surface); overflow: hidden; }
.list-card.r14 { border-radius: 14px; }
.li { min-height: 56px; padding: 8px 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border: 0; border-bottom: 1px solid var(--line); background: transparent; font-size: 15px; text-align: left; width: 100%; }
.li:last-child { border-bottom: 0; }
.list-card.r14 .li { min-height: 54px; }
.trow { padding: 10px 14px 10px 10px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); }
.trow:last-child { border-bottom: 0; }
.sched { width: 100%; padding: 12px 14px; border: 0; border-radius: 12px; background: var(--surface); display: flex; align-items: center; gap: 12px; text-align: left; }
.sched > svg:first-child { width: 20px; height: 20px; color: var(--muted); }
.row-card { display: flex; align-items: center; gap: 12px; padding: 10px 14px; min-height: 60px; border-radius: 14px; background: var(--surface); border: 0; text-align: left; width: 100%; font-size: 15px; }
.free-card { padding: 10px 14px; border-radius: 14px; background: var(--surface); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.toggle { width: 48px; height: 28px; flex-shrink: 0; border-radius: 14px; border: 0; background: var(--line-2); padding: 3px; display: flex; transition: background .2s; }
.toggle i { width: 22px; height: 22px; border-radius: 11px; background: var(--muted); transition: transform .2s, background .2s; }
.toggle.on { background: var(--accent); }
.toggle.on i { transform: translateX(20px); background: var(--bg); }
.toggle.w.on i { background: #fff; }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button { width: 36px; height: 36px; padding: 0; border-radius: 10px; border: 0; background: var(--surface-2); font-size: 18px; font-weight: 600; }
.stepper div { width: 28px; text-align: center; font-size: 16px; font-weight: 700; }
.when { position: relative; display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 14px; }
.when .chev { color: inherit; }
.when input { position: absolute; inset: 0; opacity: 0; width: 100%; }
.when.sort { font-size: 13px; }
.when select { position: absolute; inset: 0; opacity: 0; width: 100%; appearance: none; border: 0; font-size: 16px; }

/* ---------- профиль ---------- */
.avatar { width: 56px; height: 56px; border-radius: 28px; background: #4a2626; display: flex; align-items: center; justify-content: center; font-family: 'Unbounded', sans-serif; font-weight: 700; font-size: 20px; object-fit: cover; flex-shrink: 0; }
.sub-card { padding: 16px; border-radius: 18px; background: var(--surface); border: 1px solid var(--line-2); display: flex; flex-direction: column; gap: 12px; }
.sub-card .btn { height: 50px; }
.lock-big { width: 72px; height: 72px; border-radius: 36px; background: var(--surface); color: var(--accent); display: flex; align-items: center; justify-content: center; }
.lock-big svg { width: 32px; height: 32px; }

/* ---------- админка ---------- */
.cover-pick { width: 108px; height: 152px; flex-shrink: 0; border-radius: 12px; border: 1.5px dashed var(--dash); background: var(--surface) center / cover no-repeat; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.cover-hint { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--soft); }
.cover-hint svg { width: 24px; height: 24px; }
.thumbs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.thumb-img, .thumb-more, .thumb-add { height: 64px; border-radius: 8px; }
.thumb-img, .thumb-more { padding: 5px; font-size: 11px; font-weight: 700; color: var(--soft); }
.thumb-img { background: #2a2525 center / cover no-repeat; text-shadow: 0 1px 2px rgba(0, 0, 0, .8); }
.thumb-img:nth-child(8n+2), .thumb-img:nth-child(8n+4), .thumb-img:nth-child(8n+5), .thumb-img:nth-child(8n+7) { background-color: #332d2d; }
.thumb-more { background: #332d2d; display: flex; align-items: flex-end; justify-content: center; }
.thumb-add { border: 1.5px dashed var(--dash); background: transparent; color: var(--text); display: flex; align-items: center; justify-content: center; }
.cta-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; padding: 12px 16px calc(16px + var(--safe-bottom)); background: var(--bg); border-top: 1px solid var(--hair); display: flex; flex-direction: column; gap: 6px; }
.cta-bar > * { max-width: 608px; margin: 0 auto; width: 100%; }

/* ---------- таббар ---------- */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; height: calc(68px + var(--safe-bottom)); padding-bottom: var(--safe-bottom); display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); background: var(--nav); border-top: 1px solid #2a2020; }
.tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; color: var(--muted); font-size: 12px; font-weight: 600; }
.tabbar a.on { color: var(--accent); }

/* ---------- читалка ---------- */
body.v-reader { background: #000; }
.reader { min-height: 100vh; background: #000; }
.r-top { position: fixed; top: 0; left: 0; right: 0; z-index: 10; height: 60px; padding: 0 8px; background: var(--bg); display: grid; grid-template-columns: 44px minmax(0, 1fr) 44px; align-items: center; transition: transform .25s; }
.r-top .icon-btn svg { width: 24px; height: 24px; }
.r-count { font-size: 13px; color: var(--muted); text-align: center; }
.pages { padding-top: 60px; max-width: 800px; margin: 0 auto; }
.pages { background: #151212; }
/* страница показывается целиком, когда загрузилась, а не прорисовывается полосками сверху вниз */
.pages img { display: block; width: 100%; height: auto; min-height: 60vh; opacity: 0; transition: opacity .15s; }
.pages img.loaded { min-height: 0; opacity: 1; background: #000; }
.r-end { max-width: 800px; margin: 0 auto; padding: 32px 16px calc(150px + var(--safe-bottom)); display: flex; flex-direction: column; align-items: center; gap: 14px; }
.r-bottom { position: fixed; left: 10px; right: 10px; bottom: calc(12px + var(--safe-bottom)); z-index: 10; max-width: 620px; margin: 0 auto; padding: 12px; border-radius: 18px; background: var(--surface); display: flex; flex-direction: column; gap: 10px; transition: transform .25s, opacity .25s; }
.r-bottom .bar { height: 5px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
body.ui-hidden .r-top { transform: translateY(-100%); }
body.ui-hidden .r-bottom { transform: translateY(140%); opacity: 0; }

/* ---------- прочее ---------- */
.loader { width: 32px; height: 32px; margin: 40vh auto 0; border-radius: 50%; border: 3px solid var(--track); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#toast { position: fixed; left: 50%; top: 16px; z-index: 50; transform: translate(-50%, calc(-100% - 32px)); max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 12px; background: #2d2424; color: var(--text); font-size: 14px; box-shadow: 0 6px 24px rgba(0, 0, 0, .4); transition: transform .25s; pointer-events: none; }
#toast.show { transform: translate(-50%, 0); }

/* ---------- ВКонтакте: своя кнопка «назад» (в Telegram она встроена в шапку) ---------- */
#vkback { display: none; position: fixed; top: 8px; left: 8px; z-index: 40; box-shadow: 0 4px 16px rgba(0, 0, 0, .4); }
body.has-vkback #vkback { display: flex; }
body.has-vkback #app { padding-top: 52px; }
