:root {
    --bg: #f2f0e7;
    --bg-strong: #e2e4d8;
    --surface: #fbfaf5;
    --surface-alt: #e8ede1;
    --primary: #315f45;
    --primary-deep: #183a2e;
    --primary-soft: #bdd0b9;
    --accent: #d59a3a;
    --accent-soft: #f3e2bc;
    --danger: #a8432e;
    /* IUCN status colours, shared by the field-guide page and every badge on the home page. */
    --status-cr: var(--danger);
    --status-en: #b67627;
    --status-vu: #677446;
    --text: #1e2d25;
    --muted: #5d6b62;
    --line: #cbd0c4;
    --shadow: 0 24px 60px rgba(25, 49, 38, 0.18);
    --radius: 14px;
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    margin: 0;
    font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
    line-height: 1.7;
    color: var(--text);
    background: var(--bg);
    overflow-x: hidden;
}

a {
    color: var(--primary);
    transition: color 0.2s ease, opacity 0.2s ease;
}

a:hover,
a:focus-visible {
    color: var(--primary-deep);
}

header,
body > footer {
    color: white;
    background: var(--primary-deep);
    box-shadow: var(--shadow);
}

header {
    padding: 1rem 2rem;
}

body > footer {
    display: flex;
    gap: 1rem 2rem;
    align-items: center;
    justify-content: space-between;
    padding: 1.1rem 2rem;
}

nav {
    display: flex;
    gap: 1rem;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
}

nav a {
    color: white;
    text-decoration: none;
}

nav .logo {
    display: inline-flex;
    gap: 0.7rem;
    align-items: center;
    font-size: 1.2rem;
    font-weight: 800;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

nav .logo svg {
    flex: 0 0 auto;
    color: #d7b56f;
}

nav .links {
    display: flex;
    gap: 1.5rem;
    padding: 0;
    margin: 0 auto;
    list-style: none;
}

nav .links a {
    position: relative;
    font-weight: 600;
    opacity: 0.9;
}

nav .links a::after {
    content: "";
    position: absolute;
    left: 0;
    bottom: -0.35rem;
    width: 100%;
    height: 2px;
    background: var(--accent);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.2s ease;
}

nav .links a:hover::after,
nav .links a:focus-visible::after {
    transform: scaleX(1);
}

.nav-toggle {
    display: none;
}

header.has-toggle .nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    margin-left: 0.5rem;
    padding: 0;
    color: #f2f0e7;
    font: inherit;
    line-height: 1;
    background: rgba(3, 7, 17, 0.35);
    border: 1px solid rgba(242, 240, 231, 0.35);
    border-radius: 50%;
    cursor: pointer;
    backdrop-filter: blur(6px);
}

.nav-toggle:hover,
.nav-toggle:focus-visible {
    background: rgba(3, 7, 17, 0.6);
}

/* The panel wrapper is layout-neutral on the horizontal bar. */
.nav-panel {
    display: contents;
}

header:not(.is-collapsed) .nav-toggle {
    order: 1;
}

header.is-collapsed nav {
    justify-content: flex-end;
}

header.is-collapsed .nav-panel {
    display: none;
}

nav a:hover,
nav a:focus-visible {
    color: #fff7e8;
}

main {
    flex: 1;
    width: 100%;
    min-width: 0;
    max-width: 1120px;
    padding: 1.4rem 2rem 4rem;
    margin: 0 auto;
}

.home-page {
    padding-top: 2rem;
}

.wild-hero {
    position: relative;
    min-height: clamp(520px, 72vh, 700px);
    overflow: hidden;
    color: white;
    background: var(--primary-deep);
    border-radius: 0 0 28px 28px;
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 100%;
}

.wild-hero::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, rgba(12, 32, 24, .92) 0%, rgba(18, 42, 30, .58) 45%, rgba(18, 42, 30, .08) 76%);
}

.wild-hero img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    object-fit: cover;
    border: 0;
    border-radius: 0;
    box-shadow: none;
}

.wild-hero__content {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: inherit;
    max-width: 640px;
    width: 100%;
    padding: clamp(2rem, 7vw, 5rem);
}

.eyebrow {
    margin: 0 0 1rem;
    color: #8ce1dc;
    font-size: .78rem;
    font-weight: 800;
    letter-spacing: .16em;
    text-transform: uppercase;
}

.wild-hero h1 {
    max-width: 8ch;
    margin: 0 0 1.2rem;
    color: white;
    font-family: Georgia, "Times New Roman", serif;
    font-size: clamp(3.2rem, 8vw, 5.8rem);
    line-height: .95;
    letter-spacing: -.035em;
}

.wild-hero__content > p {
    max-width: 46ch;
    margin: 0;
    color: #f2efe4;
    font-size: clamp(1.05rem, 2vw, 1.35rem);
    overflow-wrap: anywhere;
}

.primary-link {
    align-self: flex-start;
    margin-top: 2rem;
    padding: .75rem 1.1rem;
    color: var(--primary-deep);
    font-weight: 800;
    text-decoration: none;
    background: var(--accent);
    border-radius: 8px;
}

.intro-grid {
    display: grid;
    grid-template-columns: 1.1fr .9fr;
    gap: clamp(2rem, 7vw, 6rem);
    align-items: start;
    padding: clamp(3.5rem, 8vw, 7rem) 0;
}

.intro-grid h2 {
    margin-top: 0;
}

.field-notes {
    margin: 0;
    border-top: 1px solid var(--line);
}

.field-notes div {
    display: grid;
    grid-template-columns: 7rem 1fr;
    gap: 1rem;
    align-items: baseline;
    padding: 1.15rem 0;
    border-bottom: 1px solid var(--line);
}

.field-notes dt {
    color: var(--primary);
    font-family: Georgia, "Times New Roman", serif;
    font-size: 1.5rem;
    font-weight: 850;
}

.field-notes dd {
    margin: 0;
    color: var(--muted);
}

.pathways {
    padding: 0 0 3rem;
}

.pathways__grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    border-top: 1px solid var(--line);
}

.pathways__grid a {
    display: flex;
    flex-direction: column;
    gap: .5rem;
    min-height: 180px;
    padding: 1.5rem;
    text-decoration: none;
    border-bottom: 1px solid var(--line);
    border-right: 1px solid var(--line);
}

.pathways__grid a:last-child {
    border-right: 0;
}

.pathways__grid strong {
    font-size: 1.15rem;
}

.pathways__grid span {
    color: var(--muted);
}

.pathways__grid a::after {
    content: "→";
    margin-top: auto;
    color: var(--accent);
    font-size: 1.5rem;
}

.lead {
    max-width: 62ch;
    color: var(--muted);
    font-size: 1.2rem;
}

.page-intro {
    max-width: 900px;
    padding: clamp(2.5rem, 7vw, 5.5rem) 0 3rem;
    border-bottom: 1px solid var(--line);
}

.page-intro h1 {
    max-width: 12ch;
    margin-bottom: 1rem;
    font-size: clamp(3rem, 7vw, 5.5rem);
}

.page-intro p {
    max-width: 54ch;
    margin: 0;
    color: var(--muted);
    font-size: 1.2rem;
}

.section-heading {
    display: flex;
    gap: 2rem;
    align-items: end;
    justify-content: space-between;
    margin: 3.5rem 0 1.5rem;
}

#habitats {
    position: relative;
    isolation: isolate;
}

.habitat-content {
    position: relative;
    z-index: 1;
}

.ocean-scene {
    position: sticky;
    top: 0;
    z-index: 0;
    width: 100vw;
    height: 100vh;
    margin-bottom: -100vh;
    margin-left: calc(50% - 50vw);
    overflow: hidden;
    pointer-events: none;
    background: #092c3d;
    opacity: 0;
    visibility: hidden;
    transition: opacity 520ms cubic-bezier(0.16, 1, 0.3, 1), visibility 0s linear 520ms;
}

.ocean-scene canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.ocean-scene__readout {
    position: absolute;
    right: clamp(1.2rem, 4vw, 3rem);
    bottom: 1.35rem;
    display: flex;
    gap: 1rem;
    align-items: center;
    color: rgba(236, 249, 246, .88);
    font-size: .7rem;
    font-weight: 750;
    letter-spacing: .13em;
    text-transform: uppercase;
    text-shadow: 0 2px 12px rgba(0, 24, 36, .72);
}

.ocean-scene__readout span + span {
    padding-left: 1rem;
    border-left: 1px solid rgba(226, 247, 243, .38);
    font-variant-numeric: tabular-nums;
}

#habitats.is-ocean {
    padding-bottom: 14vh;
}

#habitats.is-ocean .ocean-scene {
    opacity: 1;
    visibility: visible;
    transition: opacity 620ms cubic-bezier(0.16, 1, 0.3, 1), visibility 0s;
}

#habitats.is-ocean .section-heading {
    padding: 1.25rem 1.4rem;
    background: rgba(242, 240, 231, .92);
    border-radius: var(--radius);
    box-shadow: 0 18px 46px rgba(0, 35, 50, .18);
    -webkit-backdrop-filter: blur(10px) saturate(112%);
    backdrop-filter: blur(10px) saturate(112%);
}

#habitats.is-ocean .animal-list {
    border-color: rgba(218, 231, 226, .56);
    background: rgba(198, 218, 212, .52);
    box-shadow: 0 28px 80px rgba(0, 28, 44, .24);
}

#habitats.is-ocean .animal-profile {
    background: rgba(251, 250, 245, .91);
    -webkit-backdrop-filter: blur(12px) saturate(110%);
    backdrop-filter: blur(12px) saturate(110%);
}

#habitats.is-ocean .filter-status {
    display: inline-block;
    padding: .35rem .7rem;
    color: #effbf8;
    background: rgba(5, 45, 61, .62);
    border-radius: 6px;
    text-shadow: 0 1px 7px rgba(0, 20, 32, .7);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
}

.ocean-scene--fallback .ocean-scene {
    background:
        radial-gradient(circle at 68% 16%, rgba(255, 218, 145, .58), transparent 16%),
        linear-gradient(180deg, #73b8d2 0%, #d4b67f 36%, #1a6576 39%, #06324a 100%);
}

.section-heading h2,
.section-heading p { margin: 0; }
.section-heading p { color: var(--muted); }

.filters { display: flex; flex-wrap: wrap; gap: .55rem; }
.filter {
    padding: .55rem .9rem;
    color: var(--primary-deep);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    background: transparent;
    border: 1px solid var(--primary-soft);
    border-radius: 999px;
}
.filter:hover,
.filter.is-active { color: white; background: var(--primary); border-color: var(--primary); }
.filter:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

.animal-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1px;
    overflow: hidden;
    background: var(--line);
    border: 1px solid var(--line);
    border-radius: 18px;
}
.animal-profile {
    position: relative;
    display: grid;
    grid-template-columns: minmax(9.5rem, .72fr) minmax(0, 1.28fr);
    gap: 1.5rem;
    align-items: start;
    min-height: 520px;
    padding: 1.7rem;
    overflow: hidden;
    background: var(--surface);
}
.animal-profile__image {
    position: relative;
    z-index: 1;
    grid-column: 1 / -1;
    width: calc(100% + 3.4rem);
    aspect-ratio: 16 / 9;
    margin: -1.7rem -1.7rem 0;
    overflow: hidden;
    background: var(--surface-alt);
}
.animal-profile__image img {
    width: 100%;
    height: 100%;
    margin: 0;
    object-fit: cover;
    border: 0;
    border-radius: 0;
    box-shadow: none;
}
.animal-profile__image.is-unavailable {
    display: grid;
    place-items: center;
    color: var(--muted);
    font-size: .82rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
}
.animal-profile::after {
    content: "";
    position: absolute;
    right: -3rem;
    bottom: -4rem;
    width: 10rem;
    height: 10rem;
    background: radial-gradient(circle, rgba(189, 208, 185, .32) 0 33%, transparent 34% 100%);
    border: 1px solid rgba(49, 95, 69, .12);
    border-radius: 50%;
}
.animal-profile__identity,
.animal-profile__body { position: relative; z-index: 1; }
.animal-profile__identity { display: flex; flex-direction: column; align-items: flex-start; }
.animal-profile__body { display: grid; gap: .75rem; padding-top: 2.35rem; }
.specimen-number {
    display: block;
    margin-bottom: 1rem;
    color: var(--primary);
    font-size: .72rem;
    font-weight: 800;
    letter-spacing: .12em;
    text-transform: uppercase;
}
.scientific-name {
    margin-top: .4rem !important;
    font-family: Georgia, "Times New Roman", serif;
    font-size: .9rem;
    font-style: italic;
}
.animal-profile__feature {
    color: var(--text) !important;
    font-size: 1.03rem;
    line-height: 1.55;
}
.animal-profile[hidden] { display: none; }
.animal-profile h3 { margin: .85rem 0 0; color: var(--text); font-family: Georgia, "Times New Roman", serif; font-size: 1.55rem; }
.animal-profile p { margin: 0; color: var(--muted); }
.status { align-self: start; width: fit-content; padding: .28rem .55rem; color: white !important; font-size: .75rem; font-weight: 800; line-height: 1.25; text-transform: uppercase; border-radius: 4px; }
.status--critical { background: var(--status-cr); }
.status--endangered { background: var(--status-en); }
.status--vulnerable { background: var(--status-vu); }
.filter-status { margin: .9rem 0 0; color: var(--muted); font-size: .9rem; }
.coursework-plan { max-width: 780px; padding: 4rem 0 1rem; }

main > p,
main > ul,
main > dl {
    max-width: 70ch;
}

h1,
h2,
h3 {
    color: var(--primary);
    font-weight: 800;
    line-height: 1.2;
    letter-spacing: -0.02em;
}

h1,
h2 {
    font-family: Georgia, "Times New Roman", serif;
}

h1 {
    margin: 0 0 1rem;
    font-size: clamp(2.2rem, 3vw, 3.3rem);
}

h2 {
    margin: 2.4rem 0 0.85rem;
    font-size: clamp(1.5rem, 2vw, 2.2rem);
}

img {
    display: block;
    width: 100%;
    max-width: 100%;
    height: auto;
    margin-top: 1.5rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.image-credit {
    margin: 0.6rem 0 0;
    color: var(--muted);
    font-size: 0.85rem;
}

footer p,
footer address {
    margin: 0;
}

body > footer a {
    color: white;
}

.project-details {
    padding: 1rem 1.2rem;
    background: rgba(255, 255, 255, 0.7);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.project-details dt {
    margin-top: 1rem;
    font-weight: 800;
    color: var(--primary);
}

.project-details dt:first-child {
    margin-top: 0;
}

.project-details dd {
    margin: 0.35rem 0 0;
    color: var(--muted);
}

a:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 3px;
}

::selection {
    color: white;
    background: var(--primary);
}

@media (max-width: 820px) {
    header,
    body > footer {
        padding: 1rem 1.1rem;
    }

    nav {
        flex-direction: column;
        align-items: flex-start;
    }

    nav .links {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.75rem 1rem;
        width: 100%;
        margin: 0;
    }

    body > footer {
        flex-direction: column;
        align-items: flex-start;
    }

    main {
        padding: 2rem 1.25rem 3rem;
    }

    .home-page {
        padding-top: 1.25rem;
    }

    .wild-hero {
        min-height: 570px;
        border-radius: 0 0 24px 24px;
    }

    .wild-hero::after {
        background: linear-gradient(0deg, rgba(12, 32, 24, .96) 0%, rgba(12, 32, 24, .22) 76%);
    }

    .wild-hero img {
        object-position: 67% center;
    }

    .wild-hero__content {
        justify-content: flex-end;
        width: 100%;
        min-width: 0;
        padding: 2rem 1.4rem 2.5rem;
    }

    .wild-hero__content > p {
        max-width: 100%;
        font-size: 1rem;
    }

    .intro-grid,
    .pathways__grid {
        grid-template-columns: 1fr;
    }

    .pathways__grid a {
        min-height: 145px;
        border-right: 0;
    }

    .section-heading { align-items: flex-start; flex-direction: column; }
    #habitats.is-ocean { padding-bottom: 8vh; }
    #habitats.is-ocean .section-heading { padding: 1rem; }
    .ocean-scene__readout { right: 1rem; bottom: 1rem; gap: .65rem; font-size: .62rem; }
    .ocean-scene__readout span + span { padding-left: .65rem; }
    .animal-list { grid-template-columns: 1fr; }
    .animal-profile { grid-template-columns: minmax(0, 1fr); gap: .75rem; min-height: 0; padding: 1.4rem; }
    .animal-profile__image { width: calc(100% + 2.8rem); margin: -1.4rem -1.4rem .35rem; }
    .animal-profile__body { padding-top: .25rem; }
}

@media (prefers-reduced-motion: reduce) {
    .ocean-scene {
        transition-duration: 160ms;
    }
}

/* Language menu under "Settings" on the field-guide page (the home page styles it as .habitat-menu). */
body:not(.home) nav .links li { position: relative; }
body:not(.home) .settings-menu { position: absolute; top: calc(100% + .6rem); right: 0; z-index: 20; display: none; min-width: 7rem; margin: 0; padding: .5rem .8rem; list-style: none; color: var(--text); background: var(--surface); border: 1px solid rgba(0,0,0,.15); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.18); }
body:not(.home) .settings-menu.is-open { display: grid; gap: .4rem; }
body:not(.home) .settings-menu button { padding: 0; color: inherit; font: inherit; text-align: left; background: none; border: 0; cursor: pointer; opacity: .75; }
body:not(.home) .settings-menu button:hover, body:not(.home) .settings-menu button:focus-visible { opacity: 1; }
body:not(.home) .settings-menu button[aria-pressed="true"] { color: var(--accent); font-weight: 700; opacity: 1; }

/* Language switch: page text fades out, changes language, then fades back in (i18n.js). */
html.i18n-out body > :not(.earth-viewport):not(script):not(style) { opacity: 0 !important; transition: opacity .9s ease !important; }
html.i18n-in body > :not(.earth-viewport):not(script):not(style) { transition: opacity 1.4s ease !important; }
