/* --- Base --- */
:root {
    /* Colors */
    --bg-page: #ffffff;
    --bg-subtle: #fafafa;
    --bg-active: #f4f4f5;

    --text-primary: #09090b;
    --text-secondary: #71717a;
    --text-tertiary: #a1a1aa;

    --border: #e4e4e7;
    --border-light: #f4f4f5;

    --brand: #4f46e5;
    --success: #16a34a;
    --danger: #dc2626;

    --btn-primary-bg: #09090b;
    --btn-primary-text: #ffffff;

    --badge-win-bg: #dcfce7;
    --badge-loss-bg: #fee2e2;

    /* Dimensions & Spacing System */
    --container-width: 1100px;
    --nav-height: 60px;

    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 2rem;
    --space-xl: 3rem;
}

[data-theme="dark"] {
    /* Dark Mode Colors */
    --bg-page: #141416;
    --bg-subtle: #1d1d20;
    --bg-active: #27272a;

    --text-primary: #fafafa;
    --text-secondary: #a1a1aa;
    --text-tertiary: #71717a;

    --border: #27272a;
    --border-light: #1d1d20;

    --brand: #6366f1;
    /* Slightly lighter indigo for dark mode visibility */

    --btn-primary-bg: #fafafa;
    --btn-primary-text: #09090b;

    --badge-win-bg: rgba(22, 163, 74, 0.2);
    /* Soft success green */
    --badge-loss-bg: rgba(220, 38, 38, 0.2);
    /* Soft danger red */
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: "Source Sans 3", sans-serif;
}

body {
    color: var(--text-primary);
    background-color: var(--bg-page);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.main-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
}

a {
    text-decoration: none;
    color: inherit;
}

button {
    cursor: pointer;
    border: none;
    background: none;
}

img {
    display: block;
    /* Remove bottom space */
}

/* --- Navbar --- */
.navbar {
    height: var(--nav-height);
    border-bottom: 1px solid var(--border);
    background: var(--bg-page);
    position: sticky;
    top: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
}

/* Navbar Desktop Defaults */
.nav-header-mobile {
    display: contents;
    /* On desktop, brand behaves normally as flex child */
}

.brand {
    font-weight: 800;
    font-size: 1.1rem;
    letter-spacing: -0.02em;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: 8px;
}

.brand-tag {
    background: var(--brand);
    color: white;
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 2px;
}

.btn.btn-icon.nav-burger {
    display: none;
}

.nav-menu-container {
    display: flex;
    justify-content: space-between;
    flex-grow: 1;
    align-items: center;
    margin-left: 3rem;
}

.nav-left-links,
.nav-right-links {
    display: flex;
    gap: 2rem;
    align-items: center;
}

.nav-link {
    font-size: 0.85rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    text-align: left;
}

.nav-link:hover {
    color: var(--text-primary);
}

.nav-link.active {
    color: var(--brand);
}

.nav-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.nav-actions .btn:not(.btn-icon) {
    width: auto;
}

/* --- Hero --- */
.hero {
    position: relative;
    height: 45vh;
    width: 100%;
    background: var(--bg-page);
    display: flex;
    justify-content: center;
    z-index: 10;
}

.hero-bg,
.panel-bg,
.auth-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center 25%;
    z-index: 0;
    pointer-events: none;
}

.hero-bg {
    filter: grayscale(10%);
}

.hero::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 50%;
    background: linear-gradient(to bottom,
            rgba(0, 0, 0, 0) 0%,
            rgba(0, 0, 0, 0.05) 100%);
    z-index: 1;
    pointer-events: none;
}

.hero-content-wrapper {
    width: 100%;
    max-width: var(--container-width);
    height: 100%;
    position: relative;
    margin: 0 auto;
    padding: 0 1.5rem;
    pointer-events: none;
}

.hero-logo-container {
    pointer-events: auto;
    z-index: 20;
    position: absolute;

    /* Positioning logic: Hang off the bottom left */
    bottom: -2.5rem;
    left: 1.5rem;

    /* Card Visuals */
    background: var(--bg-page);
    padding: 1.5rem 1.5rem;
    border-radius: 4px;
    border: 1px solid var(--border);

    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;

    max-width: 50%;
    /* Ensure it doesn't overflow container width */
}

.hero-song-title {
    font-size: clamp(2rem, 5vw, 3.5rem);
    /* Clamp size to prevent massive overflow */
    font-weight: 850;
    letter-spacing: -0.03em;
    line-height: 1.1;
    color: var(--text-primary);
    text-align: center;

    /* Handle Text Overflow */
    overflow-wrap: break-word;
    word-wrap: break-word;
    hyphens: auto;
    max-width: 100%;
}

.hero-artist-name {
    font-size: 1.5rem;
    font-weight: 500;
    color: var(--text-secondary);
    letter-spacing: -0.01em;
    margin-top: 2px;
}

.hero-artist-name:hover {
    color: var(--brand);
    text-decoration: underline;
}

/* Fallback for Artist view if needed, or re-use logic */
.hero-logo {
    display: block;
    width: 100%;
    max-width: 320px;
    height: 180px;
    object-fit: contain;
    object-position: center;
    margin: 0 auto;
}

/* --- Info Bar --- */
.info-bar-container {
    border-bottom: 1px solid var(--border);
    background: var(--bg-page);
    padding: 1rem 0;
    /* Vertical efficiency */
    margin-bottom: 2rem;
    /* Reduce gap to content */
}

.info-bar-content {
    max-width: var(--container-width);
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.info-actions-group {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.info-stats-group {
    display: flex;
    gap: 3.5rem;
    align-items: center;
    margin-left: auto; /* Push to the right even if it's the only child */
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

/* Typography: Rating & Data */
.rating-value {
    font-family: "JetBrains Mono", "Courier New", monospace;
    letter-spacing: -0.05em;
    font-weight: 700;
    font-size: 1.4rem;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.rating-icon {
    font-family: "Inter", sans-serif;
    font-size: 0.8em;
    margin-right: 4px;
    vertical-align: 1px;
}

.rating-global {
    color: var(--text-secondary);
}

.rating-personal .rating-icon {
    color: var(--brand);
}

.rating-personal {
    color: var(--brand);
}

.stat-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 4px;
}

.stat-divider {
    width: 1px;
    height: 2.5rem;
    background-color: var(--border);
}

.win-loss-container {
    display: flex;
    gap: 0.5rem;
    font-size: 1.1rem;
    font-weight: 800;
    align-items: center;
}

.text-win {
    color: var(--success);
}

.text-loss {
    color: var(--danger);
}

.text-neutral {
    color: var(--text-tertiary);
}

/* --- Layout --- */
.layout {
    max-width: var(--container-width);
    width: 100%;
    margin: 0 auto;
    padding: 0 1.5rem 5rem 1.5rem;

    display: grid;
    grid-template-columns: 2fr 1fr;
    /* Main (2) | Sidebar (1) */
    gap: 3rem;
    /* Tighter gap */
}

.sidebar-group {
    margin-bottom: 2.5rem;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    border-spacing: 0;
}

.data-table th {
    text-align: left;
    padding: 1rem 0.5rem;
    /* Reduced padding */
    border-bottom: 2px solid var(--border);
    color: var(--text-secondary);
    font-weight: 800;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
}

.data-table td {
    padding: 1rem 0.5rem;
    /* Reduced padding */
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
}

.data-table tr:hover td {
    background-color: var(--bg-subtle);
}

.table-rank {
    width: 2rem;
    font-weight: 700;
    text-align: center;
    color: var(--text-tertiary);
    padding-right: 0;
}

.table-main a {
    font-weight: 800;
    font-size: 1rem;
    color: var(--text-primary);
    display: block;
}

.table-sub a {
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-tertiary);
    display: block;
    margin-top: 2px;
}

.table-value {
    text-align: right;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

/* Fix for Huge Rating in Tables */
.data-table .rating-value {
    font-size: 0.9rem;
    /* Much smaller than the 1.4rem global default */
    font-weight: 700;
}

/* --- Content Headers --- */
.tab-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-light);
    min-height: 2rem;
    /* Ensure consistent height even without tabs */
}

.section-title {
    font-size: 0.85rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin: 0;
    /* Reset margins to rely on parent container */
}

/* --- Media Wrappers --- */
.video-wrapper {
    width: 100%;
    aspect-ratio: 16 / 9;
    background-color: #000;
    position: relative;
    overflow: hidden;
    margin-bottom: 2rem;
}

.video-wrapper iframe {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.spotify-wrapper {
    margin-bottom: 2rem;
}

.spotify-wrapper iframe {
    border-radius: 12px;
}

/* --- Sidebar History Table --- */
.sidebar-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.sidebar-table tr {
    border-bottom: 1px solid var(--border-light);
}

.sidebar-table tr:last-child {
    border-bottom: none;
}

.sidebar-table td {
    padding: 0.8rem 0;
    vertical-align: top;
}

.history-meta {
    text-align: right;
    color: var(--text-tertiary);
    font-size: 0.75rem;
    white-space: nowrap;
}

.history-content {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.history-user {
    font-weight: 700;
    color: var(--text-primary);
}

.history-user:hover {
    text-decoration: underline;
}

.history-detail {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.result-badge {
    font-weight: 800;
    text-transform: uppercase;
    font-size: 0.7rem;
    padding: 1px 4px;
    border-radius: 3px;
    margin-right: 4px;
}

.badge-win {
    background: var(--badge-win-bg);
    color: var(--success);
}

.badge-loss {
    background: var(--badge-loss-bg);
    color: var(--danger);
}

/* --- Pill Toggle (shared base) --- */
.pill-toggle {
    display: inline-flex;
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 3px;
    gap: 0;
}

.pill-toggle__btn {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    padding: 5px 12px;
    border-radius: 999px;
    display: flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
}

.pill-toggle__btn:hover {
    color: var(--text-primary);
}

.pill-toggle__btn.active {
    background-color: var(--btn-primary-bg);
    color: var(--btn-primary-text);
    font-weight: 800;
}

/* Full-width variant (mobile section tabs) */
.pill-toggle--full {
    display: flex;
    width: 100%;
    border-radius: 999px;
}

.pill-toggle--full .pill-toggle__btn {
    flex: 1;
    justify-content: center;
    padding: 0.7rem 1rem;
    font-size: 0.85rem;
    font-weight: 700;
}

/* --- Lists --- */
.list-content {
    display: none;
}

.list-content.active {
    display: block;
}

.data-list {
    display: flex;
    flex-direction: column;
}

.data-row {
    display: flex;
    align-items: center;
    padding: 0.8rem 0;
    border-bottom: 1px solid var(--border-light);
    font-size: 0.9rem;
    gap: 1rem;
    cursor: pointer;
}

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

.data-row:hover {
    opacity: 0.7;
}

.data-rank {
    width: 1.5rem;
    font-weight: 600;
    color: var(--text-tertiary);
    font-variant-numeric: tabular-nums;
    font-size: 0.75rem;
}

.data-main {
    flex: 1;
    font-weight: 600;
    color: var(--text-primary);
}

.data-value {
    text-align: right;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

/* Override specifically for rating data values */
.data-value .rating-value,
.data-value.rating-value {
    font-size: 0.9rem;
    font-weight: 600;
}

.data-row.is-active {
    background: var(--bg-active);
    margin: 0 -0.75rem;
    padding-left: 0.75rem;
    padding-right: 0.75rem;
    border-radius: 4px;
    border-bottom: 1px solid transparent;
}

/* --- Admin --- */
.badge-admin {
    background: var(--brand);
    color: white;
    font-size: 0.7rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 2px 6px;
    border-radius: 4px;
    display: inline-block;
}





/* --- Login Prompt --- */
.login-prompt {
    text-align: center;
    padding: 3rem 1rem;
}

.login-prompt p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

.login-prompt .nav-actions {
    justify-content: center;
}

/* --- Footer --- */
.footer {
    margin-top: auto;
    border-top: 1px solid var(--border);
    padding: 4rem 1.5rem;
    background-color: var(--bg-active);
}

.footer-content {
    max-width: var(--container-width);
    margin: 0 auto;
    display: grid;
    grid-template-columns: 2fr 1fr 1fr;
    gap: 4rem;
}

.footer-brand-title {
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: -0.02em;
    display: block;
    margin-bottom: 0.5rem;
}

.footer-copy {
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

.footer-header {
    font-size: 0.7rem;
    font-weight: 800;
    text-transform: uppercase;
    color: var(--text-primary);
    margin-bottom: 1rem;
    letter-spacing: 0.05em;
}

.footer-link {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.6rem;
}

.footer-link:hover {
    color: var(--text-primary);
}

/* --- Skip Button --- */
#skip-form {
    position: absolute;
    bottom: 3rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
}




.mobile-section-tabs {
    display: none;
}

/* (Moved to top of section) */

@media (min-width: 901px) {
    .section-content {
        display: block;
        /* Always show both side by side on desktop */
    }
}

/* --- Arena (Vote Screen) - Keeping minimal overrides for compatibility with old templates if needed, but updated colors --- */
.arena {
    display: grid;
    grid-template-columns: 1fr 1fr;
    min-height: calc(100vh - 60px);
    background-color: var(--bg-page);
}

.song-panel {
    position: relative;
    display: flex;
    flex-direction: column;
    padding: 2rem;
    justify-content: center;
    align-items: center;
    z-index: 1;
}

.panel-bg {
    opacity: 0.25;
}

.panel-content {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 80%;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    text-align: center;
}

.panel-content>.video-wrapper {
    margin: 0;
}

.song-title {
    font-size: 2.8rem;
    font-weight: 850;
    color: var(--text-primary);
    letter-spacing: -0.02em;
    line-height: 0.9;
}

.song-artist {
    display: block;
    margin-top: 0.5rem;
    font-size: 1.2rem;
    font-weight: 800;
    text-transform: uppercase;
    color: var(--brand);
    letter-spacing: 0.05em;
}



/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.85rem 1rem;
    border-radius: 4px;
    font-size: 1rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    text-align: center;
    cursor: pointer;
    border: none;
    width: 100%;
}

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

.btn-primary:hover {
    background-color: var(--brand);
    color: #ffffff;
}

.btn-primary:active {
    background-color: var(--brand);
    color: #ffffff;
    filter: brightness(0.9);
}

.btn-secondary {
    background: var(--bg-subtle);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background-color: var(--brand);
    color: #ffffff;
    border-color: var(--brand);
}

.btn-secondary:active {
    background-color: var(--brand);
    color: #ffffff;
    border-color: var(--brand);
    filter: brightness(0.7);
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.75rem;
}

.btn.btn-icon {
    width: 2.4rem;
    height: 2.4rem;
    padding: 0;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* --- Auth Pages --- */
.auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 80vh;
    padding: 1.5rem;
    position: relative;
    overflow: hidden;
}

.auth-card {
    background: var(--bg-page);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 2.5rem;
    width: 100%;
    max-width: 400px;
    position: relative;
    z-index: 10;
}

.auth-title {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: 2rem;
    text-align: center;
    letter-spacing: -0.02em;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.auth-input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.auth-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.auth-input {
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.95rem;
    outline: none;
    width: 100%;
    background-color: var(--bg-page);
    color: var(--text-primary);
}

.auth-input:focus {
    border-color: var(--brand);
}

/* Ensure background image class is shared or follows same rules as panel-bg */
.auth-bg {
    opacity: 0.25;
    filter: grayscale(10%);
}





.auth-footer {
    margin-top: 1.5rem;
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.auth-link {
    color: var(--brand);
    font-weight: 600;
}

.auth-link:hover {
    text-decoration: underline;
}

.helptext {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    margin-top: 0.25rem;
}

.errorlist {
    list-style: none;
    color: var(--danger);
    font-size: 0.8rem;
    font-weight: 600;
    margin-top: 0.25rem;
}

/* --- Mobile / Responsive Tweaks --- */
@media (max-width: 900px) {
    .layout {
        grid-template-columns: 1fr;
        gap: 2rem;
    }

    .hero {
        height: 30vh;
    }

    .hero-logo-container {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        bottom: auto;
        margin: 0;
        width: 90%;
        max-width: 400px;
        text-align: center;
        align-items: center;
        padding: 1.5rem;
    }

    .hero-song-title {
        font-size: 2.5rem;
    }

    .hero-artist-name {
        font-size: 1.2rem;
    }

    .info-bar-container {
        /* Simplify on mobile if needed, or re-layout. Currently hiding per minimal simplified request or just fix layout. Let's fix layout below */
        display: block;
        /* Restore */
    }

    .info-bar-content {
        justify-content: center;
        text-align: center;
    }

    .info-stats-group {
        justify-content: space-between;
        width: 100%;
        gap: 1rem;
    }

    .stat-item {
        align-items: center;
    }

    /* Navbar Mobile Overrides */
    .navbar {
        padding: 0 1rem;
        position: sticky;
        /* Navbar becomes container for header + dropdown */
        display: block;
        height: auto;
    }

    .nav-header-mobile {
        display: flex;
        justify-content: space-between;
        align-items: center;
        height: var(--nav-height);
    }

    .nav-menu-container {
        display: none;
        flex-direction: column;
        width: 100%;
        margin-left: 0;
        padding-bottom: 0;
        border-top: 1px solid var(--border-light);
    }

    .nav-menu-container.active {
        display: flex;
    }

    .nav-left-links,
    .nav-right-links {
        flex-direction: column;
        width: 100%;
        gap: 0;
        align-items: flex-start;
    }

    /* Action buttons row at bottom of mobile menu */
    .nav-actions {
        padding: 1rem 0;
        border-top: 1px solid var(--border-light);
        width: 100%;
    }

    .nav-link {
        display: block;
        width: 100%;
        padding: 1rem 0;
        border-bottom: 1px solid var(--border-light);
        font-size: 1rem;
    }

    /* Remove border from the very last link in right-links */
    .nav-right-links .nav-link:last-child {
        border-bottom: none;
    }

    .btn.btn-icon.nav-burger {
        display: inline-flex;
    }

    /* Footer */
    .footer-content {
        grid-template-columns: 1fr;
        gap: 2rem;
    }

    /* Vote Page Mobile */
    .arena {
        grid-template-columns: 1fr;
        min-height: auto;
        /* Allow scrolling */
        padding-bottom: 0;
    }

    .song-panel {
        min-height: auto;
        padding: 1.5rem 1rem;
        /* Reduce side and vertical padding */
        border-bottom: none;
    }

    /* Expand content width to allow wider video */
    .panel-content {
        max-width: 100%;
        gap: 1rem;
    }

    #skip-form {
        position: relative;
        bottom: auto;
        left: auto;
        transform: none;
        padding: 1.5rem 1rem;
        width: 100%;
        max-width: var(--container-width);
        margin: 0 auto;
    }



    /* Mobile Section Tabs — just show the pill-toggle--full variant */
    .mobile-section-tabs {
        display: flex;
        margin-bottom: 1.5rem;
    }

    /* Hide/Show sections based on mobile tabs */
    .section-content {
        display: none;
    }

    .section-content.active-mobile {
        display: block;
    }

    /* On larger screens, ensure these helper classes don't mess up layout */
}