:root {
    color-scheme: dark;
    --ink: #eef8f9;
    --muted: #8aa4ad;
    --muted-bright: #b9cbd0;
    --bg: #07131d;
    --panel: rgba(11, 28, 39, 0.82);
    --panel-strong: #0d202c;
    --line: rgba(174, 224, 231, 0.13);
    --line-strong: rgba(174, 224, 231, 0.24);
    --cyan: #69e6ec;
    --cyan-dim: #2aa9b8;
    --lime: #c8f169;
    --shadow: 0 28px 70px rgba(0, 5, 10, 0.34);
    --sun-x: 50%;
    --sun-y: 0%;
    --sun-glow-alpha: 0.025;
    --sun-glow-color: 116 176 202;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html[data-sun-phase="day"] {
    --bg: #2d5262;
    --sun-glow-color: 255 229 169;
}
html[data-sun-phase="civil"] {
    --bg: #193746;
    --sun-glow-color: 255 159 91;
}
html[data-sun-phase="nautical"] {
    --bg: #10283a;
    --sun-glow-color: 219 119 132;
}
html[data-sun-phase="astronomical"] {
    --bg: #0a1c2b;
    --sun-glow-color: 91 119 174;
}
html[data-sun-phase="night"] {
    --bg: #07131d;
    --sun-glow-color: 77 130 160;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { min-width: 320px; background: var(--bg); }

body {
    min-height: 100vh;
    margin: 0;
    color: var(--ink);
    background:
        radial-gradient(circle at var(--sun-x) var(--sun-y), rgb(var(--sun-glow-color) / var(--sun-glow-alpha)) 0, transparent 30rem),
        linear-gradient(rgba(105, 230, 236, 0.025) 1px, transparent 1px),
        linear-gradient(90deg, rgba(105, 230, 236, 0.025) 1px, transparent 1px),
        radial-gradient(circle at 16% 0%, #123246 0, transparent 31rem),
        radial-gradient(circle at 92% 90%, #102f39 0, transparent 34rem),
        var(--bg);
    background-size: auto, 36px 36px, 36px 36px, auto, auto, auto;
    transition: background-color 800ms ease;
    overflow-x: hidden;
}

button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.ambient {
    position: fixed;
    z-index: -1;
    width: 24rem;
    height: 24rem;
    border-radius: 50%;
    filter: blur(90px);
    opacity: 0.09;
    pointer-events: none;
}

.ambient-one { top: 18%; left: -12rem; background: var(--cyan); }
.ambient-two { right: -12rem; bottom: -4rem; background: var(--lime); }

.app-shell {
    width: 100%;
    margin: 0;
    padding: 24px max(24px, calc((100vw - 1440px) / 2)) 190px;
}

.app-title {
    margin: 0 0 16px;
}

.viewer-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.65fr) minmax(360px, 0.9fr);
    gap: 18px;
}

.panel, .timeline-panel {
    border: 1px solid var(--line);
    border-radius: 20px;
    background: var(--panel);
    box-shadow: var(--shadow);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
}

.panel { overflow: hidden; }

.panel-heading {
    min-height: 52px;
    padding: 14px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.panel-heading.compact { min-height: 52px; }
.eyebrow { margin: 0 0 6px; color: var(--cyan); font-size: 0.7rem; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase; }
.panel-heading .eyebrow:last-child { margin-bottom: 0; }
h1, h2, p { margin-top: 0; }
h1, h2 { margin-bottom: 0; line-height: 1.15; }
h1 { font-size: clamp(1.3rem, 2vw, 1.75rem); font-weight: 580; letter-spacing: -0.025em; }
h2 { font-size: 1.1rem; font-weight: 560; letter-spacing: -0.015em; }

.counter {
    flex: none;
    padding: 5px 10px;
    color: var(--muted-bright);
    border: 1px solid var(--line);
    border-radius: 999px;
    font: 600 0.72rem/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.image-stage {
    position: relative;
    min-height: 420px;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    background: #061019;
}

.image-stage > img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
    animation: image-in 380ms ease both;
}

#capture-image { cursor: zoom-in; }
#capture-image:focus-visible { outline: 3px solid var(--cyan); outline-offset: -5px; }

.image-lightbox {
    width: 100vw;
    height: 100dvh;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    border: 0;
    color: var(--ink);
    background: #010609;
}
.image-lightbox[open] { display: grid; place-items: center; }
.image-lightbox::backdrop { background: rgba(0, 4, 7, 0.96); }
.image-lightbox > img { width: auto; height: auto; max-width: 100%; max-height: 100%; display: block; object-fit: contain; }
.image-lightbox-close {
    position: fixed;
    z-index: 2;
    top: max(18px, env(safe-area-inset-top));
    right: max(18px, env(safe-area-inset-right));
    width: 46px;
    height: 46px;
    padding: 0;
    display: grid;
    place-items: center;
    color: var(--ink);
    border: 1px solid rgba(255, 255, 255, 0.24);
    border-radius: 50%;
    background: rgba(4, 13, 19, 0.76);
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.32);
    backdrop-filter: blur(10px);
    cursor: pointer;
}
.image-lightbox-close:hover { color: #07131d; border-color: var(--cyan); background: var(--cyan); }
.image-lightbox-close:focus-visible { outline: 3px solid rgba(105, 230, 236, 0.42); outline-offset: 3px; }
.image-lightbox-close svg { width: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }

@keyframes image-in { from { opacity: 0.35; transform: scale(1.012); } to { opacity: 1; transform: scale(1); } }

.image-shade {
    position: absolute;
    inset: 50% 0 0;
    background: linear-gradient(transparent, rgba(1, 8, 13, 0.74));
    pointer-events: none;
}

.image-caption {
    position: absolute;
    right: 24px;
    bottom: 22px;
    left: 24px;
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 16px;
    text-shadow: 0 2px 18px #000;
}

.image-caption span, .image-caption strong {
    color: #d4e1e4;
    font: 500 0.88rem/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    letter-spacing: 0;
}
.image-time, .image-weather { display: inline-grid; gap: 5px; }
.image-weather { justify-items: end; text-align: right; }
.image-caption .image-caption-label { color: var(--muted); font: 500 0.68rem/1.2 Inter, ui-sans-serif, system-ui, sans-serif; letter-spacing: 0.08em; text-transform: uppercase; }
.image-weather-values { display: inline-flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 5px 9px; }
.image-weather-values > * + *::before { content: "·"; margin-right: 9px; color: rgba(212, 225, 228, 0.54); }
.image-weather #weather-temperature { color: #d4e1e4; }
#weather-condition { display: inline-flex; align-items: center; font-size: 1.12rem; line-height: 1; }
#capture-time { white-space: nowrap; }

.loading-state, .empty-state {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: grid;
    place-content: center;
    justify-items: center;
    padding: 32px;
    text-align: center;
    background: radial-gradient(circle at center, rgba(40, 111, 126, 0.18), transparent 58%);
}

.loading-state p { margin: 16px 0 0; color: var(--muted); font-size: 0.9rem; }
.loader { width: 32px; height: 32px; border: 2px solid var(--line-strong); border-top-color: var(--cyan); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state svg { width: 70px; color: var(--cyan-dim); fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.empty-state h2 { margin: 20px 0 9px; font-size: 1.25rem; }
.empty-state p { max-width: 360px; margin-bottom: 0; color: var(--muted); line-height: 1.55; }

.map-panel { display: flex; flex-direction: column; }
.map-wrap { position: relative; min-height: 370px; flex: 1; background: #081720; border-top: 1px solid var(--line); }
#map { position: absolute; inset: 0; z-index: 1; background: #0b1c27; }
#map::after { content: ""; position: absolute; inset: 0; z-index: 500; pointer-events: none; box-shadow: inset 0 0 60px rgba(0, 8, 13, 0.44); }
.leaflet-container { overflow: hidden; font-family: inherit; outline-offset: 1px; }
.leaflet-pane, .leaflet-tile, .leaflet-marker-icon, .leaflet-marker-shadow, .leaflet-tile-container, .leaflet-pane > svg, .leaflet-pane > canvas, .leaflet-zoom-box, .leaflet-image-layer, .leaflet-layer { position: absolute; left: 0; top: 0; }
.leaflet-tile, .leaflet-marker-icon, .leaflet-marker-shadow { user-select: none; -webkit-user-drag: none; }
.leaflet-tile-pane { z-index: 200; }
.leaflet-overlay-pane { z-index: 400; }
.leaflet-shadow-pane { z-index: 500; }
.leaflet-marker-pane { z-index: 600; }
.leaflet-tooltip-pane { z-index: 650; }
.leaflet-popup-pane { z-index: 700; }
.leaflet-map-pane canvas { z-index: 100; }
.leaflet-map-pane svg { z-index: 200; }
.leaflet-control { position: relative; z-index: 800; pointer-events: auto; }
.leaflet-top, .leaflet-bottom { position: absolute; z-index: 1000; pointer-events: none; }
.leaflet-top { top: 0; }
.leaflet-right { right: 0; }
.leaflet-bottom { bottom: 0; }
.leaflet-left { left: 0; }
.leaflet-bottom.leaflet-right { top: 0; bottom: auto; }
.leaflet-bottom.leaflet-right .leaflet-control { margin: 10px 10px 0 0; }
.leaflet-control { margin: 10px; }
.leaflet-control-zoom a { width: 30px; height: 30px; display: block; border-bottom: 1px solid var(--line); line-height: 30px; text-align: center; text-decoration: none; }
.leaflet-control-zoom a:first-child { border-radius: 6px 6px 0 0; }
.leaflet-control-zoom a:last-child { border: 0; border-radius: 0 0 6px 6px; }
.base-map-tile { filter: saturate(0.72) brightness(0.68) contrast(1.18) hue-rotate(145deg); transition: filter 800ms ease; }
.seamark-tile { filter: brightness(0.96) saturate(0.92); transition: filter 800ms ease; }
html[data-sun-phase="astronomical"] .base-map-tile { filter: saturate(0.76) brightness(0.72) contrast(1.15) hue-rotate(128deg); }
html[data-sun-phase="nautical"] .base-map-tile { filter: saturate(0.82) brightness(0.8) contrast(1.1) hue-rotate(88deg); }
html[data-sun-phase="civil"] .base-map-tile { filter: saturate(0.9) brightness(0.9) contrast(1.04) hue-rotate(32deg); }
html[data-sun-phase="day"] .base-map-tile,
html[data-sun-phase="day"] .seamark-tile { filter: none; }
html[data-sun-phase="day"] #map { background: #dbe4e7; }
html[data-sun-phase="day"] #map::after { box-shadow: none; }
.leaflet-control-zoom a { color: var(--ink) !important; background: rgba(7, 19, 29, 0.88) !important; border-color: var(--line) !important; }
.leaflet-control-attribution { color: #9ab0b6; background: rgba(7, 19, 29, 0.82) !important; font-size: 10px !important; }
.leaflet-control-attribution a { color: var(--cyan); }
.ship-marker {
    border: 0;
    background: transparent;
    filter: drop-shadow(0 0 7px rgba(200, 241, 105, 0.88));
}
.ship-marker__icon {
    position: absolute;
    inset: 3px;
    display: block;
    transform: rotate(var(--ship-bearing, 0deg));
    transform-origin: center;
    transition: transform 700ms cubic-bezier(0.22, 1, 0.36, 1);
}
.ship-marker__icon svg { width: 100%; height: 100%; overflow: visible; }
.ship-marker__icon path { fill: var(--lime); stroke: #07131d; stroke-width: 1.7; stroke-linejoin: round; }
.ship-marker__icon .ship-marker__detail { fill: none; stroke: rgba(7, 19, 29, 0.86); stroke-width: 1.25; stroke-linecap: round; }
.map-message { position: absolute; inset: 0; z-index: 600; display: grid; place-content: center; justify-items: center; gap: 14px; padding: 24px; color: var(--muted); text-align: center; background: rgba(8, 23, 32, 0.94); }
.map-message p { margin: 0; max-width: 260px; line-height: 1.5; }
.map-crosshair { width: 34px; height: 34px; border: 1px solid var(--cyan-dim); border-radius: 50%; position: relative; }
.map-crosshair::before, .map-crosshair::after { content: ""; position: absolute; background: var(--cyan-dim); }
.map-crosshair::before { width: 48px; height: 1px; top: 16px; left: -8px; }
.map-crosshair::after { height: 48px; width: 1px; left: 16px; top: -8px; }

.photo-route-point { cursor: pointer; }

.telemetry {
    position: absolute;
    z-index: 650;
    right: 18px;
    bottom: 18px;
    left: 18px;
    min-height: 74px;
    margin: 0;
    padding: 14px 16px;
    display: grid;
    grid-template-columns: 1.4fr 1fr 0.75fr;
    gap: 12px;
    align-items: center;
    border: 1px solid var(--line-strong);
    border-radius: 12px;
    background: rgba(7, 19, 29, 0.86);
    box-shadow: 0 12px 32px rgba(0, 7, 11, 0.28);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}
.telemetry div { min-width: 0; padding-left: 14px; border-left: 1px solid var(--line); }
.telemetry div:first-child { padding-left: 0; border-left: 0; }
.telemetry dt { margin-bottom: 6px; color: var(--muted); font-size: 0.68rem; letter-spacing: 0.08em; text-transform: uppercase; }
.telemetry dd { margin: 0; overflow: hidden; color: var(--ink); font: 520 0.83rem/1.25 ui-monospace, SFMono-Regular, Menlo, monospace; text-overflow: ellipsis; white-space: nowrap; }

.timeline-panel {
    position: fixed;
    z-index: 1200;
    right: 0;
    bottom: max(16px, env(safe-area-inset-bottom));
    left: 0;
    width: min(1440px, calc(100% - 48px));
    margin: 0 auto;
    padding: 18px 24px;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 34px;
    background: rgba(9, 25, 35, 0.58);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
}
.timeline-topline { display: flex; justify-content: space-between; align-items: end; gap: 24px; }
.timeline-controls { margin-top: 0; display: grid; grid-template-columns: 44px minmax(0, 1fr) 44px; align-items: start; gap: 18px; }
.icon-button { width: 44px; height: 44px; display: grid; place-items: center; color: var(--ink); border: 1px solid var(--line-strong); border-radius: 50%; background: rgba(105, 230, 236, 0.045); cursor: pointer; transition: 160ms ease; }
.icon-button:hover:not(:disabled) { color: #07131d; border-color: var(--cyan); background: var(--cyan); transform: translateY(-1px); }
.icon-button:focus-visible, #retry-button:focus-visible { outline: 3px solid rgba(105, 230, 236, 0.35); outline-offset: 3px; }
.icon-button:disabled { opacity: 0.3; cursor: not-allowed; }
.icon-button svg { width: 21px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.range-wrap { min-width: 0; }

.timeline-previews {
    --preview-count: 1;
    height: 38px;
    margin: 0 9px 2px;
    display: grid;
    grid-template-columns: repeat(var(--preview-count), minmax(0, 1fr));
    gap: 2px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(4, 13, 19, 0.66);
}
.timeline-preview {
    position: relative;
    min-width: 0;
    padding: 0;
    overflow: hidden;
    border: 0;
    background: linear-gradient(135deg, rgba(105, 230, 236, 0.035), rgba(105, 230, 236, 0.1));
}
.timeline-preview.is-loaded { cursor: pointer; opacity: 0.68; }
.timeline-preview.is-loaded:hover { opacity: 1; }
.timeline-preview.is-active {
    z-index: 1;
    opacity: 1;
    box-shadow: inset 0 0 0 2px var(--lime), 0 0 12px rgba(200, 241, 105, 0.32);
}
.timeline-preview img { width: 100%; height: 100%; display: block; object-fit: cover; }
.timeline-preview:focus-visible { z-index: 2; outline: 2px solid var(--cyan); outline-offset: -2px; }
.timeline-preview:disabled { cursor: default; }

input[type="range"] {
    --progress: 0%;
    width: 100%;
    height: 28px;
    margin: 0;
    appearance: none;
    background: transparent;
    cursor: ew-resize;
}

input[type="range"]::-webkit-slider-runnable-track { height: 3px; border-radius: 3px; background: linear-gradient(90deg, var(--cyan) var(--progress), var(--line-strong) var(--progress)); }
input[type="range"]::-moz-range-track { height: 3px; border-radius: 3px; background: var(--line-strong); }
input[type="range"]::-moz-range-progress { height: 3px; background: var(--cyan); }
input[type="range"]::-webkit-slider-thumb { width: 18px; height: 18px; margin-top: -7.5px; appearance: none; border: 4px solid #0d202c; border-radius: 50%; background: var(--lime); box-shadow: 0 0 0 1px var(--lime), 0 0 16px rgba(200, 241, 105, 0.5); }
input[type="range"]::-moz-range-thumb { width: 11px; height: 11px; border: 4px solid #0d202c; border-radius: 50%; background: var(--lime); box-shadow: 0 0 0 1px var(--lime); }
input[type="range"]:focus-visible { outline: none; }
input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px rgba(105, 230, 236, 0.35), 0 0 0 1px var(--lime); }
input[type="range"]:disabled { opacity: 0.35; cursor: not-allowed; }
.range-labels { margin-top: 3px; display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font: 500 0.72rem/1.3 ui-monospace, SFMono-Regular, Menlo, monospace; }

.error-banner { margin-top: 18px; padding: 16px 18px; display: flex; align-items: center; justify-content: space-between; gap: 18px; border: 1px solid rgba(255, 142, 113, 0.34); border-radius: 12px; color: #ffd8cd; background: rgba(90, 31, 23, 0.38); }
#retry-button { color: #07131d; border: 0; border-radius: 999px; padding: 9px 14px; background: #ffd8cd; cursor: pointer; font-weight: 700; }

.update-banner {
    position: fixed;
    z-index: 1800;
    top: max(18px, env(safe-area-inset-top));
    left: 50%;
    min-width: min(360px, calc(100% - 32px));
    padding: 10px 11px 10px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    color: var(--ink);
    border: 1px solid rgba(200, 241, 105, 0.42);
    border-radius: 999px;
    background: rgba(7, 19, 29, 0.94);
    box-shadow: 0 16px 44px rgba(0, 5, 10, 0.46), 0 0 22px rgba(200, 241, 105, 0.1);
    backdrop-filter: blur(16px);
    transform: translateX(-50%);
    animation: update-in 260ms ease both;
    font-size: 0.84rem;
}
.update-banner button {
    flex: none;
    padding: 8px 13px;
    color: #07131d;
    border: 0;
    border-radius: 999px;
    background: var(--lime);
    cursor: pointer;
    font-size: 0.78rem;
    font-weight: 750;
}
.update-banner button:hover { background: var(--cyan); }
.update-banner button:focus-visible { outline: 3px solid rgba(105, 230, 236, 0.38); outline-offset: 3px; }
@keyframes update-in { from { opacity: 0; transform: translate(-50%, -10px); } to { opacity: 1; transform: translate(-50%, 0); } }

@media (max-width: 980px) {
    .viewer-grid { grid-template-columns: 1fr; }
    .image-stage { min-height: 0; }
    .map-wrap { min-height: 340px; }
}

@media (max-width: 640px) {
    .app-shell { width: 100%; margin: 0; padding: 14px 14px 180px; }
    .panel, .timeline-panel { border-radius: 15px; }
    .panel-heading { min-height: 48px; padding: 12px 16px; }
    .panel-heading.compact { min-height: 48px; }
    .image-stage { aspect-ratio: 4 / 3; }
    .image-caption { right: 18px; bottom: 17px; left: 18px; }
    .map-wrap { min-height: 320px; }
    .telemetry { right: 10px; bottom: 10px; left: 10px; min-height: 0; padding: 11px 12px; grid-template-columns: 1.4fr 1fr 0.6fr; gap: 8px; }
    .telemetry div { padding-left: 8px; }
    .timeline-panel {
        bottom: max(10px, env(safe-area-inset-bottom));
        width: calc(100% - 20px);
        padding: 16px 18px 15px;
        grid-template-columns: 1fr;
        gap: 14px;
    }
    .timeline-controls { gap: 10px; }
    .error-banner { align-items: flex-start; flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
