:root {
    --background: #f1ede4;
    --surface: #fffdf8;
    --surface-soft: rgba(255, 253, 248, .9);

    --text: #18201d;
    --muted: #65706b;

    --border: rgba(24, 32, 29, .14);

    --accent: #a84f31;
    --accent-dark: #77351f;

    --shadow:
        0 24px 70px
        rgba(25, 32, 29, .16);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
}

body {
    min-height: 100%;
    margin: 0;

    color: var(--text);

    background:
        radial-gradient(
            circle at 12% 10%,
            rgba(168, 79, 49, .08),
            transparent 34%
        ),
        radial-gradient(
            circle at 88% 80%,
            rgba(50, 100, 79, .08),
            transparent 32%
        ),
        var(--background);

    font-family:
        Inter,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
}

body.gallery-is-open {
    overflow: hidden;
}

button,
select,
input,
textarea {
    font: inherit;
}

button {
    color: inherit;
}

img {
    max-width: 100%;
}

[hidden] {
    display: none !important;
}

/*
|--------------------------------------------------------------------------
| Шапка
|--------------------------------------------------------------------------
*/

.site-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;

    gap: 30px;

    padding:
        24px
        clamp(18px, 4vw, 58px)
        18px;
}

.site-heading {
    max-width: 900px;
}

.eyebrow {
    margin: 0 0 8px;

    color: var(--accent);

    font-size: .76rem;
    font-weight: 800;
    letter-spacing: .16em;

    text-transform: uppercase;
}

h1 {
    margin: 0;

    font-family:
        Georgia,
        "Times New Roman",
        serif;

    font-size:
        clamp(2.6rem, 6vw, 5.6rem);

    font-weight: 500;
    letter-spacing: -.055em;
    line-height: .92;
}

.site-description {
    max-width: 720px;

    margin: 14px 0 0;

    color: var(--muted);

    line-height: 1.5;
}

.timeline-form {
    display: grid;
    gap: 7px;

    min-width: 240px;
}

.timeline-form label {
    color: var(--muted);

    font-size: .76rem;
    font-weight: 800;
    letter-spacing: .1em;

    text-transform: uppercase;
}

.timeline-form select {
    width: 100%;

    padding:
        13px
        42px
        13px
        15px;

    border: 1px solid var(--border);
    border-radius: 14px;

    color: var(--text);
    background: rgba(255, 255, 255, .82);

    cursor: pointer;

    font-weight: 700;
}

/*
|--------------------------------------------------------------------------
| Основная область
|--------------------------------------------------------------------------
*/

.site-main {
    padding:
        0
        clamp(12px, 3vw, 42px)
        30px;
}

.map-card {
    overflow: hidden;

    border: 1px solid var(--border);
    border-radius: 26px;

    background: rgba(255, 255, 255, .38);

    box-shadow: var(--shadow);
}

.map-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;

    gap: 24px;

    padding: 16px 20px;

    border-bottom: 1px solid var(--border);

    background: var(--surface-soft);

    backdrop-filter: blur(14px);
}

.map-toolbar-heading {
    min-width: 0;
}

.period-label {
    display: block;

    margin-bottom: 4px;

    color: var(--accent);

    font-size: .75rem;
    font-weight: 800;
    letter-spacing: .14em;

    text-transform: uppercase;
}

.map-toolbar h2 {
    margin: 0;

    font-family:
        Georgia,
        "Times New Roman",
        serif;

    font-size: 1.45rem;
    font-weight: 500;
}

.map-toolbar p {
    max-width: 850px;

    margin: 5px 0 0;

    color: var(--muted);

    line-height: 1.45;
}

/*
|--------------------------------------------------------------------------
| Кнопки масштабирования
|--------------------------------------------------------------------------
*/

.map-buttons {
    display: flex;
    align-items: center;

    gap: 8px;

    flex: 0 0 auto;
}

.map-buttons button {
    min-width: 42px;

    padding: 9px 12px;

    border: 1px solid var(--border);
    border-radius: 999px;

    background: rgba(255, 255, 255, .78);

    cursor: pointer;
}

.map-buttons button:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.map-buttons button:focus-visible {
    outline: 3px solid rgba(168, 79, 49, .18);
    outline-offset: 2px;
}

#zoomIndicator {
    min-width: 58px;

    color: var(--muted);

    text-align: center;

    font-size: .85rem;
    font-weight: 700;
}

/*
|--------------------------------------------------------------------------
| Переключатель нескольких карт периода
|--------------------------------------------------------------------------
*/

.map-tabs {
    display: flex;

    gap: 9px;

    overflow-x: auto;

    padding: 13px 16px;

    border-bottom: 1px solid var(--border);

    background: rgba(255, 253, 248, .72);

    scrollbar-width: thin;
}

.map-tab {
    flex: 0 0 auto;

    padding: 9px 14px;

    border: 1px solid var(--border);
    border-radius: 999px;

    color: var(--text);
    background: rgba(255, 255, 255, .72);

    text-decoration: none;

    font-size: .86rem;
    font-weight: 700;

    transition:
        border-color .15s ease,
        color .15s ease,
        background .15s ease;
}

.map-tab:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.map-tab.is-active {
    border-color: var(--accent);

    color: white;
    background: var(--accent);
}

.selected-map-title {
    display: flex;
    align-items: center;

    gap: 10px;

    flex-wrap: wrap;

    padding: 10px 18px;

    border-bottom: 1px solid var(--border);

    color: var(--muted);
    background: rgba(255, 255, 255, .58);

    font-size: .82rem;
}

.selected-map-title strong {
    color: var(--text);
}

.selected-map-count {
    margin-left: auto;
}

/*
|--------------------------------------------------------------------------
| Историческая карта
|--------------------------------------------------------------------------
*/

.image-map-viewport {
    position: relative;

    height: clamp(480px, 68vh, 820px);

    overflow: hidden;

    background: #d6cdbc;

    cursor: grab;
    touch-action: none;
}

.image-map-viewport.is-dragging {
    cursor: grabbing;
}

.image-map-stage {
    position: absolute;
    top: 0;
    left: 0;

    transform-origin: 0 0;

    user-select: none;
    will-change: transform;
}

.image-map-stage > img {
    display: block;

    width: 100%;
    height: auto;

    pointer-events: none;
    user-select: none;
}

.marker-layer {
    position: absolute;
    inset: 0;
}

/*
|--------------------------------------------------------------------------
| Маленькие метки
|--------------------------------------------------------------------------
*/

.map-marker {
    position: absolute;

    width: 25px;
    height: 25px;

    padding: 0;

    border: 2px solid rgba(255, 255, 255, .98);
    border-radius: 50% 50% 50% 7px;

    color: white;
    background: var(--accent);

    box-shadow:
        0 5px 14px
        rgba(76, 36, 22, .4);

    cursor: pointer;

    rotate: -45deg;

    transform:
        translate(-50%, -100%);

    transition:
        scale .15s ease,
        background .15s ease,
        box-shadow .15s ease;
}

.map-marker:hover,
.map-marker:focus-visible {
    z-index: 20;

    scale: 1.18;

    background: var(--accent-dark);

    box-shadow:
        0 7px 20px
        rgba(76, 36, 22, .5);
}

.map-marker:focus-visible {
    outline: 3px solid rgba(255, 255, 255, .75);
    outline-offset: 3px;
}

.map-marker span {
    position: absolute;
    inset: 0;

    display: grid;
    place-items: center;

    rotate: 45deg;

    font-size: .58rem;
    font-weight: 800;
}

.map-marker strong {
    position: absolute;
    left: 50%;
    bottom: calc(100% + 13px);

    width: max-content;
    max-width: 220px;

    padding: 7px 10px;

    border-radius: 10px;

    color: white;
    background: rgba(24, 32, 29, .92);

    opacity: 0;
    pointer-events: none;

    rotate: 45deg;
    transform: translateX(-50%);

    font-size: .78rem;
    font-weight: 600;
    line-height: 1.3;

    transition: opacity .15s ease;
}

.map-marker:hover strong,
.map-marker:focus-visible strong {
    opacity: 1;
}

.map-help {
    position: absolute;
    left: 15px;
    bottom: 15px;

    max-width:
        calc(100% - 30px);

    padding: 8px 12px;

    border:
        1px solid
        rgba(255, 255, 255, .35);

    border-radius: 999px;

    color: white;
    background: rgba(24, 32, 29, .72);

    pointer-events: none;

    font-size: .78rem;
    line-height: 1.35;

    backdrop-filter: blur(8px);
}

/*
|--------------------------------------------------------------------------
| Яндекс Карта
|--------------------------------------------------------------------------
*/

.yandex-map-wrapper {
    position: relative;

    width: 100%;

    height: min(64vh, 700px);
    min-height: 440px;

    overflow: hidden;

    background: #e5e7eb;
}

.yandex-map-frame {
    display: block;

    width: 100%;
    height: 100%;

    border: 0;
}

/*
|--------------------------------------------------------------------------
| Пустые состояния
|--------------------------------------------------------------------------
*/

.empty-state,
.empty-map {
    padding: 60px 30px;

    text-align: center;
}

.empty-state {
    max-width: 720px;

    margin: 40px auto;

    border: 1px solid var(--border);
    border-radius: 24px;

    background: var(--surface);
}

.empty-state h2,
.empty-map h3 {
    margin-top: 0;

    font-family:
        Georgia,
        "Times New Roman",
        serif;

    font-weight: 500;
}

.empty-state p,
.empty-map p {
    color: var(--muted);

    line-height: 1.55;
}

.empty-map code {
    display: inline-block;

    margin-top: 8px;
    padding: 8px 11px;

    border-radius: 7px;

    color: var(--accent);
    background: rgba(168, 79, 49, .08);
}

.primary-link {
    display: inline-flex;

    margin-top: 10px;
    padding: 12px 18px;

    border-radius: 10px;

    color: white;
    background: var(--accent);

    text-decoration: none;

    font-weight: 700;
}

/*
|--------------------------------------------------------------------------
| Затемнение страницы
|--------------------------------------------------------------------------
*/

.sidebar-backdrop {
    position: fixed;
    inset: 0;

    z-index: 90;

    background: rgba(18, 24, 21, .36);

    backdrop-filter: blur(3px);
}

/*
|--------------------------------------------------------------------------
| Боковая карточка места
|--------------------------------------------------------------------------
*/

.place-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;

    z-index: 100;

    width: min(460px, 94vw);

    overflow-y: auto;

    background: var(--surface);

    box-shadow:
        -24px 0 70px
        rgba(18, 24, 21, .25);

    transform: translateX(105%);

    transition: transform .25s ease;
}

.place-sidebar.is-open {
    transform: translateX(0);
}

.sidebar-close {
    position: absolute;
    top: 14px;
    right: 14px;

    z-index: 4;

    width: 44px;
    height: 44px;

    border: 1px solid var(--border);
    border-radius: 50%;

    color: var(--text);
    background: rgba(255, 255, 255, .9);

    cursor: pointer;

    font-size: 1.7rem;
    line-height: 1;

    box-shadow:
        0 6px 20px
        rgba(0, 0, 0, .12);
}

.sidebar-main-image-button {
    position: relative;

    display: block;

    width: 100%;

    overflow: hidden;
    padding: 0;

    border: 0;

    background: #ded7ca;

    cursor: zoom-in;
}

.sidebar-image {
    display: block;

    width: 100%;
    height: 320px;

    object-fit: cover;

    transition: transform .25s ease;
}

.sidebar-main-image-button:hover .sidebar-image {
    transform: scale(1.025);
}

.sidebar-image-hint {
    position: absolute;
    right: 14px;
    bottom: 14px;

    padding: 7px 10px;

    border:
        1px solid
        rgba(255, 255, 255, .3);

    border-radius: 999px;

    color: white;
    background: rgba(15, 20, 18, .7);

    font-size: .75rem;
    font-weight: 700;

    backdrop-filter: blur(7px);
}

.sidebar-content {
    padding: 28px;
}

.sidebar-subtitle {
    margin: 0 0 8px;

    color: var(--accent);

    font-size: .76rem;
    font-weight: 800;
    letter-spacing: .12em;

    text-transform: uppercase;
}

.sidebar-content h2 {
    margin: 0 0 18px;

    font-family:
        Georgia,
        "Times New Roman",
        serif;

    font-size: 2rem;
    font-weight: 500;
    line-height: 1.12;
}

.sidebar-description {
    margin: 0;

    color: var(--text);

    line-height: 1.7;

    white-space: pre-line;
}

.gallery-open-button {
    width: 100%;

    margin-top: 22px;
    padding: 12px 16px;

    border: 0;
    border-radius: 10px;

    color: white;
    background: var(--accent);

    cursor: pointer;

    font-weight: 800;

    transition:
        background .15s ease,
        transform .15s ease;
}

.gallery-open-button:hover {
    background: var(--accent-dark);
}

.gallery-open-button:active {
    transform: translateY(1px);
}

/*
|--------------------------------------------------------------------------
| Полноэкранная галерея
|--------------------------------------------------------------------------
*/

.gallery-modal {
    position: fixed;
    inset: 0;

    z-index: 300;
}

.gallery-modal-backdrop {
    position: absolute;
    inset: 0;

    background: rgba(9, 13, 11, .88);

    backdrop-filter: blur(7px);
}

.gallery-dialog {
    position: absolute;
    inset: 4vh 4vw;

    display: flex;
    flex-direction: column;

    overflow: hidden;

    border:
        1px solid
        rgba(255, 255, 255, .16);

    border-radius: 20px;

    color: white;
    background: #111714;

    box-shadow:
        0 28px 90px
        rgba(0, 0, 0, .5);
}

.gallery-dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;

    gap: 20px;

    padding: 15px 20px;

    border-bottom:
        1px solid
        rgba(255, 255, 255, .12);
}

.gallery-dialog-header h2 {
    margin: 3px 0 0;

    font-family:
        Georgia,
        "Times New Roman",
        serif;

    font-size: clamp(1.25rem, 3vw, 2rem);
    font-weight: 500;
    line-height: 1.15;
}

#galleryCounter {
    color: rgba(255, 255, 255, .58);

    font-size: .78rem;
    font-weight: 700;
}

.gallery-close-button {
    width: 44px;
    height: 44px;

    flex: 0 0 auto;

    border:
        1px solid
        rgba(255, 255, 255, .18);

    border-radius: 50%;

    color: white;
    background: rgba(255, 255, 255, .08);

    cursor: pointer;

    font-size: 1.7rem;
    line-height: 1;
}

.gallery-close-button:hover {
    background: rgba(255, 255, 255, .16);
}

.gallery-stage {
    position: relative;

    min-height: 0;

    flex: 1;

    display: grid;
    place-items: center;

    overflow: hidden;

    padding: 18px 72px;

    background:
        radial-gradient(
            circle at center,
            rgba(255, 255, 255, .045),
            transparent 62%
        );
}

.gallery-stage > img {
    display: block;

    max-width: 100%;
    max-height: 100%;

    object-fit: contain;

    user-select: none;
}

.gallery-arrow {
    position: absolute;
    top: 50%;

    z-index: 2;

    width: 48px;
    height: 48px;

    border:
        1px solid
        rgba(255, 255, 255, .2);

    border-radius: 50%;

    color: white;
    background: rgba(0, 0, 0, .38);

    cursor: pointer;

    transform: translateY(-50%);

    font-size: 2rem;
    line-height: 1;

    backdrop-filter: blur(5px);

    transition:
        background .15s ease,
        scale .15s ease;
}

.gallery-arrow:hover {
    background: rgba(0, 0, 0, .65);
    scale: 1.06;
}

.gallery-arrow-left {
    left: 16px;
}

.gallery-arrow-right {
    right: 16px;
}

.gallery-thumbnails {
    display: flex;

    gap: 9px;

    min-height: 88px;

    overflow-x: auto;

    padding: 12px 16px 16px;

    border-top:
        1px solid
        rgba(255, 255, 255, .1);

    scrollbar-width: thin;
}

.gallery-thumbnail {
    width: 90px;
    height: 64px;

    flex: 0 0 auto;

    overflow: hidden;

    padding: 0;

    border: 2px solid transparent;
    border-radius: 8px;

    background: transparent;

    cursor: pointer;

    opacity: .58;

    transition:
        opacity .15s ease,
        border-color .15s ease,
        transform .15s ease;
}

.gallery-thumbnail:hover {
    opacity: .86;
    transform: translateY(-2px);
}

.gallery-thumbnail.is-active {
    border-color: white;
    opacity: 1;
}

.gallery-thumbnail img {
    display: block;

    width: 100%;
    height: 100%;

    object-fit: cover;
}

/*
|--------------------------------------------------------------------------
| Адаптивность
|--------------------------------------------------------------------------
*/

@media (max-width: 900px) {
    .site-header {
        align-items: stretch;
        flex-direction: column;
    }

    .timeline-form {
        min-width: 0;
    }

    .map-toolbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .map-buttons {
        flex-wrap: wrap;
    }
}

@media (max-width: 680px) {
    .site-header {
        padding-top: 18px;
    }

    h1 {
        font-size: clamp(2.5rem, 14vw, 4rem);
    }

    .site-main {
        padding-right: 8px;
        padding-left: 8px;
    }

    .map-card {
        border-radius: 18px;
    }

    .map-toolbar {
        padding: 14px 15px;
    }

    .image-map-viewport {
        height: 65vh;
        min-height: 420px;
    }

    .yandex-map-wrapper {
        height: 60vh;
        min-height: 400px;
    }

    .map-help {
        right: 10px;
        left: 10px;
        bottom: 10px;

        width: auto;

        border-radius: 12px;

        text-align: center;
    }

    .selected-map-title {
        align-items: flex-start;
        flex-direction: column;
    }

    .selected-map-count {
        margin-left: 0;
    }

    .sidebar-image {
        height: 260px;
    }

    .sidebar-content {
        padding: 23px;
    }

    .gallery-dialog {
        inset: 8px;

        border-radius: 14px;
    }

    .gallery-dialog-header {
        padding: 12px 14px;
    }

    .gallery-stage {
        padding: 12px 48px;
    }

    .gallery-arrow {
        width: 38px;
        height: 38px;

        font-size: 1.6rem;
    }

    .gallery-arrow-left {
        left: 6px;
    }

    .gallery-arrow-right {
        right: 6px;
    }

    .gallery-thumbnail {
        width: 74px;
        height: 54px;
    }
}

@media (max-width: 420px) {
    .map-buttons {
        width: 100%;
    }

    .map-buttons button {
        flex: 1 1 auto;
    }

    #zoomIndicator {
        width: 100%;

        padding-top: 3px;
    }

    .place-sidebar {
        width: 100%;
    }

    .gallery-stage {
        padding-right: 42px;
        padding-left: 42px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .place-sidebar,
    .map-marker,
    .gallery-thumbnail,
    .gallery-arrow,
    .gallery-open-button,
    .sidebar-image {
        transition: none;
    }

    html {
        scroll-behavior: auto;
    }
}