:root {
    --bg-dark: #020617;
    --card-bg: rgba(15, 23, 42, 0.75);
    --primary: #38bdf8;

    --safe: #22c55e;
    --warning: #facc15;
    --danger: #ef4444;

    --text-main: #f8fafc;
    --text-muted: #94a3b8;
}

/* ---------------- GLOBAL ---------------- */

body {
    background: radial-gradient(circle at top, #0f172a, #020617 70%);
    color: var(--text-main);
    font-family: 'Outfit', sans-serif;
    margin: 0;
    padding: 40px 20px;
    display: flex;
    justify-content: center;
}

.main-wrapper {
    width: 100%;
    max-width: 1000px;
}

/* ---------------- HEADER ---------------- */

h1 {
    color: var(--primary);
    font-size: 3rem;
    text-align: center;
    margin-bottom: 30px;
    text-shadow: 0 0 30px rgba(56, 189, 248, 0.6);
}

/* ---------------- CARD BASE ---------------- */

.location-container,
.decision-container,
.map-container,
.chart-container {
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    border-radius: 20px;
    padding: 20px;
    margin-bottom: 25px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

/* ---------------- LOCATION SELECTOR (PREMIUM) ---------------- */

.premium-location {
    background: linear-gradient(135deg, rgba(15, 23, 42, 0.85), rgba(2, 6, 23, 0.95));
    backdrop-filter: blur(10px);
    border: 1px solid rgba(56, 189, 248, 0.2);
    border-radius: 16px;
    padding: 20px 24px;
    box-shadow: 0 0 15px rgba(56, 189, 248, 0.05);
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: all 0.3s ease;
    /* Optional animated gradient border effect via pseudo-element */
    position: relative;
    overflow: hidden;
}

.premium-location:hover {
    transform: scale(1.02);
    box-shadow: 0 0 25px rgba(56, 189, 248, 0.15);
}

/* Subtle Animated Glow inside container */
.premium-location::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(56, 189, 248, 0.03) 0%, transparent 60%);
    animation: rotateGlow 10s linear infinite;
    pointer-events: none;
    z-index: 0;
}

@keyframes rotateGlow {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.location-header {
    display: flex;
    align-items: center;
    gap: 10px;
    position: relative;
    z-index: 1;
}

.pulse-dot {
    width: 8px;
    height: 8px;
    background-color: var(--safe);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--safe);
    animation: livePulse 1.5s infinite ease-in-out;
}

.premium-location label {
    font-weight: 600;
    font-size: 1.1rem;
    color: rgba(226, 232, 240, 0.9);
    background: linear-gradient(90deg, #e2e8f0, #94a3b8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    display: flex;
    align-items: center;
    gap: 8px;
}

.premium-select-wrapper {
    position: relative;
    width: 100%;
    max-width: 300px;
    z-index: 1;
}

.custom-select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    width: 100%;
    background: rgba(30, 41, 59, 0.8);
    border: 1px solid rgba(56, 189, 248, 0.3);
    border-radius: 10px;
    padding: 12px 40px 12px 16px;
    color: white;
    font-family: 'Outfit', sans-serif;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    outline: none;
    transition: all 0.3s ease;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.custom-select:hover {
    border-color: rgba(56, 189, 248, 0.6);
    box-shadow: 0 0 12px rgba(56, 189, 248, 0.2);
}

.custom-select:focus {
    border-color: #38bdf8;
    box-shadow: 0 0 15px rgba(56, 189, 248, 0.4);
    background: rgba(15, 23, 42, 0.9);
}

.custom-select option {
    background: #0f172a;
    color: white;
    padding: 10px;
}

.custom-arrow {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    transition: transform 0.3s ease;
}

.custom-select:focus+.custom-arrow {
    transform: translateY(-50%) rotate(180deg);
}

@media (min-width: 768px) {
    .premium-location {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }

    .premium-select-wrapper {
        width: 250px;
    }
}

/* ---------------- AI PANEL (PREMIUM) ---------------- */

.ai-panel {
    background: linear-gradient(135deg, rgba(15, 23, 42, 0.9), rgba(2, 6, 23, 0.95));
    backdrop-filter: blur(12px);
    border: 1px solid rgba(56, 189, 248, 0.2);
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 0 20px rgba(56, 189, 248, 0.05);
    transition: all 0.3s ease;
}

.ai-panel:hover {
    transform: scale(1.02);
    box-shadow: 0 0 30px rgba(56, 189, 248, 0.1);
    border: 1px solid rgba(56, 189, 248, 0.4);
}

.decision-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    font-size: 1.25rem;
    font-weight: 800;
}

.ai-icon-wrapper {
    position: relative;
    font-size: 1.5rem;
    filter: drop-shadow(0 0 8px rgba(56, 189, 248, 0.6));
}

.ai-live-dot {
    position: absolute;
    top: -2px;
    right: -4px;
    width: 8px;
    height: 8px;
    background: #38bdf8;
    border-radius: 50%;
    box-shadow: 0 0 8px #38bdf8;
    animation: livePulse 1.5s infinite ease-in-out;
}

@keyframes livePulse {
    0% {
        transform: scale(0.8);
        opacity: 0.5;
    }

    50% {
        transform: scale(1.2);
        opacity: 1;
    }

    100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
}

.ai-title {
    background: linear-gradient(90deg, #38bdf8, #818cf8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.decision-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.decision-main {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.1rem;
}

.decision-label {
    color: var(--text-muted);
}

.decision-badge {
    padding: 6px 14px;
    border-radius: 20px;
    font-weight: 800;
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    transition: all 0.3s ease;
}

.decision-badge.safe {
    background: rgba(34, 197, 94, 0.2);
    border-color: var(--safe);
    box-shadow: 0 0 10px rgba(34, 197, 94, 0.4);
    animation: pulseSafe 2s infinite;
}

.decision-badge.warning {
    background: rgba(250, 204, 21, 0.2);
    border-color: var(--warning);
    box-shadow: 0 0 10px rgba(250, 204, 21, 0.4);
}

.decision-badge.danger {
    background: rgba(239, 68, 68, 0.2);
    border-color: var(--danger);
    box-shadow: 0 0 10px rgba(239, 68, 68, 0.4);
}

@keyframes pulseSafe {
    0% {
        box-shadow: 0 0 10px rgba(34, 197, 94, 0.4);
    }

    50% {
        box-shadow: 0 0 20px rgba(34, 197, 94, 0.6);
    }

    100% {
        box-shadow: 0 0 10px rgba(34, 197, 94, 0.4);
    }
}

.ai-reason-wrapper {
    font-size: 0.95rem;
    color: var(--text-main);
}

.shimmer-text {
    background: linear-gradient(90deg, var(--text-muted) 0%, #fff 50%, var(--text-muted) 100%);
    background-size: 200% 100%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: shimmer 2.5s infinite linear;
}

@keyframes shimmer {
    to {
        background-position: -200% 0;
    }
}

.confidence-bar-wrapper {
    background: rgba(0, 0, 0, 0.3);
    padding: 12px;
    border-radius: 12px;
}

.confidence-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 8px;
    font-weight: 600;
}

.confidence-value {
    color: var(--primary);
}

.confidence-track {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
    overflow: hidden;
}

.confidence-fill {
    height: 100%;
    background: linear-gradient(90deg, #38bdf8, #818cf8);
    border-radius: 3px;
    transition: width 1s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 0 8px #38bdf8;
}

.ai-alert-box {
    display: flex;
    gap: 12px;
    background: rgba(250, 204, 21, 0.1);
    border-left: 4px solid var(--warning);
    padding: 12px 16px;
    border-radius: 0 8px 8px 0;
    align-items: flex-start;
}

.alert-icon {
    font-size: 1.2rem;
    animation: gentleShake 3s infinite;
}

@keyframes gentleShake {

    0%,
    100% {
        transform: rotate(0deg);
    }

    10%,
    30%,
    50% {
        transform: rotate(-10deg);
    }

    20%,
    40% {
        transform: rotate(10deg);
    }

    60% {
        transform: rotate(0deg);
    }
}

.alert-text .prediction {
    color: #facc15;
    font-weight: 700;
    font-size: 0.95rem;
    margin: 0 0 4px 0;
}

.alert-text .proactive {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.85rem;
    margin: 0;
    line-height: 1.4;
}

.ai-footer {
    display: flex;
    justify-content: flex-end;
    margin-top: 4px;
}

.source-tag {
    font-size: 0.75rem;
    padding: 4px 8px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    color: var(--text-muted);
}


/* ---------------- MAP FIXED ---------------- */

.stadium-container {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    max-width: 400px;
    margin: 20px auto;
    /* overflow: hidden; removed to prevent gate labels from being clipped */
}

/* CLEAN RINGS */

.circle {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 56%;
    height: 56%;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.15);
    box-shadow: none;
    box-sizing: border-box;
}

.inner-circle {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 28%;
    height: 28%;
    border-radius: 50%;
    border: 1px dashed rgba(255, 255, 255, 0.15);
    box-sizing: border-box;
}

/* ---------------- GATES FIXED ---------------- */

.gate-wrapper {
    position: absolute;
    z-index: 10;
    transform: var(--base-transform) scale(var(--gate-scale, 1));
    transition: transform 0.3s ease;
}

/* Vertical Gates: A and C */
.gate-a,
.gate-c {
    width: 12%;
    height: 14%;
}

.gate-a {
    top: 8%;
    left: 50%;
    --base-transform: translateX(-50%);
}

.gate-c {
    bottom: 8%;
    left: 50%;
    --base-transform: translateX(-50%);
}

/* Horizontal Gates: B and D */
.gate-b,
.gate-d {
    width: 14%;
    height: 12%;
}

.gate-b {
    top: 50%;
    right: 8%;
    --base-transform: translateY(-50%);
}

.gate-d {
    top: 50%;
    left: 8%;
    --base-transform: translateY(-50%);
}

/* FORCE SVG TO NEVER EXPLODE */
.gate-wrapper svg {
    position: absolute;
    top: 0;
    left: 0;
    /* Strict pixel locking */
    width: 100% !important;
    height: 100% !important;
    overflow: visible;
    /* Prevents the drop-shadow from getting cut off */
}

/* LABELS EXACTLY LIKE TARGET IMAGE */
.gate-label {
    position: absolute;
    font-weight: 600;
    font-size: 13px;
    color: var(--text-muted);
    white-space: nowrap;
    margin: 0;
    transition: all 0.3s ease;
}

/* Push labels outward perfectly from the wrapper */
.gate-a .gate-label {
    bottom: 100%;
    left: 50%;
    transform: translate(-50%, -4px);
}

.gate-b .gate-label {
    left: 100%;
    top: 50%;
    transform: translate(8px, -50%);
}

.gate-c .gate-label {
    top: 100%;
    left: 50%;
    transform: translate(-50%, 4px);
}

.gate-d .gate-label {
    right: 100%;
    top: 50%;
    transform: translate(-8px, -50%);
}

/* CLEAN SHAPE */
.gate-poly {
    fill: #334155;
    transition: all 0.3s ease;
}

/* SOFT EDGE GLOW (NO BOX) */
.gate-wrapper.safe .gate-poly {
    fill: var(--safe);
    filter: drop-shadow(0 0 6px var(--safe));
}

.gate-wrapper.warning .gate-poly {
    fill: var(--warning);
    filter: drop-shadow(0 0 6px var(--warning));
}

.gate-wrapper.danger .gate-poly {
    fill: var(--danger);
    filter: drop-shadow(0 0 6px var(--danger));
}

/* BEST GATE (WHITE OUTLINE + HIGHLIGHT) */
@keyframes subtlePulse {
    0% {
        filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.4)) drop-shadow(0 0 8px var(--safe));
    }

    50% {
        filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.7)) drop-shadow(0 0 12px var(--safe));
    }

    100% {
        filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.4)) drop-shadow(0 0 8px var(--safe));
    }
}

.gate-wrapper.best-gate {
    --gate-scale: 1.05;
}

.gate-wrapper.best-gate .gate-poly {
    stroke: white;
    stroke-width: 2;
    animation: subtlePulse 2.5s infinite ease-in-out;
}

.gate-wrapper.best-gate .gate-label {
    color: #f8fafc;
    font-weight: 700;
}

/* ---------------- ROUTE FIXED & ANIMATED ---------------- */

.route-line {
    position: absolute;
    width: calc(50% - 23%);
    height: 3px;
    top: 50%;
    left: 50%;
    margin-top: -1.5px;
    transform-origin: 0% 50%;

    /* Background-based Dashes for Animation */
    background-image: linear-gradient(to right, var(--safe) 50%, transparent 50%);
    background-size: 12px 100%;

    /* Fade from center outwards */
    mask-image: linear-gradient(to right, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 1) 40%);
    -webkit-mask-image: linear-gradient(to right, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 1) 40%);

    opacity: 0;
    transition: opacity 0.4s ease;
    z-index: 5;
}

.route-line.active {
    opacity: 1;
    animation: flowDash 1s linear infinite;
}

/* Optional Enhancement: Pulsing dot at the gate end */
.route-line.active::after {
    content: '';
    position: absolute;
    right: -2px;
    /* slightly cap the line */
    top: 50%;
    margin-top: -3px;
    /* centers the 6px dot */
    width: 6px;
    height: 6px;
    background-color: #fff;
    border-radius: 50%;
    box-shadow: 0 0 6px var(--safe);
    animation: pulseEnd 1.5s ease-in-out infinite;
}

@keyframes flowDash {
    to {
        background-position: 12px 0;
    }
}

@keyframes pulseEnd {
    0% {
        transform: scale(1);
        box-shadow: 0 0 6px var(--safe);
    }

    50% {
        transform: scale(1.6);
        box-shadow: 0 0 12px var(--safe);
    }

    100% {
        transform: scale(1);
        box-shadow: 0 0 6px var(--safe);
    }
}

.route-a {
    transform: rotate(-90deg);
}

.route-b {
    transform: rotate(0deg);
}

.route-c {
    transform: rotate(90deg);
}

.route-d {
    transform: rotate(180deg);
}

/* ---------------- CHART ---------------- */

.chart-container {
    background: linear-gradient(145deg, #0f172a, #020617);
    border-radius: 22px;
    padding: 25px;
    height: 340px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.chart-wrapper {
    height: 250px;
}

/* ---------------- REST (BOTTOM CARDS) ---------------- */

.container {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.gate {
    flex: 1;
    min-width: 220px;
    padding: 22px;
    border-radius: 18px;
    background: linear-gradient(145deg, #0f172a, #020617);
    border: 1px solid rgba(255, 255, 255, 0.05);
    position: relative;
    transition: all 0.25s ease;
}

.gate:hover {
    transform: translateY(-6px);
}

/* FIXED: Attached these strictly to `.gate` so the inset box-shadow
   doesn't accidentally leak onto the map's `.gate-wrapper` elements 
*/
.gate.safe {
    box-shadow: inset 3px 0 0 var(--safe);
}

.gate.warning {
    box-shadow: inset 3px 0 0 var(--warning);
}

.gate.danger {
    box-shadow: inset 3px 0 0 var(--danger);
}

.wait {
    color: var(--primary);
    margin-bottom: 14px;
}

.rush-btn {
    width: 100%;
    padding: 10px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: #e2e8f0;
    cursor: pointer;
}

.trigger-alert {
    background: rgba(127, 29, 29, 0.4);
    /* dark red glass */
    border: 1px solid rgba(239, 68, 68, 0.5);
    color: #fecaca;

    padding: 12px;
    margin: 20px 0;

    border-radius: 12px;
    text-align: center;
    font-weight: 500;

    backdrop-filter: blur(6px);

    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* FOOTER */
.app-footer {
    text-align: center;
    margin-top: 20px;
    padding: 12px;
    font-size: 14px;
    color: #94a3b8;
    opacity: 0.8;
}
