@import url("https://fonts.googleapis.com/css2?family=Ubuntu:ital,wght@0,300;0,400;0,500;0,700;1,400&display=swap");

/* ==========================================================================
   Variables
   ========================================================================== */

:root {
    --font-family: "Ubuntu", sans-serif;
    --secondary-color: #00bfff;
    --header-height: 2.5rem;
    --gui-width: 20rem;
    --splitter-size: 12px;
    --white-08: hsla(0, 0%, 100%, 0.08);
    --white-10: hsla(0, 0%, 100%, 0.1);
    --white-15: hsla(0, 0%, 100%, 0.15);
    --white-20: hsla(0, 0%, 100%, 0.2);
    --white-30: hsla(0, 0%, 100%, 0.3);
    --white-60: hsla(0, 0%, 100%, 0.6);
    --white-70: hsla(0, 0%, 100%, 0.7);
    --white-80: hsla(0, 0%, 100%, 0.8);
    --white-90: hsla(0, 0%, 100%, 0.9);
    --radius: 0.375rem;
    --radius-sm: 0.25rem;
}

/* ==========================================================================
   Reset
   ========================================================================== */

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

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

body {
    min-height: 100vh;
    font-family: var(--font-family);
    font-size: 16px;
    line-height: 1em;
    color: #fff;
    background: #000;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
}

input, button, select, textarea {
    font-family: var(--font-family);
}

/* ==========================================================================
   Header
   ========================================================================== */

#site-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: #000;
    border-bottom: 1px solid var(--white-10);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    z-index: 2000;
}

.header-logo {
    display: flex;
    align-items: center;
    text-decoration: none;
    color: var(--white-90);
    font-size: 1.25rem;
    transition: color 0.2s ease;
}

.header-logo:hover {
    color: #fff;
}

.logo-svg {
    height: 1.25rem;
    width: auto;
}

.header-link {
    color: var(--white-60);
    text-decoration: none;
    font-size: 0.8rem;
    font-weight: 400;
    transition: color 0.2s ease;
}

.header-link:hover {
    color: #fff;
}

/* ==========================================================================
   App Layout
   ========================================================================== */

#app-container {
    display: flex;
    width: calc(100vw - var(--gui-width) - var(--splitter-size));
    height: calc(100vh - var(--header-height));
    overflow: hidden;
    flex-direction: column;
    margin: 0;
    padding: 0;
    position: fixed;
    top: var(--header-height);
    left: 0;
}

#map-panel {
    width: 100%;
    height: 50%;
    position: relative;
    background: #000;
    min-height: 20%;
}

#canvas-panel {
    width: 100%;
    flex: 1;
    position: relative;
    min-height: 20%;
    display: flex;
    align-items: center;
    justify-content: center;
}

#canvas-panel canvas {
    width: 100% !important;
    height: 100% !important;
    display: block !important;
}

#leaflet-map-main {
    width: 100%;
    height: 100%;
    z-index: 1;
    background: #000;
}

/* ==========================================================================
   Splitters
   ========================================================================== */

#splitter {
    width: 100%;
    height: var(--splitter-size);
    cursor: ns-resize;
    background: #111;
    flex-shrink: 0;
    transition: background-color 0.2s ease;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    position: relative;
    z-index: 10;
}

#splitter:hover,
#splitter:active {
    background: #333;
}

#splitter::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #666;
    border-radius: 999px;
    width: 3rem;
    height: 0.25rem;
}

#controls-splitter {
    background: #111;
    flex-shrink: 0;
    transition: background-color 0.2s ease;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    position: fixed;
    z-index: 1001;
    top: var(--header-height);
    bottom: 0;
    right: var(--gui-width);
    left: auto;
    width: var(--splitter-size);
    height: auto;
    cursor: ew-resize;
}

#controls-splitter:hover,
#controls-splitter:active {
    background: #333;
}

#controls-splitter::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #666;
    border-radius: 999px;
    width: 0.25rem;
    height: 3rem;
}

/* ==========================================================================
   Loading Overlay
   ========================================================================== */

#wind-loading-overlay {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 200;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

#wind-loading-overlay.visible {
    display: flex;
}

.loading-spinner {
    width: 2.5rem;
    height: 2.5rem;
    border: 3px solid var(--white-15);
    border-top-color: #0df;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-text {
    color: var(--white-80);
    font-size: 0.8rem;
    letter-spacing: 0.05em;
}

/* ==========================================================================
   Pan Controls
   ========================================================================== */

#pan-controls {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 100;
    pointer-events: none;
}

.pan-btn {
    position: absolute;
    width: 2rem;
    height: 2rem;
    background: var(--white-08);
    border: 1px solid var(--white-20);
    border-radius: var(--radius-sm);
    color: #fff;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    pointer-events: auto;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.pan-btn:hover {
    background: hsla(0, 0%, 100%, 0.12);
    border-color: var(--white-30);
}

.pan-btn:active {
    background: var(--white-15);
}

.pan-btn i {
    pointer-events: none;
}

.pan-up    { top: 1rem; left: 50%; transform: translateX(-50%); }
.pan-down  { bottom: 1rem; left: 50%; transform: translateX(-50%); }
.pan-left  { left: 1rem; top: 50%; transform: translateY(-50%); }
.pan-right { right: 1rem; top: 50%; transform: translateY(-50%); }

.pan-up:hover    { transform: translateX(-50%) scale(1.05); }
.pan-up:active   { transform: translateX(-50%) scale(0.95); }
.pan-down:hover  { transform: translateX(-50%) scale(1.05); }
.pan-down:active { transform: translateX(-50%) scale(0.95); }
.pan-left:hover  { transform: translateY(-50%) scale(1.05); }
.pan-left:active { transform: translateY(-50%) scale(0.95); }
.pan-right:hover { transform: translateY(-50%) scale(1.05); }
.pan-right:active{ transform: translateY(-50%) scale(0.95); }

/* ==========================================================================
   Wind Visualization Elements
   ========================================================================== */

.wind-arrow-3d {
    position: absolute;
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 16px solid var(--secondary-color);
    transform-origin: center bottom;
    pointer-events: none;
    z-index: 1 !important;
    filter: none;
    transition: transform 0.1s ease;
}

.wind-cube-cell {
    transition: opacity 0.2s ease;
}

.wind-cube-cell:hover {
    opacity: 1 !important;
}

/* ==========================================================================
   Tooltip
   ========================================================================== */

#tooltip {
    position: absolute;
    background-color: rgba(0, 0, 0, 0.6);
    color: #fff;
    padding: 0.5rem 0.75rem;
    border-radius: 0.75rem;
    font-size: 0.8rem;
    pointer-events: none;
    z-index: 1500;
    display: none;
    white-space: nowrap;
    border: 2px solid #fff;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

#tooltip.visible {
    display: block;
}

/* ==========================================================================
   Map Overlays
   ========================================================================== */

.state-overlay {
    cursor: pointer;
    transition: fill-opacity 0.15s ease;
}

.state-tooltip {
    font-family: var(--font-family);
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
}

/* ==========================================================================
   GUI Panel
   ========================================================================== */

.custom-gui {
    position: fixed;
    top: var(--header-height);
    right: 0;
    bottom: 0;
    width: var(--gui-width);
    background: #000;
    padding: 1.5rem;
    padding-bottom: 6rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 1000;
}

.custom-gui::-webkit-scrollbar {
    width: 0.5rem;
}

.custom-gui::-webkit-scrollbar-track {
    background: var(--white-10);
}

.custom-gui::-webkit-scrollbar-thumb {
    background: var(--white-30);
    border-radius: var(--radius-sm);
}

.custom-gui::-webkit-scrollbar-thumb:hover {
    background: hsla(0, 0%, 100%, 0.5);
}

/* ==========================================================================
   GUI Sections & Controls
   ========================================================================== */

.gui-section {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-width: fit-content;
}

.gui-section-title {
    color: #fff;
    font-size: 0.8rem;
    margin: 0;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.gui-controls {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    align-items: stretch;
}

.gui-control {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    width: 100%;
}

.gui-control label {
    color: var(--white-70);
    font-size: 0.75rem;
    font-weight: 400;
}

.gui-control select,
.gui-control input[type="range"],
.gui-control input[type="text"] {
    background: var(--white-08);
    border: 1px solid var(--white-20);
    border-radius: var(--radius);
    color: #fff;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    outline: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.gui-control select:hover,
.gui-control input[type="range"]:hover,
.gui-control input[type="text"]:hover {
    background-color: hsla(0, 0%, 100%, 0.12);
    border-color: var(--white-30);
}

.gui-control select:focus,
.gui-control input[type="range"]:focus,
.gui-control input[type="text"]:focus {
    background-color: hsla(0, 0%, 100%, 0.12);
    border-color: hsla(0, 0%, 100%, 0.4);
}

.gui-control select {
    padding-right: 2rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='rgba(255,255,255,0.7)' d='M0 0l5 5 5-5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.625rem center;
    background-size: 0.625rem;
    appearance: none;
}

.gui-control select option {
    background: #1a1a1a;
    color: #fff;
    padding: 0.5rem;
}

/* Range Slider */

.gui-control input[type="range"] {
    padding: 0;
    height: 0.375rem;
    appearance: none;
    background: var(--white-15);
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.gui-control input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 1.125rem;
    height: 1.125rem;
    background: #fff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.3), 0 0 0 0.125rem var(--white-10);
    transition: all 0.2s ease;
}

.gui-control input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.15);
    box-shadow: 0 0.25rem 0.5rem rgba(0, 0, 0, 0.4), 0 0 0 0.125rem var(--white-20);
}

.gui-control input[type="range"]::-webkit-slider-thumb:active {
    transform: scale(1.05);
}

.gui-control input[type="range"]::-moz-range-thumb {
    appearance: none;
    width: 1.125rem;
    height: 1.125rem;
    background: #fff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.3), 0 0 0 0.125rem var(--white-10);
    transition: all 0.2s ease;
}

.gui-control input[type="text"] {
    cursor: text;
}

/* Control Row & Value */

.gui-control-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.gui-control-row label {
    flex-shrink: 0;
}

.gui-control-value {
    color: var(--white-90);
    font-size: 0.75rem;
    text-align: right;
    min-width: 3rem;
}

/* Time Controls */

.gui-time-control {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.gui-time-control .gui-time-value {
    flex: 1;
    background: var(--white-08);
    border: 1px solid var(--white-20);
    border-radius: var(--radius);
    padding: 0.5rem 0.75rem;
    text-align: center;
    color: #fff;
    font-size: 0.875rem;
}

.gui-time-control button {
    background: var(--white-08);
    border: 1px solid var(--white-20);
    border-radius: var(--radius);
    color: #fff;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 2.5rem;
}

.gui-time-control button:hover {
    background: hsla(0, 0%, 100%, 0.12);
    border-color: var(--white-30);
}

.gui-time-control button:active {
    transform: scale(0.95);
}

/* ==========================================================================
   GUI Status & Source
   ========================================================================== */

.gui-status {
    background: hsla(0, 0%, 100%, 0.05);
    border: 1px solid var(--white-10);
    border-radius: var(--radius);
    padding: 0.75rem;
    text-align: center;
    color: yellow;
    font-size: 0.8rem;
    font-style: italic;
}

.status-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    margin-right: 4px;
    vertical-align: middle;
}

.status-dot.live {
    background: #4ade80;
    animation: blink 1.5s ease-in-out infinite;
}

.status-dot.offline {
    background: yellow;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.gui-source-link {
    display: block;
    text-align: center;
    font-size: 0.7rem;
    color: hsla(0, 0%, 100%, 0.4);
    margin-top: 0.25rem;
    text-decoration: none;
}

.gui-source-link:hover {
    color: var(--white-70);
}

/* ==========================================================================
   Radio & Checkbox
   ========================================================================== */

.gui-radio,
.gui-checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    user-select: none;
}

.gui-radio label,
.gui-checkbox label {
    color: var(--white-90);
    font-size: 0.875rem;
    cursor: pointer;
    margin: 0;
}

/* Radio */

.gui-radio input[type="radio"] {
    width: 1.125rem;
    height: 1.125rem;
    cursor: pointer;
    appearance: none;
    background: var(--white-08);
    border: 1px solid var(--white-20);
    border-radius: 50%;
    position: relative;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.gui-radio input[type="radio"]:hover {
    background: hsla(0, 0%, 100%, 0.12);
    border-color: var(--white-30);
}

.gui-radio input[type="radio"]:checked {
    background: var(--white-90);
    border-color: var(--white-90);
}

.gui-radio input[type="radio"]:checked::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 0.375rem;
    height: 0.375rem;
    background: #000;
    border-radius: 50%;
}

/* Checkbox */

.gui-checkbox input[type="checkbox"] {
    width: 1.125rem;
    height: 1.125rem;
    cursor: pointer;
    appearance: none;
    background: var(--white-08);
    border: 1px solid var(--white-20);
    border-radius: var(--radius-sm);
    position: relative;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.gui-checkbox input[type="checkbox"]:hover {
    background: hsla(0, 0%, 100%, 0.12);
    border-color: var(--white-30);
}

.gui-checkbox input[type="checkbox"]:checked {
    background: var(--white-90);
    border-color: var(--white-90);
}

.gui-checkbox input[type="checkbox"]:checked::after {
    content: "";
    position: absolute;
    left: 0.25rem;
    top: 0.0625rem;
    width: 0.375rem;
    height: 0.625rem;
    border: solid #000;
    border-width: 0 0.125rem 0.125rem 0;
    transform: rotate(45deg);
}

/* ==========================================================================
   Legal Links & Modal
   ========================================================================== */

.gui-legal {
    margin-top: auto;
    padding-top: 1rem;
    text-align: center;
    font-size: 0.65rem;
}

.gui-legal a {
    color: var(--white-30);
    text-decoration: none;
    transition: color 0.2s ease;
}

.gui-legal a:hover {
    color: var(--white-70);
}

.gui-legal-sep {
    color: var(--white-20);
    margin: 0 0.375rem;
}

.legal-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 3000;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.legal-modal.visible {
    display: flex;
}

.legal-modal-content {
    background: #111;
    border: 1px solid var(--white-15);
    border-radius: 0.5rem;
    width: 90%;
    max-width: 32rem;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

.legal-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--white-10);
}

.legal-modal-header h2 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--white-90);
    margin: 0;
}

.legal-modal-close {
    background: none;
    border: none;
    color: var(--white-60);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    transition: color 0.2s ease;
}

.legal-modal-close:hover {
    color: #fff;
}

.legal-modal-body {
    padding: 1.25rem;
    overflow-y: auto;
    font-size: 0.75rem;
    line-height: 1.6;
    color: var(--white-60);
}

.legal-modal-body h3 {
    color: var(--white-80);
    font-size: 0.8rem;
    font-weight: 600;
    margin: 1rem 0 0.5rem;
}

.legal-modal-body h3:first-child {
    margin-top: 0;
}

.legal-modal-body p {
    margin: 0 0 0.75rem;
}

.legal-modal-body a {
    color: var(--secondary-color);
    text-decoration: none;
}

.legal-modal-body a:hover {
    text-decoration: underline;
}

/* ==========================================================================
   404 Page
   ========================================================================== */

.not-found {
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    background: #000;
    color: #fff;
    text-align: center;
    padding: 2rem;
}

.not-found__code {
    font-size: 5rem;
    font-weight: 700;
    line-height: 1;
    color: var(--white-15);
}

.not-found__message {
    font-size: 0.875rem;
    color: var(--white-60);
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.not-found__link {
    display: inline-block;
    background: var(--white-08);
    border: 1px solid var(--white-20);
    border-radius: var(--radius);
    color: #fff;
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
    text-decoration: none;
    transition: all 0.2s ease;
}

.not-found__link:hover {
    background: hsla(0, 0%, 100%, 0.12);
    border-color: var(--white-30);
}

/* ==========================================================================
   Mobile
   ========================================================================== */

@media screen and (max-width: 800px) {
    #app-container {
        width: 100vw;
        height: calc((100svh - var(--header-height) - var(--splitter-size)) / 2);
        top: var(--header-height);
    }

    #map-panel {
        height: calc(50% - 6px);
        min-height: 0;
    }

    #canvas-panel {
        min-height: 0;
    }

    .custom-gui {
        top: auto;
        right: 0;
        bottom: 0;
        left: 0;
        width: auto;
        height: calc((100svh - var(--header-height) - var(--splitter-size)) / 2);
        padding-bottom: calc(6rem + env(safe-area-inset-bottom, 0px));
    }

    #controls-splitter {
        top: auto;
        bottom: calc((100svh - var(--header-height) - var(--splitter-size)) / 2);
        left: 0;
        right: 0;
        width: auto;
        height: var(--splitter-size);
        cursor: ns-resize;
    }

    #controls-splitter::after {
        width: 3rem;
        height: 0.25rem;
    }
}
