:root {
    --bg: #0b0d13;
    --surface: #141720;
    --surface-hover: #1a1e2a;
    --border: #252a37;
    --text: #e2e4ea;
    --text-muted: #6c7186;
    --accent: #6d5cff;
    --accent-hover: #7f70ff;
    --radius: 10px;
    --radius-sm: 6px;

    --yt: #ff0000;
    --tt: #00f2ea;
    --ig: #e4405f;
    --fb: #1877f2;
    --x: #a0a0a0;

    /* Available height for the embed: viewport minus header, input row, toolbar, padding */
    --embed-h: calc(100dvh - 230px);
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
}

#app {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    overflow: hidden;
}

/* ── Header ─────────────────────────────────────── */

header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    flex-shrink: 0;
    z-index: 100;
}

.logo {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text);
    text-decoration: none;
    letter-spacing: -0.5px;
}

.logo span {
    color: var(--accent);
}

.tabs {
    display: flex;
    gap: 4px;
}

.tab {
    padding: 8px 16px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all 0.15s;
}

.tab:hover {
    color: var(--text);
    background: var(--surface-hover);
}

.tab.active {
    color: var(--text);
    background: var(--accent);
}

.header-share {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s;
    flex-shrink: 0;
}

.header-share:hover {
    color: var(--text);
    background: var(--surface-hover);
    border-color: var(--text-muted);
}

.header-share[hidden] {
    display: none;
}

/* ── Main ───────────────────────────────────────── */

main {
    flex: 1;
    min-height: 0;
    display: flex;
    justify-content: center;
    overflow: hidden;
}

.tab-content {
    display: none;
    width: 100%;
    max-width: 900px;
    padding: 20px 24px 16px;
    flex-direction: column;
    min-height: 0;
}

.tab-content.active {
    display: flex;
}

/* ── Input Row ──────────────────────────────────── */

.input-row {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
    margin-bottom: 16px;
}

#url-input {
    flex: 1;
    padding: 14px 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.15s;
}

#url-input::placeholder {
    color: var(--text-muted);
}

#url-input:focus {
    border-color: var(--accent);
}

#watch-btn {
    padding: 14px 28px;
    background: var(--accent);
    border: none;
    border-radius: var(--radius);
    color: #fff;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s;
    flex-shrink: 0;
}

#watch-btn:hover {
    background: var(--accent-hover);
}

/* ── Autoplay Toggle ───────────────────────────── */

.autoplay-toggle {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    user-select: none;
}

.toggle-chevron {
    display: none;
}

.toggle-inner {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.toggle-inner input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-track {
    position: relative;
    width: 36px;
    height: 20px;
    background: var(--border);
    border-radius: 10px;
    transition: background 0.2s;
    flex-shrink: 0;
}

.toggle-track::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 14px;
    height: 14px;
    background: var(--text-muted);
    border-radius: 50%;
    transition: all 0.2s;
}

.toggle-inner input:checked + .toggle-track {
    background: var(--accent);
}

.toggle-inner input:checked + .toggle-track::after {
    left: 19px;
    background: #fff;
}

.toggle-label {
    font-size: 0.82rem;
    color: var(--text-muted);
    white-space: nowrap;
}

/* ── Player ─────────────────────────────────────── */

.player {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.player.hidden {
    display: none;
}

/* ── Embed Area ─────────────────────────────────── */

.embed-area {
    flex: 1;
    min-height: 0;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #000;
    overflow: hidden;
}

.embed-area iframe {
    display: block;
    border: none;
    color-scheme: dark;
}

/* Landscape (YouTube, Facebook video) - 16:9 filling the available space */
.embed-area.landscape {
    width: 100%;
}

.embed-area.landscape iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

/* Portrait (TikTok, Instagram) - tall, centered, width derived from height */
.embed-area.portrait {
    background: var(--bg);
}

.embed-area.portrait iframe {
    height: 100%;
    aspect-ratio: 9 / 16;
    max-width: 100%;
}

/* Instagram - embed.js creates its own iframe, scaled to fit via JS */
.embed-area.ig {
    background: var(--bg);
    overflow: hidden auto;
    padding-bottom: 16px;
}


/* Tweet / Facebook post - centered card */
.embed-area.tweet,
.embed-area.fb-post {
    background: var(--bg);
}

.embed-area.tweet iframe,
.embed-area.fb-post iframe {
    width: 100%;
    max-width: 550px;
    height: 100%;
}

/* ── Toolbar ────────────────────────────────────── */

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    flex-wrap: wrap;
    gap: 8px;
    background: var(--surface);
}

.toolbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.toolbar-right {
    display: flex;
    gap: 8px;
}

.platform-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
}

.original-link {
    color: var(--text-muted);
    font-size: 0.82rem;
    text-decoration: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 300px;
}

.original-link:hover {
    color: var(--text);
}

.action-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: var(--surface-hover);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
}

.action-btn:hover {
    background: var(--border);
    border-color: var(--text-muted);
}

.action-btn svg {
    flex-shrink: 0;
}

/* ── Empty State ────────────────────────────────── */

.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 24px;
    overflow-y: auto;
    min-height: 0;
}

.empty-state.hidden {
    display: none;
}

.empty-icon {
    font-size: 3rem;
    color: var(--accent);
    margin-bottom: 16px;
}

.empty-state h2 {
    font-size: 1.3rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.empty-state p {
    color: var(--text-muted);
    margin-bottom: 24px;
}

.platform-list {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
}

/* ── Features ───────────────────────────────────── */

.features {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    width: 100%;
    max-width: 560px;
    margin-top: 28px;
}

.feature-card {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-align: left;
}

.feature-icon {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(109, 92, 255, 0.12);
    border-radius: 8px;
    color: var(--accent);
}

.feature-text {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}

.feature-text strong {
    font-size: 0.82rem;
    color: var(--text);
    font-weight: 600;
}

.feature-text span {
    font-size: 0.73rem;
    color: var(--text-muted);
    line-height: 1.4;
}

/* ── Pills ─────────────────────────────────────── */

.pill {
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.82rem;
    font-weight: 600;
    color: #fff;
}

.pill.yt { background: var(--yt); }
.pill.tt { background: #25f4ee33; color: var(--tt); border: 1px solid var(--tt); }
.pill.ig { background: var(--ig); }
.pill.fb { background: var(--fb); }
.pill.x  { background: #333; color: var(--x); border: 1px solid #555; }

/* ── History ───────────────────────────────────── */

.history-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    flex-shrink: 0;
}

.history-tabs {
    display: flex;
    gap: 6px;
}

.clear-history-btn {
    padding: 5px 12px;
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 0.78rem;
    cursor: pointer;
    transition: all 0.15s;
}

.clear-history-btn:hover {
    color: #ff6b6b;
    border-color: #ff6b6b;
    background: rgba(255, 107, 107, 0.1);
}

.history-tab {
    padding: 6px 16px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 20px;
    transition: all 0.15s;
}

.history-tab:hover {
    color: var(--text);
    background: var(--surface-hover);
}

.history-tab.active {
    color: #fff;
    background: var(--accent);
    border-color: var(--accent);
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.history-entry {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.history-entry:hover {
    background: var(--surface-hover);
    border-color: var(--text-muted);
}

.history-thumb {
    width: 72px;
    height: 48px;
    object-fit: cover;
    border-radius: 4px;
    flex-shrink: 0;
    background: var(--bg);
}

.history-entry .pill {
    font-size: 0.72rem;
    padding: 3px 10px;
    flex-shrink: 0;
}

.history-entry-info {
    flex: 1;
    min-width: 0;
}

.history-entry-title {
    font-size: 0.85rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

.history-entry-url {
    font-size: 0.78rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* When there's no title, make the URL the primary text */
.history-entry-info:not(:has(.history-entry-title)) .history-entry-url {
    font-size: 0.85rem;
    color: var(--text);
}

.history-entry-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    flex-shrink: 0;
}

.history-entry-time {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.history-delete {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 6px;
    font-size: 1rem;
    line-height: 1;
    border-radius: var(--radius-sm);
    transition: color 0.15s, background 0.15s;
}

.history-delete:hover {
    color: #ff6b6b;
    background: rgba(255, 107, 107, 0.1);
}

/* ── Analytics ──────────────────────────────────── */

.analytics-view {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 28px;
}

.analytics-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.analytics-heading {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}

.analytics-bars {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.analytics-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.analytics-row .pill {
    width: 80px;
    text-align: center;
    font-size: 0.72rem;
    padding: 3px 0;
    flex-shrink: 0;
}

.analytics-bar-wrap {
    flex: 1;
    height: 24px;
    background: var(--surface);
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.analytics-bar {
    height: 100%;
    border-radius: 4px;
    min-width: 2px;
    transition: width 0.4s ease;
}

.analytics-bar.yt  { background: var(--yt); }
.analytics-bar.tt  { background: var(--tt); opacity: 0.7; }
.analytics-bar.ig  { background: var(--ig); }
.analytics-bar.fb  { background: var(--fb); }
.analytics-bar.x   { background: var(--x); }

.analytics-count {
    font-size: 0.78rem;
    color: var(--text-muted);
    width: 36px;
    text-align: right;
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
}

.analytics-empty {
    font-size: 0.8rem;
    color: var(--text-muted);
    padding: 8px 0;
}

/* ── Footer ────────────────────────────────────── */

footer {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px 24px;
    border-top: 1px solid var(--border);
    background: var(--surface);
    flex-shrink: 0;
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* ── Toast ──────────────────────────────────────── */

.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 12px 24px;
    border-radius: var(--radius);
    font-size: 0.9rem;
    pointer-events: none;
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 1000;
    white-space: nowrap;
}

.toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ── Error ──────────────────────────────────────── */

.error-message {
    text-align: center;
    padding: 40px 24px;
    color: var(--text-muted);
}

.error-message h3 {
    color: #ff6b6b;
    margin-bottom: 8px;
}

/* ── Responsive ─────────────────────────────────── */

@media (max-width: 600px) {
    header {
        padding: 12px 16px;
    }

    .tab-content {
        padding: 16px 16px 12px;
    }

    .input-row {
        flex-wrap: wrap;
    }

    #url-input {
        width: 100%;
    }

    #watch-btn {
        flex: 1;
        padding: 14px 16px;
    }

    .toggle-chevron {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 28px;
        height: 28px;
        font-size: 1.2rem;
        color: var(--text-muted);
        cursor: pointer;
        transition: transform 0.2s;
    }

    .autoplay-toggle .toggle-inner {
        max-width: 0;
        overflow: hidden;
        opacity: 0;
        transition: max-width 0.25s ease, opacity 0.2s ease;
    }

    .autoplay-toggle.expanded .toggle-chevron {
        transform: rotate(90deg);
    }

    .autoplay-toggle.expanded .toggle-inner {
        max-width: 150px;
        opacity: 1;
    }

    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .toolbar-left {
        justify-content: center;
    }

    .toolbar-right {
        width: 100%;
    }

    .toolbar-right .action-btn {
        flex: 1;
        justify-content: center;
    }

    .original-link {
        max-width: 200px;
    }

    .embed-area {
        overflow: hidden;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    .embed-area::-webkit-scrollbar {
        display: none;
    }

    .features {
        grid-template-columns: 1fr;
    }

    .history-entry {
        padding: 10px 12px;
        gap: 8px;
    }

    .history-thumb {
        width: 56px;
        height: 38px;
    }

    .history-entry-title {
        font-size: 0.8rem;
    }

    .history-entry-url {
        font-size: 0.72rem;
    }
}
