/* Formula1 Custom Fonts (via jsDelivr CDN) */
@font-face {
    font-family: 'Formula1';
    src: url('https://cdn.jsdelivr.net/gh/rahulbhatara/samcjgv-tools@main/assets/Formula1-Regular_web_0.ttf') format('truetype');
    font-weight: 400;
    font-style: normal;
}

@font-face {
    font-family: 'Formula1';
    src: url('https://cdn.jsdelivr.net/gh/rahulbhatara/samcjgv-tools@main/assets/Formula1-Bold_web_0.ttf') format('truetype');
    font-weight: 700;
    font-style: normal;
}

@font-face {
    font-family: 'Formula1-Bold';
    src: url('https://cdn.jsdelivr.net/gh/rahulbhatara/samcjgv-tools@main/assets/Formula1-Bold_web_0.ttf') format('truetype');
    font-weight: 700;
    font-style: normal;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
    -webkit-user-drag: none;
}

body {
    background-color: transparent !important;
    font-family: 'Formula1', sans-serif;
    color: #f8fafc;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    letter-spacing: 0.3px;
}

/* ---------- Layout ---------- */
/* Kiri bawah: minimap di atas scoreboard */
.hud-left {
    position: fixed;
    left: 24px;
    bottom: 24px;
    width: 420px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Kanan atas: panel lap */
.lap-panel {
    position: fixed;
    top: 24px;
    right: 24px;
    width: 250px;
    padding: 6px 14px;
    background: rgba(10, 10, 14, 0.4);
    border-radius: 6px;
}

/* ---------- Panel Lap (Lap / Last / Best / Current) ---------- */
.lap-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

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

.lap-label {
    font-family: 'Formula1-Bold', 'Formula1', sans-serif;
    font-weight: 700;
    font-size: 15px;
    color: #f8fafc;
}

.lap-val {
    font-family: 'Formula1-Bold', 'Formula1', sans-serif;
    font-weight: 700;
    font-size: 18px;
    color: #f8fafc;
    font-variant-numeric: tabular-nums;
}

.lap-val.is-best {
    color: #4ade80;
}

/* ---------- Scoreboard ---------- */
.raceroom-container {
    width: 100%;
    background: rgba(10, 10, 14, 0.7);
    border-radius: 6px;
    overflow: hidden;
    font-size: 15px;
    font-family: 'Formula1', sans-serif;
}

.race-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.race-badge {
    background: #ef4444;
    color: #ffffff;
    font-family: 'Formula1-Bold', 'Formula1', sans-serif;
    font-weight: 700;
    font-size: 13px;
    padding: 4px 10px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.race-badge.circuit { background: #3b82f6; }
.race-badge.sprint { background: #10b981; }
.race-badge.endurance { background: #f59e0b; }

.header-time {
    font-family: 'Formula1-Bold', 'Formula1', sans-serif;
    font-weight: 700;
    font-size: 20px;
    color: #f8fafc;
    font-variant-numeric: tabular-nums;
}

.scoreboard-section {
    max-height: 38vh;
    overflow-y: auto;
}

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

.scoreboard-table td {
    padding: 8px 8px;
    font-family: 'Formula1', sans-serif;
    font-size: 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    white-space: nowrap;
}

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

/* Baris pemain lokal: highlight abu-abu seperti referensi */
.scoreboard-table tr.is-me {
    background: linear-gradient(90deg, rgba(130, 135, 148, 0.78), rgba(88, 93, 106, 0.78));
}

.col-pos {
    width: 40px;
    padding-left: 14px !important;
    font-family: 'Formula1-Bold', 'Formula1', sans-serif;
    font-weight: 700;
    text-align: left;
}

.pos-1 { color: #facc15; }
.pos-2 { color: #cbd5e1; }
.pos-3 { color: #f97316; }

/* Nomor pembalap (tanpa logo) */
.col-num {
    width: 44px;
    font-family: 'Formula1', sans-serif;
    color: #a1a8b5;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.scoreboard-table tr.is-me .col-num { color: #e5e7eb; }

.col-driver {
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    font-family: 'Formula1-Bold', 'Formula1', sans-serif;
    font-weight: 700;
}

.col-lap {
    text-align: right;
    font-size: 12px !important;
    color: #94a3b8;
}

.col-time {
    padding-right: 14px !important;
    text-align: right;
    font-family: 'Formula1-Bold', 'Formula1', sans-serif;
    font-size: 14px !important;
    color: #f1f5f9;
    font-variant-numeric: tabular-nums;
}

.placeholder-row td {
    text-align: center;
    color: #64748b;
    padding: 18px 12px;
    font-style: italic;
    border-bottom: none;
}

/* ---------- Minimap (kanan atas, di kiri panel lap) ---------- */
.track-minimap-section {
    position: fixed;
    top: 24px;
    right: calc(24px + 262px * var(--ui-scale, 1));   /* di kiri panel lap (250px + jarak 12px) */
    width: 286px;   /* 220px x 1.3 (track map overlay diperbesar 30%) */
    aspect-ratio: 4 / 3;
    background: transparent;
    border-radius: 6px;
    overflow: hidden;
}

#track-canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* ---------- Lap time per pembalap + ikon tercepat ---------- */
.col-fl {
    width: 26px;
    padding-left: 2px !important;
    padding-right: 2px !important;
    text-align: center;
}

.fl-icon {
    display: inline-block;
    width: 18px;
    height: 18px;
    vertical-align: middle;
}

.col-lapt {
    text-align: right;
    font-family: 'Formula1', sans-serif;
    font-size: 13px !important;
    color: #cbd5e1;
    font-variant-numeric: tabular-nums;
}

/* ---------- Banner Race Control (Safety Car / Red Flag) ---------- */
.flag-banner {
    position: fixed;
    top: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 50;
    padding: 12px 32px;
    border-radius: 6px;
    font-family: 'Formula1-Bold', 'Formula1', sans-serif;
    font-weight: 700;
    font-size: 26px;
    letter-spacing: 2px;
    text-transform: uppercase;
    text-align: center;
    color: #ffffff;
    white-space: nowrap;
    border: 2px solid rgba(255, 255, 255, 0.85);
}
.flag-banner[hidden] { display: none; }
.flag-banner.sc { background: #ca8a04; color: #111; border-color: #111; }
.flag-banner.green { background: #16a34a; }
.flag-banner.red { background: #dc2626; animation: flag-blink 1s steps(2, start) infinite; }
@keyframes flag-blink { to { opacity: 0.45; } }

/* ---------- Pembalap sedang PIT: baris diberi garis amber + badge "IN PIT" di kolom gap ---------- */
.scoreboard-table tr.in-pit td:first-child { box-shadow: inset 4px 0 0 #f59e0b; }
.scoreboard-table tr.in-pit .col-driver,
.scoreboard-table tr.in-pit .col-num,
.scoreboard-table tr.in-pit .col-lapt { opacity: 0.7; }

.pit-tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 3px;
    background: #f59e0b;
    color: #111;
    font-family: 'Formula1-Bold', 'Formula1', sans-serif;
    font-weight: 700;
    font-size: 12px;
    letter-spacing: 0.5px;
}

/* Timer PIT: sedang di pit (amber) / baru keluar (hijau, tampil 3 detik) */
.pit-tag.done { background: #22c55e; color: #052e16; }

/* ---------- Banner flag di atas scoreboard ---------- */
.flag-banner-sb {
    padding: 8px 14px;
    border-radius: 6px;
    font-family: 'Formula1-Bold', 'Formula1', sans-serif;
    font-weight: 700;
    font-size: 15px;
    letter-spacing: 1px;
    text-transform: uppercase;
    text-align: center;
    color: #ffffff;
    border: 2px solid rgba(255, 255, 255, 0.85);
}
.flag-banner-sb[hidden] { display: none; }
.flag-banner-sb.sc { background: #ca8a04; color: #111; border-color: #111; }
.flag-banner-sb.green { background: #16a34a; }
.flag-banner-sb.red { background: #dc2626; animation: flag-blink 1s steps(2, start) infinite; }

/* ---------- Notifikasi finish pembalap (di atas scoreboard) ---------- */
.finish-toasts { display: flex; flex-direction: column; gap: 6px; }
.finish-toast {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 14px;
    border-radius: 6px;
    background: rgba(10, 10, 14, 0.85);
    border-left: 5px solid #f8fafc;
    font-family: 'Formula1-Bold', 'Formula1', sans-serif;
    font-weight: 700;
    font-size: 14px;
    color: #f8fafc;
    animation: toast-in 0.25s ease-out;
}
.finish-toast.p1 { border-left-color: #facc15; }
.finish-toast .ft-flag { font-size: 16px; }
.finish-toast .ft-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.finish-toast .ft-time { font-variant-numeric: tabular-nums; color: #cbd5e1; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* Badge FINISH di kolom gap */
.finish-tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 3px;
    background: #f8fafc;
    color: #111;
    font-family: 'Formula1-Bold', 'Formula1', sans-serif;
    font-weight: 700;
    font-size: 12px;
    letter-spacing: 0.5px;
}

/* ---------- Delta real-time vs lap terbaik ---------- */
.lap-delta-row { justify-content: space-between; }
.lap-delta { font-size: 22px; color: #f87171; }
.lap-delta.is-ahead { color: #4ade80; }
.lap-row[hidden] { display: none; }


/* ==========================================================
   LAYOUT SCOREBOARD BARU (POSITION / LAP TIME / GAP / INTERVAL / LAP)
   ========================================================== */
.hud-left { width: 450px; }
.raceroom-container { overflow: visible; background: rgba(10, 10, 14, 0.78); }
.scoreboard-section { max-height: none; overflow: visible; }
.race-header { border-bottom: none; }
.header-lap {
    font-family: 'Formula1-Bold', 'Formula1', sans-serif;
    font-weight: 700;
    font-size: 20px;
    color: #f8fafc;
    font-variant-numeric: tabular-nums;
}
.scoreboard-table { table-layout: auto; }
.scoreboard-table .head-row th {
    padding: 4px 6px 6px;
    font-family: 'Formula1', sans-serif;
    font-weight: 400;
    font-size: 10px;
    letter-spacing: 0.5px;
    color: #94a3b8;
    text-align: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}
.scoreboard-table .head-row th.h-pos { text-align: left; padding-left: 12px; }
.scoreboard-table td { padding: 7px 6px; font-size: 13px; }
.scoreboard-table td.c-pos {
    width: 26px; padding-left: 12px; padding-right: 2px;
    font-family: 'Formula1-Bold', 'Formula1', sans-serif; font-weight: 700; text-align: left;
}
.scoreboard-table td.c-code {
    width: 86px; text-align: left;
    font-family: 'Formula1-Bold', 'Formula1', sans-serif; font-weight: 700; letter-spacing: 0.5px;
}
.scoreboard-table td.c-lt,
.scoreboard-table td.c-gap,
.scoreboard-table td.c-int,
.scoreboard-table td.c-lap {
    text-align: center; font-variant-numeric: tabular-nums; color: #f1f5f9;
}
.scoreboard-table td.c-lt.is-pb { color: #4ade80; }
.scoreboard-table td.c-lt.is-fastest { color: #c084fc; }
.scoreboard-table td.c-lap { width: 36px; font-family: 'Formula1-Bold', 'Formula1', sans-serif; font-weight: 700; }
.scoreboard-table .dash { color: #94a3b8; letter-spacing: -1px; }

/* Tag PIT / flag finish: di luar sisi kanan scoreboard, sejajar barisnya */
.scoreboard-table td.c-side { position: relative; width: 0; padding: 0; border-bottom: none; }
.side-tag { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); white-space: nowrap; }
.side-tag .pit-tag { font-size: 13px; padding: 3px 9px; }
.side-flag svg { width: 24px; height: 18px; display: block; }


/* ---------- Start system (tengah atas): 5 lampu LED matriks merah dalam rumah serat karbon ---------- */
.start-system {
    position: fixed;
    top: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 60;
    display: flex;
    gap: 6px;
    padding: 8px;
    background: #000;
    border-radius: 10px;
    border: 2px solid #1c1c1c;
}
.start-system[hidden] { display: none; }
.start-light {
    position: relative;
    box-sizing: border-box;
    width: 84px;
    height: 84px;
    border-radius: 6px;
    border: 1px solid #3a3a3a;
    /* 4 baut di sudut + tekstur serat karbon */
    background:
        radial-gradient(circle at 7px 7px, #cfcfcf 0 1px, #5a5a5a 2px, #050505 3.6px, transparent 4.2px) no-repeat,
        radial-gradient(circle at calc(100% - 7px) 7px, #cfcfcf 0 1px, #5a5a5a 2px, #050505 3.6px, transparent 4.2px) no-repeat,
        radial-gradient(circle at 7px calc(100% - 7px), #cfcfcf 0 1px, #5a5a5a 2px, #050505 3.6px, transparent 4.2px) no-repeat,
        radial-gradient(circle at calc(100% - 7px) calc(100% - 7px), #cfcfcf 0 1px, #5a5a5a 2px, #050505 3.6px, transparent 4.2px) no-repeat,
        repeating-conic-gradient(#1c1c1c 0 25%, #0d0d0d 0 50%) 0 0 / 6px 6px;
    font-family: 'Formula1-Bold', 'Formula1', sans-serif;
    font-weight: 700;
    font-size: 40px;
    color: transparent;
}
/* lensa lampu: matriks titik LED (mati = merah gelap) */
.start-light::before {
    content: "";
    position: absolute;
    inset: 9px;
    border-radius: 50%;
    box-sizing: border-box;
    border: 3px solid #0a0a0a;
    background: radial-gradient(circle, #4a0808 0 1.2px, #1d0303 1.7px) 0 0 / 5px 5px;
}
.start-light.on::before {
    background: radial-gradient(circle, #ffc0b0 0 0.8px, #ff3030 1.4px, #a00808 2.3px) 0 0 / 5px 5px;
    box-shadow: 0 0 14px 3px rgba(255, 30, 30, 0.65), inset 0 0 12px rgba(255, 60, 60, 0.6);
}


/* ---------- Safety Car: DEPLOYED = orange muda (tetap), IN THIS LAP = orange tua + berkedip ---------- */
.flag-banner.sc-deployed, .flag-banner-sb.sc-deployed { background: #fb923c; color: #111; border-color: #111; }
.flag-banner.sc-lap, .flag-banner-sb.sc-lap {
    background: #ca8a04; color: #111; border-color: #111;
    animation: flag-blink 1s steps(2, start) infinite;
}


/* ==========================================================
   HUD MOVEABLE (posisi dasar tetap; geseran via --dx / --dy)
   ========================================================== */
.hud-left, .lap-panel { transform: translate(var(--dx, 0px), var(--dy, 0px)); }

body.hud-edit .hud-moveable {
    cursor: move;
    touch-action: none;
    outline: 2px dashed #facc15;
    outline-offset: 3px;
}
body.hud-edit .hud-moveable::before {
    content: attr(data-hud-label) " - DRAG";
    position: absolute;
    top: -22px; left: 0;
    padding: 2px 8px;
    border-radius: 3px;
    background: #facc15;
    color: #111;
    font-family: 'Formula1-Bold', 'Formula1', sans-serif;
    font-weight: 700;
    font-size: 11px;
    letter-spacing: 0.5px;
    pointer-events: none;
    white-space: nowrap;
}
/* di luar mode edit: HUD tidak menangkap mouse */
body:not(.hud-edit) .hud-moveable { pointer-events: none; }

/* Nomor balap di depan kode pembalap (scoreboard) */
.scoreboard-table .drv-num {
    display: inline-block;
    min-width: 24px;
    margin-right: 6px;
    text-align: right;
    color: #94a3b8;
    font-family: 'Formula1', sans-serif;
    font-weight: 400;
    font-variant-numeric: tabular-nums;
}
.scoreboard-table tr.is-me .drv-num { color: #e5e7eb; }


/* ---------- Formation Lap (biru, tetap) ---------- */
.flag-banner.formation, .flag-banner-sb.formation { background: #2563eb; color: #ffffff; border-color: #ffffff; }

/* ---------- Checkered Flag: pola kotak-kotak berkedip (pola bertukar hitam/putih + fade) ---------- */
.flag-banner.checkered, .flag-banner-sb.checkered {
    position: relative;
    overflow: hidden;
    isolation: isolate;
    background: #111;
    border-color: #ffffff;
    animation: checker-blink 0.8s steps(2, start) infinite;
}
.flag-banner.checkered { position: fixed; }
.flag-banner.checkered::before, .flag-banner-sb.checkered::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    --cs: 14px;
    background-color: #ffffff;
    background-image:
        conic-gradient(#111 25%, transparent 0 50%, #111 0 75%, transparent 0);
    background-size: calc(var(--cs) * 2) calc(var(--cs) * 2);
    animation: checker-swap 0.8s steps(1, end) infinite;
}
.flag-banner-sb.checkered::before { --cs: 9px; }
.flag-banner.checkered .fb-text, .flag-banner-sb.checkered .fb-text {
    position: relative;
    display: inline-block;
    padding: 2px 14px;
    background: #111;
    color: #ffffff;
    border-radius: 4px;
}
@keyframes checker-swap {
    0%   { background-position: 0 0; }
    50%  { background-position: var(--cs) 0; }
}
@keyframes checker-blink { to { opacity: 0.55; } }

/* kolom GAP/INT gabungan: lebar tetap supaya tidak melompat saat berganti */
.scoreboard-table td.c-gap, .scoreboard-table th.h-gap { width: 70px; }
