:root {
    --primary-color: #ff0000;
    --primary-hover: #cc0000;
    --bg-color: #f4f5f7;
    --card-bg: #ffffff;
    --text-primary: #333333;
    --text-secondary: #666666;
    --border-color: #e0e0e0;

    /* Rank Colors */
    --rank-1-bg: linear-gradient(135deg, #fff9c4 0%, #fff176 100%);
    --rank-1-text: #f57f17;
    --row-odd-bg: #f9f9f9;
    --row-hover-bg: #f0f0f0;

    /* Spacing */
    --container-width: 1200px;
    --spacing-md: 1rem;
    --spacing-lg: 2rem;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Noto Sans KR', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.5;
}

.container {
    max-width: var(--container-width);
    margin: 0 auto;
    padding: 0 1rem;
}

/* Header */
.app-header {
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.05);
    padding: 1rem 0;
    margin-bottom: 2rem;
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid rgba(255, 255, 255, 0.3);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

/* Admin & Logo */
.hidden {
    display: none !important;
}

.logo-container img {
    height: 40px;
    width: auto;
    object-fit: contain;
}

.admin-controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    background: rgba(0, 0, 0, 0.05);
    padding: 0.5rem;
    border-radius: 8px;
}

#apiKeyInput {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    width: 200px;
}

/* Controls */
.controls-panel {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: flex-end;
    gap: 1.5rem;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
}

select,
input[type="number"] {
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 1rem;
    min-width: 120px;
    background-color: #fff;
    cursor: pointer;
    transition: box-shadow 0.2s;
}

select:focus,
input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(255, 0, 0, 0.1);
}

button {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(255, 0, 0, 0.2);
}

.btn-secondary {
    background-color: #f0f0f0;
    color: var(--text-primary);
}

.btn-secondary:hover {
    background-color: #e0e0e0;
}

/* Video List Table Structure */
.video-rank-section {
    background: var(--card-bg);
    border-radius: 12px;
    overflow: hidden;
    /* For rounded corners on children */
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
}

.table-header {
    display: flex;
    padding: 1rem;
    background-color: #fafafa;
    border-bottom: 1px solid var(--border-color);
    font-weight: 700;
    color: var(--text-secondary);
}

.col-rank {
    width: 80px;
    text-align: center;
}

.col-thumb {
    width: 150px;
}

.col-info {
    flex: 1;
    min-width: 200px;
    padding-left: 1rem;
}

.col-stats {
    width: 150px;
    text-align: right;
}

.video-item {
    display: flex;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    transition: background-color 0.2s;
}

.video-item:last-child {
    border-bottom: none;
}

.video-item:nth-child(odd) {
    background-color: var(--row-odd-bg);
}

.video-item:hover {
    background-color: var(--row-hover-bg);
}

/* Rank 1 Styling */
.video-item:first-child {
    background: var(--rank-1-bg);
    position: relative;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.video-item:first-child .rank-number {
    color: var(--rank-1-text);
    font-size: 1.5rem;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.rank-number {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-secondary);
    display: flex;
    justify-content: center;
    align-items: center;
}

.thumbnail-wrapper {
    width: 120px;
    height: 90px;
    overflow: hidden;
    border-radius: 6px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    position: relative;
}

.thumbnail-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.thumbnail-wrapper:hover img {
    transform: scale(1.1);
}

.video-info h3 {
    font-size: 1rem;
    margin-bottom: 0.5rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.video-info a {
    text-decoration: none;
    color: var(--text-primary);
    transition: color 0.2s;
}

.video-info a:hover {
    color: var(--primary-color);
}

.channel-name {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.status-item {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

/* Loading State */
.loading-state {
    padding: 3rem;
    text-align: center;
    color: var(--text-secondary);
    font-style: italic;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .table-header {
        display: none;
        /* Hide table header on mobile */
    }

    .video-list {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
        gap: 1rem;
        padding: 1rem;
        background: var(--bg-color);
        /* Reset background for grid gap */
    }

    .video-rank-section {
        background: transparent;
        box-shadow: none;
    }

    .video-item {
        background: var(--card-bg);
        border-radius: 12px;
        flex-direction: column;
        align-items: flex-start;
        padding: 0;
        overflow: hidden;
        box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
        border: none;
        position: relative;
    }

    /* Reset odd child rule for card view */
    .video-item:nth-child(odd) {
        background-color: var(--card-bg);
    }

    .col-rank {
        position: absolute;
        top: 0.5rem;
        left: 0.5rem;
        width: 30px;
        height: 30px;
        background: rgba(0, 0, 0, 0.7);
        color: white;
        border-radius: 50%;
        font-size: 0.9rem;
        z-index: 10;
        text-align: center;
        line-height: 30px;
    }

    .video-item:first-child {
        background: var(--card-bg);
        /* Reset rank 1 bg for cards, or keep it */
        background: linear-gradient(to bottom, #fff9c4, #fff);
    }

    .col-thumb {
        width: 100%;
    }

    .thumbnail-wrapper {
        width: 100%;
        height: 180px;
        border-radius: 0;
    }

    .col-info {
        padding: 1rem;
        width: 100%;
    }

    .col-stats {
        padding: 0 1rem 1rem;
        text-align: left;
        width: 100%;
        display: flex;
        gap: 1rem;
        font-size: 0.8rem;
    }
}