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

:root {
    /* Backgrounds */
    --bg-page: #f1f5f9;
    --bg-card: #ffffff;
    --bg-card-hover: #f8fafc;
    --bg-disabled: #fef2f2;

    /* Text */
    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #64748b;

    /* Borders */
    --border-color: #e2e8f0;

    /* Game Mode Colors */
    --mode-race: #f59e0b;
    --mode-deathmatch: #ef4444;
    --mode-team-battle: #8b5cf6;
    --mode-greedy-piggy: #10b981;
    --mode-lobbies: #06b6d4;
    --mode-arbitrary: #ec4899;

    /* Rating Colors */
    --color-like: #22c55e;
    --color-dislike: #ef4444;
    --color-plays: #3b82f6;

    /* Radius */
    --radius: 12px;
    --radius-sm: 8px;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-page);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    font-size: 14px;
}

/* Dashboard Container */
.dashboard {
    max-width: 2200px;
    margin: 0 auto;
    padding: 24px;
}

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

.header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
}

.total-stat {
    background: var(--bg-card);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

/* Modes Grid - 4 game modes + wider Test List + normal Lobbies */
.modes-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr) 1.5fr 1fr;
    gap: 20px;
    align-items: start;
}

/* Mode Column - no individual scroll */
.mode-column {
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border-color);
    min-width: 240px;
}

/* Mode Header */
.mode-header {
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: white;
    position: sticky;
    top: 0;
    z-index: 10;
}

.mode-header h2 {
    font-size: 1rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.mode-count {
    background: rgba(255, 255, 255, 0.2);
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.875rem;
    font-weight: 600;
}

/* Mode Header Colors */
.mode-header.mode-race {
    background: linear-gradient(135deg, var(--mode-race), #d97706);
}

.mode-header.mode-deathmatch {
    background: linear-gradient(135deg, var(--mode-deathmatch), #dc2626);
}

.mode-header.mode-team-battle {
    background: linear-gradient(135deg, var(--mode-team-battle), #7c3aed);
}

.mode-header.mode-greedy-piggy {
    background: linear-gradient(135deg, var(--mode-greedy-piggy), #059669);
}

.mode-header.mode-lobbies {
    background: linear-gradient(135deg, var(--mode-lobbies), #0891b2);
}

.mode-header.mode-arbitrary {
    background: linear-gradient(135deg, var(--mode-arbitrary), #db2777);
}

.mode-header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.add-level-btn {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

.add-level-btn:hover {
    background: rgba(255, 255, 255, 0.35);
}

.add-level-btn svg {
    width: 16px;
    height: 16px;
}

.header-subtitle {
    font-size: 0.75rem;
    font-weight: 500;
    opacity: 0.8;
    text-transform: none;
    letter-spacing: normal;
}

.add-level-btn-large {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: none;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.25);
    color: white;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    cursor: pointer;
    transition: background 0.15s;
}

.add-level-btn-large:hover {
    background: rgba(255, 255, 255, 0.4);
}

.add-level-btn-large svg {
    width: 14px;
    height: 14px;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
}

.modal-overlay.open {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--bg-card);
    border-radius: var(--radius);
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border-color);
    transform: scale(0.95);
    transition: transform 0.2s;
}

.modal-overlay.open .modal {
    transform: scale(1);
}

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

.modal-header h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}

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

.modal-close svg {
    width: 18px;
    height: 18px;
}

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

.modal-section h4 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.modal-section.hidden {
    display: none;
}

.search-input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-page);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.875rem;
    margin-bottom: 16px;
    outline: none;
    transition: border-color 0.15s;
}

.search-input:focus {
    border-color: var(--mode-arbitrary);
}

.search-input::placeholder {
    color: var(--text-muted);
}

.creators-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
    max-height: 400px;
    overflow-y: auto;
}

.creator-card {
    background: var(--bg-page);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    cursor: pointer;
    transition: border-color 0.15s, transform 0.15s;
}

.creator-card:hover {
    border-color: var(--mode-arbitrary);
    transform: translateY(-2px);
}

.creator-card .name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.875rem;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.creator-card .count {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.section-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.back-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    background: var(--bg-page);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 0.8125rem;
    cursor: pointer;
    transition: background 0.15s;
}

.back-btn:hover {
    background: var(--bg-card-hover);
}

.back-btn svg {
    width: 14px;
    height: 14px;
}

.levels-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 400px;
    overflow-y: auto;
}

.level-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-page);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    transition: border-color 0.15s;
}

.level-item.in-arbitrary {
    border-color: var(--mode-arbitrary);
    background: rgba(236, 72, 153, 0.1);
}

.level-item.in-lobbies {
    border-color: var(--mode-lobbies);
    background: rgba(6, 182, 212, 0.1);
}

.add-btn.lobby-add-btn {
    background: var(--mode-lobbies);
}

.add-btn.lobby-add-btn:hover {
    background: #0891b2;
}

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

.level-item-name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9375rem;
    text-transform: uppercase;
    margin-bottom: 4px;
}

.level-item-stats {
    display: flex;
    gap: 12px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.level-item-modes {
    display: flex;
    gap: 4px;
    margin-top: 6px;
}

.level-item-action {
    margin-left: 12px;
}

.add-btn, .remove-btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.add-btn {
    background: var(--mode-arbitrary);
    color: white;
}

.add-btn:hover {
    background: #db2777;
}

.remove-btn {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

.remove-btn:hover {
    background: rgba(239, 68, 68, 0.3);
}

/* Game mode badges for AR levels */
.level-modes {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 8px;
}

.mode-badge {
    font-size: 0.625rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    text-transform: uppercase;
    opacity: 0.9;
}

.mode-badge.race { background: var(--mode-race); color: white; }
.mode-badge.deathmatch { background: var(--mode-deathmatch); color: white; }
.mode-badge.team-battle { background: var(--mode-team-battle); color: white; }
.mode-badge.greedy-piggy { background: var(--mode-greedy-piggy); color: white; }
.mode-badge.off { background: #e5e7eb; color: #6b7280; }

/* Levels List - no scroll */
.levels-list {
    padding: 12px;
}

/* Level Card */
.level-card {
    background: var(--bg-page);
    border-radius: var(--radius-sm);
    padding: 16px;
    margin-bottom: 10px;
    border: 1px solid var(--border-color);
    transition: transform 0.15s, box-shadow 0.15s;
    position: relative;
}

.level-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.level-card:last-child {
    margin-bottom: 0;
}

/* Disabled level card */
.level-card.disabled {
    background: var(--bg-disabled);
    border-color: #fecaca;
    opacity: 0.9;
}

.level-card.disabled .level-name {
    color: #b91c1c;
}

/* Level header with plays */
.level-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 6px;
}

.level-name {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 0.02em;
    flex: 1;
    margin-right: 10px;
}

/* Plays badge - top right */
.level-plays {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--color-plays);
    background: rgba(59, 130, 246, 0.15);
    padding: 4px 8px;
    border-radius: 6px;
    flex-shrink: 0;
}

.level-plays svg {
    width: 12px;
    height: 12px;
}

.level-creator {
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.level-creator span {
    color: #2563eb;
}

/* Level footer with ratings */
.level-footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 12px;
}

.level-stat {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.8125rem;
    font-weight: 500;
}

.level-stat svg {
    width: 14px;
    height: 14px;
}

.stat-likes {
    color: var(--color-like);
}

.stat-dislikes {
    color: var(--color-dislike);
}

.stat-rating {
    color: var(--text-secondary);
    font-weight: 600;
}

/* Disabled badge */
.disabled-badge {
    font-size: 0.625rem;
    font-weight: 700;
    text-transform: uppercase;
    background: #dc2626;
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 8px;
}

/* Toggle switch - slider style, hidden by default */
.level-toggle-wrapper {
    position: absolute;
    left: 16px;
    bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    opacity: 0;
    transition: opacity 0.15s;
    pointer-events: none;
    background: var(--bg-page);
    padding: 4px 8px;
    border-radius: 6px;
    z-index: 10;
}

.level-card:hover .level-toggle-wrapper {
    opacity: 1;
    pointer-events: auto;
}

.level-toggle {
    position: relative;
    width: 40px;
    height: 22px;
    background: #ef4444;
    border: none;
    border-radius: 11px;
    cursor: pointer;
    transition: background 0.2s;
    padding: 0;
}

.level-toggle.enabled {
    background: #22c55e;
}

.level-toggle::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s;
}

.level-toggle.enabled::after {
    transform: translateX(18px);
}

.level-toggle-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
}

.level-delete-btn {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 6px;
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 8px;
    transition: background 0.15s;
}

.level-delete-btn:hover {
    background: rgba(239, 68, 68, 0.4);
}

.level-delete-btn svg {
    width: 14px;
    height: 14px;
}

/* Mode count badges */
.mode-counts {
    display: flex;
    gap: 8px;
}

.mode-count-active {
    background: rgba(34, 197, 94, 0.3);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.8125rem;
    font-weight: 600;
}

.mode-count-disabled {
    background: rgba(239, 68, 68, 0.3);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.8125rem;
    font-weight: 600;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.empty-state svg {
    width: 48px;
    height: 48px;
    margin-bottom: 12px;
    opacity: 0.5;
}

.empty-state p {
    font-size: 0.875rem;
}

/* Loading */
.loading {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* Card loader spinner */
.card-loader {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 24px;
    height: 24px;
    border: 3px solid var(--border-color);
    border-top-color: var(--mode-arbitrary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Arbitrary Expandable Card */
.level-card.arbitrary-card {
    cursor: pointer;
}

.level-card.arbitrary-card.expanded {
    background: var(--bg-card);
}

.arbitrary-expand-area {
    display: none;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

.level-card.arbitrary-card.expanded .arbitrary-expand-area {
    display: block;
}

.expand-section-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 10px;
}

.game-mode-checkboxes {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 16px;
}

.mode-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: var(--bg-page);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.mode-checkbox:hover {
    border-color: var(--text-muted);
}

.mode-checkbox.checked {
    border-color: var(--mode-arbitrary);
    background: rgba(236, 72, 153, 0.1);
}

.mode-checkbox input {
    display: none;
}

.mode-checkbox-indicator {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, border-color 0.15s;
}

.mode-checkbox.checked .mode-checkbox-indicator {
    background: var(--mode-arbitrary);
    border-color: var(--mode-arbitrary);
}

.mode-checkbox.checked .mode-checkbox-indicator::after {
    content: '✓';
    color: white;
    font-size: 12px;
    font-weight: bold;
}

.mode-checkbox-label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.mode-checkbox.checked .mode-checkbox-label {
    color: var(--text-primary);
}

.mode-checkbox .mode-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-left: auto;
}

.mode-checkbox .mode-indicator.race { background: var(--mode-race); }
.mode-checkbox .mode-indicator.deathmatch { background: var(--mode-deathmatch); }
.mode-checkbox .mode-indicator.team-battle { background: var(--mode-team-battle); }
.mode-checkbox .mode-indicator.greedy-piggy { background: var(--mode-greedy-piggy); }

.arbitrary-actions {
    display: flex;
    gap: 8px;
}

.deploy-btn {
    flex: 1;
    padding: 10px 16px;
    border: none;
    border-radius: 6px;
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    background: #22c55e;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.deploy-btn:hover {
    background: #16a34a;
}

.deploy-btn:disabled {
    background: #374151;
    color: #6b7280;
    cursor: not-allowed;
}

.deploy-btn svg {
    width: 14px;
    height: 14px;
}

.remove-ar-btn {
    padding: 10px 16px;
    border: none;
    border-radius: 6px;
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

.remove-ar-btn:hover {
    background: rgba(239, 68, 68, 0.3);
}

/* Hide default toggle on arbitrary cards */
.level-card.arbitrary-card .level-toggle-wrapper {
    display: none;
}

/* Responsive */
@media (max-width: 2000px) {
    .modes-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 1200px) {
    .modes-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .dashboard {
        padding: 16px;
    }

    .modes-grid {
        grid-template-columns: 1fr;
    }

    .header h1 {
        font-size: 1.375rem;
    }
}
