/* ========================================
   Pixel Series V2.1 — Design System & Utilities
   Supports dark/light/auto themes via data-theme attribute
   ======================================== */

/* Default: dark color scheme */
:root {
    color-scheme: dark;
    --mp-default: #fff;
}

/* ---- Theme Toggle Button ---- */
#theme-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-ps-surface, #1C1B1F);
    border: 1px solid var(--color-ps-border, #2A2A2E);
    color: var(--color-ps-muted, #7B7FA0);
    transition: color 0.2s, border-color 0.2s, background 0.2s;
    padding: 0;
    font: inherit;
}
#theme-toggle:hover {
    color: var(--color-ps-primary, #2C12D9);
    border-color: var(--color-ps-primary, #2C12D9);
}
.theme-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}
@media (max-width: 1023px) {
    #theme-toggle {
        top: auto;
        bottom: 20px;
        right: 20px;
    }
}

/* ---- Custom Crosshair Cursor (mix-blend-mode: difference) ---- */
@media (pointer: fine) {
    html, html * {
        cursor: none !important;
    }
    #cursor-crosshair {
        position: fixed;
        top: 0;
        left: 0;
        width: 24px;
        height: 24px;
        pointer-events: none;
        z-index: 10001;
        transform: translate(-50%, -50%);
        mix-blend-mode: difference;
        opacity: 0;
        will-change: left, top;
        background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Crect x='10' y='10' width='4' height='4' fill='white'/%3E%3Crect x='11' y='3' width='2' height='5' fill='white'/%3E%3Crect x='11' y='16' width='2' height='5' fill='white'/%3E%3Crect x='3' y='11' width='5' height='2' fill='white'/%3E%3Crect x='16' y='11' width='5' height='2' fill='white'/%3E%3C/svg%3E") center/contain no-repeat;
    }
    #cursor-crosshair.visible { opacity: 1; }
    #cursor-frame {
        position: fixed;
        top: 0; left: 0;
        width: 36px; height: 36px;
        border: 2px solid white;
        pointer-events: none;
        z-index: 10000;
        transform: translate(-50%, -50%);
        mix-blend-mode: difference;
        transition: width 0.2s cubic-bezier(0.22,1,0.36,1),
                    height 0.2s cubic-bezier(0.22,1,0.36,1),
                    background-color 0.2s ease,
                    opacity 0.3s ease;
        will-change: left, top;
        opacity: 0;
    }
    #cursor-frame.visible { opacity: 1; }
    #cursor-frame.active { width: 26px; height: 26px; background-color: rgba(255,255,255,0.15); }
    #cursor-frame.hover { width: 52px; height: 52px; background-color: rgba(255,255,255,0.06); }
    #cursor-frame.hover.active { width: 44px; height: 44px; background-color: rgba(255,255,255,0.18); }
}
@media (pointer: coarse) {
    #cursor-frame, #cursor-crosshair { display: none !important; }
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #3A3A4E; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #4A35E0; }

/* ---- Body background with subtle radial accents ---- */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: -1;
    background-image:
        radial-gradient(ellipse 60% 50% at 10% 20%, rgba(44,18,217,0.06) 0%, transparent 60%),
        radial-gradient(ellipse 50% 40% at 90% 80%, rgba(44,18,217,0.05) 0%, transparent 60%);
}

/* ---- Diagonal stripe accents ---- */
.stripe-diagonal {
    background-image: repeating-linear-gradient(-45deg, #2C12D9 0, #2C12D9 6px, transparent 6px, transparent 22px);
}
.hero-stripe {
    position: absolute; top: -10%; right: -5%; width: 45%; height: 120%;
    background: #2C12D9; transform: skewX(-12deg); opacity: 0.10;
    pointer-events: none; border-radius: 0 0 0 80px;
}
.hero-stripe-bold {
    position: absolute; top: 15%; right: 8%; width: 4px; height: 70%;
    background: #2C12D9; transform: skewX(-12deg); opacity: 0.25; pointer-events: none;
}

/* ---- Pulse animation for live indicators ---- */
@keyframes pulse-green {
    0%   { box-shadow: 0 0 0 0 rgba(34,197,94,0.5); }
    70%  { box-shadow: 0 0 0 8px rgba(34,197,94,0); }
    100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); }
}
.pulse-dot {
    display: inline-block; width: 10px; height: 10px;
    background: #22C55E; border-radius: 50%;
    animation: pulse-green 2s infinite; flex-shrink: 0;
}

/* ---- Section fade-in on scroll ---- */
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(28px); }
    to   { opacity: 1; transform: translateY(0); }
}
.fade-section { opacity: 0; transform: translateY(28px); }
.fade-section.visible { animation: fadeUp 0.7s cubic-bezier(0.22,1,0.36,1) forwards; }
.stagger-1 { animation-delay: 0.08s !important; }
.stagger-2 { animation-delay: 0.16s !important; }
.stagger-3 { animation-delay: 0.24s !important; }
.stagger-4 { animation-delay: 0.32s !important; }
.stagger-5 { animation-delay: 0.40s !important; }

/* ---- ELO Badges ---- */
.badge {
    padding: 2px 8px; border-radius: 0; font-size: 10px; font-weight: 900;
    color: #fff; text-transform: uppercase; letter-spacing: 1px;
    font-family: 'Chakra Petch', sans-serif; display: inline-block;
    line-height: 1.5; white-space: nowrap;
}
.b-bronze   { background: linear-gradient(135deg, #cd7f32, #8b5a2b); }
.b-silver   { background: linear-gradient(135deg, #b0bec5, #78909c); }
.b-gold     { background: linear-gradient(135deg, #f0c420, #c49b08); }
.b-platinum { background: linear-gradient(135deg, #b0cfe0, #6890a8); }
.b-diamond  { background: linear-gradient(135deg, #7c8cf8, #2C12D9); }
.b-master   { background: linear-gradient(135deg, #ff6b00, #d40000); animation: glowMaster 2s infinite alternate; }
@keyframes glowMaster {
    from { box-shadow: 0 0 4px rgba(255,107,0,0.6); }
    to   { box-shadow: 0 0 14px rgba(212,0,0,0.6); }
}

/* ---- Mobile nav transitions ---- */
.mobile-nav { max-height: 0; overflow: hidden; transition: max-height 0.35s cubic-bezier(0.4,0,0.2,1); }
.mobile-nav.open { max-height: 700px; transition: max-height 0.45s cubic-bezier(0.4,0,0.2,1); }

/* ---- Desktop dropdown transitions ---- */
.nav-dropdown-panel {
    opacity: 0; transform: translateY(-6px); pointer-events: none;
    transition: all 0.2s cubic-bezier(0.4,0,0.2,1); visibility: hidden;
}
.nav-dropdown::after {
    content: ''; position: absolute; top: 100%; left: 0; right: 0; height: 12px;
}
.nav-dropdown:hover .nav-dropdown-panel,
.nav-dropdown:focus-within .nav-dropdown-panel {
    opacity: 1; transform: translateY(0); pointer-events: auto; visibility: visible;
}

/* ---- KPI tabular numbers ---- */
.kpi-number { font-variant-numeric: tabular-nums; }

/* ---- Card hover micro-interaction ---- */
.card-hover {
    transition: transform 0.25s cubic-bezier(0.4,0,0.2,1), box-shadow 0.25s cubic-bezier(0.4,0,0.2,1);
}
.card-hover:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 32px rgba(44,18,217,0.15), 0 4px 12px rgba(0,0,0,0.4);
}

/* ---- Hero bottom divider ---- */
.hero-divider {
    height: 4px;
    background: linear-gradient(90deg, transparent, #2C12D9 20%, #2C12D9 80%, transparent);
    opacity: 0.5;
}

/* ---- Rank decorations ---- */
.rank-1 { color: #FBBF24; }
.rank-2 { color: #D1D5DB; }
.rank-3 { color: #D97706; }
.rank-4, .rank-5 { color: #6B7280; }

/* ---- Result row hover ---- */
.result-row { transition: background-color 0.15s ease; }
.result-row:hover { background-color: rgba(44,18,217,0.08); }

/* ---- Section title decorative line ---- */
.section-title-line::after {
    content: ''; flex: 1; height: 2px;
    background: linear-gradient(90deg, rgba(44,18,217,0.2), transparent);
    margin-left: 16px;
}

/* ========================================
   Tournament Pages — Component Styles
   Using var() references for theme switching
   ======================================== */

/* ---- Status banners ---- */
.status-banner {
    padding: 10px 20px; text-align: center; font-weight: 900;
    text-transform: uppercase; font-size: 11px; letter-spacing: 2px;
    font-family: 'Chakra Petch', sans-serif;
}
.status-banner.open { background: rgba(34,197,94,0.1); color: #4ade80; border-bottom: 2px solid #22c55e; }
.status-banner.live { background: rgba(245,158,11,0.1); color: #fbbf24; border-bottom: 2px solid #f59e0b; }
.status-banner.finished { background: rgba(107,114,128,0.1); color: #9ca3af; border-bottom: 2px solid #4b5563; }

/* ---- Tournament facepile ---- */
.facepile-v2 { display: flex; align-items: center; }
.facepile-v2 img {
    width: 32px; height: 32px;
    border: 2px solid var(--color-ps-border, #2A2A2E);
    object-fit: contain; background: var(--color-ps-elevated, #252429);
    margin-left: -8px; transition: transform 0.2s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.facepile-v2 img:first-child { margin-left: 0; }
.facepile-v2 img:hover { transform: scale(1.15); z-index: 10; }

/* ---- Modal ---- */
.modal-v2-overlay {
    display: none; position: fixed; z-index: 1000; inset: 0;
    background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
}
.modal-v2-content {
    background: var(--color-ps-surface, #1C1B1F);
    margin: 5% auto; padding: 0; width: 90%; max-width: 500px;
    box-shadow: 0 25px 60px rgba(0,0,0,0.5), 0 10px 20px rgba(0,0,0,0.3);
    border-top: 4px solid #2C12D9; position: relative; overflow: hidden;
}
.modal-v2-content .close-modal {
    position: absolute; right: 16px; top: 12px;
    color: var(--color-ps-muted, #7B7FA0);
    font-size: 24px; font-weight: bold; cursor: pointer;
    transition: color 0.2s; z-index: 10;
}
.modal-v2-content .close-modal:hover { color: var(--color-ps-dark, #fff); }

/* ---- Bracket connector lines ---- */
.bracket-connectors line,
.bracket-connectors path {
    stroke: rgba(44,18,217,0.35); stroke-width: 2; fill: none; stroke-linecap: round;
}

/* ---- Match card ---- */
.match-card-v2 {
    background: var(--color-ps-surface, #1C1B1F);
    border: 1px solid var(--color-ps-border, #2A2A2E);
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
    overflow: hidden; transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.match-card-v2:hover {
    border-color: rgba(44,18,217,0.4);
    box-shadow: 0 4px 12px rgba(44,18,217,0.15);
}

/* ---- Admin panel ---- */
.admin-panel-v2 {
    background: rgba(44,18,217,0.08); padding: 10px;
    border-top: 1px solid var(--color-ps-border, #2A2A2E);
}
.admin-panel-v2 input,
.admin-panel-v2 select {
    background: var(--color-ps-elevated, #252429);
    color: var(--color-ps-dark, #fff);
    border: 1px solid var(--color-ps-border, #2A2A2E);
    font-size: 11px; padding: 5px 8px;
    font-family: 'Chakra Petch', sans-serif; outline: none;
    transition: border-color 0.2s;
}
.admin-panel-v2 input:focus,
.admin-panel-v2 select:focus { border-color: #2C12D9; }

/* ---- BYE card ---- */
.bye-card-v2 {
    background: rgba(44,18,217,0.08);
    border: 1px dashed rgba(44,18,217,0.3);
    padding: 15px; text-align: center;
    color: var(--color-ps-muted, #7B7FA0);
    font-weight: bold; margin-bottom: 12px;
}

/* ---- Broadcast banner floating logos ---- */
@keyframes floatLogo {
    0% { transform: translateY(0px); } 50% { transform: translateY(-8px); } 100% { transform: translateY(0px); }
}
.logo-float { animation: floatLogo 4s ease-in-out infinite; }
.logo-float-delayed { animation: floatLogo 4s ease-in-out infinite; animation-delay: -2s; }

/* ---- Live pulse for match status ---- */
@keyframes pulseLive { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
.pulse-live { animation: pulseLive 2s infinite; }

/* ---- Stat table ---- */
.stat-table-v2 { width: 100%; border-collapse: collapse; }
.stat-table-v2 th {
    text-align: left; padding: 12px 10px;
    color: var(--color-ps-muted, #7B7FA0);
    font-size: 11px; text-transform: uppercase; letter-spacing: 1px;
    font-family: 'Chakra Petch', sans-serif;
    border-bottom: 1px dashed var(--color-ps-border, #2A2A2E);
}
.stat-table-v2 td {
    padding: 12px 10px;
    border-bottom: 1px dashed var(--color-ps-border-subtle, #222228);
    font-size: 14px; font-weight: 600;
}
.stat-table-v2 tr:hover { background: rgba(44,18,217,0.06); }
.stat-table-v2 .acc-val { font-family: 'Chakra Petch', monospace; font-size: 16px; font-weight: 900; }


/* ========================================
   LIGHT MODE OVERRIDES
   Applied when data-theme="light" on <html>
   ======================================== */

html[data-theme="light"] {
    color-scheme: light;
    --color-ps-light: #F4F4F4;
    --color-ps-dark: #111111;
    --color-ps-surface: #FFFFFF;
    --color-ps-elevated: #F9FAFB;
    --color-ps-muted: #6b7280;
    --color-ps-dimmed: #9ca3af;
    --color-ps-lavender: #E8E4F7;
    --color-ps-lavender-dark: #C5BBE8;
    --color-ps-border: #E5E7EB;
    --color-ps-border-subtle: #F3F4F6;
    --color-ps-hover: #F8F7FD;
    --color-ps-active: #F0EEFB;
    --mp-default: #111;
}

/* Auto mode: use system preference */
@media (prefers-color-scheme: light) {
    html[data-theme="auto"] {
        color-scheme: light;
        --color-ps-light: #F4F4F4;
        --color-ps-dark: #111111;
        --color-ps-surface: #FFFFFF;
        --color-ps-elevated: #F9FAFB;
        --color-ps-muted: #6b7280;
        --color-ps-dimmed: #9ca3af;
        --color-ps-lavender: #E8E4F7;
        --color-ps-lavender-dark: #C5BBE8;
        --color-ps-border: #E5E7EB;
        --color-ps-border-subtle: #F3F4F6;
        --color-ps-hover: #F8F7FD;
        --color-ps-active: #F0EEFB;
        --mp-default: #111;
    }
}

/* Light-mode component overrides (selectors that can't use var()) */
html[data-theme="light"] ::-webkit-scrollbar-thumb,
html[data-theme="auto"] ::-webkit-scrollbar-thumb { background: #C5BBE8; }
html[data-theme="light"] ::-webkit-scrollbar-thumb:hover,
html[data-theme="auto"] ::-webkit-scrollbar-thumb:hover { background: #2C12D9; }

html[data-theme="light"] .hero-stripe,
html[data-theme="auto"] .hero-stripe { opacity: 0.06; }
html[data-theme="light"] .hero-stripe-bold,
html[data-theme="auto"] .hero-stripe-bold { opacity: 0.15; }

html[data-theme="light"] body::before,
html[data-theme="auto"] body::before {
    background-image:
        radial-gradient(ellipse 60% 50% at 10% 20%, rgba(44,18,217,0.03) 0%, transparent 60%),
        radial-gradient(ellipse 50% 40% at 90% 80%, rgba(44,18,217,0.025) 0%, transparent 60%);
}

html[data-theme="light"] .card-hover:hover,
html[data-theme="auto"] .card-hover:hover {
    box-shadow: 0 12px 32px rgba(44,18,217,0.1), 0 4px 12px rgba(0,0,0,0.06);
}

html[data-theme="light"] .hero-divider,
html[data-theme="auto"] .hero-divider { opacity: 0.3; }

html[data-theme="light"] .rank-1,
html[data-theme="auto"] .rank-1 { color: #D97706; }
html[data-theme="light"] .rank-2,
html[data-theme="auto"] .rank-2 { color: #9CA3AF; }
html[data-theme="light"] .rank-3,
html[data-theme="auto"] .rank-3 { color: #B45309; }
html[data-theme="light"] .rank-4,
html[data-theme="light"] .rank-5,
html[data-theme="auto"] .rank-4,
html[data-theme="auto"] .rank-5 { color: #D1D5DB; }

html[data-theme="light"] .result-row:hover,
html[data-theme="auto"] .result-row:hover { background-color: rgba(232,228,247,0.5); }

html[data-theme="light"] .section-title-line::after,
html[data-theme="auto"] .section-title-line::after {
    background: linear-gradient(90deg, #E8E4F7, transparent);
}

/* Status banners light */
html[data-theme="light"] .status-banner.open,
html[data-theme="auto"] .status-banner.open { background: #f0fdf4; color: #15803d; border-bottom-color: #22c55e; }
html[data-theme="light"] .status-banner.live,
html[data-theme="auto"] .status-banner.live { background: #fffbeb; color: #b45309; border-bottom-color: #f59e0b; }
html[data-theme="light"] .status-banner.finished,
html[data-theme="auto"] .status-banner.finished { background: #f9fafb; color: #6b7280; border-bottom-color: #d1d5db; }

/* Bracket connectors light */
html[data-theme="light"] .bracket-connectors line,
html[data-theme="light"] .bracket-connectors path,
html[data-theme="auto"] .bracket-connectors line,
html[data-theme="auto"] .bracket-connectors path { stroke: #C5BBE8; }

/* Modal light */
html[data-theme="light"] .modal-v2-overlay,
html[data-theme="auto"] .modal-v2-overlay { background: rgba(0,0,0,0.4); }
html[data-theme="light"] .modal-v2-content,
html[data-theme="auto"] .modal-v2-content {
    box-shadow: 0 25px 60px rgba(44,18,217,0.15), 0 10px 20px rgba(0,0,0,0.1);
}

/* B-gold text on light bg */
html[data-theme="light"] .b-gold,
html[data-theme="auto"] .b-gold { color: #111; }

/* =============================================
   ManiaPlanet color codes — dual-theme support
   .mp-col spans are generated by MPColor() with --mc-d (dark) and --mc-l (light) CSS vars.
   Dark mode uses --mc-d (brightened), light mode uses --mc-l (darkened).
   ============================================= */
.mp-col {
    color: var(--mc-d, var(--mp-default, #fff));
}
html[data-theme="light"] .mp-col,
html[data-theme="auto"] .mp-col {
    color: var(--mc-l, var(--mp-default, #111)) !important;
}
@media (prefers-color-scheme: light) {
    html[data-theme="auto"] .mp-col { color: var(--mc-l, var(--mp-default, #111)) !important; }
}
