@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@500;700&display=swap');

:root {
    --bg-color: #0b0e14;
    --card-bg: rgba(15, 20, 25, 0.85);
    --text-primary: #f0f6fc;
    --text-secondary: #8b949e;
    --accent-primary: #3b82f6;
    --accent-glow: rgba(59, 130, 246, 0.5);
    --accent-success: #10b981;
    --border-color: rgba(255, 255, 255, 0.08);
    --glass-blur: blur(20px);
}

body {
    margin: 0;
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    background-image: radial-gradient(circle at 50% 0%, rgba(59, 130, 246, 0.15) 0%, transparent 50%);
    background-attachment: fixed;
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
}

/* CG specific override */
body.cg-mode {
    background: #000000; /* Hitam pekat untuk kemudahan Luma Key / Screen blending */
    overflow: hidden !important; /* Prevent scrollbars */
    width: 1920px;
    height: 1080px;
    position: absolute;
    top: 0;
    left: 0;
    margin: 0;
    padding: 0;
}

.leaderboard-container {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 20px;
    transition: transform 0.8s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.8s ease;
}

/* Header Styling */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--card-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    padding: 20px 30px;
    border-radius: 16px;
    border: 1px solid var(--border-color);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    margin-bottom: 24px;
    position: relative;
    overflow: hidden;
}

/* Header subtle top accent */
header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: linear-gradient(90deg, var(--accent-primary), var(--accent-success));
}

header h1 {
    margin: 0 0 8px 0;
    font-size: 1.8rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    background: linear-gradient(to right, #ffffff, #a5b4fc);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.race-status {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 600;
    font-size: 0.95rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-secondary);
}

.flag-icon {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    display: inline-block;
    border: 2px solid rgba(255,255,255,0.8);
    box-shadow: 0 0 10px rgba(255,255,255,0.2);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(255,255,255,0.4); }
    70% { box-shadow: 0 0 0 8px rgba(255,255,255,0); }
    100% { box-shadow: 0 0 0 0 rgba(255,255,255,0); }
}

.time-box {
    text-align: right;
}

.time-box .label {
    display: block;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.time-box .value {
    font-size: 2.2rem;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    color: var(--accent-primary);
    text-shadow: 0 0 20px var(--accent-glow);
}

/* Table Styling */
.table-wrapper {
    background: var(--card-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border-radius: 16px;
    border: 1px solid var(--border-color);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    overflow: hidden;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    background-color: rgba(0, 0, 0, 0.4);
    padding: 18px 24px;
    text-align: left;
    color: var(--text-secondary);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.85rem;
    letter-spacing: 1px;
    border-bottom: 1px solid var(--border-color);
}

td {
    padding: 16px 24px;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    transition: background-color 0.2s ease;
}

tr:last-child td {
    border-bottom: none;
}

tr {
    transition: transform 0.2s ease, background-color 0.2s ease;
}

tr:hover {
    background-color: rgba(255, 255, 255, 0.05);
    transform: scale(1.002);
}

/* Add a subtle highlight to P1 */
tr:nth-child(1) td {
    background-color: rgba(210, 153, 34, 0.08);
}
tr:nth-child(1):hover td {
    background-color: rgba(210, 153, 34, 0.12);
}
tr:nth-child(1) td.pos {
    color: #e3b341;
    text-shadow: 0 0 15px rgba(227, 179, 65, 0.4);
}

td.pos {
    font-weight: 800;
    color: var(--text-secondary);
    font-size: 1.25rem;
    width: 60px;
}

td.num {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    color: #a5b4fc;
    width: 80px;
}

td.driver-name {
    font-weight: 600;
    font-size: 1.15rem;
    letter-spacing: -0.2px;
}

td.laps {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 500;
    color: var(--text-secondary);
}

td.time {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    color: var(--accent-success);
    text-align: right;
}
th:last-child {
    text-align: right;
}

/* ==========================================
   STARTING GRID (MotoGP Style)
========================================== */
.sg-container {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -40%);
    width: 1400px;
    opacity: 0;
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
    display: flex;
    flex-direction: column;
}

.sg-row {
    position: relative;
    margin-bottom: 40px;
    display: flex;
    justify-content: flex-start;
}

.sg-row-label {
    position: absolute;
    right: -40px;
    top: 50%;
    transform: translateY(-50%);
    color: #0ea5e9;
    font-size: 1.4rem;
    font-weight: 800;
    font-family: 'JetBrains Mono', monospace;
    letter-spacing: 2px;
    display: flex;
    align-items: center;
    gap: 15px;
    text-shadow: 0 2px 4px rgba(255,255,255,0.8), 0 5px 15px rgba(0,0,0,0.3);
}

.sg-row-label::before {
    content: '';
    width: 40px;
    height: 3px;
    background: linear-gradient(90deg, transparent, #0ea5e9);
}

.sg-card-wrapper {
    width: 100%;
}

.sg-card {
    position: relative;
    width: 100%;
    min-height: 75px;
    background: linear-gradient(135deg, rgba(15, 20, 25, 0.95), rgba(15, 20, 25, 0.8));
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.1);
    border-bottom: 2px solid rgba(255,255,255,0.2);
    box-shadow: 0 15px 35px rgba(0,0,0,0.6);
    display: flex;
    align-items: stretch;
    border-radius: 4px;
    overflow: visible;
}

.sg-card::after {
    content: '';
    position: absolute;
    bottom: -15px;
    left: 10%;
    width: 80%;
    height: 15px;
    background: radial-gradient(ellipse at top, rgba(255,255,255,0.15), transparent 70%);
}

.sg-pos {
    position: absolute;
    top: -25px;
    left: -15px;
    font-size: 3.5rem;
    font-weight: 800;
    font-style: italic;
    color: white;
    text-shadow: 0 8px 20px rgba(0,0,0,0.8);
    font-family: 'JetBrains Mono', monospace;
    line-height: 1;
    z-index: 10;
}

.sg-info {
    flex-grow: 1;
    min-width: 0;
    padding: 8px 15px 8px 65px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: relative;
    z-index: 5;
}

.sg-meta {
    font-size: 1.0rem;
    color: #a5b4fc;
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
    margin-bottom: 2px;
    text-shadow: 0 2px 5px rgba(0,0,0,0.5);
}

.sg-name {
    font-size: 1.15rem;
    font-weight: 800;
    color: white;
    text-transform: uppercase;
    letter-spacing: -0.5px;
    line-height: 1.1;
    margin-bottom: 5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.sg-team-row {
    font-size: 0.75rem;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
    max-width: 100%;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sg-flag {
    height: 12px;
    width: 18px;
    object-fit: cover;
    border-radius: 2px;
}

.sg-assets {
    width: 110px;
    flex: 0 0 110px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.05));
    border-left: 1px solid rgba(255,255,255,0.05);
}

.sg-logo {
    max-width: 60px;
    max-height: 50px;
    object-fit: contain;
    opacity: 0.8;
}

.sg-photo {
    position: absolute;
    bottom: 0;
    right: -10px;
    height: 135px;
    width: auto;
    object-fit: contain;
    object-position: bottom right;
    z-index: 20;
    filter: drop-shadow(-5px 5px 15px rgba(0,0,0,0.6));
}

/* --- SIDE BAR STYLES --- */
#sidebar-container {
    position: absolute;
    top: 50px;
    left: 50px;
    width: 380px;
    font-family: 'Outfit', sans-serif;
    color: white;
    opacity: 0;
    transform: translateX(-50px);
    transition: all 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.sb-header {
    background: rgba(0, 0, 0, 0.9);
    padding: 15px 20px;
    border-top: 3px solid #00ffff;
    margin-bottom: 5px;
}
.sb-title-main {
    font-size: 28px;
    font-weight: 800;
    font-style: italic;
    color: #00ffff;
    line-height: 1;
}
.sb-title-sub {
    font-size: 22px;
    font-weight: 800;
    font-style: italic;
    color: white;
    margin-top: 2px;
    line-height: 1;
}
.sb-event-info {
    font-size: 16px;
    color: #00ffff;
    margin-top: 8px;
    text-transform: uppercase;
    display: none;
}

.sb-row {
    position: absolute;
    width: 100%;
    transition: top 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: stretch;
    background: rgba(0, 0, 0, 0.85);
    border-bottom: 1px solid #00ffff;
    height: 38px;
}
#sidebar-list {
    position: relative;
    height: 570px; /* 15 rows * 38px per row */
    overflow: hidden;
}
.sb-pos {
    flex: 0 0 45px;
    width: 45px;
    min-width: 45px;
    max-width: 45px;
    box-sizing: border-box;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 14px;
    font-weight: 700;
    color: white;
}
.sb-arrow {
    flex: 0 0 20px;
    width: 20px;
    min-width: 20px;
    max-width: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 12px;
}
.arrow-up {
    color: #00ff00;
}
.arrow-down {
    color: #ff0000;
}
.sb-pos-ord {
    font-size: 10px;
    margin-top: -5px;
}
.sb-num {
    flex: 0 0 50px;
    width: 50px;
    min-width: 50px;
    max-width: 50px;
    box-sizing: border-box;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #0055aa;
    color: white;
    font-family: 'JetBrains Mono', monospace;
    font-size: 18px;
    font-weight: 800;
}
.sb-name {
    flex: 1;
    min-width: 0;
    display: block;
    line-height: 38px;
    padding-left: 10px;
    font-size: 16px;
    font-weight: 700;
    text-transform: uppercase;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sb-time {
    flex: 0 0 85px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding-right: 10px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 16px;
    font-weight: 700;
    color: #00ffff;
}

/* 1st Place Highlight */
.sb-row.p1 .sb-pos { color: #00ff00; }
.sb-row.p1 .sb-num { background: #00aa00; }
.sb-row.p1 .sb-name { color: #00ff00; }
.sb-row.p1 .sb-time { color: #00ff00; }

/* Bottom Bar NASCAR Style */
#bottom-bar-container {
    position: absolute;
    bottom: 30px;
    left: 0;
    width: 1920px;
    display: flex;
    flex-direction: column;
    z-index: 1000;
    font-family: 'Inter', sans-serif;
    transform: translateY(150px);
    transition: transform 0.6s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.4s ease;
    opacity: 0;
    background: #111;
    border-top: 3px solid #fff;
    box-shadow: 0 -10px 30px rgba(0,0,0,0.8);
}

#bottom-bar-container.active {
    transform: translate(var(--offset-x, 0px), var(--offset-y, 0px));
    opacity: 1;
}

.bb-top-strip {
    display: flex;
    align-items: stretch;
    height: 40px;
    background: #222;
    border-bottom: 2px solid #000;
}

.bb-laps-box {
    background: #00d54b;
    color: black;
    font-weight: 800;
    font-size: 18px;
    padding: 0 25px;
    display: flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    text-transform: uppercase;
}

.bb-title-box {
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 20px;
    letter-spacing: 2px;
    text-transform: uppercase;
}

.bb-logo-box {
    width: 150px;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    color: black;
    font-weight: 900;
    font-style: italic;
    font-size: 22px;
    letter-spacing: -1px;
}

.bb-content-strip {
    display: flex;
    height: 55px;
    overflow: hidden;
    position: relative;
    background: linear-gradient(to bottom, #1a1a1a, #000);
}

.bb-items-wrapper {
    display: flex;
    width: max-content;
    will-change: transform;
}

.bb-item {
    flex-shrink: 0;
    min-width: 320px;
    display: flex;
    align-items: center;
    padding: 0 20px;
    border-right: 1px solid #333;
    color: white;
    box-sizing: border-box;
}

.bb-item-pos {
    color: #94a3b8;
    font-weight: 600;
    margin-right: 10px;
    font-size: 18px;
    min-width: 25px;
    transform: translateY(-2px);
}

.bb-item-num {
    font-weight: 900;
    font-style: italic;
    margin-right: 15px;
    font-size: 22px;
    color: #fff;
    text-shadow: 0 0 10px rgba(255,255,255,0.3);
}

.bb-item-details {
    display: flex;
    flex-direction: column;
    justify-content: center;
    line-height: 1.1;
    margin-left: 5px;
}

.bb-item-name {
    font-weight: 800;
    font-size: 18px;
    text-transform: uppercase;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bb-item-time-row {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin-top: 2px;
    animation: fadeSlideUp 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.bb-time-label {
    font-size: 11px;
    font-weight: 700;
    color: #94a3b8;
    letter-spacing: 0.5px;
}

.bb-time-val {
    font-family: 'Outfit', sans-serif;
    font-size: 15px;
    font-weight: 800;
    color: #facc15; /* Yellow to match side bar */
}

@keyframes fadeSlideUp {
    0% { opacity: 0; transform: translateY(10px); }
    100% { opacity: 1; transform: translateY(0); }
}

@keyframes flipRowAnim {
    0% { transform: translateY(15px); opacity: 0; }
    100% { transform: translateY(0); opacity: 1; }
}

.flip-anim {
    animation: flipRowAnim 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

/* Time To Go Graphic */
.ttg-container {
    position: absolute;
    top: 50px;
    right: 50px;
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    padding: 12px 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
    z-index: 999;
    
    /* Animation initial state */
    transform: translateX(150%);
    opacity: 0;
    transition: all 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.ttg-container.active {
    transform: translate(var(--offset-x, 0px), var(--offset-y, 0px));
    opacity: 1;
}

.ttg-label {
    font-size: 13px;
    color: #00ffff;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 2px;
    text-shadow: 0 0 5px rgba(0,255,255,0.3);
}

.ttg-value {
    font-size: 36px;
    color: #ffffff;
    font-weight: 800;
    font-family: 'Outfit', sans-serif;
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.4);
}

/* Lap To Go Graphic specific offset */
/* removed offset, shares position with Time To Go */
/* --- WINNER GRAPHIC --- */
.winner-container {
    position: absolute;
    bottom: 10%;
    left: 50%;
    transform: translate(-50%, 50px);
    opacity: 0;
    width: 800px;
    min-height: 200px;
    height: auto;
    padding: 30px 0;
    background: linear-gradient(135deg, rgba(20,20,20,0.95), rgba(40,40,40,0.95));
    border: 3px solid #facc15; /* Golden yellow */
    border-radius: 16px;
    box-shadow: 0 20px 50px rgba(250, 204, 21, 0.3), inset 0 0 20px rgba(250, 204, 21, 0.1);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: all 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 1000;
}

.winner-container.active {
    opacity: 1;
    transform: translate(calc(-50% + var(--offset-x, 0px)), var(--offset-y, 0px));
}

.winner-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        linear-gradient(45deg, #222 25%, transparent 25%),
        linear-gradient(-45deg, #222 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #222 75%),
        linear-gradient(-45deg, transparent 75%, #222 75%);
    background-size: 40px 40px;
    background-position: 0 0, 0 20px, 20px -20px, -20px 0px;
    opacity: 0.15;
    z-index: 1;
    animation: checkerScroll 20s linear infinite;
}

@keyframes checkerScroll {
    0% { background-position: 0 0, 0 20px, 20px -20px, -20px 0px; }
    100% { background-position: 400px 0, 400px 20px, 420px -20px, 380px 0px; }
}

.winner-content {
    position: relative;
    z-index: 2;
    text-align: center;
    width: 100%;
}

.winner-label {
    font-family: 'Outfit', sans-serif;
    font-size: 28px;
    font-weight: 900;
    color: #facc15;
    letter-spacing: 12px;
    text-transform: uppercase;
    text-shadow: 0 0 10px rgba(250, 204, 21, 0.5);
    margin-bottom: 5px;
}

.winner-name-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    background: rgba(250, 204, 21, 0.1);
    padding: 10px 40px;
    border-top: 1px solid rgba(250, 204, 21, 0.3);
    border-bottom: 1px solid rgba(250, 204, 21, 0.3);
}

.winner-no {
    font-family: 'Outfit', sans-serif;
    font-size: 64px;
    font-weight: 900;
    color: #ffffff;
    font-style: italic;
    text-shadow: 2px 2px 0px #facc15, 4px 4px 0px rgba(0,0,0,0.5);
}

.winner-name {
    font-family: 'Outfit', sans-serif;
    font-size: 56px;
    font-weight: 800;
    color: #ffffff;
    text-transform: uppercase;
    text-shadow: 0 5px 15px rgba(0,0,0,0.8);
}

.winner-team {
    font-family: 'Outfit', sans-serif;
    font-size: 20px;
    font-weight: 600;
    color: #cbd5e1;
    margin-top: 10px;
    letter-spacing: 2px;
    text-transform: uppercase;
}
