html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #05050a;
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
}

.hidden {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}


.menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at center, rgba(0, 0, 0, 0.15) 0%, rgba(0, 0, 0, 0.6) 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    transition: opacity 0.4s ease, visibility 0.4s ease;
}

#fps-counter {
    position: fixed;
    top: 5px;
    left: 8px;
    z-index: 9999;
    color: #2ecc71;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.75rem;
    font-weight: 800;
    background: rgba(0, 0, 0, 0.4);
    padding: 2px 6px;
    border-radius: 4px;
    pointer-events: none;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    letter-spacing: 0.05em;
}

.menu-container {
    background: rgba(15, 15, 20, 0.7);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    padding: 3rem;
    border-radius: 24px;
    max-width: 500px;
    width: 90%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.6);
}

.start-layout {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 4rem;
    box-sizing: border-box;
}

.start-header {
    text-align: center;
    margin-top: 1rem;
    text-shadow: 0px 8px 25px rgba(0, 0, 0, 0.9);
}

.start-footer {
    display: flex;
    justify-content: flex-end;
    align-items: flex-end;
    width: 100%;
}

.start-button-row {
    display: flex;
    gap: 1.5rem;
    align-items: center;
}

.center-button-wrapper {
    display: flex;
    justify-content: center;
    width: 100%;
    margin: 0 auto;
}

.brand-sub {
    font-size: 0.8rem;
    font-weight: 800;
    letter-spacing: 0.4em;
    color: #ff2828;
    margin-bottom: 0.6rem;
}

.menu-title {
    font-size: 3.2rem;
    font-weight: 900;
    color: #ffffff;
    margin: 0;
    letter-spacing: -0.03em;
    line-height: 1;
}

.menu-title .highlight {
    color: #ff2828;
}

.track-info {
    font-size: 0.95rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.7);
    letter-spacing: 0.15em;
    margin-top: 0.6rem;
    margin-bottom: 2rem;
}

.menu-description {
    color: rgba(255, 255, 255, 0.65);
    font-size: 0.95rem;
    line-height: 1.6;
    margin-bottom: 2.5rem;
    width: 100%;
}

.progress-bar-container {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    margin-top: 2rem;
    overflow: hidden;
    position: relative;
}

.progress-bar {
    width: 0%;
    height: 100%;
    background: #ff2828;
    box-shadow: 0 0 12px #ff2828;
    border-radius: 10px;
    transition: width 0.1s ease;
}

.progress-text {
    color: #ffffff;
    font-size: 0.9rem;
    margin-top: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.05em;
}

.button-group {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
}

.menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 1.1rem 2.5rem;
    font-size: 1rem;
    font-weight: 700;
    border-radius: 14px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    border: none;
    letter-spacing: 0.05em;
    margin: 0 auto;
}

.action-prompt {
    position: fixed;
    bottom: 18%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 15, 20, 0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #ffffff;
    font-size: 1.2rem;
    font-weight: 800;
    padding: 12px 25px;
    border-radius: 12px;
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    animation: pulsePrompt 1.5s infinite;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.action-prompt .key-btn {
    background: #ff2828;
    color: #fff;
    padding: 4px 10px;
    border-radius: 6px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 1.1rem;
    box-shadow: 0 0 10px rgba(255, 40, 40, 0.4);
}

.btn-large {
    padding: 1.4rem 4rem;
    font-size: 1.3rem;
    border-radius: 18px;
    margin: 0;
}

.btn-primary {
    background: #ff2828;
    color: #ffffff;
    box-shadow: 0 4px 20px rgba(255, 40, 40, 0.25);
}

.btn-primary:hover {
    background: #ff4545;
    transform: translateY(-2px);
    box-shadow: 0 6px 25px rgba(255, 40, 40, 0.45);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.06);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.12);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.25);
    transform: translateY(-2px);
}

.menu-btn:active {
    transform: translateY(0);
}

.btn-icon {
    font-size: 1.2rem;
}

#ui-game {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 100;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

#speedometer {
    background: rgba(15, 15, 20, 0.65);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    padding: 0.8rem 1.6rem;
    border-radius: 16px;
    display: flex;
    align-items: baseline;
    gap: 0.3rem;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.5);
    border-right: 4px solid #ff2828;
}

#speed-value {
    color: #ffffff;
    font-size: 2.8rem;
    font-weight: 900;
    font-family: 'Courier New', Courier, monospace;
    line-height: 1;
}

#speed-unit {
    color: #ff2828;
    font-size: 0.85rem;
    font-weight: 800;
    letter-spacing: 0.05em;
}

#pit-limiter {
    margin-top: 8px;
    text-align: center;
    background: #ff2828;
    color: #fff;
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.1em;
    padding: 4px 10px;
    border-radius: 6px;
    animation: pulseLimiter 0.8s infinite alternate;
}

@keyframes pulseLimiter {
    from { opacity: 0.7; }
    to   { opacity: 1; }
}

#pit-penalty {
    margin-top: 4px;
    text-align: center;
    background: rgba(255, 40, 40, 0.15);
    border: 1px solid #ff2828;
    color: #ff2828;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 4px;
}

#pit-penalty-toast {
    position: fixed;
    top: 35%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 40, 40, 0.9);
    color: #fff;
    font-size: 2rem;
    font-weight: 900;
    padding: 1rem 2rem;
    border-radius: 12px;
    z-index: 200;
}

#pit-penalty-toast.hidden {
    display: none;
}

@keyframes fadeOut {
    0% { opacity: 1; }
    70% { opacity: 1; }
    100% { opacity: 0; }
}

#ui-timing {
    position: fixed;
    top: 30px;
    left: 30px;
    z-index: 100;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.timing-board {
    background: rgba(15, 15, 20, 0.65);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    padding: 1rem;
    border-radius: 16px;
    box-shadow: 0 20px 45px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    min-width: 230px;
}

.track-record-display {
    display: flex;
    justify-content: space-between;
    font-size: 0.72rem;
    font-weight: 800;
    color: rgba(255, 255, 255, 0.5);
    letter-spacing: 0.06em;
}

#track-record-value {
    color: #f368e0;
}

#ui-enter-car {
    position: fixed;
    bottom: 25%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 15, 20, 0.85);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #ffffff;
    font-size: 1.5rem;
    font-weight: 800;
    padding: 10px 30px;
    border-radius: 8px;
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    animation: pulsePrompt 1.5s infinite;
}

#ui-enter-car .key-btn {
    background: #ff2828;
    color: #fff;
    padding: 5px 12px;
    border-radius: 5px;
    font-family: 'Courier New', Courier, monospace;
}

@keyframes pulsePrompt {
    0% { transform: translateX(-50%) scale(1); }
    50% { transform: translateX(-50%) scale(1.05); }
    100% { transform: translateX(-50%) scale(1); }
}

.sectors-container {
    display: flex;
    gap: 0.5rem;
    width: 100%;
}

.sector-box {
    flex: 1;
    text-align: center;
    padding: 0.4rem 0;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 900;
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.3);
    transition: background 0.25s ease, color 0.25s ease, box-shadow 0.25s ease;
}

.sector-box.slowest {
    background: #e74c3c !important;
    color: #ffffff !important;
    box-shadow: 0 0 10px rgba(231, 76, 60, 0.5);
}

.sector-box.slower {
    background: #f1c40f !important;
    color: #05050a !important;
    box-shadow: 0 0 10px rgba(241, 196, 15, 0.5);
}

.sector-box.faster {
    background: #2ecc71 !important;
    color: #ffffff !important;
    box-shadow: 0 0 10px rgba(46, 204, 113, 0.5);
}

.sector-box.record {
    background: #f368e0 !important;
    color: #ffffff !important;
    box-shadow: 0 0 14px rgba(243, 104, 224, 0.8);
}

.lap-time-display {
    font-family: 'Courier New', Courier, monospace;
    font-size: 1.8rem;
    font-weight: 900;
    color: #ffffff;
    text-align: center;
    letter-spacing: 0.02em;
    margin-top: 0.2rem;
}

.last-lap-display {
    display: flex;
    justify-content: space-between;
    font-size: 0.72rem;
    font-weight: 800;
    color: #aaaaaa;
    letter-spacing: 0.05em;
}

.personal-record-display {
    display: flex;
    justify-content: space-between;
    font-size: 0.72rem;
    font-weight: 800;
    color: #2ecc71;
    letter-spacing: 0.05em;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    padding-top: 0.5rem;
    margin-top: 0.2rem;
}


.full-width {
    width: 100%;
    box-sizing: border-box;
}

.side-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 350px;
    height: 100%;
    background: rgba(15, 15, 20, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-left: 1px solid rgba(255, 255, 255, 0.08);
    padding: 3rem 2.5rem;
    box-sizing: border-box;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.4s ease;
    box-shadow: -10px 0 40px rgba(0, 0, 0, 0.7);
}

.side-panel.hidden {
    transform: translateX(100%);
    opacity: 0;
    pointer-events: none;
}

.slider-group {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    text-align: left;
    margin-bottom: 1rem;
}

.slider-group label {
    color: #ffffff;
    font-weight: 700;
    font-size: 0.95rem;
    display: flex;
    justify-content: space-between;
    letter-spacing: 0.05em;
}

.slider-group span {
    color: #ff2828;
    font-family: 'Courier New', Courier, monospace;
    font-size: 1.1rem;
    font-weight: 900;
}

input[type=range] {
    -webkit-appearance: none;
    width: 100%;
    background: transparent;
}
input[type=range]:focus {
    outline: none;
}
input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 22px;
    width: 22px;
    border-radius: 50%;
    background: #ff2828;
    cursor: pointer;
    margin-top: -9px;
    box-shadow: 0 0 15px rgba(255, 40, 40, 0.6);
    transition: transform 0.1s ease;
}
input[type=range]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}
input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
}

#ui-controls {
    position: fixed;
    bottom: 30px;
    left: 30px;
    z-index: 100;
    background: rgba(15, 15, 20, 0.45);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.06);
    padding: 10px 16px;
    border-radius: 10px;
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.6);
    line-height: 1.9;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    pointer-events: none;
}

.controls-title {
    font-size: 0.6rem;
    font-weight: 800;
    letter-spacing: 0.15em;
    color: #ff2828;
    margin-bottom: 2px;
}

.ctrl .k {
    display: inline-block;
    background: rgba(255, 255, 255, 0.1);
    padding: 0 6px;
    border-radius: 3px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.7rem;
    font-weight: 700;
    color: #fff;
    margin-right: 3px;
}