:root {
    --zool-ink: #203128;
    --zool-muted: #52635b;
    --zool-paper: #f6f6f0;
    --zool-surface: #fff;
    --zool-line: #dfe5dc;
    --zool-green: #245440;
    --zool-deep: #17392d;
    --zool-tint: #e8f0e8;
    --zool-focus: #856224;
    --zool-radius: 12px;
    --zool-shadow: 0 1px 2px #2031280c, 0 7px 22px #20312809;
    --zool-body-font: "Golos Text", system-ui, sans-serif;
    --zool-display-font: Literata, Georgia, serif;
    --zool-ease-out: cubic-bezier(0.23, 1, 0.32, 1);
    --zool-press: 140ms;
}

.zool-ui {
    color: var(--zool-ink);
    background: var(--zool-paper);
    font-family: var(--zool-body-font);
}

.zool-ui :where(img:not(.leaflet-tile, .leaflet-marker-icon, .leaflet-marker-shadow)) {
    max-width: 100%;
    height: auto;
}

.zool-ui :is(h1, h2, h3) {
    text-wrap: balance;
}

.zool-ui :is(a, button, input, select, textarea, summary):focus-visible {
    outline: 2px solid var(--zool-focus);
    outline-offset: 3px;
}

.zool-ui :is(.navbar-collapse, #v2-navigation).collapsing {
    transition: none;
}

.zool-skip {
    position: fixed;
    top: 8px;
    left: 8px;
    z-index: 2000;
    padding: 10px 14px;
    border-radius: 6px;
    background: var(--zool-surface);
    color: var(--zool-green);
    box-shadow: var(--zool-shadow);
    clip-path: inset(50%);
}

.zool-skip:focus-visible {
    clip-path: none;
}

@media (prefers-reduced-motion: no-preference) {
    .zool-ui :is(.species-search button, .search-form button, .v2-search button,
    .tree-controls button, .fact-card button, #species-map-fullscreen,
    .visitor-filters button, .map-workspace .icon-button, .map-workspace .row-action):not(:focus-visible) {
        transition: transform var(--zool-press) var(--zool-ease-out);
    }

    .zool-ui :is(.species-search button, .search-form button, .v2-search button,
    .tree-controls button, .fact-card button, #species-map-fullscreen,
    .visitor-filters button, .map-workspace .icon-button, .map-workspace .row-action):not(:focus-visible, :disabled):active {
        transform: scale(0.97);
    }
}

@media (prefers-reduced-motion: reduce) {
    .zool-ui, .zool-ui :is(.navbar-collapse, .species-tabs, .table-scroll) {
        scroll-behavior: auto;
    }

    .zool-ui :is(#sidebars, #toggleSidebar) {
        transition: none;
    }
}

/* Legacy page shell */
.theme-legacy > header {
    background: var(--zool-surface);
    border-bottom: 1px solid var(--zool-line);
}

.theme-legacy > header img {
    display: block;
    max-width: min(70vw, 328px);
    width: auto;
    max-height: 66px;
    object-fit: contain;
}

.theme-legacy > header .container > .d-flex {
    gap: 12px;
    align-items: center;
    justify-content: space-between;
}

.theme-legacy .languages ul {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin: 0;
    padding: 0;
}

.theme-legacy .languages li {
    float: none;
    margin: 0;
}

.theme-legacy .languages a {
    display: inline-flex;
    min-height: 36px;
    align-items: center;
    justify-content: center;
    padding: 4px 7px;
    border-radius: 6px;
    color: var(--zool-green);
    font-size: .8rem;
    font-weight: 650;
}

.theme-legacy .languages [aria-current] {
    background: var(--zool-tint);
}

.theme-legacy :is(.main-d, .slider) > .navbar {
    margin: 0;
    background: var(--zool-deep);
}

.theme-legacy .navbar .navbar-nav {
    gap: 4px;
    flex-wrap: wrap;
}

.theme-legacy .navbar .nav-link {
    display: inline-flex;
    align-items: center;
    min-height: 42px;
    padding: .45rem .65rem;
    border-radius: 7px;
    color: #f7faf5;
    font-family: var(--zool-body-font);
    font-size: .875rem;
    line-height: 1.3;
}

.theme-legacy .navbar .nav-link[aria-current],
.theme-legacy .navbar .nav-link:focus-visible {
    background: #ffffff1d;
}

.theme-legacy .navbar .navbar-toggler {
    border: 1px solid #ffffff60;
    border-radius: 7px;
    color: #fff;
    min-width: 44px;
    min-height: 44px;
}

@media (hover: hover) and (pointer: fine) {
    .theme-legacy .navbar .nav-link:hover {
        background: #ffffff1d;
    }

    .theme-legacy .languages a:hover {
        background: var(--zool-tint);
    }
}

.theme-legacy .slider {
    height: auto;
    min-height: min(65vh, 540px);
    background-image: linear-gradient(90deg, #152b2220 12%, #152b2238 32%, #152b22e8 58%), url("../images/main.jpg");
    background-size: cover;
    background-position: center;
}

.theme-legacy .slider > .container {
    padding-block: clamp(2.25rem, 7vw, 6rem);
}

.theme-legacy .slider .search-form {
    position: static;
    transform: none;
    width: min(57%, 40rem);
    min-width: 0;
    margin-inline-start: auto;
    padding: 0;
    background: transparent;
}

.theme-legacy .home-title {
    margin: 0 0 1rem;
    max-width: 22ch;
    color: #fff;
    font-family: var(--zool-display-font);
    font-size: clamp(2rem, 4.2vw, 3.9rem);
    line-height: 1.12;
}

.theme-legacy .slider .search-form form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    max-width: 32rem;
}

.theme-legacy .slider .search-form input {
    float: none;
    width: 100%;
    min-width: 0;
    height: 48px;
    border: 1px solid transparent;
    border-radius: 8px 0 0 8px;
    background: #fff;
    color: var(--zool-ink);
    font: inherit;
    padding: 0 14px;
}

.theme-legacy .slider .search-form button {
    float: none;
    width: auto;
    min-width: 64px;
    height: 48px;
    padding: 0 16px;
    border: 0;
    border-radius: 0 8px 8px 0;
    background: #e6d5a9;
    color: #26382c;
    font: 650 .9375rem var(--zool-body-font);
}

.theme-legacy .slider .search-form > br {
    display: none;
}

.theme-legacy .slider .textinsearch {
    margin-top: 14px;
    color: #fff;
}

.theme-legacy .incount {
    height: auto;
    padding-block: 28px;
    background: var(--zool-tint);
}

.theme-legacy .incount h3,
.theme-legacy .incount .numbers,
.theme-legacy .incount .counttext {
    color: var(--zool-deep);
    font-family: var(--zool-body-font);
}

.theme-legacy .incount .numbers {
    font-size: clamp(1.8rem, 4vw, 3.1rem);
    font-variant-numeric: tabular-nums;
}

.theme-legacy .main-d {
    background: var(--zool-paper);
}

.theme-legacy .main-d > .container-fluid {
    width: min(calc(100% - 2rem), 1240px) !important;
    max-width: 1240px;
}

.zool-ui .desc-head {
    width: 100%;
    gap: clamp(1rem, 3vw, 2rem);
    align-items: center;
    margin-bottom: 1rem;
}

.zool-ui .desc-head > :is(h1, h2) {
    width: auto;
    max-width: 100%;
    min-width: 0;
    margin: 0;
    color: var(--zool-ink);
    font-family: var(--zool-display-font);
    font-size: clamp(1.65rem, 3vw, 2.55rem);
    line-height: 1.2;
    overflow-wrap: anywhere;
}

.zool-ui .species-search-controls {
    border-color: var(--zool-line);
    box-shadow: 0 1px 2px #17392d0b;
}

.zool-ui .species-search-controls:focus-within {
    border-color: var(--zool-focus);
    box-shadow: 0 0 0 2px #e7dac0;
}

.zool-ui .desc-head .species-search button {
    background: var(--zool-green);
    color: white;
}

.theme-legacy :is(.main-d .classes, .desc-prose) {
    min-width: 0;
    overflow-wrap: anywhere;
}

.theme-legacy .main-d .classes > :is(p, ol, ul) {
    max-width: 76ch;
}

.theme-legacy :is(.desc-box, .id-detail) {
    max-width: 100%;
    border-radius: var(--zool-radius);
}

.zool-ui .species-photo {
    display: block;
    overflow: hidden;
    aspect-ratio: 4 / 3;
    border-radius: var(--zool-radius);
    background: var(--zool-tint);
}

.zool-ui .species-photo > img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.theme-legacy #lightgallery > .species-photo {
    display: inline-block;
    width: min(200px, calc((100% - 32px) / 2));
    margin: 5px;
    vertical-align: top;
}

.zool-ui :is(.v2-card img, .randomtype a > img, .random a > img, .search-list article > img) {
    object-fit: contain;
    background: var(--zool-tint);
}

.theme-legacy :is(.randomtype a > img, .random a > img) {
    aspect-ratio: 4 / 3;
    height: auto;
}

.theme-legacy .randomtype .col-lg-4 a > img {
    width: min(100%, 267px);
    height: auto;
}

.theme-legacy .random a > img {
    width: 80%;
}

.theme-v2 .search-list article > img {
    height: 44px;
    flex-shrink: 0;
}

.zool-ui :is(#mainmap, #species-map) {
    border-radius: var(--zool-radius);
    background: #e1e8e1;
}

.theme-legacy .bottom {
    background: var(--zool-deep);
    padding: 32px 16px;
}

.theme-legacy .bottom p {
    color: #e2eae2;
    width: min(100%, 76ch);
    text-align: start;
}

.theme-legacy .bottom-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 5px 12px;
    width: 100% !important;
    padding: 0;
}

.theme-legacy .bottom-nav a {
    display: inline-flex;
    min-height: 40px;
    align-items: center;
    color: #e2eae2;
}

/* Version 2 uses the same surfaces and interactions. */
.theme-v2 {
    --c-bg: var(--zool-paper);
    --c-ink: var(--zool-ink);
    --c-forest: var(--zool-green);
    --c-muted: var(--zool-muted);
    --c-line: var(--zool-line);
    --c-surface: var(--zool-surface);
}

.zool-ui #v2-navigation {
    flex-wrap: wrap;
    gap: 4px clamp(6px, 1.15vw, 18px);
}

.zool-ui #v2-navigation > a {
    padding: 0 9px;
    border-radius: 7px;
}

.zool-ui #v2-navigation > a[aria-current] {
    background: var(--zool-tint);
    color: var(--zool-deep);
    font-weight: 650;
}

.zool-ui #v2-navigation form {
    flex: 0 1 14rem;
    min-width: 0;
}

.zool-ui #v2-navigation input {
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
    border-radius: 7px 0 0 7px;
    font-size: 1rem;
}

.zool-ui #v2-navigation form button {
    min-width: 44px;
    border-radius: 0 7px 7px 0;
    background: var(--zool-tint);
    color: var(--zool-deep);
}

.zool-ui .v2-hero {
    background-image: linear-gradient(90deg, #152b2220 12%, #152b2238 32%, #152b22ed 58%), url("../images/main.jpg");
    padding-block: clamp(2.5rem, 6vw, 5.5rem);
}

.zool-ui .v2-hero > .v2-wrap {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
}

.zool-ui .v2-hero > .v2-wrap > * {
    grid-column: 2;
    min-width: 0;
}

.zool-ui .v2-brand img {
    width: 43px;
    height: 43px;
    object-fit: cover;
    object-position: left center;
}

.zool-ui .v2-hero h1 {
    max-width: 26ch;
    line-height: 1.1;
}

.zool-ui .v2-search input {
    min-height: 48px;
    padding: 10px 14px;
    font-size: 1rem;
}

.zool-ui .v2-search button {
    background: var(--zool-green);
    color: #fff;
}

.zool-ui .v2-hero .v2-search button {
    background: #e6d5a9;
    color: var(--zool-deep);
}

.zool-ui :is(.department-grid a, .v2-card, .fact-card, .visitor-metrics article) {
    border-color: var(--zool-line);
    border-radius: var(--zool-radius);
    box-shadow: var(--zool-shadow);
}

.zool-ui .v2-card a:focus-visible {
    outline-offset: -4px;
}

.zool-ui :is(.tree-controls, .visitor-filters) {
    padding: 14px;
    border: 1px solid var(--zool-line);
    border-radius: var(--zool-radius);
    background: var(--zool-surface);
}

.zool-ui .v2-tree details[open] > summary {
    color: var(--zool-green);
}

.zool-ui .species-layout section {
    scroll-margin-top: 150px;
}

.zool-ui :is(.tree-controls input, .visitor-filters select, .visitor-filters input) {
    min-height: 44px;
    font-size: 1rem;
}

.zool-ui :is(.visitor-table, .table-scroll) {
    border: 1px solid var(--zool-line);
    border-radius: 9px;
    background: var(--zool-surface);
}

.zool-ui :is(.visitor-table, .table-scroll) thead {
    background: var(--zool-tint);
}

@media (max-width: 767px) {
    .theme-legacy > header img {
        max-width: min(56vw, 230px);
        max-height: 54px;
    }

    .theme-legacy .languages ul {
        justify-content: end;
    }

    .theme-legacy .slider,
    .zool-ui .v2-hero {
        background-image: linear-gradient(90deg, #152b22d9, #152b22ac), url("../images/main.jpg");
    }

    .theme-legacy .slider .search-form {
        width: 100%;
    }

    .zool-ui .v2-hero > .v2-wrap {
        display: block;
    }

    .zool-ui .v2-brand img {
        width: 34px;
        height: 34px;
    }

    .theme-legacy .main-d > .container-fluid {
        width: calc(100% - 1rem) !important;
    }

    .zool-ui .desc-head {
        display: block;
    }

    .zool-ui .desc-head .species-search {
        width: 100%;
        margin: .85rem 0 0;
    }

    .zool-ui #v2-navigation form {
        flex: 0 0 auto;
    }

    .zool-ui .species-layout section {
        scroll-margin-top: 90px;
    }

    .zool-ui .search-list article {
        flex-wrap: wrap;
    }

    .zool-ui .search-list article > span {
        white-space: normal;
    }
}

.zool-ui :is(.analytics, .activity, .visitors) h1 {
    margin-bottom: .65rem;
    color: var(--zool-ink);
    font-family: var(--zool-display-font);
    font-size: clamp(1.9rem, 4vw, 2.7rem);
}

.zool-ui .visitor-filters button,
.zool-ui :is(.analytics, .activity) button[type="submit"] {
    min-height: 44px;
    border-color: var(--zool-green);
    background: var(--zool-green);
    color: #fff;
}

/* Standalone map */
.zool-ui .map-workspace {
    --green: var(--zool-green);
    --border: var(--zool-line);
    --shadow: var(--zool-shadow);
    font-family: var(--zool-body-font);
}

.zool-ui .map-workspace .panel {
    background: var(--zool-surface);
    border-color: var(--zool-line);
    border-radius: var(--zool-radius);
    backdrop-filter: none;
}

.zool-ui .map-workspace .search-results {
    transform-origin: top left;
}

.zool-ui .map-workspace .switch-label input:before {
    transition: transform var(--zool-press) var(--zool-ease-out);
}

.zool-ui .map-workspace .switch-label input:focus-visible:before {
    transition: none;
}

/* Django administration keeps the native theme mechanics. */
html[data-theme="light"],
html[data-theme="auto"] {
    --primary: #386e55;
    --secondary: var(--zool-deep);
    --accent: #f6e6b9;
    --body-bg: #fbfcf9;
    --hairline-color: var(--zool-line);
    --button-bg: var(--zool-green);
    --default-button-bg: var(--zool-deep);
}

@media (prefers-color-scheme: dark) {
    html[data-theme="auto"] {
        --body-bg: #152119;
        --hairline-color: #33483c;
    }
}

html[data-theme="dark"] {
    --primary: #366d52;
    --secondary: #1e4031;
    --accent: #f6e6b9;
    --button-bg: #2d5f49;
}

html[data-theme] :is(button, input, select, textarea, a):focus-visible {
    outline: 2px solid var(--zool-focus);
    outline-offset: 2px;
}

html[data-theme] :is(.module, .submit-row, .selector, .object-tools a) {
    border-radius: 8px;
}

.zool-ui .guide-page {
    max-width: 1050px;
    padding-block: clamp(2rem, 5vw, 3.5rem);
}

.zool-ui .guide-step {
    margin-top: 2.5rem;
}

.zool-ui .guide-step p {
    max-width: 72ch;
}

.zool-ui .guide-image {
    display: block;
    overflow: hidden;
    border: 1px solid var(--zool-line);
    border-radius: var(--zool-radius);
    box-shadow: var(--zool-shadow);
    background: var(--zool-surface);
}

.zool-ui .guide-image img {
    display: block;
    width: 100%;
    height: auto;
}
