:root {
    color-scheme: light;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: #eef2ed;
    color: #162016;
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    min-height: 100%;
    margin: 0;
}

body {
    min-height: 100vh;
}

body:not(.route-camera):not(.route-photos) {
    height: 100%;
    overflow: hidden;
}

.map-shell {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    background: #dfe7dd;
}

.map-brand,
.auth-actions,
.map-actions,
.location-status,
.photo-location-edit,
.photo-location-anchor,
.auth-gate {
    position: fixed;
    z-index: 800;
}

.map-brand {
    top: max(14px, env(safe-area-inset-top));
    left: max(14px, env(safe-area-inset-left));
}

.brand-link,
.auth-pill,
.auth-button {
    display: inline-flex;
    align-items: center;
    min-height: 38px;
    border: 1px solid rgba(20, 31, 20, 0.14);
    border-radius: 8px;
    font-weight: 750;
    letter-spacing: 0;
    text-decoration: none;
}

.brand-link,
.auth-pill {
    padding: 0 14px;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 8px 28px rgba(21, 31, 21, 0.14);
    color: #162016;
    font-size: 16px;
    backdrop-filter: blur(12px);
}

.auth-actions {
    top: max(14px, env(safe-area-inset-top));
    right: max(14px, env(safe-area-inset-right));
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.auth-pill {
    min-width: 78px;
    justify-content: center;
}

.auth-avatar {
    width: 34px;
    height: 34px;
    padding: 2px;
    border: 1px solid rgba(20, 31, 20, 0.14);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 8px 28px rgba(21, 31, 21, 0.14);
    object-fit: cover;
}

.auth-avatar[hidden] {
    display: none;
}

.map-actions {
    right: max(14px, env(safe-area-inset-right));
    bottom: max(18px, env(safe-area-inset-bottom));
    display: grid;
    gap: 10px;
}

.map-action {
    display: grid;
    width: 52px;
    height: 52px;
    place-items: center;
    border: 1px solid rgba(20, 31, 20, 0.14);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 8px 28px rgba(21, 31, 21, 0.16);
    color: #162016;
    font-size: 24px;
    line-height: 1;
    text-decoration: none;
    backdrop-filter: blur(12px);
    cursor: pointer;
    appearance: none;
}

.map-action:focus-visible,
.brand-link:focus-visible,
.auth-pill:focus-visible,
.auth-button:focus-visible {
    outline: 3px solid #2d7ff9;
    outline-offset: 3px;
}

.map-action.is-working {
    color: #2d7ff9;
}

.map-action.is-error {
    color: #b42318;
}

.map-action:disabled {
    cursor: default;
    opacity: 0.55;
}

.map-action-count {
    display: grid;
    min-width: 24px;
    height: 24px;
    place-items: center;
    color: #162016;
    font-size: 18px;
    font-weight: 850;
    line-height: 1;
}

.photo-location-edit {
    top: max(66px, calc(env(safe-area-inset-top) + 66px));
    left: 50%;
    z-index: 850;
    display: grid;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 58px;
    max-width: min(360px, calc(100vw - 28px));
    padding: 9px 10px;
    border: 1px solid rgba(20, 31, 20, 0.14);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 12px 34px rgba(21, 31, 21, 0.18);
    color: #162016;
    font-size: 14px;
    font-weight: 750;
    line-height: 1.2;
    text-align: center;
    transform: translateX(-50%);
    backdrop-filter: blur(12px);
}

.photo-location-edit[hidden] {
    display: none;
}

.photo-location-edit-actions {
    display: flex;
    justify-content: center;
    gap: 8px;
}

.photo-location-edit button {
    min-width: 92px;
    min-height: 34px;
    border: 0;
    border-radius: 8px;
    background: #256f54;
    color: #ffffff;
    font: inherit;
    cursor: pointer;
}

.photo-location-edit button + button {
    border: 1px solid rgba(20, 31, 20, 0.16);
    background: #ffffff;
    color: #162016;
}

.photo-location-edit button:disabled {
    cursor: wait;
    opacity: 0.74;
}

.photo-location-anchor {
    top: 50%;
    left: 50%;
    z-index: 830;
    pointer-events: none;
    transform: translate(-50%, -50%);
}

.photo-location-anchor[hidden] {
    display: none;
}

.photo-map-marker.is-editing {
    transform: scale(1.18);
    box-shadow: 0 12px 28px rgba(22, 32, 22, 0.3);
}

.auth-gate {
    inset: 0;
    z-index: 760;
    display: grid;
    place-items: center;
    padding: 24px;
    pointer-events: none;
}

.auth-gate[hidden] {
    display: none;
}

.auth-gate-panel {
    width: min(390px, calc(100vw - 32px));
    padding: 18px;
    border: 1px solid rgba(20, 31, 20, 0.14);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 18px 52px rgba(21, 31, 21, 0.2);
    text-align: center;
    pointer-events: auto;
    backdrop-filter: blur(14px);
}

.auth-gate-panel p {
    margin: 0 0 14px;
    color: #162016;
    font-size: 16px;
    line-height: 1.35;
}

.auth-button {
    justify-content: center;
    min-width: 104px;
    padding: 0 18px;
    background: #256f54;
    color: #ffffff;
    font-size: 15px;
}

.user-location-marker {
    width: 16px;
    height: 16px;
    border: 3px solid #ffffff;
    border-radius: 999px;
    background: #2d7ff9;
    box-shadow: 0 0 0 2px rgba(45, 127, 249, 0.4), 0 8px 18px rgba(22, 32, 22, 0.24);
}

.photo-map-marker {
    width: 24px;
    height: 24px;
    border: 2px solid #ffffff;
    border-radius: 8px;
    background: #256f54;
    box-shadow: 0 8px 18px rgba(22, 32, 22, 0.24);
}

.photo-map-marker.is-latest {
    background: #2d7ff9;
    box-shadow: 0 0 0 2px rgba(45, 127, 249, 0.22), 0 8px 18px rgba(22, 32, 22, 0.24);
}

.photo-map-marker.is-shared {
    background: #f97316;
    box-shadow: 0 0 0 2px rgba(249, 115, 22, 0.2), 0 8px 18px rgba(22, 32, 22, 0.24);
}

.photo-map-marker-icon {
    -webkit-touch-callout: none;
    touch-action: none;
    user-select: none;
}

.photo-map-marker::before {
    content: "";
    display: block;
    width: 8px;
    height: 8px;
    margin: 6px auto 0;
    border-radius: 999px;
    background: #ffffff;
}

.photo-cluster-marker {
    display: grid;
    width: 38px;
    height: 38px;
    place-items: center;
    border: 2px solid #ffffff;
    border-radius: 10px;
    background: #256f54;
    box-shadow: 0 10px 22px rgba(22, 32, 22, 0.28);
    color: #ffffff;
    font-size: 15px;
    font-weight: 800;
    line-height: 1;
}

.photo-cluster-marker.is-shared {
    background: #f97316;
}

.photo-cluster-marker.is-latest {
    background: #2d7ff9;
    box-shadow: 0 0 0 2px rgba(45, 127, 249, 0.22), 0 10px 22px rgba(22, 32, 22, 0.28);
}

.photo-cluster-marker span {
    display: grid;
    min-width: 24px;
    height: 24px;
    place-items: center;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.18);
}

.photo-map-popup {
    display: grid;
    gap: 6px;
    width: 152px;
    color: #162016;
    font-size: 12px;
}

.photo-map-thumb {
    display: block;
    color: inherit;
    text-decoration: none;
}

.photo-map-thumb img {
    width: 152px;
    aspect-ratio: 4 / 3;
    border-radius: 6px;
    object-fit: cover;
    background: #dfe7dd;
}

.photo-map-popup-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.photo-share-button {
    display: grid;
    width: 30px;
    height: 30px;
    place-items: center;
    border: 1px solid rgba(20, 31, 20, 0.14);
    border-radius: 8px;
    background: #ffffff;
    color: #162016;
    font: inherit;
    font-size: 17px;
    line-height: 1;
    cursor: pointer;
}

.photo-share-button:disabled {
    cursor: wait;
    opacity: 0.74;
}

.photo-cluster-popup {
    width: min(224px, calc(100vw - 64px));
}

.photo-cluster-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
}

.photo-cluster-grid.is-large {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.photo-cluster-grid:not(.is-large) .photo-cluster-thumb-wrap:nth-child(3):last-child {
    grid-column: 1 / -1;
    width: calc((100% - 6px) / 2);
    justify-self: center;
}

.photo-cluster-thumb-wrap {
    position: relative;
    min-width: 0;
    aspect-ratio: 1;
}

.photo-cluster-thumb {
    display: block;
    width: 100%;
    height: 100%;
    color: inherit;
    text-decoration: none;
}

.photo-cluster-thumb img {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 6px;
    object-fit: cover;
    background: #dfe7dd;
}

.photo-cluster-share-button {
    position: absolute;
    right: 4px;
    bottom: 4px;
    display: grid;
    width: 26px;
    height: 26px;
    place-items: center;
    border: 1px solid rgba(20, 31, 20, 0.14);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 4px 12px rgba(22, 32, 22, 0.2);
    color: #162016;
    font: inherit;
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
}

.photo-cluster-share-button:disabled {
    cursor: wait;
    opacity: 0.74;
}

.location-status {
    right: max(78px, calc(env(safe-area-inset-right) + 78px));
    bottom: max(18px, env(safe-area-inset-bottom));
    max-width: min(280px, calc(100vw - 110px));
    padding: 9px 11px;
    border: 1px solid rgba(20, 31, 20, 0.14);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 8px 28px rgba(21, 31, 21, 0.16);
    color: #162016;
    font-size: 13px;
    line-height: 1.3;
    backdrop-filter: blur(12px);
}

.location-status.is-error {
    color: #b42318;
}

.route-photos {
    min-height: 100vh;
    background: #eef2ed;
}

.photos-stage {
    min-height: 100vh;
    padding: 78px 14px 24px;
}

.photos-panel {
    width: min(1120px, 100%);
    margin: 0 auto;
}

.photos-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.photos-header h1 {
    margin: 0;
    font-size: 28px;
    line-height: 1.15;
}

.photos-header-actions {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.photos-layer-toggle {
    min-height: 38px;
    padding: 0 12px;
    border: 1px solid rgba(20, 31, 20, 0.14);
    border-radius: 8px;
    background: #ffffff;
    color: #425142;
    font: inherit;
    font-size: 14px;
    font-weight: 750;
    cursor: pointer;
}

.photos-layer-toggle.is-active {
    background: #256f54;
    color: #ffffff;
}

.photos-sections {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
    align-items: start;
}

.photos-section {
    min-width: 0;
}

.photos-section[hidden] {
    display: none;
}

.photos-section h2 {
    margin: 0 0 10px;
    color: #162016;
    font-size: 18px;
    line-height: 1.2;
}

.photos-section.is-empty .photos-grid::before {
    content: "No photos yet.";
    color: #425142;
    font-size: 14px;
}

.photos-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(156px, 1fr));
    gap: 10px;
}

.photo-card {
    overflow: hidden;
    border: 1px solid rgba(20, 31, 20, 0.12);
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 8px 22px rgba(21, 31, 21, 0.08);
}

.photo-card-link {
    display: block;
    color: inherit;
    text-decoration: none;
}

.photo-card img {
    display: block;
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    background: #dfe7dd;
}

.photo-card-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 9px 10px 10px;
    color: #425142;
    font-size: 12px;
    line-height: 1.25;
}

.photo-delete-button {
    display: grid;
    width: 30px;
    height: 30px;
    flex: 0 0 auto;
    place-items: center;
    border: 1px solid rgba(180, 35, 24, 0.22);
    border-radius: 8px;
    background: #ffffff;
    color: #b42318;
    font: inherit;
    font-size: 17px;
    line-height: 1;
    cursor: pointer;
}

.photo-delete-button:disabled {
    cursor: wait;
    opacity: 0.72;
}

.photos-empty,
.photos-error {
    margin: 26px 0 0;
    color: #425142;
}

.photos-error {
    color: #b42318;
}

.shared-photo-stage {
    min-height: 100vh;
    padding: 78px 14px 24px;
}

.shared-photo-view,
.shared-photo-message {
    width: min(860px, 100%);
    margin: 0 auto;
}

.shared-photo-view {
    display: grid;
    gap: 12px;
}

.shared-photo-view img {
    display: block;
    width: 100%;
    max-height: calc(100vh - 156px);
    border-radius: 8px;
    object-fit: contain;
    background: #dfe7dd;
}

.shared-photo-view figcaption {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    color: #425142;
    font-size: 14px;
}

.shared-photo-view figcaption a {
    color: #256f54;
    font-weight: 750;
}

.shared-photo-message {
    padding: 18px;
    border: 1px solid rgba(20, 31, 20, 0.14);
    border-radius: 8px;
    background: #ffffff;
}

.route-camera {
    height: 100vh;
    overflow: hidden;
    background: #101610;
}

.route-camera .map-brand,
.route-camera .auth-actions {
    z-index: 860;
}

.camera-stage {
    position: fixed;
    inset: 0;
    min-height: 100vh;
    overflow: hidden;
    background: #101610;
}

.camera-panel {
    position: absolute;
    inset: 0;
}

.camera-view {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #101610;
}

.camera-video,
.camera-preview {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.camera-video[hidden],
.camera-preview[hidden] {
    display: none;
}

.camera-blocker {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(16, 22, 16, 0.74);
    color: #ffffff;
    text-align: center;
}

.camera-blocker[hidden] {
    display: none;
}

.camera-blocker p {
    max-width: 280px;
    margin: 0;
    font-size: 15px;
    line-height: 1.35;
}

.camera-controls {
    position: absolute;
    z-index: 840;
    left: max(14px, env(safe-area-inset-left));
    right: max(14px, env(safe-area-inset-right));
    bottom: max(96px, calc(env(safe-area-inset-bottom) + var(--mapmess-visual-bottom-inset, 0px) + 28px));
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    min-height: 76px;
    pointer-events: none;
}

.camera-control {
    min-height: 44px;
    padding: 0 18px;
    border: 1px solid rgba(20, 31, 20, 0.14);
    border-radius: 8px;
    background: #ffffff;
    color: #162016;
    font: inherit;
    font-weight: 750;
    cursor: pointer;
    pointer-events: auto;
}

.camera-control[hidden] {
    display: none;
}

.camera-control.is-primary {
    width: 74px;
    height: 74px;
    min-height: 74px;
    padding: 0;
    border: 4px solid rgba(255, 255, 255, 0.92);
    border-radius: 999px;
    background:
        radial-gradient(circle at 34% 28%, rgba(255, 255, 255, 1) 0 18%, rgba(245, 247, 245, 0.96) 34%, rgba(221, 225, 221, 0.98) 72%, rgba(252, 252, 252, 1) 100%);
    box-shadow:
        0 14px 34px rgba(0, 0, 0, 0.36),
        inset 0 5px 9px rgba(255, 255, 255, 0.95),
        inset 0 -7px 12px rgba(143, 150, 143, 0.28);
    color: transparent;
    font-size: 0;
    line-height: 0;
}

.camera-control.is-primary::before {
    content: "";
    display: block;
    width: 54px;
    height: 54px;
    margin: auto;
    border: 1px solid rgba(144, 151, 144, 0.36);
    border-radius: 999px;
    background:
        radial-gradient(circle at 32% 24%, rgba(255, 255, 255, 0.96) 0 14%, rgba(248, 249, 248, 0.98) 44%, rgba(232, 234, 232, 0.95) 100%);
    box-shadow:
        inset 0 3px 8px rgba(255, 255, 255, 0.92),
        inset 0 -5px 9px rgba(152, 158, 152, 0.2);
}

.camera-control.is-primary:active {
    transform: scale(0.97);
}

.camera-control:disabled {
    cursor: default;
    opacity: 0.55;
}

.camera-control[hidden] {
    display: none;
}

.camera-panel h1,
.photos-panel h1 {
    margin: 0 0 10px;
    font-size: 22px;
    letter-spacing: 0;
}

.camera-panel p,
.photos-panel p {
    margin: 0;
    color: #465247;
    font-size: 15px;
    line-height: 1.45;
}

.leaflet-control-layers,
.leaflet-bar {
    border: 1px solid rgba(20, 31, 20, 0.14) !important;
    border-radius: 8px !important;
    box-shadow: 0 8px 28px rgba(21, 31, 21, 0.14) !important;
    overflow: hidden;
}

.leaflet-top.leaflet-left {
    top: max(62px, calc(env(safe-area-inset-top) + 62px));
    left: max(4px, calc(env(safe-area-inset-left) + 4px));
}

.leaflet-control-layers-toggle,
.leaflet-bar a {
    width: 38px !important;
    height: 38px !important;
    line-height: 38px !important;
}

.leaflet-control-attribution {
    font-size: 11px;
}

@media (max-width: 520px) {
    .brand-link,
    .auth-pill {
        min-height: 36px;
        padding: 0 12px;
        font-size: 15px;
    }

    .auth-pill {
        min-width: 72px;
    }

    .auth-avatar {
        width: 32px;
        height: 32px;
    }

    .map-action {
        width: 50px;
        height: 50px;
    }

    .location-status {
        right: max(74px, calc(env(safe-area-inset-right) + 74px));
        max-width: min(240px, calc(100vw - 104px));
        font-size: 12px;
    }

    .photos-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .photos-header-actions {
        width: 100%;
        flex-wrap: wrap;
    }

    .photos-layer-toggle,
    .photos-header-actions .auth-button {
        flex: 1 1 auto;
    }

    .photos-sections {
        grid-template-columns: 1fr;
    }
}
