@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600;800&display=swap');

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

body {
    height: 100vh;
    background: #000;
    color: #0ff;
    font-family: 'JetBrains Mono', monospace;
    overflow: hidden;
    image-rendering: pixelated;
}

#terminal {
    position: relative;
    height: 100%;
    padding: 15px;
    background: radial-gradient(circle at center, #001, #000);
}

#header {
    background: rgba(0,15,15,0.9);
    border: 2px solid #0ff;
    padding: 12px 20px;
    margin-bottom: 15px;
    box-shadow: 0 0 20px #0ff;
    text-align: center;
    z-index: 10;
}

#header h1 {
    font-size: 1.8em;
    letter-spacing: 6px;
    text-shadow: 0 0 10px #0ff, 0 0 20px #0ff;
    margin-bottom: 8px;
    color: #0ff;
}

.status-line {
    font-size: 0.9em;
    color: #0f8;
    letter-spacing: 3px;
}

.blink { animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

#main {
    display: flex;
    height: calc(100% - 120px);
    gap: 15px;
}

#map-container {
    flex: 6;
    position: relative;
    border: 2px solid #0ff;
    box-shadow: 0 0 20px #0ff inset;
    overflow: hidden;
}

#map { height: 100%; filter: brightness(0.92) contrast(1.3); }

.corner-tr, .corner-tl {
    position: absolute;
    font-size: 0.8em;
    color: #0ff;
    text-shadow: 0 0 10px #0ff;
    pointer-events: none;
}
.corner-tr { top: 8px; right: 12px; }
.corner-tl { bottom: 8px; left: 12px; }

#panels {
    flex: 4;
    display: flex;
    flex-direction: column;
    gap: 15px;
    height: 100%;
}

.panel {
    background: rgba(0,5,10,0.85);
    border: 2px solid #0ff;
    box-shadow: 0 0 15px #0ff;
    padding: 8px 12px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.panel h2 {
    color: #0ff;
    text-shadow: 0 0 10px #0ff;
    font-size: 0.95em;
    margin-bottom: 6px;
    letter-spacing: 2px;
    flex-shrink: 0;
}

/* Content area of every panel (table wrapper, pre, etc.) */
.panel > *:not(h2) {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

/* Table specific styles */
#station-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85em;
}
#station-table th {
    color: #ff0;
    text-align: left;
    padding: 4px 0;
    border-bottom: 1px dashed #0f0;
    cursor: pointer;
}
#station-table td { padding: 3px 0; }
#station-table td:nth-child(5), #station-table td:nth-child(6) { color: #ff0; }  /* Speed/course yellow */
#station-table td:nth-child(7) { max-width: 150px; overflow: hidden; text-overflow: ellipsis; }  /* Comment truncate */
#station-table td:nth-child(8) { color: #f0f; font-weight: bold; }  /* TM purple */

/* Log styling */
pre {
    margin: 0;
    font-size: 0.8em;
    line-height: 1.4;
    padding: 4px 0;
    white-space: pre-wrap;
    word-break: break-all;
}

pre::-webkit-scrollbar {
    width: 8px;
    background: #000;
}
pre::-webkit-scrollbar-thumb {
    background: #0ff;
    box-shadow: 0 0 10px #0ff;
}

/* CRT overlay */
#crt {
    position: fixed;
    inset: 0;
    pointer-events: none;
    background: repeating-linear-gradient(0deg, rgba(0,0,0,0.05), rgba(0,0,0,0.05) 1px, transparent 1px, transparent 2px);
    box-shadow: inset 0 0 50px #000;
    z-index: 9999;
    animation: flicker 8s infinite;
}
@keyframes flicker {
    0%,100% { opacity: 0.99; }
    2% { opacity: 0.95; }
    4% { opacity: 1; }
}

/* Cyber markers */
.cyber-marker .icon {
    width: 32px; height: 32px;
    background: #000;
    border: 2px solid #0ff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    box-shadow: 0 0 20px #0ff;
    inset: 0 0 8px rgba(0,255,255,0.2);
    animation: pulse 3s infinite;
}
.cyber-marker .icon.tm {
    border-color: #f0f;
    box-shadow: 0 0 20px #f0f;
    background: rgba(255,0,255,0.1);
}
@keyframes pulse {
    0%,100% { box-shadow: 0 0 15px #0ff; }
    50% { box-shadow: 0 0 25px #0ff; }
}

/* Mobile */
@media (max-width: 950px) {
    #main { flex-direction: column; height: auto; }
    #map-container { height: 45vh !important; min-height: 300px; }
    #panels { flex: none; }
    #header h1 { font-size: 1.4em; letter-spacing: 3px; }
}
@media (max-width: 600px) {
    #header h1 { font-size: 1.2em; }
    .status-line span { display: block; margin: 2px 0; }
    #station-table { font-size: 0.75em; }
}

/* Dark tint overlay */
#map::before {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.42);   /* adjust the last value for more/less darkness */
    pointer-events: none;             /* lets clicks pass through to the map */
    z-index: 1000;                    /* above tiles but below markers/popups */
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip,
.leaflet-control {
    filter: brightness(1.5);         /* makes white text/icons pop on dark background */
}


#station-table td:nth-child(2) { color: #0f8; font-weight: bold; }  /* HOPS: Bright green */
#station-table td:nth-child(4) {  /* PATH (was 5) */
    max-width: 160px;  /* Slightly wider now */
    overflow: hidden; 
    text-overflow: ellipsis; 
    white-space: nowrap;
    color: #ff0;  /* Yellow for paths */
}
#station-table td:nth-child(5) {  /* COMMENT (was 6) */
    max-width: 140px;  /* Wider for more context */
    overflow: hidden; 
    text-overflow: ellipsis; 
    white-space: nowrap;
}
#station-table tr.direct td:nth-child(2) { color: #0ff; }  /* Highlight DIRECT in cyan for emphasis */

#station-table tr.telemetry-only {
    background: rgba(255, 0, 255, 0.08) !important;
    border-left: 4px solid #f0f;
    animation: pulse-purple 4s infinite;
}

#station-table tr.telemetry-only td {
    color: #ff77ff !important;
}

@keyframes pulse-purple {
    0%, 100% { background: rgba(255, 0, 255, 0.08); }
    50%      { background: rgba(255, 0, 255, 0.18); }
}

/* ========================================= */
/*          MOBILE-FIRST RESPONSIVE FIXES     */
/* ========================================= */

@media (max-width: 950px) {
    body { overflow: hidden; }              /* Prevent double scroll */

    #main {
        flex-direction: column;
        height: 100vh;                       /* Full height */
        gap: 8px;
    }

    #map-container {
        flex: none !important;
        height: 45vh !important;             /* Map gets top half-ish */
        min-height: 300px;
    }

    #panels {
        flex: 1;
        overflow: hidden;
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    .panel {
        flex: 1;
        min-height: 0;                       /* Crucial for flex children with overflow */
        padding: 8px;
    }

    /* Active stations table – mobile readable */
    #station-table {
        font-size: 0.78em;
        width: 100%;
    }
    #station-table th:nth-child(3),
    #station-table td:nth-child(3) { display: none; }  /* Hide AGE column on mobile */

    #station-table th,
    #station-table td {
        padding: 6px 4px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Make callsigns and comments slightly larger */
    #station-table td:first-child { font-weight: bold; font-size: 1.05em; }
    #station-table td:last-child  { max-width: 120px; }

    /* Log panel – bigger text, better touch */
    #activity-log, pre {
        font-size: 0.92em !important;
        line-height: 1.5;
    }

    /* Better touch targets for markers */
    .cyber-marker .icon {
        width: 40px !important;
        height: 40px !important;
        font-size: 1.4em;
    }

    /* Reduce CRT flicker intensity on mobile (saves battery + less nausea) */
    #crt {
        background: repeating-linear-gradient(0deg, rgba(0,0,0,0.03), rgba(0,0,0,0.03) 1px, transparent 1px, transparent 2px);
        animation: flicker 15s infinite;     /* Slower, gentler */
    }
}

@media (max-width: 480px) {
    #header h1 { font-size: 1.1em; letter-spacing: 2px; }
    .status-line { font-size: 0.75em; }
    .status-line span { display: block; margin: 1px 0; }

    /* On very small screens, hide PATH column too */
    #station-table th:nth-child(4),
    #station-table td:nth-child(4) { display: none; }

    /* Only show CALLSIGN + COMMENT */
    #station-table td:first-child { width: 38%; }
    #station-table td:last-child  { width: 62%; font-size: 0.95em; }
}
.path-good { color: #0f8; }
.path-warn { color: #ff0; animation: pulse-yellow 3s infinite; }
.path-bad  { color: #f00; animation: pulse-red 2s infinite; }

@keyframes pulse-yellow { 0%,100% { opacity: 1; } 50% { opacity: 0.6; } }
@keyframes pulse-red    { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

tr.good td { color: #0f8; }
tr.warn td { color: #ff0; }
tr.bad  td { color: #f00; font-weight: bold; }
