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

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
            background: #e8e8e8;
            height: 100vh;
            overflow: hidden;
        }

        #map {
            position: absolute;
            top: 0;
            bottom: 0;
            width: 100%;
        }

        /* Search Panel */
        .search-panel {
            position: absolute;
            top: 20px;
            left: 20px;
            background: rgba(255, 255, 255, 0.98);
            padding: 10px;
            border-radius: 6px;
            box-shadow: 0 2px 12px rgba(11, 45, 39, 0.2);
            border: 3px solid #0b2d27;
            z-index: 1000;
            width: 360px;
        }

        .search-container {
            display: flex;
            gap: 8px;
        }

        /* Empty message / info take no space — keeps the box compact until there's something to say */
        .message:empty,
        #infoPanel:empty {
            display: none;
        }

        #postcodeInput {
            flex: 1;
            padding: 12px;
            border: 2px solid #0b2d27;
            border-radius: 4px;
            background: #ffffff;
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
            font-size: 14px;
            color: #0b2d27;
            text-transform: uppercase;
            font-weight: 500;
        }

        #postcodeInput::placeholder {
            color: #666;
            text-transform: none;
            font-weight: 400;
        }

        #postcodeInput:focus {
            outline: none;
            border-color: #0b2d27;
            box-shadow: 0 0 0 3px rgba(11, 45, 39, 0.1);
        }

        #searchBtn {
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 0 14px;
            background: #0b2d27;
            color: #ffffff;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            flex-shrink: 0;
            transition: all 0.2s;
        }

        #searchBtn:hover {
            background: #164038;
        }

        #searchBtn:disabled {
            background: #999;
            cursor: not-allowed;
        }

        .message {
            padding: 10px;
            border-radius: 4px;
            font-size: 14px;
            margin-top: 10px;
            text-align: center;
        }

        .message.success {
            background: rgba(76, 175, 80, 0.1);
            color: #2e7d32;
            border: 1px solid rgba(76, 175, 80, 0.3);
        }

        .message.error {
            background: rgba(196, 30, 58, 0.1);
            color: #c41e3a;
            border: 1px solid rgba(196, 30, 58, 0.3);
        }

        #infoPanel {
            display: none;
            margin-top: 15px;
            padding: 15px;
            background: #f5f5f5;
            border-radius: 4px;
            border: 1px solid #ddd;
        }

        .info-item {
            margin-bottom: 8px;
            font-size: 14px;
            color: #333;
        }

        .info-item:last-child {
            margin-bottom: 0;
        }


        .nearest-stations {
            display: none;
            position: absolute;
            top: 20px;
            right: 20px;
            min-width: 220px;
            padding: 15px;
            background: rgba(255, 255, 255, 0.98);
            border-radius: 6px;
            box-shadow: 0 2px 12px rgba(11, 45, 39, 0.2);
            border: 3px solid #0b2d27;
            z-index: 1000;
        }
        .nearest-stations h3 {
            font-size: 13px;
            color: #0b2d27;
            font-weight: 600;
        }
        .ns-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 10px;
        }
        .ns-toggle-btn {
            background: transparent;
            border: none;
            cursor: pointer;
            color: #0b2d27;
            padding: 2px;
            border-radius: 4px;
            display: flex;
            line-height: 0;
        }
        .ns-toggle-btn:hover { background: rgba(11, 45, 39, 0.1); }
        .ns-toggle-btn .icon-expand { display: none; }
        .ns-body { margin-top: 8px; }
        .nearest-stations.minimized .ns-body { display: none; }
        .nearest-stations.minimized .icon-collapse { display: none; }
        .nearest-stations.minimized .icon-expand { display: block; }

        .station-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 6px 0;
            border-bottom: 1px solid #eee;
            cursor: pointer;
            font-size: 13px;
        }

        .station-item:last-child {
            border-bottom: none;
        }

        .station-item:hover {
            color: #0b2d27;
            background: rgba(11, 45, 39, 0.05);
            margin: 0 -10px;
            padding: 6px 10px;
        }

        .station-name {
            color: #333;
        }

        .station-distance {
            color: #666;
            font-size: 12px;
        }

        @media (max-width: 600px) {
            .search-panel {
                left: 10px;
                right: 10px;
                width: auto;
            }
            /* Compact search box sits at the top-left; nearest-stations below it */
            .nearest-stations {
                top: 84px;
                left: 10px;
                right: 10px;
                min-width: auto;
            }
        }

        /* Legend Panel */
        .legend-panel {
            position: absolute;
            bottom: 20px;
            left: 20px;
            background: rgba(255, 255, 255, 0.98);
            padding: 15px;
            border-radius: 6px;
            box-shadow: 0 2px 12px rgba(11, 45, 39, 0.2);
            border: 3px solid #0b2d27;
            z-index: 1000;
            min-width: 180px;
        }

        .legend-panel h2 {
            font-size: 14px;
            color: #0b2d27;
            margin-bottom: 10px;
            font-weight: 600;
            letter-spacing: 0.3px;
        }

        .legend-item {
            display: flex;
            align-items: center;
            margin-top: 8px;
            padding-left: 11px;   /* align swatch with the toggle pills' inset content */
            font-size: 12px;
        }

        .legend-color {
            width: 20px;
            height: 12px;
            border-radius: 2px;
            margin-right: 10px;
            border: 1px solid rgba(0, 0, 0, 0.2);
        }

        .legend-label {
            color: #333;
            font-weight: 500;
        }

        .legend-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 12px;
            margin-bottom: 10px;
        }
        .legend-header h2 { margin-bottom: 0; }

        .legend-toggle-btn {
            background: transparent;
            border: none;
            cursor: pointer;
            color: #0b2d27;
            padding: 2px;
            border-radius: 4px;
            display: flex;
            line-height: 0;
        }
        .legend-toggle-btn:hover { background: rgba(11, 45, 39, 0.1); }
        .legend-toggle-btn .icon-expand { display: none; }

        /* Toggles styled as button-like pills: filled when on, dimmed when off */
        .legend-toggle {
            display: flex;
            align-items: center;
            gap: 8px;
            margin-top: 6px;
            padding: 5px 10px;
            border: 1.5px solid #d5d5d5;
            border-radius: 14px;
            font-size: 12px;
            color: #333;
            cursor: pointer;
            user-select: none;
            transition: border-color .15s, background .15s, opacity .15s;
        }
        .legend-toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; }
        .legend-toggle:has(input:focus-visible) { outline: 2px solid #0b2d27; outline-offset: 1px; }
        .legend-toggle:hover { border-color: #0b2d27; }
        .legend-toggle:has(input:checked) {
            border-color: #0b2d27;
            background: rgba(11, 45, 39, 0.07);
            font-weight: 600;
        }
        .legend-toggle:not(:has(input:checked)) { opacity: 0.5; }

        /* "Colour-code" stays a plain checkbox (a mode toggle, not a layer pill) */
        .legend-check {
            display: flex;
            align-items: center;
            gap: 6px;
            margin-top: 8px;
            font-size: 12px;
            color: #333;
            cursor: pointer;
        }
        .legend-check input { cursor: pointer; margin: 0; }
        .legend-hr { border: none; border-top: 1px solid #ddd; margin: 12px 0 2px; }

        /* HS2 sub-key: the build-stage colours, shown only while the HS2 layer is on */
        .legend-subkey {
            margin: 2px 0 4px 22px;
            padding-left: 8px;
            border-left: 2px solid #eee;
        }
        .legend-subitem {
            display: flex;
            align-items: center;
            gap: 8px;
            font-size: 12px;
            color: #555;
            padding: 2px 0;
        }

        /* When colour-coding is off, dim the bridge/tunnel rows */
        .legend-panel.plain .legend-item.toggleable { opacity: 0.35; }

        /* Minimised key: collapse to just the header button */
        .legend-panel.minimized { min-width: auto; }
        .legend-panel.minimized .legend-body { display: none; }
        .legend-panel.minimized .legend-header { margin-bottom: 0; }
        .legend-panel.minimized h2 { display: none; }
        .legend-panel.minimized .icon-collapse { display: none; }
        .legend-panel.minimized .icon-expand { display: block; }

        @media (max-width: 600px) {
            .legend-panel {
                left: 10px;
                min-width: auto;
                bottom: 44px;   /* lift clear of the attribution bar below it */
            }
        }

        /* "What's new" + maintainer links sit inside the attribution bar (bottom-right) */
        .maplibregl-ctrl-attrib a[href="/changelog.html"],
        .maplibregl-ctrl-attrib a[href="https://optional.org.uk"] {
            color: #0b2d27;
            font-weight: 600;
        }

        /* Station popup: name with info (Wikipedia) + navigation (Google Maps) links */
        .station-popup .maplibregl-popup-content {
            display: flex;
            align-items: center;
            gap: 8px;
            padding: 8px 28px 8px 12px;   /* room for the close button on the right */
        }
        .station-popup .popup-name { font-size: 14px; color: #0b2d27; }
        .popup-closed { font-size: 12px; color: #777; }
        .popup-links { display: inline-flex; gap: 4px; }
        .popup-link {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            color: #0b2d27;
            opacity: 0.7;
            transition: opacity 0.15s;
        }
        .popup-link:hover { opacity: 1; }
        .popup-link svg { width: 18px; height: 18px; fill: currentColor; display: block; }
    
