:root {
    --bg-dark: #0f1115;
    --bg-panel: #1a1d24;
    --text-primary: #ffffff;
    --text-secondary: #8b9bb4;
    --accent: #e10600;
    /* F1 Red */
    --accent-hover: #ff1e19;
    --success: #22c55e;
    --warning: #eab308;
    --danger: #ef4444;

    --font-heading: 'Titillium Web', sans-serif;
    --font-body: 'Outfit', sans-serif;
}

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

body {
    background-color: var(--bg-dark);
    color: var(--text-primary);
    font-family: var(--font-body);
    height: 100vh;
    overflow: hidden;
}

#app {
    height: 100%;
    width: 100%;
    position: relative;
}

.screen {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    padding: 20px;
    background: var(--bg-dark);
    transition: opacity 0.5s;
    z-index: 1;
}

.screen.hidden {
    opacity: 0;
    pointer-events: none;
    z-index: 0;
}

.active {
    opacity: 1;
    z-index: 2;
}

/* Typography */
h1,
h2,
h3 {
    font-family: var(--font-heading);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.logo {
    font-size: 3rem;
    text-align: center;
    margin-bottom: 2rem;
}

.accent {
    color: var(--accent);
}

/* Start Screen */
.setup-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    max-width: 1400px;
    margin: 0 auto;
    height: 70vh;
}

.selection-group {
    background: var(--bg-panel);
    padding: 20px;
    border-radius: 8px;
    border: 1px solid #333;
    overflow-y: auto;
}

.grid-select {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
    margin-top: 15px;
}

.driver-card,
.track-card {
    background: #252932;
    padding: 10px;
    border-radius: 4px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s;
}

.driver-card:hover,
.track-card:hover {
    border-color: var(--text-secondary);
}

.driver-card.selected,
.track-card.selected {
    border-color: var(--accent);
    background: #2a1a1a;
}

.action-btn {
    grid-column: 1 / -1;
    padding: 20px;
    background: var(--accent);
    color: white;
    font-family: var(--font-heading);
    font-size: 1.5rem;
    border: none;
    cursor: pointer;
    text-transform: uppercase;
    font-weight: 700;
}

.action-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    filter: grayscale(1);
}

/* Race Dashboard */
.race-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 20px;
    border-bottom: 2px solid #333;
    margin-bottom: 20px;
}

.race-dashboard {
    display: grid;
    grid-template-columns: 300px 1fr 300px;
    gap: 20px;
    height: calc(100vh - 100px);
    /* Fill remaining space minus header */
    overflow: hidden;
    /* Prevent body scroll */
}

.leaderboard-panel,
.controls-panel,
.center-console {
    background: var(--bg-panel);
    padding: 15px;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    height: 100%;
    /* Fill grid cell */
    overflow: hidden;
    /* Contain children */
}

/* Center Console Split */
.center-console {
    display: grid;
    /* Track Map gets remaining space, Radio gets fixed height */
    grid-template-rows: 1fr 250px;
    gap: 15px;
    padding: 0;
    /* Remove padding for children to fit */
    background: transparent;
    /* Let children handle bg */
}

#track-map-container,
.messages-feeds {
    background: var(--bg-panel);
    border-radius: 8px;
    padding: 15px;
    overflow: hidden;
    position: relative;
}

#track-svg {
    width: 100%;
    height: 100%;
    background: #111;
    border-radius: 4px;
}

/* Leaderboard */
#leaderboard-list {
    flex-grow: 1;
    overflow-y: auto;
    font-family: 'Titillium Web';
}

.lb-row {
    display: flex;
    justify-content: space-between;
    padding: 8px;
    border-bottom: 1px solid #333;
    font-size: 0.9rem;
}

.lb-row.player {
    background: #2a3a50;
    border-left: 4px solid var(--accent);
}

.lb-pos {
    width: 30px;
    font-weight: bold;
    color: var(--text-secondary);
}

.lb-name {
    flex-grow: 1;
}

.lb-gap {
    width: 60px;
    text-align: right;
    font-family: monospace;
}

.lb-tyre {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: inline-block;
    margin-left: 8px;
    text-align: center;
    font-size: 10px;
    line-height: 20px;
    color: black;
    font-weight: bold;
}

/* Comms */
.messages-feeds {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.log-container {
    flex-grow: 1;
    background: #000;
    padding: 10px;
    font-family: monospace;
    overflow-y: auto;
    border: 1px solid #333;
    display: flex;
    flex-direction: column-reverse;
    max-height: 100%;
    /* Enforce limit */
}

.msg {
    margin-bottom: 5px;
    opacity: 0.8;
}

.msg.urgent {
    color: var(--accent);
    font-weight: bold;
    opacity: 1;
}

/* Controls */
.telemetry-box {
    margin-bottom: 20px;
    flex-shrink: 0;
}

.bar-container {
    height: 6px;
    background: #333;
    margin-top: 5px;
    border-radius: 3px;
}

.bar {
    height: 100%;
    background: var(--success);
    border-radius: 3px;
    transition: width 0.5s;
}

.strategy-controls {
    margin-top: auto;
    flex-shrink: 0;
    /* Prevent squishing */
    background: #252932;
    /* Slight highlight */
    padding: 10px;
    border-radius: 4px;
}

.btn-group {
    display: flex;
    gap: 5px;
    margin-bottom: 10px;
}

.strat-btn {
    flex: 1;
    padding: 10px;
    border: 1px solid #444;
    background: transparent;
    color: #fff;
    cursor: pointer;
}

.strat-btn:hover {
    background: #333;
}

.strat-btn.active {
    background: var(--text-secondary);
    color: #000;
    border-color: var(--text-secondary);
}

.box-btn {
    width: 100%;
    padding: 15px;
    background: #333;
    color: white;
    font-weight: bold;
    border: 2px solid #555;
    cursor: pointer;
    font-size: 1.2rem;
}

.box-btn:hover {
    background: #444;
}

.box-btn.pending {
    background: var(--warning);
    color: black;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0% {
        opacity: 1;
    }

    50% {
        opacity: 0.6;
    }

    100% {
        opacity: 1;
    }
}

#pit-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 5px;
    margin-top: 10px;
}

.tyre-select {
    padding: 10px;
    border: none;
    font-weight: bold;
    cursor: pointer;
    color: black;
}

/* Post Race Styles */
.podium-container {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    margin-bottom: 40px;
    gap: 20px;
}

.podium-spot {
    text-align: center;
    width: 200px;
}

.podium-bar {
    border-radius: 8px 8px 0 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 20px;
    color: black;
    font-weight: bold;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}

.podium-spot.p1 .podium-bar {
    height: 250px;
    background: #FFD700;
    order: 2;
}

.podium-spot.p2 .podium-bar {
    height: 180px;
    background: #C0C0C0;
    order: 1;
}

.podium-spot.p3 .podium-bar {
    height: 140px;
    background: #CD7F32;
    order: 3;
}

.podium-spot.p1 {
    order: 2;
}

.podium-spot.p2 {
    order: 1;
}

.podium-spot.p3 {
    order: 3;
}

.driver-name {
    font-size: 1.2rem;
    margin-bottom: 5px;
}

.team-name {
    font-size: 0.9rem;
    opacity: 0.8;
    margin-bottom: 10px;
}

.classification-table {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    border-collapse: collapse;
    background: var(--bg-panel);
}

.classification-table th,
.classification-table td {
    padding: 10px;
    text-align: left;
    border-bottom: 1px solid #333;
}

.points-col {
    color: var(--success);
    font-weight: bold;
}


#post-race-screen {
    overflow-y: auto;
    justify-content: flex-start;
    /* Ensure scrolling works from top */
}