:root {
    --map-land:     #d7e9cc;
    --map-water:    #e5f6fd;
    --map-area:     #f0efeb;
    --map-block:    #e3e3e5;
    --map-bld:      #dae0e9;
    --map-white:    #ffffff;
    --map-road:     #ffffff;
    --map-rail:     #9aa0a6;
    --map-ink:      #1f2933;
    --map-ink-soft: #5f6b78;
    --map-halo:     #ffffff;

    --map-spot-work:    #fca404;
    --map-spot-bank:    #0cbc04;
    --map-spot-carshop: #a41c0c;
    --map-spot-rail:    #fcd404;
    --map-spot-hub:     #045c64;
    --map-spot-airport: #44b4f4;
    --map-spot-sight:   #a46434;

    --map-spot-atlas:      #1a9485;
    --map-spot-autoschool: #ec407a;
    --map-spot-fuel:       #546e7a;
    --map-spot-hospital:   #e53935;
    --map-spot-police:     #1e40af;
    --map-spot-cityhall:   #7e57c2;
    --map-spot-hotel:      #827717;
    --map-spot-food:       #e65100;
    --map-spot-light:   #ffffff;
    --map-spot-dark:    #1f2933;
}

[data-theme="dark"],
[data-theme="halloween"] {
    --map-land:     #252641;
    --map-water:    #203453;
    --map-area:     #2a304a;
    --map-block:    #2a304f;
    --map-bld:      #302c4d;
    --map-white:    #3a4b61;
    --map-road:     #3a4b61;
    --map-rail:     #9d9e9e;
    --map-ink:      #e6e8f2;
    --map-ink-soft: #9aa1b9;
    --map-halo:     #1c1d33;
}

[data-theme="dark"] .map-base .s-rail,
[data-theme="halloween"] .map-base .s-rail {
    stroke-dasharray: 3 3;
}

.map-base .f-land  { fill: var(--map-land); }
.map-base .f-water { fill: var(--map-water); }
.map-base .f-area  { fill: var(--map-area); }
.map-base .f-block { fill: var(--map-block); }
.map-base .f-bld   { fill: var(--map-bld); }
.map-base .f-white { fill: var(--map-white); }
.map-base .s-road  { stroke: var(--map-road); }
.map-base .s-rail  { stroke: var(--map-rail); }

.map-view {
    position: relative;
    overflow: hidden;
    background: var(--map-water);
    border: 1px solid var(--border);
    border-radius: 12px;
    user-select: none;
    cursor: grab;
}

.map-view.is-dragging {
    cursor: grabbing;
}

.map-view:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.map-svg {
    display: block;
    width: 100%;
    height: 100%;
}

.map-svg--lines {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.map-under {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
}

.map-view:not(.is-loaded) .map-svg {
    visibility: hidden;
}

.map-ctrls {
    position: absolute;
    right: 12px;
    bottom: 12px;
    z-index: 2;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.map-ctrls .btn {
    box-shadow: var(--shadow-card);
}

.map-dots {
    fill: none;
    stroke-linecap: round;
    vector-effect: non-scaling-stroke;
}

.map-line {
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.map-marks {
    position: absolute;
    inset: 0;
    z-index: 1;
    overflow: hidden;
    pointer-events: none;
}

.map-mark {
    position: absolute;
    left: 0;
    top: 0;
    will-change: transform;
}

.map-layout {
    --map-layout-h: 640px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 400px;
    gap: 20px;
    align-items: start;
}

.map-layout-main {
    position: relative;
    min-width: 0;
}

.map-layout-main > .map-view {
    height: var(--map-layout-h);
    min-height: 480px;
}

.map-layout-side {
    display: flex;
    flex-direction: column;
    gap: 14px;
    height: var(--map-layout-h);
    min-height: 480px;
    min-width: 0;
}

.map-chip {
    position: absolute;
    z-index: 2;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-card);
    box-shadow: var(--shadow-card);
    color: var(--text-secondary);
    font-size: 12.5px;
    pointer-events: none;
}

.map-chip--top {
    top: 12px;
    left: 12px;
    max-width: calc(100% - 80px);
}

.map-chip--xy {
    left: 12px;
    bottom: 12px;
    font-family: var(--font-mono);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

.map-stops {
    display: flex;
    flex-direction: column;
}

.map-stop {
    --map-stop-mid: 22px;
    position: relative;
    display: grid;
    grid-template-columns: 26px minmax(0, 1fr) auto;
    align-items: center;
    column-gap: 12px;
    padding: 9px 10px;
    border-radius: 10px;
}

.map-stop::before,
.map-stop-gap::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 22px;
    width: 2px;
    background: var(--route-color, var(--accent));
    opacity: 0.35;
}

.map-stop:first-child::before {
    top: var(--map-stop-mid);
}

.map-stop:last-child::before {
    bottom: calc(100% - var(--map-stop-mid));
}

.map-stop:only-child::before {
    display: none;
}

.map-stop-gap {
    position: relative;
}

.map-stop-num {
    position: relative;
    display: grid;
    place-items: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--route-color, var(--accent));
    color: var(--text-on-accent);
    font-size: 11.5px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.map-stop-num.is-quiet {
    background: var(--bg-card);
    color: var(--route-color, var(--accent));
    box-shadow: inset 0 0 0 2px var(--route-color, var(--accent));
}

.map-stop-title {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}

.map-stop-name {
    font-size: 13px;
    font-weight: 600;
    overflow-wrap: anywhere;
}

.map-stop-city {
    font-size: 11.5px;
    color: var(--text-muted);
}

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

.map-photo {
    position: relative;
    display: block;
    padding: 0;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-input);
    cursor: zoom-in;
}

.map-photo img {
    display: block;
    width: 100%;
    aspect-ratio: 16 / 10;
    object-fit: cover;
}

.map-photo span {
    position: absolute;
    left: 6px;
    bottom: 6px;
    padding: 2px 8px;
    border-radius: 6px;
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 11px;
    font-weight: 600;
}

.map-pin {
    width: 14px;
    height: 14px;
    padding: 0;
    border: 2px solid var(--map-halo);
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 1px 4px var(--accent-border);
    cursor: pointer;
    pointer-events: auto;
}

.map-pin.is-selected {
    width: 18px;
    height: 18px;
    background: var(--accent-hover);
    outline: 4px solid var(--accent-border);
}

.map-pin-name {
    position: absolute;
    left: 100%;
    top: 50%;
    margin-left: 6px;
    transform: translateY(-50%);
    color: var(--map-ink);
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
    text-shadow: 0 0 2px var(--map-halo);
    pointer-events: none;
    isolation: isolate;
}

.map-pin-name::before {
    content: "";
    position: absolute;
    inset: -2px -5px;
    z-index: -1;
    border-radius: 8px;
    background: color-mix(in srgb, var(--map-halo) 75%, transparent);
    filter: blur(5px);
}

.is-label-top > .map-pin-name {
    top: auto;
    bottom: 100%;
    left: 50%;
    margin: 0 0 5px;
    transform: translateX(-50%);
}

.is-label-bottom > .map-pin-name {
    top: 100%;
    left: 50%;
    margin: 5px 0 0;
    transform: translateX(-50%);
}

.is-label-left > .map-pin-name {
    right: 100%;
    left: auto;
    margin: 0 6px 0 0;
}

.is-label-none > .map-pin-name {
    visibility: hidden;
}

.map-far .map-pin-name {
    display: none;
}

.map-route-case {
    stroke: var(--map-halo);
    stroke-width: clamp(3.5px, calc(var(--map-px) * 3.8px), 10px);
    vector-effect: non-scaling-stroke;
}

.map-route-line {
    stroke: var(--rc, var(--accent));
    stroke-width: clamp(1.5px, calc(var(--map-px) * 2px), 6px);
    vector-effect: non-scaling-stroke;
}

.map-route-case.is-selected {
    stroke-width: clamp(5px, calc(var(--map-px) * 5px), 12px);
}

.map-route-line.is-selected {
    stroke-width: clamp(2.5px, calc(var(--map-px) * 3px), 7px);
}

.map-pin.map-stop-pin {
    width: clamp(7px, calc(var(--map-px) * 6px), 14px);
    height: clamp(7px, calc(var(--map-px) * 6px), 14px);
    border-width: clamp(1.5px, calc(var(--map-px) * 1px), 2px);
}

.map-pin.map-stop-pin.is-request {
    background: var(--orange);
    box-shadow: 0 1px 4px var(--orange-border);
}

.map-pin.map-stop-pin.is-terminal {
    width: clamp(11px, calc(var(--map-px) * 9px), 20px);
    height: clamp(11px, calc(var(--map-px) * 9px), 20px);
    border-width: clamp(2px, calc(var(--map-px) * 1.5px), 3px);
    box-shadow: 0 0 0 2px var(--accent), 0 1px 6px var(--accent-border);
}

.map-pin.map-stop-pin.is-transfer {
    width: clamp(9px, calc(var(--map-px) * 8px), 16px);
    height: clamp(9px, calc(var(--map-px) * 8px), 16px);
    border: clamp(2px, calc(var(--map-px) * 1.6px), 3px) solid var(--map-ink);
    background: var(--map-halo);
    box-shadow: var(--shadow-card);
}

.map-pin.map-stop-pin.is-terminal .map-pin-name {
    font-size: 14px;
    font-weight: 800;
}

.map-route-line.is-dim {
    stroke: var(--map-ink-soft);
    opacity: 0.6;
}

.map-route-case.is-current {
    stroke-width: clamp(6px, calc(var(--map-px) * 6px), 14px);
}

.map-route-line.is-current {
    stroke-width: clamp(3px, calc(var(--map-px) * 3.6px), 8px);
}

.map-pin.map-stop-pin.is-photo {
    width: clamp(9px, calc(var(--map-px) * 7.5px), 16px);
    height: clamp(9px, calc(var(--map-px) * 7.5px), 16px);
    box-shadow: 0 0 0 2px var(--accent-border), 0 1px 4px var(--accent-border);
}

.map-pin.map-stop-pin.is-dim {
    background: var(--map-ink-soft);
    box-shadow: none;
}

.map-pin.map-stop-pin.is-dim .map-pin-name {
    color: var(--map-ink-soft);
}

.map-pin.map-stop-pin.is-next {
    width: clamp(14px, calc(var(--map-px) * 11px), 22px);
    height: clamp(14px, calc(var(--map-px) * 11px), 22px);
    box-shadow: 0 0 0 3px var(--accent), 0 2px 8px var(--accent-glow);
    animation: map-next 1.8s ease-out infinite;
}

.map-pin.map-stop-pin.is-next .map-pin-name {
    font-size: 14px;
    font-weight: 800;
}

.map-far .map-pin.map-stop-pin.is-next .map-pin-name {
    display: block;
}

@keyframes map-next {
    0%   { outline: 0 solid var(--accent-border); }
    70%  { outline: 10px solid transparent; }
    100% { outline: 0 solid transparent; }
}

@media (prefers-reduced-motion: reduce) {
    .map-pin.map-stop-pin.is-next {
        animation: none;
    }
}

.map-bus {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border: 2px solid var(--map-halo);
    border-radius: 8px;
    background: var(--accent);
    color: var(--text-on-accent);
    box-shadow: 0 2px 8px var(--accent-glow);
    pointer-events: none;
}

.map-spot {
    display: grid;
    place-items: center;
    width: 22px;
    height: 22px;
    padding: 0;
    border: 2px solid var(--map-halo);
    border-radius: 50%;
    background: var(--map-spot);
    color: var(--map-spot-light);
    box-shadow: var(--shadow-card);
}

.map-spot > svg {
    width: 12px;
    height: 12px;
}

.map-spot.is-work    { --map-spot: var(--map-spot-work);    color: var(--map-spot-dark); }
.map-spot.is-bank    { --map-spot: var(--map-spot-bank); }
.map-spot.is-carshop { --map-spot: var(--map-spot-carshop); }
.map-spot.is-rail    { --map-spot: var(--map-spot-rail);    color: var(--map-spot-dark); }
.map-spot.is-hub     { --map-spot: var(--map-spot-hub); }
.map-spot.is-airport { --map-spot: var(--map-spot-airport); }
.map-spot.is-sight   { --map-spot: var(--map-spot-sight); }
.map-spot.is-atlas      { --map-spot: var(--map-spot-atlas); }
.map-spot.is-autoschool { --map-spot: var(--map-spot-autoschool); }
.map-spot.is-fuel       { --map-spot: var(--map-spot-fuel); }
.map-spot.is-hospital   { --map-spot: var(--map-spot-hospital); }
.map-spot.is-police     { --map-spot: var(--map-spot-police); }
.map-spot.is-cityhall   { --map-spot: var(--map-spot-cityhall); }
.map-spot.is-hotel      { --map-spot: var(--map-spot-hotel); }
.map-spot.is-food       { --map-spot: var(--map-spot-food); }

.map-far .map-spot {
    width: 14px;
    height: 14px;
    border-width: 1px;
}

.map-far .map-spot > svg {
    width: 8px;
    height: 8px;
}

.map-spot-name {
    position: absolute;
    left: 100%;
    top: 50%;
    display: none;
    margin-left: 5px;
    transform: translateY(-50%);
    color: var(--map-ink);
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
    text-shadow: 0 0 3px var(--map-halo), 0 0 3px var(--map-halo), 0 0 2px var(--map-halo);
    pointer-events: none;
}

.map-near .map-spot-name {
    display: block;
}

.map-name-text {
    display: block;
    transform: rotate(var(--map-name-angle, 0deg));
    color: var(--map-ink-soft);
    font-size: 11px;
    font-weight: 700;
    line-height: 1.15;
    letter-spacing: 0.2em;
    text-align: center;
    text-transform: uppercase;
    white-space: pre;
    text-shadow: 0 0 3px var(--map-halo), 0 0 3px var(--map-halo), 0 0 2px var(--map-halo);
}

.map-name.is-city .map-name-text {
    color: var(--map-ink);
    font-size: 16px;
    font-weight: 800;
    letter-spacing: 0.14em;
}

.map-name.is-street .map-name-text {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: none;
}

.map-far .map-name.is-district,
.map-near .map-name.is-city,
.map-name.is-street {
    display: none;
}

.map-near .map-name.is-street {
    display: block;
}

.map-name-bend {
    display: block;
    width: 1px;
    height: 1px;
    overflow: visible;
}

.map-name-bend .map-name-text {
    fill: currentColor;
    stroke: var(--map-halo);
    stroke-width: 3px;
    stroke-linejoin: round;
    paint-order: stroke;
    text-shadow: none;
    text-anchor: middle;
    dominant-baseline: central;
}

.map-name.is-crowded {
    visibility: hidden;
}

.map-far .map-pin:not(.is-selected):not(.is-next) {
    width: 10px;
    height: 10px;
    border-width: 1.5px;
}
