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

:root {
    --bg: #ffffff;
    --bg-secondary: #f5f5f5;
    --bg-tertiary: #e8e8e8;
    --text: #1a1a1a;
    --text-secondary: #555555;
    --border: #ddd;
    --accent: #ff0033;
    --accent-hover: #cc0029;
    --active-bg: #fff0f2;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.12);
    --radius: 8px;
    --radius-lg: 12px;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0f0f0f;
        --bg-secondary: #1a1a1a;
        --bg-tertiary: #272727;
        --text: #f1f1f1;
        --text-secondary: #aaaaaa;
        --border: #333;
        --accent: #ff3355;
        --accent-hover: #ff1a40;
        --active-bg: #2a1520;
        --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
        --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.4);
    }
}

[data-theme="dark"] {
    --bg: #0f0f0f;
    --bg-secondary: #1a1a1a;
    --bg-tertiary: #272727;
    --text: #f1f1f1;
    --text-secondary: #aaaaaa;
    --border: #333;
    --accent: #ff3355;
    --accent-hover: #ff1a40;
    --active-bg: #2a1520;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.4);
}

html {
    color-scheme: light dark;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: background-color 0.2s, color 0.2s;
}

/* Header */
.header {
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
}

.header-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    font-size: 1.4rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--accent);
    text-decoration: none;
}

.logo-icon {
    flex-shrink: 0;
}

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

.header-icon-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px;
    cursor: pointer;
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

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

.theme-toggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px;
    cursor: pointer;
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

.theme-toggle:hover {
    background: var(--bg-tertiary);
}

.icon-moon {
    display: none;
}

[data-theme="dark"] .icon-sun {
    display: none;
}

[data-theme="dark"] .icon-moon {
    display: block;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .icon-sun {
        display: none;
    }
    :root:not([data-theme="light"]) .icon-moon {
        display: block;
    }
}

[data-theme="light"] .icon-sun {
    display: block;
}

[data-theme="light"] .icon-moon {
    display: none;
}

/* Main */
.main {
    flex: 1;
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
    width: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

/* Input Section */
.input-section {
    margin-bottom: 24px;
}

.input-wrapper {
    display: flex;
    gap: 12px;
    max-width: 700px;
    margin: 0 auto;
}

.playlist-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    background: var(--bg);
    color: var(--text);
    outline: none;
    transition: border-color 0.2s;
}

.playlist-input:focus {
    border-color: var(--accent);
}

.shuffle-btn {
    padding: 12px 24px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color 0.2s;
}

.shuffle-btn:hover {
    background: var(--accent-hover);
}

.shuffle-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Loading */
.loading {
    text-align: center;
    padding: 48px 0;
    color: var(--text-secondary);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    margin: 0 auto 16px;
    animation: spin 0.8s linear infinite;
}

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

/* Error */
.error {
    max-width: 700px;
    margin: 0 auto 24px;
    padding: 12px 16px;
    background: #ff003310;
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    color: var(--accent);
    text-align: center;
}

/* Input tagline */
.input-tagline {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-bottom: 20px;
}

/* Change Playlist Button */
.change-playlist-btn {
    padding: 8px 14px;
    margin-right: 24px;
    background: none;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.8rem;
    cursor: pointer;
    transition: background-color 0.2s;
}

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

/* Content */
.content {
    flex: 1;
    min-height: 0;
}

/* Content Grid */
.content-grid {
    display: grid;
    grid-template-columns: 1fr 420px;
    gap: 24px;
    align-items: start;
    height: 100%;
}

/* Player */
.player-column {
    position: sticky;
    top: 24px;
}

.player-wrapper {
    position: relative;
    width: 100%;
    padding-bottom: 56.25%;
    background: #000;
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}

.player-wrapper iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.now-playing {
    margin-top: 16px;
}

.now-playing-title {
    font-size: 1.1rem;
    font-weight: 600;
    line-height: 1.4;
}

.now-playing-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 4px;
}

.now-playing-channel {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.now-playing-date {
    color: var(--text-secondary);
    font-size: 0.85rem;
    flex-shrink: 0;
}

/* Controls */
.controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-top: 16px;
}

.control-btn {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text);
    transition: background-color 0.2s, transform 0.1s;
}

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

.control-btn:active {
    transform: scale(0.95);
}

.reshuffle-btn {
    width: 56px;
    height: 56px;
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.reshuffle-btn:hover {
    background: var(--accent-hover);
}

/* Playlist Column */
.playlist-column {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.playlist-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

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

.playlist-count {
    font-size: 0.95rem;
    font-weight: 600;
}

.shuffle-again-btn {
    padding: 4px 12px;
    background: none;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: background-color 0.2s;
}

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

.filter-input {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.85rem;
    background: var(--bg);
    color: var(--text);
    outline: none;
    transition: border-color 0.2s;
}

.filter-input:focus {
    border-color: var(--accent);
}

/* Playlist List */
.playlist-list {
    list-style: none;
    overflow-y: auto;
    flex: 1;
}

.playlist-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background-color 0.15s;
}

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

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

.playlist-item.active {
    background: var(--active-bg);
    border-left: 3px solid var(--accent);
    padding-left: 13px;
}

.playlist-item-index {
    font-size: 0.8rem;
    color: var(--text-secondary);
    min-width: 24px;
    text-align: center;
    flex-shrink: 0;
}

.playlist-item-thumb {
    width: 64px;
    height: 36px;
    border-radius: 4px;
    object-fit: cover;
    flex-shrink: 0;
    background: var(--bg-tertiary);
}

.playlist-item-info {
    min-width: 0;
    flex: 1;
}

.playlist-item-title {
    font-size: 0.85rem;
    font-weight: 500;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Hidden utility */
.hidden {
    display: none !important;
}

/* Scrollbar */
.playlist-list::-webkit-scrollbar {
    width: 6px;
}

.playlist-list::-webkit-scrollbar-track {
    background: transparent;
}

.playlist-list::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

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

/* Responsive */
@media (max-width: 900px) {
    body {
        height: auto;
        overflow: auto;
    }

    .content-grid {
        grid-template-columns: 1fr;
        height: auto;
    }

    .player-column {
        position: static;
    }

    .playlist-column {
        max-height: 60vh !important;
    }

    .header-inner {
        padding: 12px 16px;
    }

    .main {
        padding: 16px;
    }
}

@media (max-width: 480px) {
    .input-wrapper {
        flex-direction: column;
    }

    .shuffle-btn {
        width: 100%;
    }

    .logo {
        font-size: 1.2rem;
    }
}
