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

:root {
    /* Background colors */
    --bg-gradient-start: #1a1a2e;
    --bg-gradient-mid: #16213e;
    --bg-gradient-end: #0f3460;
    --widget-bg: rgb(45, 26, 45);
    --panel-bg: rgba(40, 20, 36, 0.95);
    --status-bg: rgba(46, 26, 42, 0.92);
    --toast-bg: rgba(51, 30, 46, 0.95);

    /* Text colors */
    --text-primary: #fff;
    --text-secondary: rgba(255, 255, 255, 0.6);
    --text-muted: rgba(255, 255, 255, 0.3);

    /* Border and shadow */
    --border-color: rgba(255, 255, 255, 0.1);
    --shadow-color: rgba(0, 0, 0, 0.3);
    --shadow-heavy: rgba(0, 0, 0, 0.5);

    /* Map colors */
    --map-fill: rgba(255, 255, 255, 0.08);
    --map-stroke: #544551;
    --map-neighbor-stroke: #473944;
    --station-dot: rgba(255, 255, 255, 0.7);
    --station-dot-hover: #fff;
    --station-ghost: rgba(255, 255, 255, 0.25);
    --tooltip-bg: rgba(0, 0, 0, 0.8);

    /* Accent colors */
    --accent-selected: #4ecdc4;
    --accent-highlight: #ffdd57;
    --accent-user: #3b82f6;
    --accent-error: #ff6b6b;
    --accent-stale: rgba(255, 200, 100, 0.7);
    --toast-text: rgba(255, 200, 100, 0.9);
    --toast-border: rgba(255, 200, 100, 0.3);

    /* Station label (always dark text on yellow) */
    --label-bg: rgba(255, 221, 87, 0.95);
    --label-text: #251a23;

    /* Scrollbar */
    --scrollbar-thumb: rgba(255, 255, 255, 0.2);
    --scrollbar-thumb-hover: rgba(255, 255, 255, 0.3);

    /* Interactive hover states */
    --hover-bg: rgba(255, 255, 255, 0.1);
    --selected-bg: rgba(255, 255, 255, 0.12);
    --condition-bg: rgba(255, 255, 255, 0.05);
}

@media (prefers-color-scheme: light) {
    :root {
        /* Background colors */
        --bg-gradient-start: #e8f4f8;
        --bg-gradient-mid: #d4e8ed;
        --bg-gradient-end: #c0dce4;
        --widget-bg: rgb(255, 255, 255);
        --panel-bg: rgba(255, 255, 255, 0.97);
        --status-bg: rgba(255, 255, 255, 0.95);
        --toast-bg: rgba(255, 248, 230, 0.98);

        /* Text colors */
        --text-primary: #1a1a2e;
        --text-secondary: rgba(26, 26, 46, 0.6);
        --text-muted: rgba(26, 26, 46, 0.4);

        /* Border and shadow */
        --border-color: rgba(0, 0, 0, 0.1);
        --shadow-color: rgba(0, 0, 0, 0.12);
        --shadow-heavy: rgba(0, 0, 0, 0.2);

        /* Map colors */
        --map-fill: rgba(0, 100, 150, 0.08);
        --map-stroke: #8ba5b0;
        --map-neighbor-stroke: #b0c4cc;
        --station-dot: rgba(26, 26, 46, 0.6);
        --station-dot-hover: #1a1a2e;
        --station-ghost: rgba(26, 26, 46, 0.2);
        --tooltip-bg: rgba(26, 26, 46, 0.9);

        /* Accent colors - slightly adjusted for light bg */
        --accent-selected: #0d9488;
        --accent-highlight: #d97706;
        --accent-user: #2563eb;
        --accent-error: #dc2626;
        --accent-stale: rgba(180, 120, 40, 0.8);
        --toast-text: rgba(146, 94, 24, 0.95);
        --toast-border: rgba(180, 130, 50, 0.4);

        /* Station label */
        --label-bg: rgba(251, 191, 36, 0.95);
        --label-text: #1a1a2e;

        /* Scrollbar */
        --scrollbar-thumb: rgba(0, 0, 0, 0.2);
        --scrollbar-thumb-hover: rgba(0, 0, 0, 0.3);

        /* Interactive hover states */
        --hover-bg: rgba(0, 0, 0, 0.06);
        --selected-bg: rgba(0, 0, 0, 0.08);
        --condition-bg: rgba(0, 0, 0, 0.04);
    }
}

html {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-mid) 50%, var(--bg-gradient-end) 100%);
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    color: var(--text-primary);
}

.widget {
    position: relative;
    background: var(--widget-bg);
    backdrop-filter: blur(10px);
    border-radius: 24px;
    padding: 32px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 8px 32px var(--shadow-color);
    border: 1px solid var(--border-color);
    transition: opacity 0.15s;
    user-select: none;
    -webkit-user-select: none;
}

.widget.refreshing {
    opacity: 0.6;
}

.header {
    text-align: center;
    margin-top: 16px;
    margin-bottom: 24px;
}

.header h1 {
    font-size: 2rem;
    font-weight: 600;
}

.temperature-display {
    text-align: center;
    margin: 32px 0;
}

.temperature-value {
    position: relative;
    display: inline-block;
    font-size: 5rem;
    font-weight: 300;
    line-height: 1;
    letter-spacing: -4px;
}

.temperature-value .unit {
    position: absolute;
    left: 100%;
    top: 0;
    font-size: 2rem;
    letter-spacing: normal;
    margin-left: 4px;
}

.station-info {
    text-align: center;
    margin-top: 16px;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.stale {
    color: var(--accent-stale);
}

/* Map modal */
.map-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 200;
    padding: 20px;
}

.map-modal[hidden] {
    display: none;
}

.map-container {
    position: relative;
    background: var(--panel-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 20px;
    max-width: 500px;
    width: 100%;
    box-shadow: 0 12px 40px var(--shadow-heavy);
    overflow: hidden;
}

/* Larger map on big screens */
@media (min-width: 768px) {
    .map-modal {
        padding: 40px;
    }

    .map-container {
        /* Size to fit viewport while maintaining aspect ratio */
        max-width: min(calc(100vw - 80px), calc((100vh - 80px) * 519 / 476));
        max-height: min(calc(100vh - 80px), calc((100vw - 80px) * 476 / 519));
    }

    /* Smaller circles on large screens (they scale with viewBox) */
    .station-dot {
        r: 0.5;
    }

    .station-dot.prehighlight,
    .station-dot.tapped {
        r: 0.8;
    }

    .user-dot {
        r: 0.5;
    }

    .user-dot-pulse {
        r: 0.5;
    }
}

.map-source {
    position: absolute;
    top: 12px;
    left: 12px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
    padding: 4px 8px;
    z-index: 10;
}

.map-source:hover {
    color: var(--text-secondary);
}

.map-source:focus-visible {
    outline: 2px solid var(--text-secondary);
    outline-offset: 2px;
    border-radius: 4px;
}

.map-close {
    position: absolute;
    top: 12px;
    right: 12px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 4px 8px;
    z-index: 10;
}

.map-close:hover {
    color: var(--text-primary);
}

.map-close:focus-visible {
    outline: 2px solid var(--text-secondary);
    outline-offset: 2px;
}

#station-map {
    width: 100%;
    height: auto;
    display: block;
    touch-action: none; /* Prevent browser gesture handling */
    overflow: hidden;
}

#croatia-outline path {
    fill: var(--map-fill);
    stroke: var(--map-stroke);
    stroke-width: 1;
    vector-effect: non-scaling-stroke;
}

#neighbor-outlines path {
    fill: none;
    stroke: var(--map-neighbor-stroke);
    stroke-width: 1;
    vector-effect: non-scaling-stroke;
}

.station-dot {
    fill: var(--station-dot);
    cursor: pointer;
    transition: fill 0.15s;
}

.station-dot:hover {
    fill: var(--station-dot-hover);
}

.station-dot.prehighlight,
.station-dot.prehighlight:hover {
    fill: var(--accent-highlight);
}

.station-dot.selected {
    fill: var(--accent-selected);
}

.station-dot.selected.prehighlight,
.station-dot.selected.prehighlight:hover {
    fill: var(--accent-highlight);
}

.station-dot.tapped {
    fill: var(--accent-highlight);
}

.station-dot.nearest-highlight {
    stroke: var(--accent-user);
    stroke-width: 0.4;
}

.station-dot.ghost {
    fill: var(--station-ghost);
    cursor: default;
}

.user-dot.selected {
    stroke: var(--accent-selected);
    stroke-width: 0.4;
}

.user-dot.tapped,
.user-dot.prehighlight {
    fill: var(--accent-highlight);
}

.user-dot {
    fill: var(--accent-user);
    cursor: pointer;
}

.user-dot-pulse {
    fill: var(--accent-user);
    opacity: 0.4;
    animation: pulse 2s ease-out infinite;
}

@keyframes pulse {
    0% { r: 0.5; opacity: 0.4; }
    100% { r: 3; opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
    .user-dot-pulse {
        animation: none;
        opacity: 0.3;
    }
}

.map-tooltip {
    position: absolute;
    background: var(--tooltip-bg);
    color: #fff;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 0.75rem;
    pointer-events: none;
    white-space: nowrap;
    z-index: 20;
}

.station-label {
    position: absolute;
    background: var(--label-bg);
    color: var(--label-text);
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    pointer-events: none;
    white-space: nowrap;
    z-index: 21;
    transform: translateX(-50%);
    box-shadow: 0 2px 8px var(--shadow-color);
}

.details {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-top: 32px;
    padding-top: 24px;
    padding-bottom: 16px;
    border-top: 1px solid var(--border-color);
}

.detail-item {
    text-align: center;
}

.detail-item.empty {
    visibility: hidden;
}

.detail-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.detail-value {
    font-size: 1.125rem;
    font-weight: 500;
    white-space: nowrap;
}

.trend {
    font-size: 0.75rem;
    opacity: 0.6;
}

.weather-condition {
    text-align: center;
    margin-top: 24px;
    padding: 12px 20px;
    background: var(--condition-bg);
    border-radius: 12px;
    font-size: 0.9rem;
    color: var(--text-secondary);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

/* Source switcher */
.source-switcher {
    position: absolute;
    top: 20px;
    left: 20px;
}

.source-trigger {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.75rem;
    cursor: pointer;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.source-trigger:hover {
    color: var(--text-secondary);
}

.source-trigger:focus-visible {
    outline: 2px solid var(--text-secondary);
    outline-offset: 2px;
    border-radius: 4px;
}

/* Forecast link - hidden until URL is resolved */
.forecast-link {
    position: absolute;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    visibility: hidden;
    color: var(--text-muted);
    font-size: 0.75rem;
    text-decoration: none;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    -webkit-tap-highlight-color: transparent;
}

.forecast-link:hover {
    color: var(--text-secondary);
}

.forecast-link:focus-visible {
    outline: 2px solid var(--text-secondary);
    outline-offset: 2px;
    border-radius: 4px;
}

.location-picker {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.map-trigger {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    line-height: 1;
    display: flex;
    align-items: center;
    user-select: none;
}

.map-trigger svg,
.location-trigger svg {
    display: block;
}

.map-trigger:hover {
    color: var(--text-secondary);
}

.map-trigger:focus-visible {
    outline: 2px solid var(--text-secondary);
    outline-offset: 2px;
    border-radius: 4px;
}

.location-trigger {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    line-height: 1;
    display: flex;
    align-items: center;
    user-select: none;
}

.location-trigger:hover {
    color: var(--text-secondary);
}

.location-trigger:focus-visible {
    outline: 2px solid var(--text-secondary);
    outline-offset: 2px;
    border-radius: 4px;
}

.location-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: auto;
    margin-top: 8px;
    background: var(--panel-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 6px;
    min-width: 220px;
    max-height: min(400px, 60vh);
    overflow-y: auto;
    box-shadow: 0 12px 40px var(--shadow-heavy);
    z-index: 100;
}

/* On touch devices, larger icons and dropdown opens to the left */
@media (pointer: coarse) {
    .map-trigger svg,
    .location-trigger svg {
        width: 20px;
        height: 20px;
    }

    .location-dropdown {
        left: auto;
        right: 0;
    }
}

/* Custom scrollbar */
.location-dropdown::-webkit-scrollbar {
    width: 6px;
}

.location-dropdown::-webkit-scrollbar-track {
    background: transparent;
}

.location-dropdown::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 3px;
}

.location-dropdown::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
}

/* Larger dropdown on desktop */
@media (min-height: 600px) and (pointer: fine) {
    .location-dropdown {
        max-height: min(500px, 70vh);
    }
}

.location-option {
    padding: 10px 14px 10px 30px;
    color: var(--text-secondary);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.15s;
    border-radius: 10px;
    margin: 2px 0;
    position: relative;
}

.location-option:hover,
.location-option.focused {
    background: var(--hover-bg);
    color: var(--text-primary);
}

.location-option.selected {
    background: var(--selected-bg);
    color: var(--text-primary);
}

.location-option.selected::before {
    content: '✓';
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.8rem;
}

.location-option.unavailable {
    color: var(--text-muted);
    pointer-events: none;
    cursor: default;
}

.location-option.map-option {
    margin-bottom: 6px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.error {
    text-align: center;
    padding: 24px;
    color: var(--accent-error);
}

.error-icon {
    font-size: 3rem;
    margin-bottom: 16px;
}

.retry-btn {
    margin-top: 16px;
    padding: 12px 24px;
    background: var(--hover-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.2s;
}

.retry-btn:hover {
    background: var(--selected-bg);
}

.retry-btn:focus-visible {
    outline: 2px solid var(--text-secondary);
    outline-offset: 2px;
}

/* Status/loading state - overlays the widget */
.status {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--status-bg);
    border-radius: 24px;
    text-align: center;
    padding: 24px;
    color: var(--text-secondary);
    z-index: 10;
}

.status[hidden] {
    display: none;
}

.status p {
    margin: 0 0 8px 0;
    font-size: 1.1rem;
}

.cancel-btn {
    margin-top: 16px;
    padding: 8px 16px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

.cancel-btn:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
}

/* Toast notification */
.toast {
    position: absolute;
    bottom: 12px;
    left: 12px;
    right: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: var(--toast-bg);
    color: var(--toast-text);
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 0.8rem;
    border: 1px solid var(--toast-border);
    z-index: 50;
}

.toast[hidden] {
    display: none;
}

.toast-dismiss {
    background: none;
    border: none;
    color: var(--toast-border);
    font-size: 1rem;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
    flex-shrink: 0;
}

.toast-dismiss:hover {
    color: var(--toast-text);
}

/* Responsive adjustments */
@media (max-width: 360px) {
    .widget {
        padding: 24px;
    }

    .temperature-value {
        font-size: 4rem;
    }

    .details {
        gap: 12px;
    }
}
