/* Viral feed — mobile first, dark. */
:root {
    --bg: #000;
    --panel: #0b0b0d;
    --chip: #1c1c1f;
    --chip-hover: #2a2a2e;
    --fg: #fff;
    --muted: #a1a1aa;
    --accent: #ff2d55;
    --accent-2: #ff8a00;
    --header-h: 52px;
    --radius: 16px;
    color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); }
body {
    font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}
a { color: inherit; }
button { font: inherit; color: inherit; cursor: pointer; }

.app {
    height: 100vh;
    height: 100dvh;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto auto; /* header, feed, comments, banner */
    grid-template-columns: minmax(0, 1fr);
}

/* ---------- Header ---------- */
.topbar {
    position: relative;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: var(--header-h);
    padding: env(safe-area-inset-top) 12px 0;
    background: var(--bg);
    border-bottom: 1px solid #141416;
}
.logo { display: flex; align-items: center; gap: 6px; text-decoration: none; flex: none; font-weight: 800; letter-spacing: -0.02em; }
.logo-mark {
    display: grid; place-items: center; width: 28px; height: 28px; border-radius: 9px; font-size: 13px;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.logo-text { font-size: 18px; }
.chips {
    flex: 1; min-width: 0; display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none;
    padding: 8px 2px; -webkit-mask-image: linear-gradient(90deg, #000 92%, transparent);
    mask-image: linear-gradient(90deg, #000 92%, transparent);
}
.chips::-webkit-scrollbar { display: none; }
.chip {
    flex: none; white-space: nowrap; padding: 6px 12px; border-radius: 999px; font-size: 14px;
    background: var(--chip); color: #ddd; text-decoration: none; transition: background .15s;
}
.chip:hover { background: var(--chip-hover); }
.chip.is-active { background: var(--fg); color: #000; font-weight: 600; }
.icon-btn { flex: none; width: 38px; height: 38px; border: 0; border-radius: 50%; background: var(--chip); font-size: 17px; }
.menu {
    position: absolute; right: 12px; top: calc(100% + 6px); min-width: 220px; padding: 6px;
    background: #17171a; border: 1px solid #26262b; border-radius: 14px; box-shadow: 0 12px 40px rgba(0,0,0,.6);
}
.menu-item { display: block; width: 100%; padding: 10px 12px; border: 0; border-radius: 9px; background: none; text-align: left; text-decoration: none; font-size: 15px; }
.menu-item:hover { background: var(--chip-hover); }

/* ---------- Feed ---------- */
.feed {
    height: 100%;
    overflow-y: auto;
    scroll-snap-type: y mandatory;
    overscroll-behavior-y: contain;
    scrollbar-width: none;
}
.feed::-webkit-scrollbar { display: none; }
.slide {
    position: relative;
    height: 100%;
    scroll-snap-align: start;
    scroll-snap-stop: always;
    display: flex;
    flex-direction: column;
}
.slide-loading, .slide-end { align-items: center; justify-content: center; text-align: center; padding: 24px; }

/* The player box. Nothing of ours is ever drawn on top of a player (YouTube policy). */
.stage { position: relative; flex: 1; min-height: 0; background: #000; overflow: hidden; }
.stage iframe, .stage .yt-host { position: absolute; inset: 0; z-index: 2; width: 100%; height: 100%; border: 0; }
/* Without controls YouTube shows a black box until it plays; show our thumbnail instead. */
.stage:not(.is-started) iframe[src*="youtube"] { opacity: 0; }
/* Placeholder (thumbnail + spinner) shown until the player paints over it. Its own
   stacking layer keeps the spinner underneath the player. */
.poster {
    position: absolute; inset: 0; z-index: 0; display: grid; place-items: center;
    background: #0d0d0f center / cover no-repeat;
}
.poster::after { content: ""; position: absolute; inset: 0; background: rgba(0,0,0,.45); }
.poster .spinner { position: relative; z-index: 1; }
.poster .platform-badge {
    position: absolute; z-index: 1; left: 50%; top: calc(50% + 34px); transform: translateX(-50%);
    font-size: 12px; color: var(--muted);
}
/* Invisible tap layer over a player, switched per platform in Admin → Settings. On by default
   for TikTok; off for YouTube, whose rules forbid anything over its player. */
.tap-layer { position: absolute; inset: 0; z-index: 3; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.heart-pop {
    position: absolute; left: 50%; top: 50%; color: #ff2d55; font-size: 110px; line-height: 1; pointer-events: none;
    text-shadow: 0 6px 24px rgba(0,0,0,.4); opacity: 0; transform: translate(-50%, -50%) scale(.4); animation: heart-pop .8s ease-out;
}
@keyframes heart-pop {
    15% { opacity: 1; transform: translate(-50%, -50%) scale(1.15); }
    30% { transform: translate(-50%, -50%) scale(1); }
    75% { opacity: 1; }
    100% { opacity: 0; transform: translate(-50%, -65%) scale(1); }
}
.tap-layer.is-paused::after {
    content: "▶"; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
    display: grid; place-items: center; box-sizing: border-box; width: 72px; height: 72px; padding-left: 6px;
    border-radius: 50%; background: rgba(0,0,0,.45); color: #fff; font-size: 30px;
}
.broken-note { position: absolute; inset: 0; z-index: 3; display: grid; place-items: center; text-align: center; padding: 24px; color: var(--muted); background: #0d0d0f; }

.meta {
    flex: none;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 12px calc(6px + env(safe-area-inset-bottom));
    background: var(--panel);
}
.has-banner .meta { padding-bottom: 8px; }
/* Phones get a single line (creator · source + buttons) to leave room for the banner;
   the title and category show on desktop only. */
.info { flex: 1; min-width: 0; }
.author { display: flex; align-items: center; gap: 6px; margin: 0; font-weight: 700; font-size: 14px; max-width: 100%; }
.author .src { color: var(--muted); font-weight: 500; white-space: nowrap; }
.author .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.title {
    display: none; margin: 2px 0 0; font-size: 13px; color: #d4d4d8;
    -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.cat-tag { display: none; color: var(--muted); font-size: 12px; text-decoration: none; }
.actions { flex: none; display: flex; gap: 6px; }
.act {
    display: flex; flex-direction: column; align-items: center; gap: 1px;
    padding: 0; border: 0; background: none; text-decoration: none; font-size: 11px; color: var(--muted);
}
.act > span:not(.ic) { display: none; }
/* Phones: counts sit as small badges on the icons, so the row stays one line. */
.act { position: relative; }
.act > span.n {
    display: block; position: absolute; top: -4px; right: -6px; box-sizing: border-box; min-width: 18px; padding: 0 4px;
    border-radius: 999px; background: #fff; color: #000; font-size: 10px; font-weight: 800; line-height: 16px; text-align: center; pointer-events: none;
}
.act-views { cursor: default; }
.act-views .ic { background: transparent; font-size: 16px; }
.act .ic {
    display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%;
    background: var(--chip); color: var(--fg); font-size: 18px; transition: transform .12s, background .15s;
}
.act:active .ic { transform: scale(.9); }
.act.is-on .ic { background: var(--accent); }
.act.sound-off .ic { background: #3a1d24; }

/* ---------- Ads ---------- */
.slide-ad { align-items: center; justify-content: center; padding: 20px; }
.ad-card {
    position: relative; width: min(420px, 100%); max-height: 100%; overflow: auto; text-align: center;
    padding: 20px; border-radius: 20px; background: #121215; border: 1px solid #26262b;
}
.ad-label { position: absolute; top: 10px; left: 12px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.ad-card img { display: block; width: 100%; max-height: 52vh; object-fit: cover; border-radius: 14px; margin: 14px 0 12px; }
.ad-card h2 { margin: 6px 0; font-size: 22px; line-height: 1.2; }
.ad-card p { margin: 0 0 14px; color: #d4d4d8; }
.ad-code { min-height: 250px; display: grid; place-items: center; margin-top: 18px; }

/* ---------- Comments ----------
   A panel below the feed (phones) or beside it (desktop); the video shrinks to make room
   and is never covered. Its height leaves the video at least ~220px tall. */
.comments {
    display: flex; flex-direction: column; min-height: 0; height: min(55dvh, calc(100dvh - 400px));
    background: var(--panel); border-top: 1px solid #26262b;
}
.comments-head { flex: none; display: flex; align-items: center; justify-content: space-between; padding: 6px 8px 6px 16px; border-bottom: 1px solid #26262b; }
.comments-head h2 { margin: 0; font-size: 15px; }
.comments-count { margin-left: 4px; color: var(--muted); font-weight: 500; }
.comments-list { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 4px 16px; }
.comments-list > .spinner { margin: 24px auto; }
.comments-empty { margin: 24px 0; color: var(--muted); text-align: center; }
.comments-older { display: flex; margin: 10px auto 6px; padding: 8px 14px; font-size: 13px; }
.comment { padding: 9px 0; border-bottom: 1px solid #1d1d21; }
.comment-head { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.comment-time { color: var(--muted); font-size: 12px; }
.comment-more { margin-left: auto; padding: 0 6px; border: 0; background: none; color: var(--muted); font-size: 18px; line-height: 1; }
.comment-body { margin: 3px 0 0; font-size: 14px; white-space: pre-line; overflow-wrap: anywhere; }
.comment-menu { display: flex; gap: 8px; margin-top: 6px; }
.comment-menu button { padding: 6px 12px; border: 0; border-radius: 999px; background: var(--chip); font-size: 13px; }
.comments-form { flex: none; display: flex; flex-direction: column; gap: 6px; padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid #26262b; }
.has-banner .comments-form { padding-bottom: 8px; }
.comments-form input[type=text], .comments-form textarea {
    box-sizing: border-box; width: 100%; padding: 10px 12px; border: 1px solid #2c2c32; border-radius: 12px;
    background: #0d0d0f; color: var(--fg); font: inherit; font-size: 16px; resize: none; /* 16px: no zoom-in on iPhone */
}
.comments-row { display: flex; align-items: flex-end; gap: 8px; }
.comments-row textarea { flex: 1; max-height: 96px; }
.comments-row .btn { flex: none; padding: 10px 16px; }
.comments-row .btn:disabled { opacity: .6; }
.comments-as { margin: 0; color: var(--muted); font-size: 12px; }
.comments-as strong { color: var(--fg); }
.link-btn { padding: 0; border: 0; background: none; color: var(--fg); font-size: inherit; text-decoration: underline; }
.comments-note { margin: 0; color: #fca5a5; font-size: 12px; }
.comments-note:empty { display: none; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }

/* Banner under the video, in its own row below the feed. The border and padding keep it
   apart from the buttons above (ad networks require space between ads and controls). */
.banner {
    position: relative; display: flex; justify-content: center; align-items: center;
    min-height: 50px; padding: 10px 12px calc(6px + env(safe-area-inset-bottom));
    background: var(--bg); border-top: 1px solid #26262b;
}
.banner-box { position: relative; display: flex; align-items: center; gap: 12px; max-width: 100%; min-width: 0; text-decoration: none; }
.banner img { display: block; max-width: 100%; max-height: 100px; border-radius: 6px; }
.banner .ad-label { top: 3px; left: 3px; padding: 1px 4px; border-radius: 3px; font-size: 9px; background: rgba(0,0,0,.6); color: #fff; }
.banner .ad-code { min-height: 50px; margin: 0; }
.banner-text { min-width: 0; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.banner .btn { flex: none; padding: 8px 14px; }

/* ---------- Bits ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 11px 18px; border-radius: 999px; border: 0; font-weight: 700; text-decoration: none; }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; }
.btn-accept { background: linear-gradient(135deg, #16a34a, #22c55e); color: #fff; }
.btn-ghost { background: var(--chip); }
.spinner {
    width: 34px; height: 34px; border-radius: 50%;
    border: 3px solid rgba(255,255,255,.18); border-top-color: #fff; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
    /* At the top, so it never covers the buttons or the banner ad at the bottom. */
    position: fixed; z-index: 50; left: 50%; top: calc(70px + env(safe-area-inset-top)); transform: translateX(-50%);
    width: max-content; max-width: calc(100% - 32px); padding: 10px 16px; text-align: center; border-radius: 999px; background: #fff; color: #000; font-weight: 600; font-size: 14px;
    box-shadow: 0 8px 30px rgba(0,0,0,.5);
}
.toast-sound { background: #dc2626; color: #fff; text-transform: uppercase; letter-spacing: .02em; font-size: 13px; }

/* First-visit welcome / consent. Shown before any player loads. */
.consent {
    position: fixed; z-index: 60; inset: 0; display: grid; place-items: center; padding: 16px;
    background: rgba(0,0,0,.82); backdrop-filter: blur(6px);
}
.consent > p, .consent-actions { width: min(440px, 100%); }
.consent > p { margin: 0 0 14px; padding: 20px; border-radius: 18px; background: #151518; border: 1px solid #26262b; color: #e4e4e7; }
.consent > p a { color: #fff; }
.consent { align-content: center; }
.consent-actions { display: flex; gap: 10px; justify-content: flex-end; }
.consent-actions .btn { flex: 1; }

.side-nav, .sidebar { display: none; }
.noscript { position: fixed; inset: auto 0 0; padding: 16px; text-align: center; background: #222; }

/* ---------- Desktop ---------- */
@media (min-width: 900px) {
    .slide { flex-direction: row; align-items: stretch; justify-content: center; gap: 18px; padding: 16px 0; }
    .slide-ad, .slide-loading, .slide-end { align-items: center; }
    .stage { flex: none; height: 100%; aspect-ratio: 9 / 16; max-width: 46vw; border-radius: var(--radius); background: #0d0d0f; }
    .meta {
        width: 280px; flex-direction: column; align-items: flex-start; justify-content: flex-end; gap: 18px;
        padding: 0 0 6px; background: none;
    }
    .info { flex: none; width: 100%; }
    .actions { flex-direction: column; gap: 10px; order: -1; }
    .act { flex-direction: row; gap: 10px; font-size: 13px; }
    .act > span:not(.ic) { display: inline; }
    .act > span.n { position: static; min-width: 0; padding: 0; background: none; color: inherit; font-size: 13px; font-weight: 400; line-height: inherit; }
    /* Comments open in a column beside the feed. */
    .topbar { grid-column: 1 / -1; }
    .feed, .banner { grid-column: 1; }
    .comments-open .app { grid-template-columns: minmax(0, 1fr) 380px; }
    .comments { grid-column: 2; grid-row: 2 / span 2; height: auto; border-top: 0; border-left: 1px solid #26262b; }
    .comments-open .stage { max-width: max(240px, calc(100vw - 720px)); }
    .comments-open .side-nav { right: 408px; }
    .comments-open .sidebar { display: none !important; }
    .act .ic { width: 46px; height: 46px; }
    .author { font-size: 15px; }
    .title { display: -webkit-box; font-size: 14px; -webkit-line-clamp: 4; line-clamp: 4; }
    .cat-tag { display: inline; }
    .side-nav { display: flex; position: fixed; z-index: 10; right: 28px; top: 50%; transform: translateY(-50%); flex-direction: column; gap: 12px; }
    .nav-btn { width: 46px; height: 46px; border: 0; border-radius: 50%; background: var(--chip); font-size: 14px; }
    .nav-btn:hover { background: var(--chip-hover); }
    .topbar { padding-left: 20px; padding-right: 20px; }
}
@media (min-width: 1320px) {
    .sidebar:not(:empty) { display: block; position: fixed; z-index: 5; right: 100px; bottom: 24px; width: 300px; }
    .has-banner .sidebar:not(:empty) { bottom: 130px; }
    .sidebar .ad-card { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
    .spinner { animation-duration: 2s; }
}
