@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&display=swap');

/* ──────── Design Tokens ──────── */
:root {
    --accent: #3FCFC0;
    --accentText: #0d1414;
    --sidebar-width: 264px;
    --topbar-height: 64px;
    --transition: 0.15s ease;
    --radius-card: 14px;
    --radius-panel: 12px;
    --radius-row: 10px;
    --radius-pill: 19px;
}

[data-theme="dark"] {
    --bg: #12141a;
    --bgElevated: #181b21;
    --surface: #1d2027;
    --surfaceHover: #252932;
    --border: #2b2f38;
    --text: #f2f3f5;
    --textSub: #9aa1ab;
    --textFaint: #6b7280;
    --amber: #e8a93f;
    --accentSoft: rgba(255, 255, 255, 0.07);
    --logo-cutout: #12141a;
}

[data-theme="light"] {
    --bg: #f7f7f5;
    --bgElevated: #ffffff;
    --surface: #ffffff;
    --surfaceHover: #f0f0ee;
    --border: #e2e2df;
    --text: #1a1c1f;
    --textSub: #5b6068;
    --textFaint: #8b9098;
    --amber: #b5791f;
    --accentSoft: rgba(0, 0, 0, 0.05);
    --logo-cutout: #f7f7f5;
}

/* ──────── Reset ──────── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Space Grotesk', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    transition: background var(--transition), color var(--transition);
    overflow-x: hidden;
}

button { font-family: inherit; cursor: pointer; }
img { display: block; }

/* ──────── File Warning ──────── */
.file-warning {
    background: rgba(232, 169, 63, 0.1);
    border-bottom: 1px solid rgba(232, 169, 63, 0.3);
    color: var(--amber);
    padding: 12px 24px;
    font-size: 13px;
    line-height: 1.5;
}
.file-warning code {
    background: rgba(0, 0, 0, 0.2);
    padding: 1px 6px;
    border-radius: 4px;
    font-family: monospace;
}

/* ──────── App Shell ──────── */
.app-shell {
    display: flex;
    min-height: 100vh;
}

/* ──────── Sidebar ──────── */
.sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    background: var(--bgElevated);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 24px 16px;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 200;
    transition: transform var(--transition), background var(--transition), border-color var(--transition);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 32px;
    padding: 0 4px;
}

/* Logo mark: accent rounded square with closed-eye cutout */
.logo-mark {
    width: 34px;
    height: 34px;
    background: var(--accent);
    border-radius: 10px;
    flex-shrink: 0;
    position: relative;
}

.logo-mark::before {
    content: '';
    position: absolute;
    width: 13px;
    height: 13px;
    background: var(--logo-cutout);
    border-radius: 50%;
    top: 8px;
    left: 10px;
}

.logo-mark::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 4px;
    background: var(--accent);
    border-radius: 2px;
    bottom: 9px;
    left: 7px;
}

.logo-text {
    display: flex;
    flex-direction: column;
}

.logo-wordmark {
    font-size: 19px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.1;
}

.logo-tagline {
    font-size: 10.5px;
    color: var(--textFaint);
    font-weight: 500;
    line-height: 1.4;
}

/* Sidebar nav */
.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-row);
    border: none;
    background: transparent;
    color: var(--textSub);
    font-size: 14px;
    font-weight: 500;
    width: 100%;
    text-align: left;
    transition: background var(--transition), color var(--transition);
}

.nav-item:hover {
    background: var(--surfaceHover);
    color: var(--text);
}

.nav-item.active {
    background: var(--accentSoft);
    color: var(--accent);
    font-weight: 700;
}

.nav-item svg {
    flex-shrink: 0;
    opacity: 0.7;
    transition: opacity var(--transition);
}

.nav-item.active svg,
.nav-item:hover svg {
    opacity: 1;
}

.sidebar-footer {
    font-size: 11px;
    color: var(--textFaint);
    line-height: 1.5;
    padding: 0 4px;
    margin-top: 24px;
}

.disguise-toggle-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    margin-top: 24px;
    padding: 10px 12px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-row);
    color: var(--textSub);
    font-size: 12.5px;
    font-weight: 600;
    transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.disguise-toggle-btn:hover {
    background: var(--accentSoft);
    color: var(--text);
    border-color: var(--accent);
}

.disguise-toggle-btn svg {
    flex-shrink: 0;
}

/* Drawer backdrop */
.drawer-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 150;
}

.drawer-backdrop.open { display: block; }

/* ──────── Main Area ──────── */
.main-area {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 100vh;
}

/* ──────── Top Bar ──────── */
.top-bar {
    position: sticky;
    top: 0;
    height: var(--topbar-height);
    background: var(--bgElevated);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 24px;
    z-index: 100;
    flex-wrap: wrap;
    transition: background var(--transition), border-color var(--transition);
}

.hamburger {
    display: none;
    flex-direction: column;
    gap: 4px;
    background: none;
    border: none;
    padding: 4px;
    flex-shrink: 0;
}

.hamburger span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--text);
    border-radius: 1px;
    transition: background var(--transition);
}

/* Search wrap */
.search-wrap {
    flex: 1;
    max-width: 640px;
    position: relative;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 12px;
    color: var(--textFaint);
    pointer-events: none;
    flex-shrink: 0;
}

.search-wrap input {
    width: 100%;
    height: 40px;
    padding: 0 36px 0 36px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    outline: none;
    transition: border-color var(--transition), background var(--transition);
}

.search-wrap input::placeholder {
    color: var(--textFaint);
    font-weight: 500;
}

.search-wrap input:focus {
    border-color: var(--accent);
    background: var(--bgElevated);
}

.search-clear {
    position: absolute;
    right: 10px;
    background: none;
    border: none;
    color: var(--textFaint);
    font-size: 18px;
    line-height: 1;
    padding: 2px 4px;
    display: none;
    align-items: center;
    justify-content: center;
    transition: color var(--transition);
}

.search-clear.visible { display: flex; }
.search-clear:hover { color: var(--text); }

/* Privacy badge */
.privacy-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--textSub);
    white-space: nowrap;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 20px;
    flex-shrink: 0;
    transition: border-color var(--transition), color var(--transition);
}

.accent-dot {
    width: 6px;
    height: 6px;
    background: var(--accent);
    border-radius: 50%;
    flex-shrink: 0;
    animation: dot-pulse 2.5s ease-in-out infinite;
}

@keyframes dot-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Theme toggle */
.theme-toggle-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.theme-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--textSub);
}

.toggle-track {
    width: 40px;
    height: 22px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 11px;
    position: relative;
    cursor: pointer;
    padding: 0;
    transition: background var(--transition), border-color var(--transition);
}

[data-theme="dark"] .toggle-track {
    background: var(--accent);
    border-color: var(--accent);
}

.toggle-thumb {
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    position: absolute;
    top: 2px;
    left: 2px;
    transition: transform var(--transition);
    pointer-events: none;
}

[data-theme="dark"] .toggle-thumb {
    transform: translateX(18px);
}

/* ──────── Views ──────── */
.view { display: none; flex: 1; }
.view.active { display: block; }

.content-area {
    padding: 32px 40px;
}

.view-heading {
    font-size: 19px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 22px;
}

/* ──────── Error Toast ──────── */
.error-toast {
    display: none;
    align-items: center;
    gap: 8px;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #f87171;
    padding: 10px 14px;
    border-radius: var(--radius-row);
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 20px;
}

/* ──────── Video Grid ──────── */
.video-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 22px;
}

/* Video Card */
.video-card {
    background: var(--surface);
    border-radius: var(--radius-card);
    overflow: hidden;
    cursor: pointer;
    transition: transform var(--transition), box-shadow var(--transition);
    position: relative;
}

.video-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.card-thumb-wrap {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    background: #000;
}

.card-thumb-wrap img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.2s ease;
}

.video-card:hover .card-thumb-wrap img {
    transform: scale(1.03);
}

.duration-badge {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.75);
    color: #fff;
    padding: 2px 6px;
    font-size: 11px;
    font-weight: 600;
    border-radius: 4px;
    backdrop-filter: blur(4px);
    pointer-events: none;
}

.live-badge {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: #e53935;
    color: #fff;
    padding: 2px 6px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.3px;
    border-radius: 4px;
    pointer-events: none;
}

/* Bookmark button on card */
.card-bookmark-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 30px;
    height: 30px;
    background: rgba(0, 0, 0, 0.55);
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity var(--transition), background var(--transition);
    z-index: 2;
}

.video-card:hover .card-bookmark-btn,
.card-bookmark-btn.saved { opacity: 1; }

.card-bookmark-btn:hover { background: rgba(0, 0, 0, 0.8); }

.card-bookmark-btn .bookmark-shape {
    width: 13px;
    height: 15px;
    background: rgba(255, 255, 255, 0.75);
    clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 74%, 0 100%);
    transition: background var(--transition);
}

.card-bookmark-btn.saved .bookmark-shape {
    background: var(--accent);
}

/* Card meta */
.card-meta {
    padding: 12px;
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.card-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    color: #14161a;
    flex-shrink: 0;
}

.card-info { flex: 1; min-width: 0; }

.card-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 4px;
}

.card-channel {
    font-size: 12px;
    color: var(--textSub);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
    width: fit-content;
    max-width: 100%;
    transition: color var(--transition);
}

.card-channel:hover {
    text-decoration: underline;
    color: var(--text);
}

.card-stats {
    font-size: 12px;
    color: var(--textFaint);
    margin-top: 2px;
}

/* ──────── Grid Loader ──────── */
.grid-loader {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 48px 0;
    color: var(--textSub);
    font-size: 14px;
    font-weight: 500;
}

.spinner {
    width: 28px;
    height: 28px;
    border: 2.5px solid rgba(63, 207, 192, 0.15);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
}

.spinner.small {
    width: 20px;
    height: 20px;
    border-width: 2px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ──────── Empty State ──────── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 80px 20px;
    text-align: center;
    color: var(--textFaint);
    font-size: 14px;
    font-weight: 500;
    line-height: 1.6;
}

.empty-icon { color: var(--border); }

/* ──────── Watch View ──────── */
.back-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: none;
    color: var(--textSub);
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 20px;
    padding: 4px 0;
    transition: color var(--transition);
}

.back-btn:hover { color: var(--text); }

.watch-layout {
    display: flex;
    gap: 28px;
    align-items: flex-start;
}

.player-col {
    flex: 1;
    min-width: 0;
}

.player-wrap {
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #000;
    border-radius: var(--radius-card);
    overflow: hidden;
}

.player-wrap iframe {
    width: 100%;
    height: 100%;
    border: none;
}

.video-title {
    font-size: 21px;
    font-weight: 700;
    color: var(--text);
    margin-top: 18px;
    line-height: 1.3;
}

/* Video meta row */
.video-meta-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 14px;
    flex-wrap: wrap;
}

.meta-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.channel-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    color: #14161a;
    flex-shrink: 0;
}

.channel-name {
    font-size: 13.5px;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    width: fit-content;
    transition: color var(--transition);
}

.channel-name:hover {
    text-decoration: underline;
    color: var(--accent);
}

.video-stats {
    font-size: 12px;
    color: var(--textSub);
    margin-top: 2px;
}

.meta-right {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.pill-btn {
    height: 38px;
    padding: 0 16px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    white-space: nowrap;
    transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.pill-btn:hover {
    background: var(--surfaceHover);
    border-color: var(--accent);
}

.pill-btn.saved-active {
    background: rgba(63, 207, 192, 0.1);
    border-color: var(--accent);
    color: var(--accent);
}

.bookmark-icon {
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: fill var(--transition);
}

.pill-btn.saved-active .bookmark-icon {
    fill: var(--accent);
    stroke: var(--accent);
}

/* Privacy strip */
.privacy-strip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    padding: 8px 14px;
    border-radius: 20px;
    font-size: 12px;
    color: var(--textSub);
    margin-top: 14px;
    font-weight: 500;
    transition: background var(--transition);
}

/* ──────── Suggested Rail ──────── */
.suggested-col {
    width: 360px;
    flex-shrink: 0;
}

.suggested-heading {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 12px;
}

.suggested-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.suggested-loader {
    display: flex;
    justify-content: center;
    padding: 20px;
}

.suggested-item {
    display: flex;
    gap: 10px;
    cursor: pointer;
    border-radius: var(--radius-row);
    padding: 6px;
    transition: background var(--transition);
    align-items: flex-start;
}

.suggested-item:hover { background: var(--surfaceHover); }

.suggested-thumb-wrap {
    position: relative;
    width: 160px;
    height: 90px;
    flex-shrink: 0;
    border-radius: 8px;
    overflow: hidden;
    background: #000;
}

.suggested-thumb-wrap img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.suggested-thumb-wrap .duration-badge {
    font-size: 10px;
    padding: 1px 5px;
}

.suggested-info {
    flex: 1;
    min-width: 0;
    padding-top: 2px;
}

.suggested-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.4;
    margin-bottom: 4px;
}

.suggested-channel {
    font-size: 12px;
    color: var(--textSub);
    font-weight: 500;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
    width: fit-content;
    max-width: 100%;
    transition: color var(--transition);
}

.suggested-channel:hover {
    text-decoration: underline;
    color: var(--text);
}

.suggested-views {
    font-size: 11px;
    color: var(--textFaint);
}

/* ──────── History View ──────── */
.history-heading-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 22px;
}

.history-heading-row .view-heading { margin-bottom: 0; }

.amber-btn {
    background: none;
    border: none;
    color: var(--amber);
    font-size: 13px;
    font-weight: 600;
    padding: 6px 10px;
    border-radius: var(--radius-row);
    transition: background var(--transition);
    display: inline-flex;
}

.amber-btn:hover { background: rgba(232, 169, 63, 0.1); }

.history-rows {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.history-row {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 8px 10px;
    border-radius: var(--radius-row);
    cursor: pointer;
    transition: background var(--transition);
}

.history-row:hover { background: var(--surfaceHover); }

.history-row-thumb {
    width: 100px;
    height: 56px;
    border-radius: 8px;
    overflow: hidden;
    flex-shrink: 0;
    background: var(--surface);
}

.history-row-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.history-row-info {
    flex: 1;
    min-width: 0;
}

.history-row-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.4;
    margin-bottom: 3px;
}

.history-row-sub {
    font-size: 12px;
    color: var(--textSub);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-row-time {
    font-size: 11px;
    color: var(--textFaint);
    margin-top: 2px;
}

/* ──────── Responsive ──────── */
/* ──────── Mini Player ──────── */
.mini-player {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 300px;
    background: var(--bgElevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-panel);
    overflow: hidden;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
    z-index: 500;
    animation: mini-slide-in 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes mini-slide-in {
    from { opacity: 0; transform: translateY(20px) scale(0.95); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.mini-player-top {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: var(--bgElevated);
    border-bottom: 1px solid var(--border);
}

.mini-player-title {
    flex: 1;
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mini-player-actions {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
}

.mini-btn {
    background: none;
    border: none;
    color: var(--textSub);
    padding: 5px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition), color var(--transition);
}

.mini-btn:hover {
    background: var(--surfaceHover);
    color: var(--text);
}

.mini-player iframe {
    width: 100%;
    aspect-ratio: 16 / 9;
    border: none;
    display: block;
}

/* ──────── Responsive ──────── */
@media (max-width: 900px) {
    .sidebar {
        transform: translateX(-100%);
        box-shadow: none;
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.3);
    }

    .main-area { margin-left: 0; }

    .hamburger { display: flex; }

    .privacy-badge { display: none; }

    .content-area { padding: 16px; }

    .watch-layout { flex-direction: column; }

    .suggested-col { width: 100%; }

    .video-title { font-size: 17px; }

    .video-meta-row {
        flex-direction: column;
        align-items: flex-start;
    }
}

@media (max-width: 600px) {
    .top-bar {
        gap: 8px;
        padding: 0 12px;
        height: auto;
        min-height: var(--topbar-height);
        padding-top: 8px;
        padding-bottom: 8px;
    }

    .theme-toggle-wrap { display: none; }

    .meta-right { width: 100%; }

    .pill-btn {
        flex: 1;
        justify-content: center;
        font-size: 12px;
        padding: 0 12px;
    }

    .video-grid {
        grid-template-columns: 1fr;
    }
}
