/* ========================================
   Glimvǫrðr - CSS Styles
   Discord-inspired dark theme
   ======================================== */

/* CSS Variables */
:root {
    --bg-primary: #1e1f22;
    --bg-secondary: #2b2d31;
    --bg-tertiary: #313338;
    --bg-overlay: rgba(0, 0, 0, 0.6);

    --text-primary: #f2f3f5;
    --text-secondary: #b5bac1;
    --text-muted: #6d6f78;

    --accent-primary: #5865f2;
    --accent-secondary: #7289da;
    --accent-gradient: linear-gradient(135deg, #5865f2 0%, #7289da 100%);

    --border-color: #3f4147;
    --shadow-color: rgba(0, 0, 0, 0.4);

    --header-height: 52px;
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
    --transition-slow: 0.4s ease;

    --font-primary: 'Inter', 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;

    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 16px;
    --radius-full: 50%;
}

/* Reset & Base */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

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

body {
    font-family: var(--font-primary);
    background: transparent;
    color: var(--text-primary);
    line-height: 1.5;
}

html {
    background: #111214;
}

/* ========================================
   Header
   ======================================== */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: rgba(30, 31, 34, 0.95);
    border-bottom: 1px solid rgba(255,255,255,0.06);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 100;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    transform: translateZ(0);
}

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

.header-center {
    display: flex;
    align-items: center;
    gap: 20px;
}

/* Subreddit Selector */
.subreddit-selector {
    display: flex;
    align-items: center;
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
    padding: 4px 12px;
    border: 1px solid var(--border-color);
    transition: border-color var(--transition-fast);
}

.subreddit-selector:focus-within {
    border-color: var(--accent-primary);
}

.subreddit-prefix {
    color: var(--text-secondary);
    font-weight: 500;
}

#subreddit-input {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 1rem;
    width: 150px;
    outline: none;
}

.btn-go {
    background: var(--bg-tertiary);
    border: 1px solid var(--accent-primary);
    color: var(--text-primary);
    padding: 4px 12px;
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-go:hover {
    background: var(--accent-primary);
    color: white;
}

.btn-go:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(255, 71, 87, 0.4);
}

/* Sort Buttons */
.sort-selector {
    display: flex;
    gap: 8px;
}

.sort-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.sort-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.sort-btn.active {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    box-shadow: 0 0 0 1px var(--accent-primary);
}

/* Top Sort Container with Time Filter */
.top-sort-container {
    display: flex;
    align-items: center;
    gap: 4px;
}

.time-filter {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 6px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    cursor: pointer;
    outline: none;
    transition: all var(--transition-fast);
}

.time-filter:hover,
.time-filter:focus {
    border-color: var(--accent-primary);
    color: var(--text-primary);
}

/* Slideshow Controls */
.slideshow-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    padding-left: 10px;
    border-left: 1px solid var(--border-color);
}

.slideshow-btn {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.slideshow-btn:hover {
    border-color: var(--accent-primary);
    color: var(--text-primary);
}

.slideshow-btn.active {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 1px var(--accent-primary);
    color: var(--text-primary);
    animation: pulse 2s infinite;
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }
}

.slideshow-interval {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 4px 6px;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    cursor: pointer;
    outline: none;
}

/* Media Type Buttons */
.media-type-selector {
    display: flex;
    gap: 6px;
    padding-left: 10px;
    border-left: 1px solid var(--border-color);
}

.media-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.media-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.media-btn.active {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    box-shadow: 0 0 0 1px var(--accent-primary);
}

/* Icon Button */
.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: background var(--transition-fast);
}

.btn-icon:hover {
    background: var(--bg-tertiary);
}

/* ========================================
   Main Viewer
   ======================================== */
.viewer {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    z-index: 1;
}

.media-container {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.media-container img,
.media-container video {
    max-width: calc(100% - 40px);
    max-height: calc(100vh - 120px);
    object-fit: contain;
    transition: opacity var(--transition-normal), transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform, opacity;
}

.media-container img.loading,
.media-container video.loading {
    opacity: 0;
}

/* Swipe transition animations */
.media-container img.slide-out-up,
.media-container video.slide-out-up {
    transform: translateY(-100vh);
    opacity: 0;
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease;
}

.media-container img.slide-out-down,
.media-container video.slide-out-down {
    transform: translateY(100vh);
    opacity: 0;
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease;
}

.media-container img.slide-in-up,
.media-container video.slide-in-up {
    animation: slideInFromBottom 0.35s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.media-container img.slide-in-down,
.media-container video.slide-in-down {
    animation: slideInFromTop 0.35s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes slideInFromBottom {
    from {
        transform: translateY(60vh);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes slideInFromTop {
    from {
        transform: translateY(-60vh);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Progressive Image Loading - Blur-up Effect */
.media-container img.progressive-loading {
    filter: blur(15px);
    transform: scale(1.05);
    opacity: 1;
    transition: filter 0.4s ease-out, transform 0.4s ease-out;
}

.media-container img.progressive-loaded {
    filter: blur(0);
    transform: scale(1);
}

/* Loading Spinner */
.loading-spinner {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    color: var(--text-secondary);
}

.spinner {
    width: 50px;
    height: 50px;
    border: 3px solid var(--bg-tertiary);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-spinner.hidden {
    display: none;
}

/* Starfield Canvas */
#starfield-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 0;
    pointer-events: none;
}

/* ========================================
   Info Overlay
   ======================================== */
.info-overlay {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 80px 20px 30px;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.85) 0%, rgba(0, 0, 0, 0.4) 50%, transparent 100%);
    pointer-events: none;
}

.info-overlay .post-meta {
    pointer-events: auto;
}

.post-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 10px;
    max-width: 75%;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    white-space: normal;
    line-height: 1.4;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.post-meta {
    display: flex;
    gap: 20px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.upvotes {
    color: var(--accent-primary);
    font-weight: 600;
}

.post-meta .subreddit,
.post-meta .author {
    cursor: pointer;
    transition: color var(--transition-fast);
}

.post-meta .subreddit:hover,
.post-meta .author:hover {
    color: var(--accent-primary);
    text-decoration: underline;
}

/* ========================================
   Navigation Controls
   ======================================== */
.nav-controls {
    position: fixed;
    right: 20px;
    top: 70px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 150;
    transition: right var(--transition-normal);
}

.nav-btn {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-md);
    background: rgba(43, 45, 49, 0.9);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    will-change: transform;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-btn:hover {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    transform: scale(1.1);
}

.nav-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.nav-btn:disabled:hover {
    background: var(--bg-tertiary);
    transform: none;
}

/* Progress Indicator */
.progress-indicator {
    position: fixed;
    right: 20px;
    top: 168px;
    background: rgba(43, 45, 49, 0.9);
    padding: 6px 12px;
    border-radius: var(--radius-md);
    font-size: 0.8rem;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    z-index: 150;
    transition: right var(--transition-normal);
}

/* Action Buttons */
.action-buttons {
    position: fixed;
    right: 20px;
    bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 150;
    transition: right var(--transition-normal);
}

.action-btn {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-md);
    background: rgba(43, 45, 49, 0.9);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    will-change: transform;
    display: flex;
    align-items: center;
    justify-content: center;
}

.action-btn:hover {
    background: var(--bg-secondary);
    transform: scale(1.1);
}

.action-btn.saved .icon {
    color: var(--accent-primary);
}

.action-btn.saved {
    background: rgba(255, 71, 87, 0.2);
    border-color: var(--accent-primary);
}

/* ========================================
   Sidebar
   ======================================== */
.sidebar {
    position: fixed;
    top: 0;
    right: 0;
    width: 320px;
    height: 100%;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    z-index: 200;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
    display: flex;
    flex-direction: column;
}

.sidebar.open {
    transform: translateX(0);
}

.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 150;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
}

.sidebar-overlay.visible {
    opacity: 1;
    visibility: visible;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

.sidebar-content {
    padding: 20px;
    flex: 1;
    overflow-y: auto;
}

.saved-subreddits {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 20px;
}

.saved-subreddit-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border-radius: 10px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.saved-subreddit-item:hover {
    background: var(--bg-primary);
}

.saved-subreddit-item .name {
    font-weight: 500;
}

.saved-subreddit-item .remove-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.2rem;
    padding: 4px 8px;
    border-radius: 5px;
    transition: all var(--transition-fast);
}

.saved-subreddit-item .remove-btn:hover {
    background: rgba(255, 71, 87, 0.2);
    color: var(--accent-primary);
}

.btn-save-subreddit {
    width: 100%;
    padding: 12px;
    background: var(--bg-tertiary);
    border: 2px dashed var(--border-color);
    border-radius: 10px;
    color: var(--text-secondary);
    font-size: 0.95rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-save-subreddit:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.sidebar-section {
    padding: 20px;
    border-top: 1px solid var(--border-color);
}

.sidebar-section h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 15px;
    color: var(--text-secondary);
}

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

.playlist-item {
    display: flex;
    gap: 12px;
    padding: 10px;
    background: var(--bg-tertiary);
    border-radius: 10px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.playlist-item:hover {
    background: var(--bg-primary);
}

.playlist-item img {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: 8px;
}

.playlist-item .info {
    flex: 1;
    overflow: hidden;
}

.playlist-item .title {
    font-size: 0.9rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.playlist-item .meta {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.empty-message {
    color: var(--text-muted);
    font-size: 0.9rem;
    text-align: center;
    padding: 20px;
}

/* ========================================
   Animations
   ======================================== */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in {
    animation: fadeIn var(--transition-normal) ease-out;
}

.slide-up {
    animation: slideUp var(--transition-normal) ease-out;
}

/* ========================================
   Responsive
   ======================================== */

/* Tablet */
@media (max-width: 1024px) {
    .slideshow-controls {
        display: none;
    }

    .media-type-selector {
        border-left: none;
        padding-left: 0;
    }
}

/* Tablet portrait / large phone */
@media (max-width: 768px) {
    .header {
        height: auto;
        min-height: var(--header-height);
        padding: 8px 16px;
        flex-wrap: wrap;
        gap: 8px;
    }

    .header-center {
        flex-direction: row;
        gap: 8px;
        order: 3;
        width: 100%;
        overflow-x: auto;
        scrollbar-width: none;
        -ms-overflow-style: none;
        padding-bottom: 4px;
    }

    .header-center::-webkit-scrollbar {
        display: none;
    }

    .sort-selector {
        display: flex;
        flex-shrink: 0;
    }

    .sort-btn {
        padding: 6px 10px;
        font-size: 0.75rem;
        white-space: nowrap;
    }

    .media-type-selector {
        flex-shrink: 0;
    }

    .media-btn {
        padding: 6px 10px;
        font-size: 0.75rem;
        white-space: nowrap;
    }

    .subreddit-selector {
        padding: 6px 12px;
        flex-shrink: 0;
    }

    #subreddit-input {
        width: 120px;
    }

    .info-overlay {
        padding: 40px 15px 20px;
    }

    .post-title {
        font-size: 1rem;
        max-width: 65%;
    }

    .nav-controls {
        right: 10px;
    }

    .nav-btn {
        width: 44px;
        height: 44px;
    }

    .action-buttons {
        right: 10px;
    }

    .action-btn {
        width: 44px;
        height: 44px;
        font-size: 1.2rem;
    }

    .action-buttons {
        gap: 10px;
    }
}

/* Small phones */
@media (max-width: 480px) {
    .header {
        padding: 6px 12px;
    }

    .logo {
        font-size: 1.2rem;
    }

    .sort-btn {
        padding: 5px 8px;
        font-size: 0.7rem;
    }

    .media-btn {
        padding: 5px 8px;
        font-size: 0.7rem;
    }

    #subreddit-input {
        width: 90px;
        font-size: 0.9rem;
    }

    .btn-go {
        padding: 5px 12px;
        font-size: 0.85rem;
    }

    .post-title {
        font-size: 0.9rem;
        max-width: 55%;
    }

    .post-meta {
        font-size: 0.8rem;
        gap: 12px;
    }

    .nav-btn {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }

    .action-btn {
        width: 40px;
        height: 40px;
        font-size: 1.1rem;
    }

    .sidebar {
        width: 280px;
    }
}

/* Landscape mobile */
@media (max-height: 500px) and (orientation: landscape) {
    .header {
        height: 44px;
        min-height: 44px;
        padding: 4px 16px;
    }

    .header-center {
        order: 0;
        width: auto;
    }

    .logo {
        font-size: 1.1rem;
    }

    .sort-selector,
    .media-type-selector,
    .slideshow-controls {
        display: none;
    }

    .nav-controls {
        top: 50px;
        gap: 8px;
    }

    .nav-btn {
        width: 38px;
        height: 38px;
    }

    .action-buttons {
        top: auto;
        bottom: 10px;
        right: 10px;
        flex-direction: row;
        gap: 8px;
    }

    .action-btn {
        width: 38px;
        height: 38px;
        font-size: 1rem;
    }

    .info-overlay {
        padding: 30px 15px 10px;
    }

    .post-title {
        font-size: 0.85rem;
        -webkit-line-clamp: 1;
    }

    .post-meta {
        font-size: 0.75rem;
    }
}

/* Safe area insets for notch devices */
@supports (padding: env(safe-area-inset-top)) {
    .header {
        padding-top: max(8px, env(safe-area-inset-top));
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
    }

    .info-overlay {
        padding-bottom: max(30px, env(safe-area-inset-bottom));
    }

    .action-buttons {
        right: max(20px, env(safe-area-inset-right));
    }

    .nav-controls {
        right: max(20px, env(safe-area-inset-right));
    }
}

/* ========================================
   Scrollbar
   ======================================== */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
}

::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* ========================================
   Error Overlay
   ======================================== */
.error-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
    backdrop-filter: blur(10px);
}

.error-overlay.hidden {
    display: none;
}

.error-content {
    text-align: center;
    padding: 40px;
}

.error-icon {
    font-size: 4rem;
    display: block;
    margin-bottom: 20px;
}

.error-content h3 {
    font-size: 1.3rem;
    color: var(--text-primary);
    margin-bottom: 25px;
}

.btn-retry {
    background: var(--accent-gradient);
    border: none;
    color: white;
    padding: 12px 30px;
    border-radius: 25px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-retry:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(255, 71, 87, 0.4);
}

/* ========================================
   Pull to Refresh
   ======================================== */
.pull-refresh-indicator {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translate(-50%, -200px);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 15px 25px;
    background: var(--bg-secondary);
    border-radius: 30px;
    border: 1px solid var(--border-color);
    z-index: 200;
    transition: transform var(--transition-normal);
    will-change: transform;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.pull-refresh-indicator.visible {
    transform: translate(-50%, 0);
}

.pull-refresh-indicator.refreshing {
    transform: translate(-50%, 0);
}

.pull-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* ========================================
   Volume/Fullscreen Button States
   ======================================== */
.action-btn.unmuted .icon {
    color: var(--accent-primary);
}

.action-btn.fullscreen-active {
    background: rgba(255, 71, 87, 0.2);
    border-color: var(--accent-primary);
}

/* ========================================
   Utility Classes
   ======================================== */
.hidden {
    display: none !important;
}

/* ========================================
   Playlist Remove Button
   ======================================== */
.playlist-item {
    position: relative;
}

.playlist-remove-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 71, 87, 0.2);
    border: none;
    color: var(--accent-primary);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-size: 0.9rem;
    cursor: pointer;
    opacity: 0;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}

.playlist-item:hover .playlist-remove-btn {
    opacity: 1;
}

.playlist-remove-btn:hover {
    background: var(--accent-primary);
    color: white;
    transform: translateY(-50%) scale(1.1);
}

/* ========================================
   Subreddit Autocomplete
   ======================================== */
.subreddit-selector {
    position: relative;
}

.autocomplete-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 15px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 300;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    display: none;
}

.autocomplete-dropdown.visible {
    display: block;
}

.autocomplete-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.autocomplete-item:first-child {
    border-radius: 15px 15px 0 0;
}

.autocomplete-item:last-child {
    border-radius: 0 0 15px 15px;
}

.autocomplete-item:only-child {
    border-radius: 15px;
}

.autocomplete-item:hover {
    background: var(--bg-tertiary);
}

.autocomplete-item .icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
}

.autocomplete-item .icon img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.autocomplete-item .details {
    flex: 1;
    min-width: 0;
}

.autocomplete-item .name {
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.autocomplete-item .subscribers {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.autocomplete-loading {
    padding: 20px;
    text-align: center;
    color: var(--text-muted);
}

/* ========================================
   Download Button
   ======================================== */
.action-btn.downloading {
    pointer-events: none;
}

.action-btn.downloading .icon {
    animation: downloadPulse 1s ease-in-out infinite;
}

@keyframes downloadPulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.4;
    }
}

/* ========================================
   Toast Notification
   ======================================== */
.toast {
    position: fixed;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 14px 28px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    font-size: 0.9rem;
    z-index: 400;
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
    pointer-events: none;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

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

/* ========================================
   Keyboard Shortcuts Overlay
   ======================================== */
.shortcuts-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.92);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    z-index: 500;
    display: none;
    align-items: center;
    justify-content: center;
}

.shortcuts-overlay.visible {
    display: flex;
}

.shortcuts-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 30px 40px;
    max-width: 420px;
    width: 90%;
}

.shortcuts-content h2 {
    font-size: 1.2rem;
    margin-bottom: 20px;
    color: var(--text-primary);
}

.shortcut-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
}

.shortcut-row:last-child {
    border-bottom: none;
}

.shortcut-key {
    background: var(--bg-tertiary);
    padding: 4px 12px;
    border-radius: var(--radius-sm);
    font-family: monospace;
    font-size: 0.85rem;
    color: var(--accent-primary);
    border: 1px solid var(--border-color);
}

.shortcut-desc {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* ========================================
   Share Button
   ======================================== */
.action-btn.shared {
    animation: shareSuccess 0.5s ease;
}

@keyframes shareSuccess {
    0% { transform: scale(1); }
    50% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

/* ========================================
   NSFW Toggle
   ======================================== */
.nsfw-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border-radius: 10px;
    margin-bottom: 15px;
}

.nsfw-toggle .label {
    font-weight: 500;
    color: var(--text-primary);
}

.toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
    background: var(--border-color);
    border-radius: 12px;
    cursor: pointer;
    transition: background var(--transition-fast);
    border: none;
    padding: 0;
}

.toggle-switch.active {
    background: var(--accent-primary);
}

.toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: var(--radius-full);
    transition: transform var(--transition-fast);
}

.toggle-switch.active::after {
    transform: translateX(20px);
}

/* ========================================
   Gallery
   ======================================== */
.gallery-dots {
    position: fixed;
    bottom: 120px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 6px;
    z-index: 50;
    padding: 8px 14px;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 20px;
}

.gallery-dot {
    width: 8px;
    height: 8px;
    border-radius: var(--radius-full);
    background: rgba(255, 255, 255, 0.35);
    border: none;
    padding: 0;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.gallery-dot.active {
    background: var(--accent-primary);
    transform: scale(1.3);
}

.gallery-counter {
    position: fixed;
    bottom: 155px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.8rem;
    color: var(--text-secondary);
    background: rgba(0, 0, 0, 0.6);
    padding: 4px 12px;
    border-radius: 12px;
    z-index: 50;
}

.gallery-nav {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    transition: all var(--transition-fast);
    opacity: 0.7;
}

.gallery-nav:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.7);
}

.gallery-nav.gallery-prev {
    left: 20px;
}

.gallery-nav.gallery-next {
    right: 80px;
}

@media (max-width: 768px) {
    .gallery-nav {
        width: 34px;
        height: 34px;
        font-size: 1rem;
    }

    .gallery-nav.gallery-prev {
        left: 10px;
    }

    .gallery-nav.gallery-next {
        right: 60px;
    }

    .gallery-dots {
        bottom: 100px;
    }

    .gallery-counter {
        bottom: 130px;
    }
}

/* ========================================
   Image Zoom
   ======================================== */
.media-container img.zoomed {
    cursor: grab;
    transition: none;
    max-width: none;
    max-height: none;
}

.media-container img.zoomed.grabbing {
    cursor: grabbing;
}

.media-container.zoom-active {
    overflow: hidden;
}

/* ========================================
   Comments Bottom Sheet
   ======================================== */
.comments-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 60vh;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    border-radius: 20px 20px 0 0;
    z-index: 250;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
    display: flex;
    flex-direction: column;
}

.comments-sheet.visible {
    transform: translateY(0);
}

.comments-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    cursor: pointer;
    flex-shrink: 0;
}

.comments-handle::before {
    content: '';
    width: 40px;
    height: 4px;
    background: var(--border-color);
    border-radius: 2px;
}

.comments-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px 12px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.comments-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.comments-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
}

.comments-close:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.comments-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
}

.comment-item {
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
}

.comment-item:last-child {
    border-bottom: none;
}

.comment-author {
    font-size: 0.8rem;
    color: var(--accent-primary);
    font-weight: 600;
    margin-bottom: 4px;
}

.comment-score {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-left: 8px;
    font-weight: normal;
}

.comment-text {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.5;
    word-wrap: break-word;
}

.comments-loading {
    text-align: center;
    color: var(--text-muted);
    padding: 30px;
}

.comments-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 240;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
}

.comments-overlay.visible {
    opacity: 1;
    visibility: visible;
}

/* ========================================
   Theme Selector
   ======================================== */
.theme-selector {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border-radius: 10px;
    margin-bottom: 15px;
}

.theme-option {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    border: 2px solid transparent;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.theme-option:hover {
    transform: scale(1.15);
}

.theme-option.active {
    border-color: var(--accent-primary);
    box-shadow: 0 0 8px rgba(255, 71, 87, 0.4);
}

.theme-oled { background: #000000; border: 2px solid #333; }
.theme-midnight { background: #0a1628; }
.theme-reddit { background: #1a1a2e; }

/* ========================================
   Tab Navigation
   ======================================== */
.tab-nav {
    display: flex;
    gap: 4px;
    margin-left: 12px;
    background: var(--bg-tertiary);
    border-radius: 20px;
    padding: 3px;
}

.tab-btn {
    padding: 5px 14px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.tab-btn:hover {
    color: var(--text-primary);
}

.tab-btn.active {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    box-shadow: 0 0 0 1px var(--accent-primary);
}

/* ========================================
   Discover Panel
   ======================================== */
.discover-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-primary);
    z-index: 50;
    display: none;
    overflow-y: auto;
    padding: 80px 20px 30px;
}

.discover-panel.visible {
    display: block;
}

.discover-scroll {
    max-width: 100%;
}

.discover-category-header {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 30px 0 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
}

.discover-category-header:first-child {
    margin-top: 0;
}

.discover-sub-section {
    margin-bottom: 20px;
}

.discover-sub-title {
    margin-bottom: 6px;
}

.discover-sub-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color var(--transition-fast);
}

.discover-sub-name:hover {
    color: var(--accent-primary);
}

.discover-sub-row {
    display: flex;
    gap: 4px;
    overflow: hidden;
    min-height: 240px;
}

.discover-preview-card {
    flex: 1 1 0;
    min-width: 0;
    height: 280px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    cursor: pointer;
    position: relative;
    transition: transform var(--transition-fast);
}

.discover-preview-card:hover {
    transform: scale(1.05);
}

.discover-preview-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

@media (max-width: 768px) {
    .discover-panel {
        padding: 70px 12px 20px;
    }

    .discover-preview-card {
        height: 120px;
    }

    .tab-btn {
        padding: 5px 12px;
        font-size: 0.8rem;
    }
}

/* ========================================
   Grid View (Masonry)
   ======================================== */
.viewer.grid-mode {
    top: 0;
    align-items: flex-start;
    justify-content: center;
    overflow-y: auto;
}

.viewer.grid-mode > .info-overlay,
.viewer.grid-mode > .nav-controls,
.viewer.grid-mode > .progress-indicator {
    display: none !important;
}

.viewer.grid-mode .media-container {
    position: relative;
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: calc(var(--header-height) + 12px) 20px 60px;
    display: block;
}

.grid-card {
    position: absolute;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    background: var(--bg-tertiary);
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.grid-card:hover {
    transform: scale(1.03);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.7);
    z-index: 2;
}

.grid-card img {
    width: 100%;
    max-width: 100%;
    max-height: none;
    display: block;
}

.grid-card-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 28px 10px 8px;
    background: linear-gradient(to top, rgba(0,0,0,0.85), transparent);
    opacity: 0;
    transition: opacity var(--transition-fast);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.grid-card:hover .grid-card-overlay {
    opacity: 1;
}

.grid-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}

.grid-meta {
    font-size: 0.65rem;
    color: var(--text-secondary);
}

.grid-play-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 44px;
    height: 44px;
    border-radius: var(--radius-full);
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: white;
    pointer-events: none;
    opacity: 0.8;
}

.grid-card:hover .grid-play-icon {
    background: var(--accent-primary);
    opacity: 1;
}

/* Auto-scroll controls */
.autoscroll-controls {
    display: flex;
    align-items: center;
    gap: 6px;
}

.autoscroll-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 80px;
    height: 4px;
    border-radius: 2px;
    background: var(--bg-tertiary);
    outline: none;
    cursor: pointer;
}

.autoscroll-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent-primary);
    cursor: pointer;
    border: none;
}

.autoscroll-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent-primary);
    cursor: pointer;
    border: none;
}

/* Grid Settings Dropdown */
.grid-settings-wrapper {
    position: relative;
}

.grid-settings-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    min-width: 220px;
    z-index: 200;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
}

.grid-settings-dropdown.open {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.grid-settings-dropdown label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.grid-settings-dropdown label span:first-child {
    min-width: 90px;
    color: var(--text-primary);
    font-weight: 500;
}

.grid-settings-dropdown label span:last-child {
    min-width: 36px;
    text-align: right;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.grid-settings-dropdown input[type="range"] {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    border-radius: 2px;
    background: var(--bg-tertiary);
    outline: none;
    cursor: pointer;
}

.grid-settings-dropdown input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--accent-primary);
    cursor: pointer;
}

.grid-settings-dropdown input[type="range"]::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--accent-primary);
    cursor: pointer;
    border: none;
}

.grid-reset-btn {
    margin-top: 4px;
    padding: 6px 0;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.grid-reset-btn:hover {
    background: var(--accent-primary);
    color: #fff;
    border-color: var(--accent-primary);
}

/* Favorites Overlay */
.favorites-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 300;
    display: none;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.favorites-overlay.open {
    display: flex;
}

.favorites-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    width: 90vw;
    max-width: 900px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.favorites-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-color);
}

.favorites-header h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.favorites-grid {
    padding: 12px;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 6px;
}

.favorites-grid .empty-message {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--text-muted);
    padding: 40px 0;
    font-size: 0.85rem;
}

.fav-card {
    border-radius: var(--radius-sm);
    overflow: hidden;
    cursor: pointer;
    position: relative;
    transition: transform var(--transition-fast);
    aspect-ratio: 3/4;
}

.fav-card:hover {
    transform: scale(1.05);
}

.fav-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.fav-card-remove {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 22px;
    height: 22px;
    border-radius: var(--radius-full);
    background: rgba(0,0,0,0.7);
    border: none;
    color: var(--text-secondary);
    font-size: 0.7rem;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
}

.fav-card:hover .fav-card-remove {
    display: flex;
}

/* ========================================
   Subreddit Suggestion Chips
   ======================================== */
.subreddit-chips {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    max-width: 600px;
    padding: 20px;
    z-index: 10;
}

.subreddit-chip {
    padding: 10px 20px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    color: var(--text-secondary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.subreddit-chip:hover {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
    transform: scale(1.05);
}

/* ========================================
   Prefers Reduced Motion
   ======================================== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .media-container img.slide-in-up,
    .media-container video.slide-in-up,
    .media-container img.slide-in-down,
    .media-container video.slide-in-down {
        animation: none;
        opacity: 1;
        transform: none;
    }
}