:root {
  --bg: #000;
  --fg: #fff;
  --muted: rgba(255, 255, 255, 0.65);
  --line: rgba(255, 255, 255, 0.14);
  --surface: #121212;
  --surface-2: #1e1e1e;
  --accent: #3797f0;
  --done: #4cd292;
  --tabbar-h: calc(50px + env(safe-area-inset-bottom));
  --safe-top: env(safe-area-inset-top);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); font-family: var(--font); font-size: 14px; overscroll-behavior: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input { font: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.center { text-align: center; }
code { background: var(--surface-2); padding: 1px 6px; border-radius: 4px; }

/* Іконки */
.i { display: inline-flex; width: 26px; height: 26px; }
.i svg { width: 100%; height: 100%; }
.i-sm { width: 14px; height: 14px; }
.i-lg { width: 40px; height: 40px; }

/* Каркас: на десктопі стрічка — вузька колонка по центру. */
.app { position: fixed; inset: 0; max-width: 480px; margin: 0 auto; overflow: hidden; background: var(--bg); }
.view { position: absolute; inset: 0 0 var(--tabbar-h) 0; }
.view-page { overflow-y: auto; padding: calc(var(--safe-top) + 12px) 12px 24px; }

/* Верхня панель */
.topbar { position: absolute; z-index: 5; top: 0; left: 0; right: 0; padding: calc(var(--safe-top) + 10px) 14px 10px; display: flex; align-items: center; justify-content: space-between; pointer-events: none; }
.topbar > * { pointer-events: auto; }
.title-btn { display: inline-flex; align-items: center; gap: 6px; font-size: 22px; font-weight: 700; text-shadow: 0 1px 6px rgba(0,0,0,.4); }
.topbar-actions { display: flex; gap: 14px; }
.icon-btn { display: inline-flex; filter: drop-shadow(0 1px 4px rgba(0,0,0,.45)); }

/* Стрічка */
.feed { height: 100%; overflow-y: scroll; scroll-snap-type: y mandatory; scrollbar-width: none; }
.feed::-webkit-scrollbar { display: none; }
.slide { position: relative; height: 100%; scroll-snap-align: start; scroll-snap-stop: always; overflow: hidden; background: #000; }
.slide img, .slide video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.slide.landscape img, .slide.landscape video { object-fit: contain; }
.slide::after { content: ""; position: absolute; inset: 55% 0 0 0; background: linear-gradient(transparent, rgba(0,0,0,.55)); pointer-events: none; }
.touch { position: absolute; inset: 0; z-index: 1; touch-action: pan-y; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }

.flash { position: absolute; z-index: 2; top: 50%; left: 50%; width: 72px; height: 72px; margin: -36px 0 0 -36px; border-radius: 50%; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; opacity: 0; pointer-events: none; transition: opacity .2s; }
.flash .i { width: 34px; height: 34px; }
.slide.paused .flash { opacity: 1; }
.speed-badge { position: absolute; z-index: 2; top: calc(var(--safe-top) + 64px); left: 50%; transform: translateX(-50%); background: rgba(0,0,0,.55); padding: 4px 12px; border-radius: 999px; font-weight: 600; opacity: 0; transition: opacity .15s; pointer-events: none; }
.slide.fast .speed-badge { opacity: 1; }
.burst { position: absolute; z-index: 2; top: 50%; left: 50%; width: 96px; height: 96px; margin: -48px 0 0 -48px; pointer-events: none; animation: burst .8s ease-out forwards; }
@keyframes burst { 0% { transform: scale(.3); opacity: 0; } 25% { transform: scale(1.15); opacity: 1; } 60% { transform: scale(1); opacity: 1; } 100% { transform: scale(1) translateY(-30px); opacity: 0; } }

/* Колонка дій справа */
.rail { position: absolute; z-index: 3; right: 8px; bottom: 22px; display: flex; flex-direction: column; align-items: center; gap: 18px; }
.rail-btn { color: inherit; text-decoration: none; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 12px; font-weight: 500; filter: drop-shadow(0 1px 3px rgba(0,0,0,.5)); }
.rail-btn .i { width: 28px; height: 28px; }
.rail-btn.on-done .i { color: var(--done); }
.rail-btn.on-fav .i svg { fill: currentColor; }
.cover { width: 28px; height: 28px; border-radius: 7px; border: 2px solid #fff; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; }

/* Підпис знизу зліва */
.meta { position: absolute; z-index: 3; left: 12px; right: 70px; bottom: 18px; }
.author { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; flex: none; }
.author-name { font-weight: 600; }
.count-pill { border: 1px solid rgba(255,255,255,.7); border-radius: 8px; padding: 2px 8px; font-size: 12px; font-weight: 600; }
.caption { line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; cursor: pointer; }
.caption.open { -webkit-line-clamp: 12; }
.sub { margin-top: 8px; font-size: 12px; display: flex; align-items: center; gap: 6px; opacity: .9; }
.sub .i { width: 13px; height: 13px; }

.progress { position: absolute; z-index: 3; left: 0; right: 0; bottom: 0; height: 2px; background: rgba(255,255,255,.25); }
.progress i { display: block; height: 100%; width: 0; background: #fff; }

/* Нижня панель вкладок */
.tabbar { position: absolute; z-index: 10; left: 0; right: 0; bottom: 0; height: var(--tabbar-h); padding-bottom: env(safe-area-inset-bottom); background: #000; border-top: 1px solid var(--line); display: flex; justify-content: space-around; align-items: center; }
/* Застосунок з головного екрана iOS з прозорим статус-баром: вікно закінчується вище за низ екрана,
   а під ним і так лишається чорна смуга з індикатором «додому» — власний відступ знизу не потрібен. */
.short-vp { --tabbar-h: 50px; }
.short-vp .tabbar { padding-bottom: 0; }
.tab { flex: 1; height: 50px; display: flex; align-items: center; justify-content: center; opacity: .55; }
.tab.active { opacity: 1; }

/* Сторінки: пошук, обране, статистика */
.page-head { margin-bottom: 12px; }
.page-head h1 { margin: 6px 0 4px; font-size: 22px; }
.page-head input { width: 100%; height: 38px; border-radius: 10px; border: 0; padding: 0 14px; background: var(--surface-2); color: var(--fg); outline: none; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; }
.thumb { position: relative; aspect-ratio: 9 / 16; background: var(--surface-2); overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb span { position: absolute; left: 6px; right: 6px; bottom: 5px; font-size: 11px; line-height: 1.2; text-shadow: 0 1px 3px #000; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; text-align: left; }
.thumb .tick { position: absolute; top: 5px; right: 5px; width: 18px; height: 18px; color: var(--done); filter: drop-shadow(0 1px 2px #000); }

.stat-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 20px; }
.stat { background: var(--surface); border-radius: 12px; padding: 14px; }
.stat b { display: block; font-size: 26px; margin-top: 4px; }
.stat small { color: var(--muted); }
.stat-topics h2 { font-size: 16px; margin: 0 0 10px; }
.topic-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.topic-row .avatar { width: 28px; height: 28px; font-size: 12px; }
.topic-row .bar { flex: 1; height: 4px; border-radius: 2px; background: var(--surface-2); overflow: hidden; }
.topic-row .bar i { display: block; height: 100%; background: var(--done); }
.link-btn { color: var(--accent); margin-top: 18px; }

/* Нижній аркуш */
.sheet-backdrop { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.5); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 480px; max-height: 70dvh; overflow-y: auto; background: var(--surface-2); border-radius: 16px 16px 0 0; padding: 8px 0 calc(16px + env(safe-area-inset-bottom)); animation: up .2s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: rgba(255,255,255,.3); margin: 4px auto 10px; }
.sheet h3 { margin: 4px 16px 8px; font-size: 15px; text-align: center; }
.sheet-item { width: 100%; display: flex; align-items: center; gap: 12px; padding: 12px 16px; text-align: left; font-size: 15px; }
.sheet-item:active { background: rgba(255,255,255,.06); }
.sheet-item .count { margin-left: auto; color: var(--muted); }
.sheet-item.selected { font-weight: 700; }
.sheet-item.selected::after { content: "✓"; margin-left: 8px; color: var(--accent); }

/* Нагадування про час та екран відпочинку */
.nudge, .rest { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.72); display: flex; align-items: center; justify-content: center; padding: 24px; }
.rest { position: absolute; z-index: 20; background: #000; }
.nudge-card, .rest-card { width: 100%; max-width: 320px; background: var(--surface); border-radius: 16px; padding: 22px 18px 16px; text-align: center; display: flex; flex-direction: column; align-items: center; }
.rest-card { background: none; }
.nudge-card h2, .rest-card h2 { margin: 10px 0 6px; font-size: 19px; }
.nudge-card p { margin: 0 0 16px; }
.btn-primary, .btn-ghost { width: 100%; height: 42px; border-radius: 10px; font-weight: 600; }
.btn-primary { background: #fff; color: #000; margin-bottom: 8px; }
.btn-ghost { border: 1px solid rgba(255,255,255,.3); }

.empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; }
.empty p { margin: 4px 0; }
