/* Import font face */
@font-face {
    font-family: 'LeagueSpartan';
    src: url('../league-spartan.bold.ttf') format('truetype');
    font-weight: lighter;
    font-style: normal;
}

/* CSS Variables for theming */
:root {
    --primary-bg: #000;
    --secondary-bg: rgba(0, 0, 0, 0.8);
    --text-color: #fff;
    --muted-text: rgba(255, 255, 255, 0.7);
    --border-color: #333;
    --cell-bg: #111;
    --accent-color: #e11d48;
    --success-color: #22c55e;
    --warning-color: #f59e0b;
    --error-color: #ef4444;
    --border-radius: 6px;
    --transition-speed: 0.3s;
    --shadow: 0 22px 70px rgba(0,0,0,0.58);
    --session-header-height: clamp(42px, 5.5vh, 50px);
    --font-xs: clamp(0.68rem, 0.78vw, 0.82rem);
    --font-sm: clamp(0.78rem, 0.9vw, 0.95rem);
    --font-md: clamp(0.88rem, 1vw, 1.06rem);
    --table-cell-height: 26px;
    --panel-block-height: 88px;
    --map-block-height: 220px;
    --news-block-height: 240px;
}

/* Base styles */
* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

body {
    background-color: var(--primary-bg);
    background-image: url('../background-livetiming.png');
    background-size: cover;
    color: var(--text-color);
    font-family: 'LeagueSpartan', monospace;
    margin: 0;
    min-height: 100dvh;
    line-height: 1.4;
    font-size: var(--font-sm);
}

/* Utility classes */
.hidden {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Loading overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-image: url('../images/general/livetiming1.png');
    background-size: cover;
    background-position: center;
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.loading-content {
    background: rgba(0, 0, 0, 0.9);
    border-radius: 10px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 0 35px rgba(255, 255, 255, 0.2);
    padding: 40px;
    text-align: center;
    max-width: 80%;
    animation: fadeIn 1s ease;
}

.loading-content h1 {
    font-size: 2em;
    margin-bottom: 20px;
    color: var(--text-color);
    font-size: var(--font-sm);
}

.info-panel,
.display-item,
#radio-list li,
#news-content,
#weather-content {
    font-size: var(--font-sm);
}

.loading-content .features {
    margin: 20px 0;
    color: #ffcc00;
}

.loading-content .features ul {
    list-style: none;
    padding: 0;
}

.loading-content .features li {
    margin: 5px 0;
}

#demo-btn {
    background: var(--accent-color);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: var(--border-radius);
    font-size: 1em;
    cursor: pointer;
    transition: background-color var(--transition-speed);
    margin-top: 20px;
}

#demo-btn:hover {
    background: #c41e3a;
}

/* Main application */
#app {
    height: 100dvh;
    overflow: hidden;
}

#session {
    visibility: hidden;
    height: 100dvh;
    display: flex;
    flex-direction: column;
}

#session.visible {
    visibility: visible;
}

/* Layout grid */
#session-body {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1rem;
    padding: 0;
    flex: 1;
    min-height: 0;
}

#left-column {
    background-color: transparent;
    padding: 0.35rem;
    overflow: hidden;
    min-height: 0;
}

#right-column {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding: 0.35rem;
    background-color: transparent;
    overflow: hidden;
    min-height: 0;
}

#right-column > * {
    min-height: 0;
}

/* Header and settings */
#session-header {
    position: relative;
    height: var(--session-header-height);
    background: var(--secondary-bg);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.settings-container {
    position: relative;
    display: inline-block;
}

.settings-trigger {
    position: absolute;
    top: 10px;
    right: 20px;
    cursor: pointer;
    font-size: 1.2em;
    z-index: 1001;
}

.settings-dropdown {
    position: absolute;
    top: 40px;
    right: 20px;
    background: var(--secondary-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 15px;
    min-width: 200px;
    z-index: 1000;
    box-shadow: var(--shadow);
}

.settings-dropdown strong {
    display: block;
    margin-bottom: 10px;
}

/* Timing table */
.table {
    display: flex;
    flex-direction: column;
    gap: 2px;
    background-color: var(--secondary-bg);
    border: 2px solid var(--border-color);
    padding: 4px;
    border-radius: var(--border-radius);
    height: 100%;
    overflow: hidden;
}

.driver-row {
    display: grid;
    grid-template-columns: 5% 9% 10% 10% 11% 11% 11% 11% 11% 11%;
    transition: transform 2.4s ease;
    will-change: transform;
    border-radius: var(--border-radius);
    min-height: var(--table-cell-height);
}

.driver-row.highlight {
    animation: rowGlow 2.0s ease-in-out;
}

@keyframes rowGlow {
    0% {
        border-color: var(--success-color);
        box-shadow: 0 0 14px 4px var(--success-color);
    }
    100% {
        border-color: transparent;
        box-shadow: none;
    }
}

.cell {
    display: flex;
    flex-direction: column;
    background-color: var(--cell-bg);
    border: 1px solid var(--border-color);
    text-align: center;
    align-items: center;
    justify-content: center;
    border-radius: var(--border-radius);
    min-height: var(--table-cell-height);
    max-height: var(--table-cell-height);
    padding: 1px 4px;
    cursor: pointer;
    transition: background-color var(--transition-speed);
    font-size: var(--font-sm);
    line-height: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cell:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.driver-name img {
    vertical-align: middle;
    margin-right: 5px;
    width: 18px;
    height: 18px;
    object-fit: contain;
    border-radius: 3px;
}

/* Info panels */
.info-panels {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.35rem;
    margin-bottom: 0.35rem;
}

.info-panel {
    background: var(--secondary-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: clamp(8px, 1.1vh, 12px);
    min-height: var(--panel-block-height);
    max-height: var(--panel-block-height);
    overflow: hidden;
}

.info-panel strong {
    display: block;
    margin-bottom: 10px;
    color: var(--text-color);
}

/* Display row */
.display-row {
    display: grid;
    grid-template-columns: 1fr 1fr 2fr 1fr;
    gap: 0.35rem;
    margin-bottom: 0.35rem;
}

.display-item {
    background: var(--secondary-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: clamp(8px, 1.1vh, 12px);
    min-height: var(--panel-block-height);
    max-height: var(--panel-block-height);
    overflow: hidden;
}

#radio-messages {
    display: flex;
    flex-direction: column;
}

#flag-display,
#drs-display {
    position: relative;
    background-color: rgba(0, 0, 0, 0.85);
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.7);
}

#flag-display {
    background-image: url('../images/flags/flag_monitor_background.png');
}

#drs-display {
    background-image: url('../images/general/drs_ad.png');
    background-blend-mode: overlay;
    opacity: 0.6;
}

#drs-display.active {
    opacity: 1;
    filter: brightness(1.05) contrast(1.05);
}

#flag-display-overlay,
#flag-display-content,
#drs-display-content {
    position: relative;
    z-index: 1;
}

.display-item strong {
    display: block;
    margin-bottom: 10px;
    color: var(--text-color);
}

#radio-list {
    list-style: none;
    padding: 0;
    margin: 0;
    flex: 1;
    max-height: none;
    overflow-y: auto;
}

#radio-list li {
    padding: 5px 0;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background-color var(--transition-speed);
}

#radio-list li:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

#radio-list li:last-child {
    border-bottom: none;
}

/* Map container */
.map-container {
    position: relative;
    background: var(--secondary-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    margin-bottom: 0.35rem;
    min-height: var(--map-block-height);
    max-height: var(--map-block-height);
    flex: 0 0 var(--map-block-height);
    overflow: hidden;
}

.map-container canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

#raceCanvasMap {
    z-index: 1;
}

#raceCanvas {
    z-index: 2;
}

.racing-field {
    position: relative;
    width: 100%;
    height: 100%;
    z-index: 3;
    display: none;
    pointer-events: none;
}

.map-container.maximized {
    position: fixed;
    inset: 12px;
    z-index: 1500;
    min-height: auto;
    margin: 0;
    box-shadow: var(--shadow);
}

.cars-layer,
.gap-scale {
    position: absolute;
    inset: 0;
}

.racing-car {
    position: absolute;
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--text-color);
    font-size: var(--font-md);
    line-height: 1.2;
    pointer-events: none;
    transition: transform 0.6s ease;
    will-change: transform;
}

.racing-car .label {
    white-space: nowrap;
    font-size: var(--rf-label-size, 1.06em);
}

.racing-car .gap-to-leader {
    opacity: 0.85;
    color: #f59e0b;
    font-size: var(--rf-gap-size, 0.95em);
}

.racing-car.in-pit,
.racing-car.retired {
    opacity: 0.65;
}

.gap-scale {
    height: 36px;
    background: repeating-linear-gradient(
        to right,
        #888,
        #888 1px,
        transparent 1px,
        transparent 40px
    );
    font-size: var(--font-xs);
    color: var(--text-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 10px;
    z-index: 4;
}

.top-lane {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 10%;
    border-bottom: 1px dashed #aaa;
    z-index: 4;
}

.map-controls {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    gap: 5px;
    z-index: 10;
}

.map-controls button {
    background: var(--secondary-bg);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 8px 12px;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: background-color var(--transition-speed);
    font-size: var(--font-sm);
}

.map-controls button:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

#other {
    height: 100%;
    overflow: auto;
}

#weatherTable {
    width: 100%;
    font-size: var(--font-xs);
}

#weatherTable td {
    white-space: nowrap;
}

#news-window {
    min-height: var(--news-block-height);
    max-height: var(--news-block-height);
    display: flex;
    flex-direction: column;
}

#news-content {
    flex: 1;
    overflow-y: auto;
    line-height: 1.25;
    font-size: var(--font-xs);
}

#news-content > div {
    padding-bottom: 5px;
    margin-bottom: 5px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

#news-content > div:last-child {
    margin-bottom: 0;
    border-bottom: none;
}

/* Original drsview desktop layout parity */
#header {
    font-size: 1.5em;
}

#session-body {
    grid-template-columns: 2fr 1fr;
    gap: 1rem;
    padding: 0;
}

#left-column {
    padding: 0.5rem;
}

#right-column {
    gap: 0.5rem;
    padding: 0.5rem;
}

.table {
    gap: 0.1vw;
    background-color: rgba(0, 0, 0, 0.8);
    border: 2px solid #333;
    padding: 0.5vw;
}

.driver-row {
    grid-template-columns: 5% 9% 10% 10% 11% 11% 11% 11% 11% 11%;
    border-radius: 6px;
}

.cell {
    background-color: #111;
    border: 1px solid #333;
    font-size: 1.2em;
    border-radius: 5px;
    min-height: calc(max(3.9vh, 2vw));
    max-height: none;
    line-height: 1.1;
}

#flag-window {
    max-height: 100px;
    background: rgba(0, 0, 0, 0.9);
    border: 1px solid #444;
    border-radius: 8px;
    padding: 10px;
    font-size: 1em;
}

#flag-content {
    font-size: 1.2em;
}

#drs-window {
    max-height: 100px;
    background: rgba(0, 0, 0, 0.9);
    border: 1px solid #444;
    border-radius: 8px;
    padding: 10px;
    font-size: 1em;
}

#drs-content {
    font-size: 1.2em;
}

#radio-messages {
    position: relative;
    margin-top: 5px;
    height: 120px;
    border: 1px solid #444;
    border-radius: 8px;
    padding: 10px;
    font-size: 1em;
    overflow: hidden;
}

#other-window {
    margin-top: 5px;
    height: 120px;
    border: 1px solid #444;
    border-radius: 8px;
    padding: 10px;
    font-size: 1em;
    overflow-y: hidden;
}

#map {
    width: min(590px, 100%);
    aspect-ratio: 16 / 9;
    background: rgba(0, 0, 0, 0.65);
    border: 1px solid #444;
    border-radius: 8px;
    padding: 10px;
    cursor: move;
    box-shadow:
        0 6px 10px rgba(0, 0, 0, 0.5),
        0 12px 30px rgba(0, 0, 0, 0.4),
        0 20px 40px rgba(0, 0, 0, 0.3);
}

#flag-display {
    width: 130px;
    height: 130px;
    font-size: 1em;
    border-radius: 8px;
    padding: 10px;
}

#flag-display img {
    position: absolute;
    margin-top: 2px;
    top: 0;
    left: 0;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
}

#drs-display {
    width: 110px;
    height: 110px;
    margin-top: 10px;
    font-size: 1em;
    border-radius: 8px;
    padding: 10px;
    filter: brightness(2.6) contrast(1.1);
}

#drs-display.active {
    background-blend-mode: normal;
    filter: brightness(1) contrast(1);
    opacity: 1;
}

#toggleMapButtons {
    position: absolute;
    display: inline-flex;
    gap: 0;
    top: 5px;
    right: 5px;
    z-index: 2000;
}

#toggleMapButtons button {
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid #999;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1em;
}

#news-window {
    max-height: 150px;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.85);
    border: 1px solid #444;
    border-radius: 8px;
    padding: 10px;
    font-size: 1em;
}

#radio-list {
    margin-top: 10px;
}

#news-content,
#other {
    margin-top: 10px;
}

/* Disclaimer */
.disclaimer {
    font-size: var(--font-xs);
    color: var(--muted-text);
    text-align: center;
    padding: 6px;
    margin-top: 0;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

/* Modal and backdrop */
.backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.8);
    z-index: 2000;
}

.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--secondary-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 20px;
    max-width: 80%;
    max-height: 80vh;
    overflow-y: auto;
    z-index: 2001;
    box-shadow: var(--shadow);
}

/* Tooltip */
.tooltip {
    position: absolute;
    background: var(--secondary-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 10px;
    z-index: 3000;
    pointer-events: none;
    box-shadow: var(--shadow);
    font-size: var(--font-sm);
}

#driver-comparison h3 {
    margin-bottom: 10px;
    font-size: var(--font-md);
}

#driver-comparison div {
    margin-bottom: 6px;
    font-size: var(--font-sm);
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideIn {
    from {
        transform: translateX(-100%);
    }
    to {
        transform: translateX(0);
    }
}

/* Responsive design */
@media (max-width: 1500px) and (min-width: 1024px) {
    :root {
        --font-xs: clamp(0.64rem, 0.7vw, 0.76rem);
        --font-sm: clamp(0.72rem, 0.82vw, 0.88rem);
        --font-md: clamp(0.82rem, 0.92vw, 1rem);
        --table-cell-height: 24px;
        --panel-block-height: 80px;
        --map-block-height: 190px;
        --news-block-height: 210px;
    }

    .map-container {
        min-height: var(--map-block-height);
        max-height: var(--map-block-height);
        flex: 0 0 var(--map-block-height);
    }

    .map-controls button {
        padding: 6px 10px;
    }
}

@media (min-width: 2300px) {
    :root {
        --font-xs: clamp(0.74rem, 0.7vw, 0.9rem);
        --font-sm: clamp(0.84rem, 0.86vw, 1rem);
        --font-md: clamp(0.98rem, 1vw, 1.14rem);
        --table-cell-height: 30px;
        --panel-block-height: 98px;
        --map-block-height: 280px;
        --news-block-height: 300px;
    }

    .map-container {
        min-height: var(--map-block-height);
        max-height: var(--map-block-height);
        flex: 0 0 var(--map-block-height);
    }

    .map-controls button {
        padding: 9px 14px;
    }
}

@media (max-width: 1200px) {
    #session-body {
        grid-template-columns: 1.5fr 1fr;
    }
    
    .display-row {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: 1fr 1fr;
    }
    
    .display-item:nth-child(3) {
        grid-column: span 2;
    }
}

@media (max-width: 768px) {
    #session-body {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr 1fr;
    }
    
    .info-panels {
        grid-template-columns: 1fr;
    }
    
    .display-row {
        grid-template-columns: 1fr;
        grid-template-rows: repeat(4, 1fr);
    }
    
    .driver-row {
        font-size: 0.9em;
    }
}

/* Performance optimizations */
.driver-row {
    contain: layout style paint;
}

.cell {
    contain: layout style;
}

.map-container {
    contain: layout style paint;
}

/* Reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
    .driver-row {
        transition: none;
    }
    
    .row-glow {
        animation: none;
    }
    
    @keyframes fadeIn {
        from { opacity: 0; }
        to { opacity: 1; }
    }
}

/* Simulation UI Styles */
.simulation-options {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin: 20px 0;
    align-items: center;
}

.sim-button {
    background: var(--accent-color);
    color: white;
    border: none;
    padding: 15px 30px;
    font-size: 16px;
    font-family: 'LeagueSpartan', monospace;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all var(--transition-speed);
    min-width: 250px;
    text-align: center;
}

.sim-button:hover {
    background: #c21a3a;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(225, 29, 72, 0.3);
}

.sim-button.secondary {
    background: var(--secondary-bg);
    border: 2px solid var(--border-color);
}

.sim-button.secondary:hover {
    background: var(--cell-bg);
    border-color: var(--accent-color);
}

.sim-status {
    margin-top: 15px;
    padding: 10px;
    background: var(--secondary-bg);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Loading overlay enhancements */
.loading-content {
    text-align: center;
    max-width: 600px;
}

.loading-content h1 {
    margin-bottom: 20px;
    color: var(--accent-color);
}

.loading-content .features {
    margin: 20px 0;
    text-align: left;
}

.loading-content .features ul {
    margin: 10px 0;
    padding-left: 20px;
}

.loading-content .features li {
    margin: 5px 0;
    color: var(--muted-text);
}

.server-notice {
    background: var(--secondary-bg);
    border: 1px solid var(--warning-color);
    border-radius: var(--border-radius);
    padding: 15px;
    margin: 15px 0;
    text-align: left;
}

.server-notice p {
    margin: 0 0 10px 0;
    color: var(--warning-color);
}

.server-notice code {
    background: var(--cell-bg);
    color: var(--text-color);
    padding: 8px 12px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    display: inline-block;
    border: 1px solid var(--border-color);
}

/* Connection status indicator */
.connection-status {
    position: fixed;
    top: 10px;
    left: 10px;
    background: var(--secondary-bg);
    padding: 8px 15px;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    font-size: 12px;
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 8px;
}

.connection-status.live {
    border-color: var(--success-color);
}

.connection-status.simulation {
    border-color: var(--warning-color);
}

.connection-status.offline {
    border-color: var(--error-color);
}
