:root {
    color-scheme: dark;
    --ink: #eaf4ff;
    --muted: #8ba5bd;
    --space: #010611;
    --ocean: #031426;
    --panel: rgba(7, 20, 35, 0.88);
    --panel-line: rgba(129, 184, 223, 0.2);
    --cyan: #56ddff;
    --blue: #2f91d5;
    --amber: #ffbd5a;
    --green: #59e39b;
    --conflict: #ff566b;
}

* {
    box-sizing: border-box;
}

html,
body,
.map-shell,
#map {
    width: 100%;
    height: 100%;
    margin: 0;
}

body {
    overflow: hidden;
    background: var(--space);
    color: var(--ink);
    font-family: Inter, "Segoe UI", system-ui, sans-serif;
}

button,
input {
    font: inherit;
}

.map-shell {
    position: relative;
    isolation: isolate;
    background: var(--space);
}

.map-shell::before {
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    content: "";
    opacity: 0.72;
    background-image:
        radial-gradient(circle, rgba(218, 238, 255, 0.9) 0 0.8px, transparent 1.3px),
        radial-gradient(circle, rgba(116, 185, 235, 0.68) 0 0.65px, transparent 1.15px),
        radial-gradient(circle, rgba(255, 255, 255, 0.8) 0 1px, transparent 1.55px);
    background-position: 23px 41px, 109px 67px, 181px 139px;
    background-size: 157px 149px, 233px 211px, 347px 313px;
}

#map {
    position: absolute;
    inset: 0;
    z-index: 1;
    background: transparent;
}

#map::after {
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    content: "";
    background:
        radial-gradient(circle at 50% 42%, transparent 30%, rgba(2, 7, 14, 0.32) 100%),
        linear-gradient(180deg, rgba(2, 10, 18, 0.1), transparent 30%, rgba(2, 8, 16, 0.32));
}

.map-header,
.map-panel,
.map-credit {
    position: absolute;
    z-index: 5;
}

.map-header {
    top: 0;
    right: 0;
    left: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 84px;
    padding: 16px 24px;
    pointer-events: none;
    background: linear-gradient(180deg, rgba(3, 12, 22, 0.92), rgba(3, 12, 22, 0));
}

.brand-lockup,
.live-status {
    display: flex;
    align-items: center;
}

.brand-lockup {
    gap: 13px;
}

.brand-mark {
    display: grid;
    width: 48px;
    height: 48px;
    place-items: center;
    border: 1px solid rgba(86, 221, 255, 0.5);
    border-radius: 12px 4px 12px 4px;
    color: var(--cyan);
    background: rgba(18, 56, 80, 0.6);
    box-shadow: inset 0 0 24px rgba(86, 221, 255, 0.08), 0 8px 30px rgba(0, 0, 0, 0.2);
    font-family: Consolas, "SFMono-Regular", monospace;
    font-size: 14px;
    font-weight: 800;
    letter-spacing: 0.12em;
}

.eyebrow,
.section-label {
    margin: 0;
    color: var(--cyan);
    font-family: Consolas, "SFMono-Regular", monospace;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.18em;
}

h1 {
    margin: 3px 0 0;
    font-size: 20px;
    font-weight: 620;
    letter-spacing: -0.02em;
}

.live-status {
    gap: 9px;
    padding: 8px 12px;
    border: 1px solid rgba(89, 227, 155, 0.18);
    border-radius: 999px;
    color: #b7c9d9;
    background: rgba(4, 17, 28, 0.72);
    font-family: Consolas, "SFMono-Regular", monospace;
    font-size: 11px;
}

.status-light {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--amber);
    box-shadow: 0 0 10px rgba(255, 189, 90, 0.8);
}

.live-status.is-live .status-light {
    background: var(--green);
    box-shadow: 0 0 12px rgba(89, 227, 155, 0.9);
    animation: status-pulse 2.4s ease-in-out infinite;
}

.live-status.is-error .status-light {
    background: #ff6e78;
    box-shadow: 0 0 12px rgba(255, 110, 120, 0.75);
}

@keyframes status-pulse {
    0%,
    100% {
        opacity: 0.55;
    }
    50% {
        opacity: 1;
    }
}

.map-panel {
    width: min(310px, calc(100vw - 32px));
    border: 1px solid var(--panel-line);
    background:
        linear-gradient(135deg, rgba(16, 45, 67, 0.22), transparent 42%),
        var(--panel);
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.32);
    backdrop-filter: blur(14px);
}

.world-panel {
    top: 98px;
    left: 20px;
}

.ranking-panel {
    top: 98px;
    left: 346px;
    width: min(280px, calc(100vw - 32px));
    overflow: hidden;
}

.region-panel {
    top: 98px;
    right: 20px;
    z-index: 8;
    width: min(350px, calc(100vw - 32px));
    max-height: calc(100vh - 145px);
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transform: translateX(calc(100% + 32px));
    transition: opacity 180ms ease, transform 220ms ease;
}

.region-panel.is-open {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(0);
}

.traffic-panel {
    top: 98px;
    right: 20px;
    max-height: calc(100vh - 145px);
    overflow: hidden;
}

.conflict-panel {
    bottom: 20px;
    left: 20px;
    max-height: clamp(120px, calc(100vh - 500px), 390px);
    overflow: hidden;
}

.panel-section {
    padding: 16px;
    border-bottom: 1px solid rgba(129, 184, 223, 0.12);
}

.panel-section:last-child {
    border-bottom: 0;
}

.controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.controls #toggleWars {
    grid-column: 1 / -1;
}

.controls button {
    min-height: 38px;
    border: 1px solid rgba(129, 184, 223, 0.18);
    border-radius: 3px;
    color: #a7bbcd;
    background: rgba(11, 31, 49, 0.72);
    cursor: pointer;
    transition: border-color 160ms ease, color 160ms ease, background 160ms ease;
}

.controls button:hover,
.controls button:focus-visible {
    outline: none;
    border-color: rgba(86, 221, 255, 0.65);
    color: #fff;
}

.controls button.is-active {
    border-color: rgba(86, 221, 255, 0.36);
    color: var(--cyan);
    background: rgba(20, 75, 104, 0.46);
}

.controls #toggleWars.is-active {
    border-color: rgba(255, 86, 107, 0.38);
    color: #ff8796;
    background: rgba(107, 28, 43, 0.44);
}

.controls #togglePopulation.is-active {
    border-color: rgba(186, 244, 123, 0.4);
    color: #d7fa9c;
    background: rgba(50, 96, 69, 0.44);
}

.controls button span {
    display: inline-block;
    margin-right: 5px;
}

.legend {
    display: grid;
    gap: 10px;
    color: #a7bbcd;
    font-size: 11px;
}

.legend .section-label {
    margin-bottom: 2px;
}

.legend div {
    display: flex;
    align-items: center;
    gap: 9px;
}

.ranking-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid rgba(129, 184, 223, 0.14);
}

.ranking-heading h2 {
    margin: 4px 0 0;
    font-size: 18px;
    font-weight: 580;
}

.ranking-badge {
    padding: 4px 7px;
    border: 1px solid rgba(86, 221, 255, 0.28);
    color: var(--cyan);
    background: rgba(20, 75, 104, 0.38);
    font-family: Consolas, "SFMono-Regular", monospace;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.13em;
}

.country-ranking {
    margin: 0;
    padding: 5px 0;
    list-style: none;
}

.country-ranking > li {
    border-bottom: 1px solid rgba(129, 184, 223, 0.07);
}

.country-ranking > li:last-child {
    border-bottom: 0;
}

.country-rank-item {
    display: grid;
    grid-template-columns: 24px 11px minmax(0, 1fr) auto;
    align-items: center;
    gap: 9px;
    width: 100%;
    min-height: 32px;
    padding: 4px 14px;
    border: 0;
    color: inherit;
    background: transparent;
    text-align: left;
    cursor: pointer;
    transition: background 150ms ease, box-shadow 150ms ease;
}

.country-rank-item:hover,
.country-rank-item:focus-visible {
    outline: none;
    background: rgba(36, 89, 119, 0.24);
}

.country-rank-item.is-active {
    background: color-mix(in srgb, var(--country-color) 14%, rgba(5, 19, 31, 0.84));
    box-shadow: inset 3px 0 var(--country-color);
}

.country-rank-position {
    color: #66839c;
    font-family: Consolas, "SFMono-Regular", monospace;
    font-size: 9px;
}

.country-rank-color {
    width: 10px;
    height: 10px;
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: 2px;
    background: var(--country-color);
    box-shadow: 0 0 8px color-mix(in srgb, var(--country-color) 65%, transparent);
}

.country-rank-name {
    overflow: hidden;
    color: #dcecff;
    font-size: 11px;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.country-rank-count {
    color: #9fb5c8;
    font-family: Consolas, "SFMono-Regular", monospace;
    font-size: 9px;
    white-space: nowrap;
}

.country-rank-count b {
    color: #f0f7ff;
    font-size: 11px;
}

.region-panel-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px 16px;
    border-bottom: 1px solid rgba(86, 221, 255, 0.18);
}

.region-panel-heading h2 {
    margin: 4px 0 0;
    font-size: 19px;
    font-weight: 620;
}

.region-panel-close {
    display: grid;
    width: 30px;
    height: 30px;
    padding: 0;
    place-items: center;
    border: 1px solid rgba(129, 184, 223, 0.18);
    border-radius: 3px;
    color: #9fb5c8;
    background: rgba(7, 24, 39, 0.72);
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
}

.region-panel-close:hover,
.region-panel-close:focus-visible {
    outline: none;
    border-color: rgba(86, 221, 255, 0.58);
    color: #fff;
}

.region-panel-content {
    max-height: calc(100vh - 212px);
    overflow-y: auto;
    padding: 16px;
    scrollbar-color: rgba(86, 221, 255, 0.35) transparent;
}

.region-control {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 12px;
    border: 1px solid color-mix(in srgb, var(--region-color) 34%, transparent);
    background: color-mix(in srgb, var(--region-color) 12%, rgba(5, 19, 31, 0.75));
}

.region-control-swatch {
    width: 13px;
    height: 28px;
    flex: 0 0 auto;
    border: 1px solid rgba(255, 255, 255, 0.42);
    border-radius: 2px;
    background: var(--region-color);
    box-shadow: 0 0 12px color-mix(in srgb, var(--region-color) 55%, transparent);
}

.region-control small,
.region-fact small,
.region-resources-heading small {
    display: block;
    color: #718da6;
    font-family: Consolas, "SFMono-Regular", monospace;
    font-size: 8px;
    letter-spacing: 0.11em;
    text-transform: uppercase;
}

.region-control strong {
    display: block;
    margin-top: 2px;
    color: #eff8ff;
    font-size: 13px;
}

.region-facts {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 10px;
}

.region-fact {
    min-width: 0;
    padding: 10px 11px;
    border: 1px solid rgba(129, 184, 223, 0.12);
    background: rgba(7, 24, 39, 0.58);
}

.region-fact strong {
    display: block;
    margin-top: 4px;
    overflow: hidden;
    color: #dcecff;
    font-size: 11px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.region-resources-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    margin: 18px 0 8px;
}

.region-resources-heading h3 {
    margin: 0;
    color: #e8f5ff;
    font-size: 13px;
    font-weight: 620;
}

.region-resource-list {
    display: grid;
    gap: 6px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.region-resource-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 10px;
    border-left: 2px solid rgba(86, 221, 255, 0.5);
    background: rgba(12, 37, 56, 0.62);
}

.region-resource-item strong {
    color: #dcecff;
    font-size: 11px;
    font-weight: 600;
}

.region-resource-stock {
    color: #8fb0c8;
    font-family: Consolas, "SFMono-Regular", monospace;
    font-size: 9px;
    white-space: nowrap;
}

.region-resource-stock.is-depleted {
    color: #ff8796;
}

.region-resource-empty {
    padding: 13px 11px;
    border: 1px dashed rgba(129, 184, 223, 0.18);
    color: var(--muted);
    font-size: 11px;
}

.key-line,
.key-population {
    display: inline-block;
    flex: 0 0 auto;
}

.key-line {
    width: 18px;
    border-top: 2px dashed;
}

.plane-line {
    color: var(--cyan);
}

.war-line {
    color: var(--conflict);
}

.key-population {
    width: 12px;
    height: 12px;
    margin: 0 3px;
    border: 1px solid rgba(229, 253, 255, 0.82);
    border-radius: 50%;
    background: radial-gradient(circle, #ffe39a 0 18%, #72e7d6 45%, rgba(39, 176, 220, 0.12) 72%);
    box-shadow: 0 0 8px rgba(71, 224, 239, 0.58);
}

.conflict-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid rgba(255, 86, 107, 0.18);
}

.conflict-heading .section-label {
    color: #ff8796;
}

.conflict-heading h2 {
    margin: 4px 0 0;
    font-size: 18px;
    font-weight: 580;
}

.conflict-live {
    padding: 4px 7px;
    border: 1px solid rgba(255, 86, 107, 0.32);
    color: #ff8796;
    background: rgba(100, 23, 37, 0.45);
    font-family: Consolas, "SFMono-Regular", monospace;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.15em;
}

.war-list {
    max-height: clamp(70px, calc(100vh - 570px), 330px);
    overflow-y: auto;
    scrollbar-color: rgba(255, 86, 107, 0.35) transparent;
}

.war-item {
    display: block;
    width: 100%;
    padding: 11px 16px 12px;
    border: 0;
    border-bottom: 1px solid rgba(255, 86, 107, 0.1);
    color: inherit;
    background: transparent;
    text-align: left;
    cursor: pointer;
}

.war-item:hover,
.war-item:focus-visible {
    outline: none;
    background: rgba(105, 29, 43, 0.3);
}

.war-parties {
    overflow: hidden;
    color: #f6e8eb;
    font-size: 11px;
    font-weight: 650;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.war-parties b {
    color: var(--conflict);
    font-weight: 800;
}

.war-target,
.war-numbers {
    margin-top: 4px;
    color: var(--muted);
    font-family: Consolas, "SFMono-Regular", monospace;
    font-size: 9px;
}

.war-target {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.war-balance {
    height: 3px;
    margin-top: 8px;
    background: linear-gradient(
        to right,
        var(--conflict) 0,
        var(--conflict) var(--attacker-share),
        #4b8fc3 var(--attacker-share),
        #4b8fc3 100%
    );
    box-shadow: 0 0 8px rgba(255, 86, 107, 0.22);
}

.traffic-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid rgba(129, 184, 223, 0.14);
}

.traffic-heading h2 {
    margin: 4px 0 0;
    font-size: 18px;
    font-weight: 580;
}

.traffic-breakdown {
    display: flex;
    gap: 8px;
    color: var(--muted);
    font-family: Consolas, "SFMono-Regular", monospace;
    font-size: 11px;
}

.traffic-breakdown span {
    padding: 5px 7px;
    border: 1px solid rgba(129, 184, 223, 0.14);
    background: rgba(7, 24, 39, 0.72);
}

.journey-list {
    max-height: calc(100vh - 220px);
    overflow-y: auto;
    scrollbar-color: rgba(86, 221, 255, 0.35) transparent;
}

.journey-item {
    position: relative;
    padding: 13px 16px 14px 44px;
    border-bottom: 1px solid rgba(129, 184, 223, 0.1);
}

.journey-item:last-child {
    border-bottom: 0;
}

.journey-icon {
    position: absolute;
    top: 14px;
    left: 16px;
    width: 19px;
    color: var(--cyan);
    text-align: center;
}

.journey-vehicle {
    color: #dcecff;
    font-size: 11px;
    font-weight: 650;
}

.journey-route {
    margin-top: 3px;
    overflow: hidden;
    color: var(--muted);
    font-size: 11px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.journey-progress {
    height: 2px;
    margin-top: 9px;
    overflow: hidden;
    background: rgba(139, 165, 189, 0.16);
}

.journey-progress i {
    display: block;
    width: var(--progress);
    height: 100%;
    background: var(--cyan);
    box-shadow: 0 0 7px rgba(86, 221, 255, 0.75);
}

.journey-time {
    margin-top: 5px;
    color: #718da6;
    font-family: Consolas, "SFMono-Regular", monospace;
    font-size: 9px;
    letter-spacing: 0.04em;
}

.empty-state {
    margin: 0;
    padding: 20px 16px;
    color: var(--muted);
    font-size: 12px;
}

.map-credit {
    right: 12px;
    bottom: 8px;
    color: rgba(190, 211, 228, 0.55);
    font-size: 9px;
    pointer-events: none;
}

.maplibregl-ctrl-bottom-right {
    bottom: 18px;
}

.maplibregl-ctrl-attrib {
    display: none;
}

.maplibregl-ctrl-group {
    overflow: hidden;
    border: 1px solid rgba(129, 184, 223, 0.18);
    border-radius: 3px;
    background: rgba(7, 20, 35, 0.88);
}

.maplibregl-ctrl-group button {
    filter: invert(1);
    opacity: 0.72;
}

.maplibregl-popup-content {
    min-width: 190px;
    padding: 12px 14px;
    border: 1px solid rgba(86, 221, 255, 0.28);
    border-radius: 3px;
    color: #dcecff;
    background: rgba(5, 19, 31, 0.95);
    box-shadow: 0 14px 35px rgba(0, 0, 0, 0.42);
    font-size: 11px;
}

.maplibregl-popup-tip {
    border-top-color: rgba(5, 19, 31, 0.95) !important;
    border-bottom-color: rgba(5, 19, 31, 0.95) !important;
}

.popup-kicker {
    color: var(--cyan);
    font-family: Consolas, "SFMono-Regular", monospace;
    font-size: 9px;
    letter-spacing: 0.12em;
}

.popup-title {
    margin-top: 3px;
    font-size: 13px;
    font-weight: 650;
}

.popup-detail {
    margin-top: 5px;
    color: var(--muted);
    line-height: 1.45;
}

.popup-flight-grid {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 4px 11px;
    margin-top: 8px;
}

.popup-flight-grid dt {
    color: #6f91ab;
}

.popup-flight-grid dd {
    margin: 0;
    overflow: hidden;
    color: #dcecff;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.popup-progress {
    height: 3px;
    margin-top: 10px;
    overflow: hidden;
    background: rgba(139, 165, 189, 0.18);
}

.popup-progress i {
    display: block;
    width: var(--progress);
    height: 100%;
    background: var(--cyan);
    box-shadow: 0 0 8px rgba(86, 221, 255, 0.78);
}

.popup-flight-status {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    margin-top: 6px;
    color: #8ba5bd;
    font-family: Consolas, "SFMono-Regular", monospace;
    font-size: 9px;
}

@media (max-width: 1000px) {
    .ranking-panel {
        display: none;
    }
}

@media (max-width: 760px) {
    .map-header {
        min-height: 70px;
        padding: 12px;
    }

    .brand-mark {
        width: 42px;
        height: 42px;
    }

    .brand-lockup h1 {
        font-size: 16px;
    }

    .live-status {
        max-width: 150px;
    }

    #liveStatusText {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .world-panel {
        top: 82px;
        left: 10px;
        width: 210px;
    }

    .traffic-panel {
        top: auto;
        right: 10px;
        bottom: 28px;
        width: calc(100vw - 20px);
        max-height: 210px;
    }

    .region-panel {
        top: 82px;
        right: 10px;
        width: calc(100vw - 20px);
        max-height: calc(100vh - 110px);
    }

    .region-panel-content {
        max-height: calc(100vh - 178px);
    }

    .conflict-panel {
        display: none;
    }

    .world-panel .legend {
        display: none;
    }

    .panel-section {
        padding: 11px;
    }

    .controls button {
        min-height: 34px;
        font-size: 11px;
    }

    .journey-list {
        max-height: 130px;
    }

    .map-credit {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .status-light {
        animation: none !important;
    }
}
