/* ==========================================================
   Overtake Simulation Widget
   Holographic wireframe / Tron aesthetic
   ========================================================== */

/* Compatibility: map short var names (deploy) to ecu- prefixed (WP theme) */
.overtake-sim {
    --ecu-red: var(--red, #e63946);
    --ecu-red-dark: var(--red-dark, #c1121f);
    --ecu-red-light: var(--red-light, #ff6b6b);
    --ecu-green: var(--green, #3fb950);
    --ecu-text-primary: var(--text-primary, #f0f6fc);
    --ecu-text-secondary: var(--text-secondary, #9ca3af);
    --ecu-font-display: var(--font-display, 'Teko', sans-serif);
    --ecu-font-heading: var(--font-heading, 'Barlow', sans-serif);
    --ecu-font-body: var(--font-body, 'Inter', sans-serif);
    --ecu-section-padding: var(--section-padding, 80px);
    --ecu-section-padding-mobile: var(--section-padding-mobile, 48px);
}

/* --- Section --- */
.overtake-sim {
    position: relative;
    padding: var(--ecu-section-padding) 0;
    background: #050810;
    overflow: hidden;
}

/* Background grid */
.overtake-sim::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        linear-gradient(rgba(230, 57, 70, 0.025) 1px, transparent 1px),
        linear-gradient(90deg, rgba(230, 57, 70, 0.025) 1px, transparent 1px);
    background-size: 40px 40px;
    pointer-events: none;
}

.overtake-sim .section__heading {
    color: var(--ecu-red);
    text-shadow: 0 0 30px rgba(230, 57, 70, 0.3);
}

.overtake-sim__subtitle {
    text-align: center;
    color: var(--ecu-text-secondary);
    font-family: var(--ecu-font-body);
    font-size: 1.05rem;
    margin-bottom: 40px;
    max-width: 560px;
    margin-left: auto;
    margin-right: auto;
}

/* --- Holographic Frame --- */
.overtake-sim__frame {
    position: relative;
    border: 1px solid rgba(230, 57, 70, 0.15);
    border-radius: 6px;
    background: rgba(5, 8, 16, 0.85);
    box-shadow:
        0 0 40px rgba(230, 57, 70, 0.06),
        inset 0 0 60px rgba(230, 57, 70, 0.02);
    max-width: 960px;
    margin: 0 auto;
    overflow: hidden;
}

/* Corner brackets */
.overtake-sim__corner {
    position: absolute;
    width: 20px;
    height: 20px;
    z-index: 3;
}
.overtake-sim__corner::before,
.overtake-sim__corner::after {
    content: '';
    position: absolute;
    background: var(--ecu-red);
    box-shadow: 0 0 6px rgba(230, 57, 70, 0.5);
}
.overtake-sim__corner::before { width: 20px; height: 2px; }
.overtake-sim__corner::after  { width: 2px;  height: 20px; }

.overtake-sim__corner--tl { top: 0; left: 0; }
.overtake-sim__corner--tl::before { top: 0; left: 0; }
.overtake-sim__corner--tl::after  { top: 0; left: 0; }

.overtake-sim__corner--tr { top: 0; right: 0; }
.overtake-sim__corner--tr::before { top: 0; right: 0; }
.overtake-sim__corner--tr::after  { top: 0; right: 0; }

.overtake-sim__corner--bl { bottom: 0; left: 0; }
.overtake-sim__corner--bl::before { bottom: 0; left: 0; }
.overtake-sim__corner--bl::after  { bottom: 0; left: 0; }

.overtake-sim__corner--br { bottom: 0; right: 0; }
.overtake-sim__corner--br::before { bottom: 0; right: 0; }
.overtake-sim__corner--br::after  { bottom: 0; right: 0; }

/* --- Header bar --- */
.overtake-sim__header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    border-bottom: 1px solid rgba(230, 57, 70, 0.1);
    background: rgba(230, 57, 70, 0.03);
}

.overtake-sim__label {
    font-family: var(--ecu-font-heading);
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--ecu-red);
}

.overtake-sim__label--dim {
    color: rgba(230, 57, 70, 0.35);
    font-weight: 400;
}

/* --- Body layout --- */
.overtake-sim__body {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 0;
}

/* --- Canvas wrap --- */
.overtake-sim__canvas-wrap {
    position: relative;
    border-right: 1px solid rgba(230, 57, 70, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    perspective: 900px;
}

/* --- CRT Monitor effect --- */
#overtake-canvas {
    display: block;
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    transform: rotateX(3deg);
    transform-origin: center bottom;
    box-shadow:
        0 0 30px rgba(230, 57, 70, 0.08),
        inset 0 0 80px rgba(0, 0, 0, 0.25),
        0 0 2px rgba(230, 57, 70, 0.15);
    animation: crt-flicker 8s ease-in-out infinite;
}

@keyframes crt-flicker {
    0%, 100% { filter: brightness(1); }
    48% { filter: brightness(1); }
    49% { filter: brightness(0.97); }
    50% { filter: brightness(1.02); }
    51% { filter: brightness(1); }
    85% { filter: brightness(1); }
    86% { filter: brightness(0.98); }
    87% { filter: brightness(1); }
}

/* Scanline overlay + CRT phosphor effect */
.overtake-sim__scanlines {
    position: absolute;
    inset: 16px;
    border-radius: 8px;
    background:
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.06) 2px,
            rgba(0, 0, 0, 0.06) 3px
        );
    pointer-events: none;
    z-index: 2;
    transform: rotateX(3deg);
    transform-origin: center bottom;
}

/* CRT edge glow (simulates phosphor bleed at screen edges) */
.overtake-sim__scanlines::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 8px;
    box-shadow:
        inset 0 0 40px rgba(230, 57, 70, 0.03),
        inset 0 0 120px rgba(0, 0, 0, 0.2);
    pointer-events: none;
}

/* --- Controls panel --- */
.overtake-sim__controls {
    display: flex;
    flex-direction: column;
    gap: 24px;
    padding: 24px 20px;
    background: rgba(10, 15, 26, 0.5);
}

.overtake-sim__control-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.overtake-sim__control-label {
    font-family: var(--ecu-font-heading);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: rgba(230, 57, 70, 0.5);
}

/* Level number display */
.overtake-sim__level-display {
    font-family: var(--ecu-font-display);
    font-size: 3.2rem;
    font-weight: 700;
    color: var(--ecu-red);
    line-height: 1;
    text-shadow: 0 0 20px rgba(230, 57, 70, 0.4);
}

/* --- Level bar (segmented) --- */
.overtake-sim__level-bar {
    display: flex;
    gap: 3px;
}

.overtake-sim__level-seg {
    flex: 1;
    height: 32px;
    min-width: 0;
    border: 1px solid rgba(230, 57, 70, 0.15);
    border-radius: 2px;
    background: rgba(230, 57, 70, 0.04);
    color: rgba(230, 57, 70, 0.3);
    font-family: var(--ecu-font-heading);
    font-size: 0.6rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s ease;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.overtake-sim__level-seg:hover {
    border-color: rgba(230, 57, 70, 0.4);
    background: rgba(230, 57, 70, 0.1);
    color: rgba(230, 57, 70, 0.6);
}

.overtake-sim__level-seg--active {
    background: rgba(230, 57, 70, 0.2);
    border-color: rgba(230, 57, 70, 0.5);
    color: var(--ecu-red);
    box-shadow: 0 0 8px rgba(230, 57, 70, 0.15);
}

.overtake-sim__level-labels {
    display: flex;
    justify-content: space-between;
    font-family: var(--ecu-font-heading);
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: rgba(230, 57, 70, 0.3);
    margin-top: -4px;
}

/* --- Timer --- */
.overtake-sim__timer-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.overtake-sim__timer {
    font-family: var(--ecu-font-display);
    font-size: 3.6rem;
    font-weight: 700;
    color: var(--ecu-red);
    line-height: 1;
    text-shadow: 0 0 24px rgba(230, 57, 70, 0.35);
    letter-spacing: 0.02em;
}

.overtake-sim__timer span {
    font-size: 1.6rem;
    opacity: 0.6;
    margin-left: 2px;
}

/* --- Overtake button --- */
.overtake-sim__btn {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 52px;
    border: 2px solid var(--ecu-red);
    border-radius: 4px;
    background: rgba(230, 57, 70, 0.08);
    cursor: pointer;
    overflow: hidden;
    transition: all 0.2s ease;
}

.overtake-sim__btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(230, 57, 70, 0.15), transparent);
    opacity: 0;
    transition: opacity 0.2s;
}

.overtake-sim__btn:hover::before {
    opacity: 1;
}

.overtake-sim__btn:hover {
    box-shadow: 0 0 20px rgba(230, 57, 70, 0.25);
    transform: translateY(-1px);
}

.overtake-sim__btn:active {
    transform: translateY(0);
}

.overtake-sim__btn-text {
    font-family: var(--ecu-font-heading);
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.25em;
    text-transform: uppercase;
    color: var(--ecu-red);
    position: relative;
    z-index: 1;
}

/* Button active state (during overtake) */
.overtake-sim__btn--active {
    pointer-events: none;
    border-color: rgba(230, 57, 70, 0.3);
    opacity: 0.5;
}

.overtake-sim__btn--active .overtake-sim__btn-text {
    animation: btn-pulse 1s ease-in-out infinite;
}

/* Button reset state */
.overtake-sim__btn--reset {
    border-color: var(--ecu-green);
    background: rgba(63, 185, 80, 0.08);
}

.overtake-sim__btn--reset .overtake-sim__btn-text {
    color: var(--ecu-green);
}

.overtake-sim__btn--reset:hover {
    box-shadow: 0 0 20px rgba(63, 185, 80, 0.25);
}

@keyframes btn-pulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

/* --- Stats --- */
.overtake-sim__stats {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(230, 57, 70, 0.08);
    opacity: 0;
    transform: translateY(8px);
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    pointer-events: none;
}

.overtake-sim__stats--visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.overtake-sim__stat {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.overtake-sim__stat-label {
    font-family: var(--ecu-font-heading);
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: rgba(230, 57, 70, 0.4);
}

.overtake-sim__stat-value {
    font-family: var(--ecu-font-display);
    font-size: 1.3rem;
    font-weight: 700;
    color: rgba(230, 57, 70, 0.6);
}

.overtake-sim__stat-value--accent {
    color: var(--ecu-red);
    text-shadow: 0 0 10px rgba(230, 57, 70, 0.3);
}

.overtake-sim__stat-value--green {
    color: var(--ecu-green);
    text-shadow: 0 0 10px rgba(63, 185, 80, 0.3);
}

.overtake-sim__stat--highlight {
    padding-top: 6px;
    border-top: 1px solid rgba(63, 185, 80, 0.15);
}

.overtake-sim__stat--highlight .overtake-sim__stat-label {
    color: rgba(63, 185, 80, 0.5);
}

/* --- Description text below widget --- */
.overtake-sim__description {
    text-align: center;
    color: var(--ecu-text-secondary);
    font-size: 0.88rem;
    margin-top: 24px;
    max-width: 640px;
    margin-left: auto;
    margin-right: auto;
    line-height: 1.6;
}

.overtake-sim__description strong {
    color: var(--ecu-red);
    font-weight: 600;
}

/* ==========================================================
   RESPONSIVE
   ========================================================== */
@media (max-width: 768px) {
    .overtake-sim {
        padding: var(--ecu-section-padding-mobile) 0;
    }

    .overtake-sim__body {
        grid-template-columns: 1fr;
    }

    .overtake-sim__canvas-wrap {
        border-right: none;
        border-bottom: 1px solid rgba(230, 57, 70, 0.1);
        padding: 12px;
    }

    #overtake-canvas {
        transform: none;
        border-radius: 6px;
    }

    .overtake-sim__scanlines {
        transform: none;
        inset: 12px;
        border-radius: 6px;
    }

    .overtake-sim__scanlines::after {
        border-radius: 6px;
    }

    .overtake-sim__controls {
        padding: 20px 16px;
        gap: 18px;
    }

    .overtake-sim__level-display {
        font-size: 2.4rem;
    }

    .overtake-sim__timer {
        font-size: 2.8rem;
    }

    .overtake-sim__level-seg {
        height: 28px;
        font-size: 0.5rem;
    }

    .overtake-sim__header {
        flex-direction: column;
        gap: 4px;
        align-items: flex-start;
        padding: 10px 16px;
    }
}

@media (max-width: 480px) {
    .overtake-sim__level-bar {
        gap: 2px;
    }

    .overtake-sim__level-seg {
        height: 26px;
        font-size: 0;  /* hide text on very small screens */
    }

    .overtake-sim__level-seg--active::after {
        content: '';
        width: 4px;
        height: 4px;
        border-radius: 50%;
        background: var(--ecu-red);
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .overtake-sim__stats {
        transition: none;
    }
    .overtake-sim__btn--active .overtake-sim__btn-text {
        animation: none;
    }
}
