* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #6c5ce7;
    --primary-hover: #5b4cdb;
    --bg-dark: #1a1a2e;
    --bg-card: #16213e;
    --text-primary: #eee;
    --text-secondary: #a0a0a0;
    --border-color: #2d3748;
    --success-color: #00cec9;
    --warning-color: #fdcb6e;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
    overflow: hidden;
}

/* Screen Management */
.screen {
    display: none;
    width: 100vw;
    height: 100vh;
}

.screen.active {
    display: flex;
}

/* Config Screen */
#config-screen {
    justify-content: center;
    align-items: center;
    padding: 20px;
    overflow-y: auto;
}

.config-container {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 40px;
    max-width: 500px;
    width: 100%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.config-container h1 {
    font-size: 2.5rem;
    text-align: center;
    margin-bottom: 5px;
}

.subtitle {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 30px;
}

.config-section {
    margin-bottom: 30px;
}

.config-section h2 {
    font-size: 1.1rem;
    color: var(--primary-color);
    margin-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 8px;
}

.primary-btn {
    width: 100%;
    padding: 15px 25px;
    font-size: 1.1rem;
    border: none;
    border-radius: 10px;
    background: var(--primary-color);
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.primary-btn:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(108, 92, 231, 0.4);
}

.primary-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.start-btn {
    background: var(--success-color);
    margin-top: 10px;
}

.start-btn:hover:not(:disabled) {
    background: #00b3a8;
    box-shadow: 0 5px 20px rgba(0, 206, 201, 0.4);
}

.folder-path {
    margin-top: 10px;
    padding: 10px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    font-size: 0.9rem;
    color: var(--text-secondary);
    word-break: break-all;
}

.folder-path.selected {
    color: var(--success-color);
}

.setting-row {
    margin-bottom: 15px;
}

.setting-row label {
    display: block;
    margin-bottom: 5px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.setting-row input[type="number"],
.setting-row select {
    width: 100%;
    padding: 10px 15px;
    font-size: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.2);
    color: var(--text-primary);
}

.setting-row input[type="number"]:focus,
.setting-row select:focus {
    outline: none;
    border-color: var(--primary-color);
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.checkbox-row label {
    margin-bottom: 0;
    cursor: pointer;
}

.checkbox-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary-color);
    cursor: pointer;
}

.format-info {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.format-info small {
    color: var(--warning-color);
}

/* Slideshow Screen */
#slideshow-screen {
    position: relative;
    background: #000;
}

.media-container {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

.media-element {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    position: absolute;
    opacity: 0;
    transition: opacity 0.5s ease;
}

.media-element.active {
    opacity: 1;
}

.media-element.slide-in {
    animation: slideIn 0.5s ease forwards;
}

.media-element.slide-out {
    animation: slideOut 0.5s ease forwards;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(-100%);
        opacity: 0;
    }
}

/* Loading Indicator */
.loading {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    color: var(--text-secondary);
}

.loading.active {
    display: flex;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.no-media {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    color: var(--text-secondary);
    font-size: 1.2rem;
}

.no-media.active {
    display: flex;
}

/* Controls Overlay */
.controls-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        to bottom,
        rgba(0, 0, 0, 0.7) 0%,
        transparent 15%,
        transparent 85%,
        rgba(0, 0, 0, 0.7) 100%
    );
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 20px;
    opacity: 0;
    transition: opacity 0.5s ease;
    pointer-events: none;
}

.controls-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.top-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.bottom-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.playback-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.control-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
    color: white;
    flex-shrink: 0;
}

.control-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.1);
}

.control-btn svg {
    width: 20px;
    height: 20px;
}

.media-counter {
    background: rgba(0, 0, 0, 0.5);
    padding: 8px 15px;
    border-radius: 20px;
    font-size: 0.9rem;
    backdrop-filter: blur(10px);
    width: auto;
    height: auto;
    color: var(--text-primary);
    gap: 0;
}

.media-counter:hover {
    background: rgba(255, 255, 255, 0.2);
}

.progress-bar {
    flex: 1;
    height: 6px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
    overflow: hidden;
    cursor: pointer;
}

.progress-fill {
    height: 100%;
    background: var(--primary-color);
    width: 0%;
    transition: width 0.1s linear;
}

.media-info {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Toast Notification */
.toast {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: var(--success-color);
    color: #000;
    padding: 12px 25px;
    border-radius: 25px;
    font-weight: 500;
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 100;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* Fullscreen Styles */
:fullscreen .controls-overlay {
    padding: 30px;
}

/* Responsive */
@media (max-width: 600px) {
    .config-container {
        padding: 25px;
    }

    .config-container h1 {
        font-size: 2rem;
    }

    .control-btn {
        width: 36px;
        height: 36px;
    }

    .control-btn svg {
        width: 18px;
        height: 18px;
    }

    .playback-row {
        gap: 5px;
    }
}

/* Keyboard focus styles */
button:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Thumbnail Grid Screen */
#grid-screen {
    flex-direction: column;
    background: var(--bg-dark);
    overflow: hidden;
}

.grid-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px 20px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.grid-header h2 {
    font-size: 1.2rem;
    font-weight: 500;
}

.grid-header .control-btn {
    background: rgba(255, 255, 255, 0.1);
}

.grid-count {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.thumbnail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    grid-auto-rows: min-content;
    gap: 12px;
    padding: 20px;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
    align-content: start;
}

.thumbnail-item {
    position: relative;
    width: 100%;
    padding-bottom: 56.25%; /* 16:9 aspect ratio */
    border-radius: 10px;
    overflow: hidden;
    cursor: pointer;
    background: var(--bg-card);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.thumbnail-item:hover {
    transform: scale(1.03);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.4);
}

.thumbnail-item.active {
    outline: 3px solid var(--primary-color);
    outline-offset: 2px;
}

.thumbnail-item img,
.thumbnail-item video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.thumbnail-item .thumb-placeholder {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #2d3748 0%, #1a202c 100%);
    font-size: 2.5rem;
}

.thumbnail-item .thumb-label {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 8px;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.85));
    font-size: 0.75rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.thumbnail-item .thumb-index {
    position: absolute;
    top: 8px;
    left: 8px;
    background: rgba(0, 0, 0, 0.7);
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
}

.thumbnail-item .thumb-type {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.7);
    padding: 3px 6px;
    border-radius: 4px;
    font-size: 0.7rem;
}

.thumbnail-item .video-icon {
    color: var(--warning-color);
}

@media (max-width: 600px) {
    .thumbnail-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 8px;
        padding: 12px;
    }
    
    .grid-header {
        padding: 12px 15px;
    }
    
    .grid-header h2 {
        font-size: 1rem;
    }
}
