/* RESET & VARIABLE DEFINITIONS */
:root {
    --bg-main: #0f0f0f;
    --bg-card: #1a1a1a;
    --bg-modal: #242424;
    --text-main: #f1f1f1;
    --text-sub: #aaaaaa;
    --accent: #6d4aff;
    --accent-tt: #ff0050;
    --border-radius: 12px;
    --font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --header-height: 56px;
    --nav-height: 56px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    font-family: var(--font-family);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

/* APP LAYOUT */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
    position: relative;
}

.hidden-input { display: none !important; }
.hidden { display: none !important; }

/* HEADER */
.main-header {
    height: var(--header-height);
    background-color: rgba(15, 15, 15, 0.95);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    padding-top: env(safe-area-inset-top);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    z-index: 10;
    transition: transform 0.3s ease;
}

.main-header.is-hidden {
    display: none !important;
}

.logo {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.highlight { color: var(--accent); }

.mode-toggle {
    display: flex;
    background: rgba(255, 255, 255, 0.1);
    padding: 2px;
    border-radius: 20px;
}

.toggle-btn {
    background: none;
    border: none;
    color: var(--text-sub);
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 18px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.toggle-btn.active {
    background: var(--accent);
    color: #ffffff;
}

/* BUTTONS */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    min-height: 40px;
    transition: background 0.2s ease;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: rgba(255, 255, 255, 0.1); color: var(--text-main); }
.btn-danger { background: #e53935; color: #fff; }

.btn-icon {
    background: none;
    border: none;
    color: var(--text-main);
    font-size: 18px;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.btn-circle-blur {
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    padding: 8px 14px;
    border-radius: 20px;
    font-size: 12px;
    cursor: pointer;
}

/* PERMISSION BANNER */
.permission-banner {
    background: #ffe082;
    color: #000;
    padding: 10px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    font-weight: 500;
}

/* MAIN CONTENT */
.main-content {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.view-section {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
    overflow-y: auto;
    padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom));
}

.view-section.active { display: flex; }

/* SEARCH & FILTER BAR */
.search-filter-bar {
    padding: 12px 16px;
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    background: var(--bg-main);
}

.search-box {
    flex: 1;
    min-width: 200px;
    display: flex;
    align-items: center;
    background: var(--bg-card);
    border-radius: 8px;
    padding: 0 12px;
    border: 1px solid rgba(255,255,255,0.05);
}

.search-box input {
    width: 100%;
    background: none;
    border: none;
    padding: 10px 8px;
    color: var(--text-main);
    font-size: 14px;
    outline: none;
}

.filter-box select {
    background: var(--bg-card);
    color: var(--text-main);
    border: 1px solid rgba(255,255,255,0.05);
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 13px;
    outline: none;
    height: 100%;
}

/* YOUTUBE GRID */
.yt-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    padding: 0 16px 16px 16px;
}

@media (min-width: 768px) {
    .yt-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 20px;
    }
}

@media (min-width: 1024px) {
    .yt-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

.yt-card {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    cursor: pointer;
}

.yt-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 20px rgba(0,0,0,0.4);
}

.thumb-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #000;
}

.thumb-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.badge-duration {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: rgba(0,0,0,0.8);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
}

.card-info {
    padding: 10px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
}

.card-details {
    flex: 1;
    overflow: hidden;
}

.card-title {
    font-size: 13px;
    font-weight: 600;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 4px;
}

.card-meta {
    font-size: 11px;
    color: var(--text-sub);
    display: flex;
    gap: 8px;
    align-items: center;
}

.card-tags {
    color: var(--accent);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 80px;
}

.btn-edit-card {
    padding: 4px;
    min-width: 32px;
    min-height: 32px;
    opacity: 0.8;
}

/* EMPTY STATE */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
    color: var(--text-sub);
}

.empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state h2 { color: var(--text-main); font-size: 18px; margin-bottom: 6px; }

/* TIKTOK MODE (FULLSCREEN INTERACTIVE) */
.tt-view-full {
    padding-bottom: 0 !important;
    background: #000;
}

.tt-top-nav {
    position: absolute;
    top: max(16px, env(safe-area-inset-top));
    left: 16px;
    right: 16px;
    z-index: 50;
    display: flex;
    justify-content: space-between;
}

.tt-feed {
    width: 100vw;
    height: 100vh;
    overflow-y: scroll;
    scroll-snap-type: y mandatory;
    scrollbar-width: none;
}

.tt-feed::-webkit-scrollbar { display: none; }

.tt-item {
    width: 100vw;
    height: 100vh;
    scroll-snap-align: start;
    scroll-snap-stop: always;
    position: relative;
    background: #000;
}

.tt-item video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.tt-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 24px 16px 32px 16px;
    pointer-events: none;
    background: linear-gradient(to bottom, transparent 60%, rgba(0,0,0,0.85) 100%);
}

.tt-info {
    pointer-events: auto;
    max-width: 80%;
    margin-bottom: 12px;
}

.tt-title { font-size: 15px; font-weight: 700; text-shadow: 0 1px 3px rgba(0,0,0,0.8); }
.tt-tags { font-size: 13px; color: #fff; opacity: 0.9; margin-top: 4px; }

.tt-actions {
    position: absolute;
    right: 16px;
    bottom: 60px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: center;
    pointer-events: auto;
}

.action-btn {
    background: none;
    border: none;
    color: #fff;
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 26px;
    cursor: pointer;
}

.action-btn.liked { color: var(--accent-tt); }

/* INTERACTIVE DURATION SCRUBBING BAR (TIKTOK STYLE) */
.tt-scrubber-container {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 16px;
    z-index: 40;
    display: flex;
    align-items: flex-end;
    cursor: pointer;
    pointer-events: auto;
}

.tt-scrubber-track {
    width: 100%;
    height: 3px;
    background: rgba(255, 255, 255, 0.25);
    position: relative;
    transition: height 0.15s ease;
}

.tt-scrubber-container:active .tt-scrubber-track,
.tt-scrubber-container:hover .tt-scrubber-track {
    height: 6px;
}

.tt-scrubber-fill {
    height: 100%;
    background: var(--accent-tt);
    width: 0%;
    position: relative;
}

.tt-scrubber-thumb {
    position: absolute;
    right: -6px;
    top: 50%;
    transform: translateY(-50%) scale(0);
    width: 12px;
    height: 12px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.15s ease;
}

.tt-scrubber-container:active .tt-scrubber-thumb,
.tt-scrubber-container:hover .tt-scrubber-thumb {
    transform: translateY(-50%) scale(1);
}

/* SETTINGS VIEW */
#settings-view {
    padding: 16px;
    gap: 16px;
}

.settings-card {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.settings-card h2 {
    font-size: 16px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    padding-bottom: 8px;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
}

.setting-item select, .setting-item input[type="range"] {
    background: var(--bg-main);
    color: var(--text-main);
    border: 1px solid rgba(255,255,255,0.1);
    padding: 6px;
    border-radius: 6px;
}

/* BOTTOM NAVIGATION */
.bottom-nav {
    height: var(--nav-height);
    background: rgba(15, 15, 15, 0.98);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    justify-content: space-around;
    align-items: center;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 100;
}

.bottom-nav.is-hidden { display: none !important; }

.nav-item {
    background: none;
    border: none;
    color: var(--text-sub);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    min-width: 60px;
    min-height: 44px;
    justify-content: center;
    cursor: pointer;
}

.nav-item.active { color: var(--accent); }
.nav-icon { font-size: 18px; }
.nav-label { font-size: 10px; font-weight: 500; }

/* PLAYER MODAL */
.player-modal {
    position: fixed;
    inset: 0;
    background: #000;
    z-index: 1000;
    display: none;
}

.player-modal.active { display: flex; }

.video-container {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
    touch-action: none;
}

.video-container video {
    width: 100%;
    height: 100%;
    max-height: 100vh;
    object-fit: contain;
}

.player-bar {
    position: absolute;
    left: 0;
    right: 0;
    background: linear-gradient(to bottom, rgba(0,0,0,0.8), transparent);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: opacity 0.3s ease;
    z-index: 20;
}

.top-bar {
    top: 0;
    padding-top: max(12px, env(safe-area-inset-top));
}

.bottom-bar {
    bottom: 0;
    background: linear-gradient(to top, rgba(0,0,0,0.8), transparent);
    flex-direction: column;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
}

.player-bar.hidden-bar {
    opacity: 0;
    pointer-events: none;
}

.player-title-text {
    flex: 1;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.top-bar-right { display: flex; gap: 4px; }
.timeline-row { width: 100%; }

.timeline-row input[type="range"] {
    width: 100%;
    accent-color: var(--accent);
    height: 4px;
    cursor: pointer;
}

.controls-row {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.controls-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.time-display {
    font-size: 12px;
    color: var(--text-sub);
}

.speed-select {
    background: rgba(255,255,255,0.1);
    color: #fff;
    border: none;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
}

/* GESTURE OVERLAYS */
.gesture-overlay, .playstate-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.7);
    padding: 16px 24px;
    border-radius: 30px;
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 30;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.gesture-icon { font-size: 24px; }

.playstate-overlay {
    border-radius: 50%;
    padding: 20px;
    font-size: 32px;
}

/* EDIT MODAL */
.modal-content {
    background: var(--bg-modal);
    border-radius: var(--border-radius);
    width: 90%;
    max-width: 450px;
    margin: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    z-index: 1001;
}

.edit-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.thumb-edit-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.thumb-edit-box img {
    width: 100%;
    max-height: 180px;
    object-fit: cover;
    border-radius: 8px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 12px;
    color: var(--text-sub);
}

.form-input {
    background: var(--bg-main);
    border: 1px solid rgba(255,255,255,0.1);
    color: var(--text-main);
    padding: 10px;
    border-radius: 6px;
    font-size: 14px;
    outline: none;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* RIPPLE ANIMATION */
.ripple {
    position: absolute;
    width: 80px;
    height: 80px;
    background: rgba(255, 255, 255, 0.4);
    border-radius: 50%;
    transform: scale(0);
    animation: ripple-anim 0.6s linear;
    pointer-events: none;
    z-index: 25;
}

@keyframes ripple-anim {
    to {
        transform: scale(2.5);
        opacity: 0;
    }
}

/* TOAST NOTIFICATION */
.toast {
    position: fixed;
    bottom: 70px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(30, 30, 30, 0.95);
    color: white;
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 13px;
    border: 1px solid rgba(255,255,255,0.1);
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    z-index: 2000;
    transition: opacity 0.3s ease;
}