* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    width: 100%;
    height: 100%;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: #111827;
    color: #f9fafb;
}

body {
    overflow: hidden;
}

.app {
    display: grid;
    grid-template-rows: auto 1fr auto;
    width: 100%;
    height: 100dvh;
    min-height: 100vh;
}

.toolbar {
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 12px;
    background: rgba(17, 24, 39, 0.97);
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

h1 {
    margin: 0;
    font-size: 17px;
}

#status {
    margin-top: 2px;
    color: #cbd5e1;
    font-size: 12px;
}

.controls {
    display: flex;
    gap: 7px;
}

.controls button {
    padding: 7px 10px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
    cursor: pointer;
}

#map {
    width: 100%;
    min-height: 0;
    background: #dbeafe;
}

footer {
    z-index: 1000;
    padding: 6px 10px;
    text-align: center;
    color: #d1d5db;
    background: #111827;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    font-size: 12px;
}

footer b {
    color: #fff;
}

.weather-marker {
    background: transparent;
    border: 0;
}

.weather-label {
    display: inline-flex;
    align-items: baseline;
    white-space: nowrap;
    cursor: pointer;
    transform: translate(calc(-50% + var(--collision-x, 0px)), calc(-50% + var(--collision-y, 0px)));
    font-family: inherit;
    line-height: 1.1;
}

/* Dock labels inward when their city point is close to a map edge. */
.weather-label.edge-left {
    transform: translate(var(--collision-x, 0px), calc(-50% + var(--collision-y, 0px)));
}

.weather-label.edge-right {
    transform: translate(calc(-100% + var(--collision-x, 0px)), calc(-50% + var(--collision-y, 0px)));
}

.weather-label.edge-top {
    transform: translate(calc(-50% + var(--collision-x, 0px)), var(--collision-y, 0px));
}

.weather-label.edge-bottom {
    transform: translate(calc(-50% + var(--collision-x, 0px)), calc(-100% + var(--collision-y, 0px)));
}

.weather-label.edge-left.edge-top {
    transform: translate(var(--collision-x, 0px), var(--collision-y, 0px));
}

.weather-label.edge-left.edge-bottom {
    transform: translate(var(--collision-x, 0px), calc(-100% + var(--collision-y, 0px)));
}

.weather-label.edge-right.edge-top {
    transform: translate(calc(-100% + var(--collision-x, 0px)), var(--collision-y, 0px));
}

.weather-label.edge-right.edge-bottom {
    transform: translate(calc(-100% + var(--collision-x, 0px)), calc(-100% + var(--collision-y, 0px)));
}

/* Default state: small, full city name, no temperature. */
.weather-label.compact-name {
    padding: 1px 3px;
    border: 1px solid rgba(15, 23, 42, 0.22);
    border-radius: 4px;
    color: #111827;
    background: rgba(255, 255, 255, 0.82);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.weather-label.compact-name .city {
    font-size: 9px;
    font-weight: 650;
}

/* Pinned state: keep the full weather label appearance. */
.weather-label.pinned {
    gap: 5px;
    padding: 3px 6px;
    border: 2px solid rgba(15, 23, 42, 0.68);
    border-radius: 7px;
    color: #111827;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.24);
}

.weather-label.pinned .city {
    font-size: 12px;
    font-weight: 650;
}

.weather-label.pinned .current {
    font-size: 15px;
    font-weight: 750;
}

.weather-label.pinned .range {
    color: #374151;
    font-size: 11px;
    font-weight: 600;
}

.weather-label.loading {
    opacity: 0.74;
}

.weather-label.error {
    background: rgba(254, 226, 226, 0.94);
}

.weather-label:focus-visible {
    outline: 3px solid #2563eb;
    outline-offset: 2px;
}


/* Furthest two zoom levels: pinned labels stay complete, but use less space. */
.weather-label.pinned.overview-small {
    gap: 3px;
    padding: 2px 4px;
    border-width: 1px;
    border-radius: 5px;
}

.weather-label.pinned.overview-small .city {
    font-size: 9px;
}

.weather-label.pinned.overview-small .current {
    font-size: 11px;
}

.weather-label.pinned.overview-small .range {
    font-size: 8px;
}

/* Defensive rule: normal labels are also smaller if they are ever shown at overview zoom. */
.weather-label.compact-name.overview-small .city {
    font-size: 8px;
}


/* Fully zoomed out (zoom 2): make pinned labels extra compact. */
.weather-label.pinned.overview-furthest {
    gap: 2px;
    padding: 1px 3px;
}

.weather-label.pinned.overview-furthest .city {
    font-size: 7px;
}

.weather-label.pinned.overview-furthest .current {
    font-size: 9px;
}

.weather-label.pinned.overview-furthest .range {
    font-size: 6px;
}

@media (max-width: 600px) {
    .toolbar {
        padding: 7px 8px;
    }

    h1 {
        font-size: 15px;
    }

    .weather-label.compact-name .city {
        font-size: 9px;
    }

    .weather-label.pinned {
        gap: 4px;
        padding: 2px 5px;
    }

    .weather-label.pinned .city {
        font-size: 11px;
    }

    .weather-label.pinned .current {
        font-size: 14px;
    }

    .weather-label.pinned .range {
        font-size: 10px;
    }
}


@media (max-width: 480px) {
    .weather-label.compact-name {
        padding: 1px 2px;
    }

    .weather-label.compact-name .city {
        font-size: 8px;
    }
}


.weather-label.collision-hidden {
    visibility: hidden;
    pointer-events: none;
}


.weather-label.pinned.focused {
    z-index: 20000;
    border-color: rgba(15, 23, 42, 0.9);
}

.weather-label .unpin-control {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 16px;
    height: 16px;
    margin-left: 2px;
    border-radius: 50%;
    font-size: 13px;
    font-weight: 800;
    line-height: 1;
    color: #111827;
    background: rgba(255, 255, 255, 0.88);
    border: 1px solid rgba(15, 23, 42, 0.32);
}

.weather-label .unpin-control:hover {
    background: rgba(229, 231, 235, 0.95);
}


.weather-label .focus-controls {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    margin-left: 2px;
}

.weather-label .forecast-control {
    display: inline-flex;
    align-items: center;
    height: 18px;
    padding: 0 5px;
    border-radius: 5px;
    font-size: 9px;
    font-weight: 700;
    color: #111827;
    background: rgba(255,255,255,.9);
    border: 1px solid rgba(15,23,42,.32);
}


/* Focused-city forecast is attached directly beneath the city label. */
.weather-label.pinned.focused {
    position: relative;
    overflow: visible;
}

.forecast-popover {
    position: absolute;
    z-index: 30000;
    top: calc(100% + 4px);
    left: 50%;
    transform: translateX(-50%);
    display: block;
    width: 245px;
    padding: 6px;
    border: 1px solid rgba(15,23,42,.35);
    border-radius: 7px;
    color: #111827;
    background: rgba(255,255,255,.97);
    box-shadow: 0 2px 10px rgba(0,0,0,.25);
    text-align: left;
    cursor: default;
}

.forecast-popover-title {
    display: block;
    margin-bottom: 4px;
    font-size: 10px;
    font-weight: 800;
}

.forecast-list {
    display: block;
}

.forecast-row {
    display: grid;
    grid-template-columns: 54px 1fr auto;
    align-items: center;
    gap: 6px;
    min-height: 25px;
    padding: 3px 2px;
    border-top: 1px solid rgba(15,23,42,.10);
}

.forecast-row:first-child {
    border-top: 0;
}

.forecast-day {
    display: grid;
    line-height: 1.05;
    font-size: 9px;
}

.forecast-day small {
    margin-top: 2px;
    color: #6b7280;
    font-size: 7px;
}

.forecast-condition {
    color: #4b5563;
    font-size: 8px;
}

.forecast-temps {
    font-size: 9px;
    white-space: nowrap;
}

.forecast-loading {
    display: block;
    padding: 5px 1px;
    color: #4b5563;
    font-size: 9px;
}

@media (max-width: 480px) {
    .forecast-popover {
        width: 215px;
    }

    .forecast-row {
        grid-template-columns: 48px 1fr auto;
        gap: 4px;
    }
}


.weather-label-wrap {
    position: relative;
    display: inline-block;
    overflow: visible;
}

/* The popover is a sibling of .weather-label, so its size is ignored by
   the label-collision measurement. */
.weather-label-wrap > .forecast-popover {
    top: calc(100% + 4px);
    left: 50%;
}
