:root {
    --accent: #f26b1d;
    --accent-ink: #ffffff;
    --bg: #f3f2ee;
    --card: rgba(255, 255, 255, 0.94);
    --card-solid: #ffffff;
    --ink: #1d1f23;
    --ink-2: #5d6168;
    --ink-3: #8b9097;
    --line: rgba(20, 24, 31, 0.08);
    --hover: rgba(20, 24, 31, 0.05);
    --shadow: 0 1px 2px rgba(16, 20, 28, 0.08), 0 6px 24px rgba(16, 20, 28, 0.12);
    --space: radial-gradient(ellipse at 50% 60%, #dce8f5 0%, #c3d4e8 70%, #b3c6de 100%);
    --radius: 14px;
    --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color-scheme: light;
}

:root[data-theme="dark"] {
    --bg: #1d2129;
    --card: rgba(36, 40, 49, 0.94);
    --card-solid: #242831;
    --ink: #eef0f4;
    --ink-2: #a8aeb9;
    --ink-3: #7c8390;
    --line: rgba(255, 255, 255, 0.08);
    --hover: rgba(255, 255, 255, 0.06);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 28px rgba(0, 0, 0, 0.45);
    --space: radial-gradient(ellipse at 50% 60%, #121b2b 0%, #080c14 70%, #04060a 100%);
    color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

/* Английский интерфейс: русский текст разметки не показываем, пока i18n.js его не заменил */
html[lang="en"]:not(.i18n-ready) :is([data-i18n], input[data-i18n-attr]) { visibility: hidden; }

html, body {
    margin: 0;
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--ink);
    font: 15px/1.4 var(--font);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

#map {
    position: fixed;
    inset: 0;
    background: var(--space);
}

button { font: inherit; color: inherit; }

svg { fill: currentColor; }

.card {
    background: var(--card);
    -webkit-backdrop-filter: blur(16px) saturate(1.4);
    backdrop-filter: blur(16px) saturate(1.4);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

/* --- Левая панель: поиск, результаты, карточка места --- */

.panel {
    position: fixed;
    top: max(12px, env(safe-area-inset-top));
    left: max(12px, env(safe-area-inset-left));
    width: 380px;
    max-width: calc(100vw - 24px);
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 3;
    max-height: calc(100% - 24px);
    pointer-events: none;
}

.panel > * { pointer-events: auto; }

.search {
    display: flex;
    align-items: center;
    height: 48px;
    padding: 0 6px 0 8px;
    gap: 4px;
    flex: none;
}

.logo {
    width: 34px;
    height: 34px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: 10px;
}

.logo svg { width: 28px; height: 28px; }

.search input {
    flex: 1;
    min-width: 0;
    height: 100%;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--ink);
    font: inherit;
    font-size: 16px;
    padding: 0 6px;
}

.search input::placeholder { color: var(--ink-3); }
.search input::-webkit-search-cancel-button { display: none; }

.icon-btn {
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    display: grid;
    place-items: center;
    cursor: pointer;
    color: var(--ink-2);
    flex: none;
}

.icon-btn:hover { background: var(--hover); color: var(--ink); }
.icon-btn svg { width: 20px; height: 20px; }

.results {
    overflow-y: auto;
    padding: 6px;
    max-height: min(480px, calc(100vh - 100px));
    overscroll-behavior: contain;
}

.result {
    display: flex;
    gap: 12px;
    align-items: center;
    width: 100%;
    padding: 9px 10px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    text-align: left;
    cursor: pointer;
}

.result:hover, .result[aria-selected="true"] { background: var(--hover); }

.result-icon {
    width: 34px;
    height: 34px;
    flex: none;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: var(--hover);
    color: var(--ink-2);
}

.result-icon svg { width: 18px; height: 18px; }
.result-body { min-width: 0; flex: 1; }
.result-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-sub { color: var(--ink-2); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-dist { color: var(--ink-3); font-size: 12px; flex: none; }
.results-empty { padding: 14px; color: var(--ink-2); text-align: center; }

.place {
    padding: 16px;
    overflow-y: auto;
    flex: 0 1 auto;
    min-height: 0;
    animation: rise 0.18s ease-out;
}

@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

.place-head { display: flex; gap: 12px; align-items: flex-start; }

.place-icon {
    width: 44px;
    height: 44px;
    flex: none;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: var(--accent);
    color: var(--accent-ink);
}

.place-icon svg { width: 22px; height: 22px; }
.place-titles { flex: 1; min-width: 0; padding-top: 1px; }
.place-title { margin: 0; font-size: 19px; line-height: 1.25; font-weight: 650; overflow-wrap: anywhere; }
.place-kind { color: var(--ink-2); font-size: 14px; margin-top: 2px; }
.place-rows { margin: 14px 0 4px; display: grid; gap: 2px; }

.place-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 6px;
    border-radius: 10px;
    color: var(--ink);
    font-size: 14px;
    border: 0;
    background: transparent;
    text-align: left;
    width: 100%;
}

button.place-row { cursor: pointer; }
button.place-row:hover { background: var(--hover); }
.place-row svg { width: 18px; height: 18px; flex: none; color: var(--ink-3); }
.place-row .muted { color: var(--ink-3); }
.skeleton { display: inline-block; width: 60%; height: 12px; border-radius: 6px; background: var(--hover); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.4; } }

.place-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 36px;
    padding: 0 12px;
    border-radius: 18px;
    border: 0;
    background: var(--hover);
    color: var(--ink);
    font-weight: 550;
    font-size: 14px;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
}

.btn:hover { filter: brightness(0.96); }
:root[data-theme="dark"] .btn:hover { filter: brightness(1.2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn svg { width: 17px; height: 17px; }

/* --- Правые кнопки --- */

.topright {
    position: fixed;
    top: max(12px, env(safe-area-inset-top));
    right: max(12px, env(safe-area-inset-right));
    z-index: 4;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
}

.controls {
    position: fixed;
    right: max(12px, env(safe-area-inset-right));
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
}

.fab {
    width: 44px;
    height: 44px;
    border: 0;
    display: grid;
    place-items: center;
    cursor: pointer;
    color: var(--ink);
    padding: 0;
}

.fab svg { width: 22px; height: 22px; }
.fab:hover { color: var(--accent); }
.fab.text { font-weight: 700; font-size: 14px; letter-spacing: 0.02em; }
.fab[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.fab.busy svg { animation: pulse 1s ease-in-out infinite; }

.zoom { display: flex; flex-direction: column; overflow: hidden; }

.zoom button {
    width: 44px;
    height: 44px;
    border: 0;
    background: transparent;
    display: grid;
    place-items: center;
    cursor: pointer;
    padding: 0;
}

.zoom button:hover { color: var(--accent); }
.zoom button + button { border-top: 1px solid var(--line); }
.zoom svg { width: 22px; height: 22px; }

#needle { transition: transform 0.1s linear; }
#needle .n { fill: var(--accent); }
#needle .s { fill: var(--ink-3); }

.layers {
    width: 270px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    animation: rise 0.15s ease-out;
}

.layers-title { font-size: 12px; font-weight: 600; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.05em; margin-top: 2px; }

.segmented {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    background: var(--hover);
    border-radius: 10px;
    padding: 3px;
    gap: 3px;
}

.segmented button {
    border: 0;
    background: transparent;
    border-radius: 8px;
    padding: 7px 4px;
    font-size: 13px;
    font-weight: 550;
    cursor: pointer;
    color: var(--ink-2);
}

.segmented button[aria-pressed="true"] { background: var(--card-solid); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }

.switch { display: flex; align-items: center; gap: 10px; padding: 6px 2px; cursor: pointer; font-size: 14px; }
.switch input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
.layers-link { color: var(--accent); text-decoration: none; font-size: 14px; font-weight: 550; padding-top: 6px; border-top: 1px solid var(--line); }

/* --- Маркеры --- */

.pin {
    width: 34px;
    height: 44px;
    cursor: pointer;
    filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.3));
    animation: drop 0.35s cubic-bezier(0.2, 1.4, 0.4, 1);
}

@keyframes drop { from { transform: translateY(-16px); opacity: 0; } }

.me {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #2f7cf6;
    border: 3px solid #fff;
    box-shadow: 0 0 0 0 rgba(47, 124, 246, 0.5), 0 1px 4px rgba(0, 0, 0, 0.35);
    animation: ping 2s ease-out infinite;
}

@keyframes ping { 70% { box-shadow: 0 0 0 16px rgba(47, 124, 246, 0), 0 1px 4px rgba(0, 0, 0, 0.35); } 100% { box-shadow: 0 0 0 0 rgba(47, 124, 246, 0), 0 1px 4px rgba(0, 0, 0, 0.35); } }

.toast {
    position: fixed;
    left: 50%;
    bottom: 40px;
    transform: translateX(-50%);
    background: rgba(20, 22, 27, 0.92);
    color: #fff;
    padding: 10px 16px;
    border-radius: 12px;
    font-size: 14px;
    z-index: 10;
    box-shadow: var(--shadow);
    animation: rise 0.15s ease-out;
    max-width: calc(100vw - 32px);
}

/* --- MapLibre: атрибуция и масштаб под тему --- */

.maplibregl-ctrl-bottom-right, .maplibregl-ctrl-bottom-left { z-index: 1; }

.maplibregl-ctrl.maplibregl-ctrl-attrib {
    background: var(--card);
    color: var(--ink-2);
    border-radius: 10px 0 0 0;
    font-size: 11px;
}

.maplibregl-ctrl-attrib a { color: var(--ink-2); }
.maplibregl-ctrl-attrib.maplibregl-compact { border-radius: 12px; margin: 0 10px 10px 0; }
.maplibregl-ctrl-attrib.maplibregl-compact-show { padding: 3px 28px 3px 8px; }
:root[data-theme="dark"] .maplibregl-ctrl-attrib-button { filter: invert(1); }

.maplibregl-ctrl-scale {
    background: var(--card);
    color: var(--ink-2);
    border-color: var(--ink-3);
    font-size: 11px;
}

.maplibregl-ctrl-bottom-left .maplibregl-ctrl { margin: 0 0 10px 10px; }

.maplibregl-popup-content { background: var(--card-solid); color: var(--ink); border-radius: 12px; box-shadow: var(--shadow); padding: 10px 14px; font: 14px/1.35 var(--font); }
.maplibregl-popup-anchor-bottom .maplibregl-popup-tip { border-top-color: var(--card-solid); }
.maplibregl-popup-anchor-top .maplibregl-popup-tip { border-bottom-color: var(--card-solid); }

/* --- Телефон: карточка места — нижняя шторка --- */

@media (max-width: 640px) {
    .panel { right: 12px; width: auto; max-height: none; bottom: auto; }
    .topright { top: calc(max(12px, env(safe-area-inset-top)) + 58px); }
    .controls { top: auto; bottom: calc(max(24px, env(safe-area-inset-bottom)) + 16px); transform: none; }
    .controls .zoom { display: none; }

    .place {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        max-height: 55vh;
        border-radius: 18px 18px 0 0;
        padding-bottom: max(16px, env(safe-area-inset-bottom));
        z-index: 5;
    }

    .place::before {
        content: "";
        display: block;
        width: 40px;
        height: 4px;
        border-radius: 2px;
        background: var(--line);
        margin: -6px auto 12px;
    }

    .results { max-height: calc(100vh - 140px); }
}
