:root {
    --bg: #12161c;
    --panel: #1b222b;
    --line: #2c3642;
    --text: #e8edf2;
    --muted: #8a929a;
    --accent: #3dd6c3;
    --danger: #ff7a7a;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", system-ui, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.page { min-height: 100%; display: flex; flex-direction: column; }
.page--map { height: 100%; overflow: hidden; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 20px;
    background: #0e1318;
    border-bottom: 1px solid var(--line);
    z-index: 500;
}

.brand {
    font-weight: 700;
    letter-spacing: 0.08em;
    color: var(--text);
    text-decoration: none;
}

.topbar__nav {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}

.topbar__meta { color: var(--muted); font-size: 13px; }
.topbar__link { color: var(--text); font-size: 14px; }
.topbar__link--accent { color: var(--accent); }
.topbar__btn {
    background: none;
    border: 0;
    padding: 0;
    cursor: pointer;
    font: inherit;
    color: inherit;
}

.main {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px 16px;
}

.main--map {
    padding: 0;
    align-items: stretch;
    justify-content: stretch;
    position: relative;
    min-height: 0;
}

.map {
    position: absolute;
    inset: 0;
    background: #0b0f14;
}

.leaflet-control-attribution,
.leaflet-attribution-flag {
    display: none !important;
}

.map-error { display: none !important; }

.leaflet-tile-container img.leaflet-tile[src*="empty-tile.png"] {
    opacity: 0 !important;
}

.auth-card {
    width: min(420px, 100%);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 28px;
}

.auth-card--wide { width: min(560px, 100%); }

.auth-card h1 { margin: 0 0 8px; font-size: 24px; }

.settings {
    display: grid;
    gap: 16px;
    margin: 20px 0 0;
}

.settings dt {
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 6px;
}

.settings dd { margin: 0; }

.api-key {
    display: block;
    background: #10151b;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 12px;
    font-family: ui-monospace, Consolas, monospace;
    font-size: 13px;
    word-break: break-all;
    margin-bottom: 10px;
}

.btn--ghost {
    background: transparent;
    color: var(--accent);
    border: 1px solid var(--line);
}

.form { display: grid; gap: 14px; margin: 20px 0; }
.form label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.form input {
    background: #10151b;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--text);
    padding: 10px 12px;
    font: inherit;
}

.btn {
    background: var(--accent);
    color: #08201c;
    border: 0;
    border-radius: 8px;
    padding: 11px 14px;
    font-weight: 700;
    cursor: pointer;
}

.muted { color: var(--muted); font-size: 14px; }
.error, .denied { color: var(--danger); margin: 0; }

.btn--danger {
    background: #3a1f22;
    color: var(--danger);
    border: 1px solid #5a3034;
}

.map-hud {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 1100;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.map-tool {
    pointer-events: auto;
    width: 44px;
    height: 44px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: rgba(14, 19, 24, 0.92);
    color: var(--text);
    display: grid;
    place-items: center;
    cursor: pointer;
    padding: 0;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}

.map-tool svg { width: 22px; height: 22px; }
.map-tool:hover { border-color: var(--accent); }
.map-tool[aria-pressed="true"] {
    color: #08201c;
    background: var(--accent);
    border-color: var(--accent);
}

.map-sheet {
    position: absolute;
    z-index: 1200;
    top: 10px;
    right: 64px;
    width: min(360px, calc(100vw - 80px));
    max-height: min(70vh, 560px);
    overflow: auto;
    background: rgba(14, 19, 24, 0.96);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
    padding: 12px 14px 16px;
}

.map-sheet--wide { width: min(420px, calc(100vw - 80px)); }

.map-sheet__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
}

.map-sheet__head h2 {
    margin: 0;
    font-size: 16px;
}

.map-sheet__close {
    background: none;
    border: 0;
    color: var(--muted);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
}

.map-sheet__hint {
    margin: 0 0 10px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.4;
}

.map-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    border-bottom: 1px solid var(--line);
}

.map-row:last-child { border-bottom: 0; }

.map-row__name {
    flex: 1;
    min-width: 0;
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.map-row__name.is-off { color: var(--muted); }

.map-row__author {
    display: block;
    color: var(--muted);
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.map-row__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: flex-end;
}

.map-mini {
    background: transparent;
    color: var(--accent);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 6px 8px;
    font-size: 12px;
    cursor: pointer;
}

.map-mini--danger { color: var(--danger); }

.map-form {
    display: grid;
    gap: 12px;
}

.map-form label {
    display: grid;
    gap: 6px;
    font-size: 13px;
    color: var(--muted);
}

.map-form input[type="text"],
.map-form textarea,
.map-form input[type="file"] {
    background: #10151b;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--text);
    padding: 10px 12px;
    font: inherit;
    width: 100%;
}

.map-form__check {
    display: flex;
    align-items: center;
    gap: 8px;
    grid-template-columns: none;
}

.map-form__preview {
    width: 100%;
    max-height: 180px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--line);
}

.map-form__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.map-icons {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px 12px;
    margin: 0;
}

.map-icons legend {
    padding: 0 6px;
    color: var(--muted);
    font-size: 12px;
}

.map-icons label {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text);
    font-size: 13px;
}

.map-hint {
    position: absolute;
    z-index: 1150;
    left: 50%;
    top: 12px;
    transform: translateX(-50%);
    max-width: min(520px, calc(100vw - 88px));
    background: rgba(14, 19, 24, 0.94);
    border: 1px solid var(--line);
    color: var(--text);
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 13px;
    text-align: center;
    pointer-events: none;
}

.map-ruler-bar {
    position: absolute;
    z-index: 1150;
    left: 50%;
    bottom: 16px;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
    justify-content: center;
    background: rgba(14, 19, 24, 0.94);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 8px 10px;
    max-width: calc(100vw - 24px);
}

.map-ruler-bar__total {
    font-weight: 700;
    font-size: 16px;
    min-width: 4.5em;
    text-align: center;
    white-space: nowrap;
}

.ruler-cursor {
    position: absolute;
    z-index: 1160;
    left: 0;
    top: 0;
    pointer-events: none;
    background: #fff;
    color: #222;
    font: 12px/16px Arial, sans-serif;
    padding: 2px 6px;
    border-radius: 3px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
    white-space: nowrap;
}

.leaflet-div-icon.ruler-icon {
    background: none !important;
    border: none !important;
}

.ruler-label {
    display: inline-block;
    background: #fff;
    color: #222;
    font: 12px/16px Arial, sans-serif;
    padding: 2px 6px;
    border-radius: 3px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
    white-space: nowrap;
}

.ruler-label--total { font-weight: 700; }

.ruler-vertex {
    width: 12px;
    height: 12px;
    background: #fff;
    border: 2px solid #1e98ff;
    border-radius: 50%;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2);
}

.pt-mark {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    transform: translate(-10px, -28px);
}

.pt-mark__icon {
    width: 20px;
    height: 28px;
    flex: 0 0 auto;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.55));
}

.pt-mark__label {
    background: rgba(14, 19, 24, 0.9);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 3px 7px;
    max-width: 180px;
    line-height: 1.25;
}

.pt-mark__title {
    display: block;
    font-size: 12px;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pt-mark__author {
    display: block;
    font-size: 10px;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.map--crosshair .leaflet-container,
.map--crosshair { cursor: crosshair; }

.page--map .leaflet-control-zoom {
    border: 0 !important;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}

.page--map .leaflet-control-zoom a {
    background: rgba(14, 19, 24, 0.92) !important;
    color: var(--text) !important;
    border-color: var(--line) !important;
}

@media (max-width: 720px) {
    .page--map .topbar {
        padding: 8px 10px;
        gap: 8px;
    }

    .page--map .topbar__meta { display: none; }

    .map-hud {
        top: 8px;
        right: 8px;
        gap: 6px;
    }

    .map-tool {
        width: 42px;
        height: 42px;
        border-radius: 11px;
    }

    .map-sheet,
    .map-sheet--wide {
        top: auto;
        right: 0;
        left: 0;
        bottom: 0;
        width: 100%;
        max-height: min(72vh, 560px);
        border-radius: 16px 16px 0 0;
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
    }

    .map-hint {
        top: auto;
        bottom: 72px;
        left: 12px;
        right: 12px;
        transform: none;
        max-width: none;
    }

    .map-ruler-bar {
        bottom: calc(10px + env(safe-area-inset-bottom));
        left: 8px;
        right: 8px;
        transform: none;
        flex-wrap: nowrap;
    }

    .map-ruler-bar .btn {
        flex: 0 0 auto;
        padding: 10px 12px;
        white-space: nowrap;
    }

    .page--map .leaflet-control-zoom {
        margin-bottom: 12px !important;
    }
}
