/*
 * ECODEX coherent design layer
 *
 * This stylesheet is deliberately loaded after the historic page styles.
 * It harmonises the shared shell and reusable interface components while
 * leaving profile cosmetics and page-specific content behaviour intact.
 */

:root {
  --ecodex-layout-max: 1180px;
  --ecodex-page-gap: 16px;
  --ecodex-shell-padding: clamp(10px, 1.55vw, 18px);
  --ecodex-canvas-padding: clamp(10px, 1.6vw, 16px);
  --ecodex-panel-padding: clamp(14px, 2.2vw, 22px);
  --ecodex-radius-sm: 6px;
  --ecodex-radius-md: 8px;
  --ecodex-radius-lg: 12px;
  --ecodex-border: 3px;
  --ecodex-shadow: 0 7px 0 rgba(23, 24, 29, .2), 0 18px 36px rgba(23, 24, 29, .13);
  --ecodex-shadow-small: 0 4px 0 rgba(23, 24, 29, .18);
  --page-primary: #348b5d;
  --page-primary-dark: #236442;
  --page-primary-light: #b9ddc5;
  --page-accent: #f4bf45;
  --page-text: #17181d;
  --page-muted: #4e5960;
  --page-border: rgba(35, 100, 66, .76);
  --page-canvas-bg: rgba(225, 241, 227, .54);
  --page-panel-bg: rgba(255, 253, 247, .70);
  --page-field-bg: rgba(255, 253, 247, .96);
}

body[data-page-theme="collection"] {
  --page-primary: #348b5d;
  --page-primary-dark: #236442;
  --page-primary-light: #b9ddc5;
  --page-accent: #f4bf45;
  --page-border: rgba(35, 100, 66, .76);
  --page-canvas-bg: rgba(219, 238, 219, .50);
  --page-panel-bg: rgba(255, 253, 247, .68);
}

body[data-page-theme="phylogeny"] {
  --page-primary: #2f7f45;
  --page-primary-dark: #19542e;
  --page-primary-light: #b9dcb9;
  --page-accent: #e4ba51;
  --page-border: rgba(25, 84, 46, .76);
  --page-canvas-bg: rgba(219, 237, 215, .52);
  --page-panel-bg: rgba(250, 252, 244, .68);
}

body[data-page-theme="tools"] {
  --page-primary: #c89b27;
  --page-primary-dark: #8b6417;
  --page-primary-light: #efdfaa;
  --page-accent: #348b5d;
  --page-border: rgba(139, 100, 23, .78);
  --page-canvas-bg: rgba(243, 231, 190, .52);
  --page-panel-bg: rgba(255, 252, 240, .68);
}

body[data-page-theme="nature"] {
  --page-primary: #a65867;
  --page-primary-dark: #79414d;
  --page-primary-light: #e6bcc4;
  --page-accent: #f0bd45;
  --page-border: rgba(121, 65, 77, .76);
  --page-canvas-bg: rgba(235, 210, 215, .50);
  --page-panel-bg: rgba(255, 250, 247, .68);
}

body[data-page-theme="planner"] {
  --page-primary: #8b5f3d;
  --page-primary-dark: #5b3e27;
  --page-primary-light: #ddbd96;
  --page-accent: #e5b56f;
  --page-border: rgba(91, 62, 39, .8);
  --page-canvas-bg: rgba(225, 204, 180, .50);
  --page-panel-bg: rgba(255, 248, 237, .66);
}

body[data-page-theme="observations"] {
  --page-primary: #2f8fc5;
  --page-primary-dark: #21678f;
  --page-primary-light: #b9deed;
  --page-accent: #f1c34a;
  --page-border: rgba(33, 103, 143, .78);
  --page-canvas-bg: rgba(211, 234, 242, .52);
  --page-panel-bg: rgba(247, 253, 255, .68);
}

body[data-page-theme="achievements"] {
  --page-primary: #24598f;
  --page-primary-dark: #173f70;
  --page-primary-light: #b6d0e5;
  --page-accent: #f2c44c;
  --page-border: rgba(23, 63, 112, .8);
  --page-canvas-bg: rgba(204, 223, 238, .52);
  --page-panel-bg: rgba(247, 251, 254, .68);
}

body[data-page-theme="social"] {
  --page-primary: #596168;
  --page-primary-dark: #33383f;
  --page-primary-light: #cbd0d3;
  --page-accent: #73c7c2;
  --page-border: rgba(51, 56, 63, .78);
  --page-canvas-bg: rgba(218, 222, 225, .52);
  --page-panel-bg: rgba(250, 250, 247, .70);
}

body[data-page-theme="settings"] {
  --page-primary: #348b5d;
  --page-primary-dark: #236442;
  --page-primary-light: #b9ddc5;
  --page-accent: #f4bf45;
  --page-border: rgba(35, 100, 66, .76);
  --page-canvas-bg: rgba(219, 238, 219, .52);
  --page-panel-bg: rgba(255, 253, 247, .70);
}

body[data-page-theme="about"] {
  --page-primary: #be3935;
  --page-primary-dark: #82262a;
  --page-primary-light: #e9b8b4;
  --page-accent: #f0bd45;
  --page-border: rgba(130, 38, 42, .78);
  --page-canvas-bg: rgba(235, 204, 202, .50);
  --page-panel-bg: rgba(255, 249, 246, .68);
}

/* Shared fixed world layer and content width. */
body {
  color: var(--page-text);
  background-color: var(--theme-page);
}

.app-shell {
  width: min(var(--ecodex-layout-max), 100%);
  padding: max(var(--ecodex-shell-padding), env(safe-area-inset-top)) max(var(--ecodex-shell-padding), env(safe-area-inset-right)) max(var(--ecodex-shell-padding), env(safe-area-inset-bottom)) max(var(--ecodex-shell-padding), env(safe-area-inset-left));
}

.app-shell::before {
  position: fixed;
  inset: 0 auto auto 50%;
  width: 100vw;
  height: 100dvh;
  min-height: 100vh;
  background-image:
    linear-gradient(180deg, color-mix(in srgb, var(--page-primary-dark) 9%, transparent), color-mix(in srgb, var(--theme-fade) 54%, transparent)),
    var(--theme-banner);
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  pointer-events: none;
}

main {
  display: block;
  width: 100%;
  min-width: 0;
}

/* One header rhythm for every application page. */
.topbar {
  box-sizing: border-box;
  height: 108px;
  min-height: 108px;
  padding: 16px 22px;
  border: 4px solid color-mix(in srgb, var(--page-primary-dark) 72%, var(--line));
  border-radius: var(--ecodex-radius-md) var(--ecodex-radius-md) var(--ecodex-radius-lg) var(--ecodex-radius-lg);
  background: linear-gradient(180deg, color-mix(in srgb, var(--page-primary) 92%, #fff 8%), var(--page-primary-dark));
  box-shadow: var(--ecodex-shadow);
}

/* Direct manipulation while horizontally moving between primary pages. */
body.page-swiping,
body.page-swipe-settling {
  overflow-x: hidden;
}

body.page-swiping .app-shell,
body.page-swipe-settling .app-shell {
  transform: translate3d(var(--page-swipe-x, 0px), 0, 0);
  filter: none;
}

body.page-swipe-handoff > .app-shell {
  visibility: hidden;
}

body.page-swiping .app-shell {
  transition: none !important;
}

body.page-swipe-settling .app-shell,
body.page-swipe-settling .page-swipe-preview-stage {
  transition: transform 330ms cubic-bezier(.22, .78, .2, 1) !important;
}

.page-swipe-preview-stage {
  position: fixed;
  z-index: 85;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  transform: translate3d(var(--page-swipe-preview-x, 100vw), 0, 0);
  will-change: transform;
}

.page-swipe-preview-stage.is-handoff-fading {
  opacity: 0;
  transition: opacity 150ms ease-out !important;
}

.page-swipe-preview {
  position: absolute;
  inset: 0 auto auto 50%;
  width: min(var(--ecodex-layout-max), 100%);
  min-height: 100dvh;
  margin: 0;
  transform: translateX(-50%) !important;
  transition: none !important;
  overflow: hidden;
}

.page-swipe-preview :is(button, input, select, textarea, summary, a) {
  pointer-events: none !important;
}

/* Profiel gebruikt de gekozen Kleur 1 voor de paginaheader. De algemene
   paginastijl mag deze persoonlijke kleur niet terugzetten naar profielgrijs. */
body[data-view="profile"] .topbar,
body[data-view="friend-profile"] .topbar {
  border-color: color-mix(in srgb, var(--theme-top, var(--page-primary-dark)) 72%, var(--line));
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--theme-top, var(--page-primary)) 92%, #fff 8%),
    color-mix(in srgb, var(--theme-top, var(--page-primary-dark)) 82%, #17181d 18%)
  );
}

/* Het vriendenprofiel houdt zijn cosmetische kader intact; alleen de buitenrand
   krijgt een zachte, transparante afleiding van Kleur 1. */
body[data-view="friend-profile"] .topbar,
body[data-view="friend-profile"] .social-readonly-profile-shell {
  border-color: color-mix(in srgb, var(--friend-sheet-primary, var(--theme-top)) 58%, transparent);
}

/* Twee gelijke profielomslagen rond de cosmetische kaders:
   buiten en binnen 45% Kleur 1. De lijnen zijn volle
   themakleuren: buiten Kleur 1 en binnen Kleur 2. */
body[data-view="profile"] main > .profile-page.profile-page-customised,
body[data-view="friend-profile"] .social-readonly-profile-shell {
  border-color: var(--theme-page) !important;
}

body[data-view="profile"] main > .profile-page.profile-page-customised {
  background-color: color-mix(in srgb, var(--theme-page) 45%, transparent) !important;
}

body:is([data-view="profile"], [data-view="friend-profile"]) .profile-own-view {
  border-color: transparent !important;
  background: color-mix(in srgb, var(--profile-primary, var(--theme-page)) 45%, transparent) !important;
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--profile-primary, var(--theme-page)) 45%, transparent);
  outline: 3px solid var(--profile-secondary, var(--theme-bottom));
  outline-offset: 4px;
}

/* De buitenste banner vult bij het openen precies het zichtbare scherm en
   scrolt daarna normaal omhoog. */
body[data-view="profile"].profile-page-has-custom-banner .app-shell::before {
  position: absolute;
  background-color: var(--theme-page);
  background-image: var(--theme-banner);
  background-position: center top;
  /* Behoud de oorspronkelijke verhouding van de liggende banner. */
  background-size: 100vw auto;
  background-repeat: no-repeat;
}

body[data-view="profile"][data-profile-banner-fit="wide"].profile-page-has-custom-banner .app-shell::before {
  background-size: 113vw auto;
}

body[data-view="profile"].profile-page-has-custom-banner .profile-page.profile-page-customised.profile-page-has-banner {
  background-color: transparent;
  background-image: none;
}

/* Zonder een permanente transform op .app-shell kan deze laag werkelijk vast
   aan de viewport staan. De profielomslag knipt hem uitsluitend visueel af. */
body[data-view="profile"].profile-page-has-custom-banner main > .profile-page.profile-page-customised.profile-page-has-banner {
  overflow: hidden;
  background-color: color-mix(in srgb, var(--theme-page) 45%, transparent) !important;
  background-image:
    linear-gradient(
      color-mix(in srgb, var(--theme-page) 45%, transparent),
      color-mix(in srgb, var(--theme-page) 45%, transparent)
    ),
    var(--profile-page-banner) !important;
  background-position:
    0 0,
    center top !important;
  background-size: 100% 100%, 100vw auto !important;
  background-repeat: no-repeat, no-repeat !important;
  background-attachment: scroll, fixed !important;
  background-origin: border-box, border-box !important;
  background-clip: border-box, border-box !important;
  transition-property: background-color, border-color, color !important;
}

body[data-view="profile"][data-profile-banner-fit="wide"].profile-page-has-custom-banner main > .profile-page.profile-page-customised.profile-page-has-banner {
  background-size: 100% 100%, 113vw auto !important;
}

body[data-view="friend-profile"] .social-readonly-profile-shell {
  background-position: center top !important;
  background-size: cover !important;
  background-repeat: no-repeat !important;
  background-attachment: fixed !important;
}

/* Vriendenprofielen zijn gewone pagina's, ook op mobiel. Deze harde reset
   voorkomt dat eigenschappen van de mobiele popup-sheets erop doorwerken. */
@media (max-width: 700px), (max-aspect-ratio: 4/5), (max-height: 500px) and (pointer: coarse) {
  body[data-view="friend-profile"] .friend-profile-page {
    position: static !important;
    inset: auto !important;
    display: block !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: var(--ecodex-page-gap) 0 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: none !important;
    box-shadow: none !important;
    opacity: 1 !important;
    transform: none !important;
    animation: none !important;
  }

  body[data-view="friend-profile"] #friendProfilePageContent {
    position: static !important;
    width: 100% !important;
    height: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    transform: none !important;
  }

  body[data-view="friend-profile"] .social-readonly-profile-shell {
    position: static !important;
    min-height: 0 !important;
    height: auto !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 10px !important;
    overflow: visible !important;
    border-radius: 8px !important;
    transform: none !important;
  }

  body[data-view="friend-profile"] .social-readonly-profile {
    position: static !important;
    margin: 0 auto !important;
    transform: none !important;
  }
}

/* Verduisteringsthema's: geen filter over de banner en geen extra profielkader.
   Kleur 1 blijft de paginakleur; Kleur 2 is een gewone, rustige paneelvulling. */
body[data-view="profile"]:is(
  [data-dynamic-page-theme="gouden-uur-theme"],
  [data-dynamic-page-theme="nachtvlinder-theme"]
) {
  min-height: 100vh;
  background-color: var(--theme-page) !important;
  background-image: none !important;
}

body[data-view="profile"][data-dynamic-page-theme="gouden-uur-theme"] {
  animation: none;
}

body[data-view="profile"][data-dynamic-page-theme="nachtvlinder-theme"] {
  animation: none;
}

@keyframes ecodex-lunar-theme-flow {
  from { --theme-page: #a43f49; --theme-top: #7f2934; --theme-bottom: #d66b72; }
  to { --theme-page: #d66b72; --theme-top: #a43f49; --theme-bottom: #edc56c; }
}

@keyframes ecodex-solar-theme-flow {
  from { --theme-page: #b96508; --theme-top: #9d5005; --theme-bottom: #d88a14; }
  to { --theme-page: #d88912; --theme-top: #b96508; --theme-bottom: #efb43b; }
}

.profile-own-view:is(
  [data-dynamic-primary="gouden-uur-theme"],
  [data-dynamic-primary="nachtvlinder-theme"]
) {
  border: 0;
  border-radius: 0;
  padding: 0;
  background: none;
  box-shadow: none;
}

body[data-view="profile"],
.profile-own-view {
  transition: --theme-page 1s ease-in-out, --theme-top 1s ease-in-out,
    --theme-bottom 1s ease-in-out, --profile-primary 1s ease-in-out,
    --profile-secondary 1s ease-in-out, background-color 1s ease-in-out,
    border-color 1s ease-in-out;
}

.profile-own-view :is(
  .profile-header-card,
  .profile-collection-card,
  .profile-showcase,
  .profile-sticker-studio,
  .profile-style-card
) {
  transition: background-color 1s ease-in-out, border-color 1s ease-in-out,
    color 1s ease-in-out;
}

/* Pagina's wisselen direct naar hun eigen palet. De 1-seconde-overgang is
   uitsluitend voor kleurveranderingen binnen het geopende profiel. */
body.page-theme-switching,
body.page-theme-switching::before,
body.page-theme-switching .app-shell::before,
body.page-theme-switching .topbar,
body.page-theme-switching .profile-own-view,
body.page-theme-switching .profile-own-view :is(
  .profile-header-card,
  .profile-collection-card,
  .profile-showcase,
  .profile-sticker-studio,
  .profile-style-card
) {
  transition: none !important;
}

.profile-own-view:is(
  [data-dynamic-secondary="gouden-uur-theme"],
  [data-dynamic-secondary="nachtvlinder-theme"]
) :is(
  .profile-collection-card,
  .profile-showcase,
  .profile-sticker-studio,
  .profile-style-card
) {
  background-color: color-mix(in srgb, var(--profile-secondary) 72%, #fff 28%);
  background-image: none;
}

@media (prefers-reduced-motion: reduce) {
  body[data-view="profile"]:is(
    [data-dynamic-page-theme="gouden-uur-theme"],
    [data-dynamic-page-theme="nachtvlinder-theme"]
  ) {
    animation: none;
  }
}

.topbar-title {
  width: 100%;
  text-align: center;
}

.topbar-title .kicker {
  margin-bottom: 5px;
  font-size: .76rem;
  letter-spacing: .075em;
}

.topbar-title h1 {
  font-size: clamp(2.75rem, 6vw, 4.1rem);
  line-height: .9;
}

.menu-toggle,
.friend-profile-back {
  width: 52px;
  height: 52px;
  border-radius: var(--ecodex-radius-md);
  box-shadow: var(--ecodex-shadow-small);
}

/* The profile already supplies the reference layout. Other primary views use
   the same translucent canvas without touching profile cosmetics. */
main > :is(.phylogeny-view, .items-page, .nature-page, .planner-page, .observations-page, .achievements-page, .social-page, .settings-page, .about-page) {
  width: 100%;
  margin-top: var(--ecodex-page-gap);
  padding: var(--ecodex-canvas-padding);
  border: 4px solid var(--page-border);
  border-radius: var(--ecodex-radius-lg);
  background: var(--page-canvas-bg);
  box-shadow: var(--ecodex-shadow);
  backdrop-filter: blur(1.5px);
}

main > :is(.items-page, .nature-page, .planner-page, .observations-page, .achievements-page, .social-page, .settings-page) {
  gap: var(--ecodex-page-gap);
}

main > .collection-panel {
  border-color: var(--page-border);
  border-radius: var(--ecodex-radius-lg);
  background-color: var(--page-panel-bg);
  box-shadow: var(--ecodex-shadow);
  backdrop-filter: blur(1.5px);
}

/* Keep the collection cards visually together, like a page from one field
   guide, without competing with the stronger borders on the cards. */
main > #speciesGrid {
  margin-top: var(--ecodex-page-gap);
  padding: clamp(7px, 1.2vw, 14px);
  border: 4px solid var(--page-border);
  border-radius: var(--ecodex-radius-lg);
  background:
    linear-gradient(rgba(255, 255, 255, .12), rgba(255, 255, 255, .04)),
    color-mix(in srgb, var(--page-panel-bg) 78%, transparent);
  box-shadow:
    inset 0 0 0 2px color-mix(in srgb, var(--page-primary) 32%, transparent),
    var(--ecodex-shadow);
  backdrop-filter: blur(1.5px);
}

/* Shared in-page title header. */
:is(.phylogeny-header, .items-header, .nature-hero, .observations-header, .achievements-hero, .social-hero, .about-hero) {
  display: flex;
  min-height: 148px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: clamp(20px, 3vw, 28px);
  overflow: hidden;
  border: var(--ecodex-border) solid color-mix(in srgb, var(--page-primary-dark) 76%, var(--line));
  border-radius: var(--ecodex-radius-md);
  color: #fff;
  background:
    linear-gradient(112deg, color-mix(in srgb, var(--page-primary-dark) 94%, transparent), color-mix(in srgb, var(--page-primary) 76%, transparent)),
    var(--theme-banner) center / cover;
  box-shadow: var(--ecodex-shadow-small);
}

:is(.phylogeny-header, .items-header, .nature-hero, .observations-header, .achievements-hero, .social-hero, .about-hero) h2,
.planner-builder > header h2 {
  margin: 3px 0 7px;
  font-size: clamp(2.1rem, 4.6vw, 3.25rem);
  line-height: .96;
  letter-spacing: -.018em;
}

:is(.phylogeny-header, .items-header, .nature-hero, .observations-header, .achievements-hero, .social-hero, .about-hero) p:last-child,
.planner-builder > header p {
  max-width: 720px;
  margin: 0;
  color: rgba(255, 255, 255, .94);
  font-size: 1rem;
  font-weight: 750;
  line-height: 1.45;
}

/* The top bar already names the page. These compact introductions provide
   context without repeating a second oversized title underneath it. */
.compact-page-intro {
  min-height: 104px;
  padding-block: clamp(16px, 2.3vw, 22px);
}

.compact-page-intro .page-intro-copy {
  max-width: 760px;
  margin: 4px 0 0;
  font-size: clamp(.96rem, 1.6vw, 1.08rem);
  font-weight: 800;
  line-height: 1.42;
}

:is(.phylogeny-header, .items-header, .nature-hero, .observations-header, .achievements-hero, .social-hero) .kicker {
  color: color-mix(in srgb, var(--page-primary-light) 58%, #fff 42%);
}

/* Matching compact statistic tiles. */
:is(.items-counter, .nature-hero-card, .achievement-wallet, .tree-total) {
  display: grid;
  flex: 0 0 auto;
  min-width: 104px;
  min-height: 82px;
  padding: 11px 13px;
  place-items: center;
  align-content: center;
  border: var(--ecodex-border) solid var(--line);
  border-radius: var(--ecodex-radius-md);
  color: var(--page-text);
  background: var(--page-field-bg);
  box-shadow: var(--ecodex-shadow-small);
  text-align: center;
}

:is(.items-counter, .nature-hero-card, .achievement-wallet, .tree-total) strong {
  color: var(--page-primary-dark);
  font-size: clamp(1.75rem, 3.2vw, 2.35rem);
  line-height: .95;
}

:is(.items-counter, .nature-hero-card, .achievement-wallet, .tree-total) span,
:is(.items-counter, .nature-hero-card, .achievement-wallet, .tree-total) small {
  font-size: .7rem;
  font-weight: 950;
  line-height: 1.05;
  text-transform: uppercase;
}

/* Shared panels and segmented navigation. */
:is(.tree-search, .item-usage-filter, .nature-view-tabs, .nature-filter-panel, .observations-view-tabs, .observation-map-panel, .achievement-tabs, .achievement-tab-panel, .social-account-strip, .social-tab-panel, .social-sharing-section, .social-shared-view, .settings-section) {
  border-color: var(--page-border);
  border-radius: var(--ecodex-radius-md);
}

:is(.tree-search, .item-usage-filter, .nature-view-tabs, .nature-filter-panel, .observations-view-tabs, .achievement-tabs, .achievement-tab-panel, .social-account-strip, .social-tab-panel, .social-sharing-section, .social-shared-view) {
  background: var(--page-panel-bg);
  box-shadow: var(--ecodex-shadow-small);
}

.tree-search,
.item-usage-filter,
.achievement-tabs {
  padding: 10px;
}

:is(.item-usage-filter, .nature-view-tabs, .observations-view-tabs, .achievement-tabs, .social-tabs) button {
  min-height: 44px;
  border-radius: var(--ecodex-radius-sm);
}

:is(.item-usage-filter, .nature-view-tabs, .observations-view-tabs, .achievement-tabs, .social-tabs) button.active {
  color: #fff;
  border-color: var(--line);
  background: var(--page-primary-dark);
  box-shadow: inset 0 -4px rgba(0, 0, 0, .18), var(--ecodex-shadow-small);
}

/* Inputs share the compact ECODEX control language. */
:is(.collection-panel, .phylogeny-view, .page-view):not(.profile-page):not(.friend-profile-page) :is(input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), select, textarea) {
  min-height: 44px;
  border: var(--ecodex-border) solid var(--line);
  border-radius: var(--ecodex-radius-md);
  color: var(--page-text);
  background: var(--page-field-bg);
  box-shadow: inset 0 3px rgba(23, 24, 29, .06);
}

:is(.collection-panel, .phylogeny-view, .page-view) :is(button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 4px solid color-mix(in srgb, var(--page-accent) 82%, #fff 18%);
  outline-offset: 2px;
}

:is(.primary-button, .secondary-button, .danger-button) {
  min-height: 44px;
  padding: 9px 15px;
  border: var(--ecodex-border) solid var(--line);
  border-radius: var(--ecodex-radius-md);
  box-shadow: var(--ecodex-shadow-small);
  font-size: .88rem;
  font-weight: 950;
}

.primary-button {
  color: #fff;
  background: var(--page-primary-dark);
}

.secondary-button {
  color: var(--page-text);
  background: var(--page-field-bg);
}

.danger-button {
  color: #fff;
  background: #c7332f;
}

:is(.primary-button, .secondary-button, .danger-button):active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(23, 24, 29, .24);
}

/* Evolutie */
.phylogeny-view {
  display: grid;
  gap: var(--ecodex-page-gap);
}

.phylogeny-header {
  align-items: center;
}

.tree-search {
  display: grid;
  gap: 7px;
}

.phylogeny-layout {
  padding: var(--ecodex-panel-padding);
  border: var(--ecodex-border) solid var(--page-border);
  border-radius: var(--ecodex-radius-md);
  background: var(--page-panel-bg);
  box-shadow: var(--ecodex-shadow-small);
}

.taxon-info {
  --taxon-color: var(--page-primary);
  border-color: var(--page-border);
  border-radius: var(--ecodex-radius-md);
  background: var(--page-field-bg);
}

/* Items */
.items-page {
  overflow: visible;
}

.items-header {
  border-bottom: var(--ecodex-border) solid color-mix(in srgb, var(--page-primary-dark) 76%, var(--line));
}

.item-usage-filter {
  margin: 0;
}

.items-list {
  gap: 14px;
  padding: 0;
}

.items-tier {
  border-color: var(--page-border);
  border-radius: var(--ecodex-radius-md);
  background: var(--page-panel-bg);
  box-shadow: var(--ecodex-shadow-small);
}

.items-tier-header {
  border-bottom-color: var(--page-border);
}

.item-entry,
.item-entry summary {
  background-color: color-mix(in srgb, var(--page-field-bg) 80%, transparent);
}

/* Natuurgebieden */
.nature-page {
  display: grid;
}

.nature-view-tabs,
.nature-filter-panel {
  padding: 10px;
}

.nature-directory-heading,
.nature-area-section-header,
.nature-habitat-card,
.nature-area-card {
  border-color: var(--page-border);
  border-radius: var(--ecodex-radius-md);
  box-shadow: var(--ecodex-shadow-small);
}

.nature-directory-heading,
.nature-area-section-header {
  background-color: var(--page-panel-bg);
}

/* Planner: retain its warm identity while moving it onto the same light,
   translucent canvas and title-header structure as the other pages. */
.planner-builder,
.planner-reading {
  color: var(--page-text);
}

.planner-builder {
  display: grid;
  gap: var(--ecodex-page-gap);
  padding: 0;
  overflow: visible;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.planner-reading {
  overflow: hidden;
  border: var(--ecodex-border) solid var(--page-border);
  border-radius: var(--ecodex-radius-md);
  background: var(--page-panel-bg);
  box-shadow: var(--ecodex-shadow-small);
}

.planner-builder > header {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: clamp(20px, 3vw, 28px);
  color: #fff;
  background:
    linear-gradient(112deg, color-mix(in srgb, var(--page-primary-dark) 94%, transparent), color-mix(in srgb, var(--page-primary) 76%, transparent)),
    var(--theme-banner) center / cover;
  border: var(--ecodex-border) solid var(--page-border);
  border-radius: var(--ecodex-radius-md);
  box-shadow: var(--ecodex-shadow-small);
}

/* Planner gebruikt dezelfde compacte introductie als de overige hoofdpagina's,
   zonder een tweede, overgrote paginatitel onder de vaste titelbalk. */
.planner-builder > header.compact-page-intro {
  min-height: 104px;
  padding-block: clamp(16px, 2.3vw, 22px);
}

.planner-builder > header.compact-page-intro h2.kicker {
  margin: 0 0 5px;
  color: rgba(255, 255, 255, .94);
  font-size: .78rem;
  font-weight: 850;
  line-height: 1.2;
  letter-spacing: .075em;
  text-transform: uppercase;
}

.planner-mode-tabs {
  margin: 0;
  padding: 10px;
  border: var(--ecodex-border) solid var(--page-border);
  border-radius: var(--ecodex-radius-md);
  background: var(--page-panel-bg);
  box-shadow: var(--ecodex-shadow-small);
}

.planner-mode-tabs button,
#buildPlanner,
#analyzeFavorites {
  min-height: 44px;
  border-radius: var(--ecodex-radius-md);
}

.planner-mode-tabs button.active,
#buildPlanner,
#analyzeFavorites {
  background: color-mix(in srgb, var(--page-accent) 78%, #fff 22%);
}

[data-planner-mode-panel] {
  display: grid;
  gap: var(--ecodex-page-gap);
  padding: 0;
}

.planner-builder-fields,
.planner-item-selector,
.planner-favorite-selection-card,
.planner-builder-result {
  margin: 0;
  padding: var(--ecodex-panel-padding);
  border: var(--ecodex-border) solid var(--page-border);
  border-radius: var(--ecodex-radius-md);
  background: var(--page-panel-bg);
  box-shadow: var(--ecodex-shadow-small);
}

.planner-builder-fields {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.planner-filter-group {
  display: grid;
  gap: 7px;
  min-width: 0;
  padding: 10px;
  border: 2px solid color-mix(in srgb, var(--page-border) 72%, transparent);
  border-radius: var(--ecodex-radius-sm);
  background: color-mix(in srgb, var(--page-field-bg) 82%, transparent);
}

.planner-filter-title {
  font-size: .78rem;
  font-weight: 950;
  letter-spacing: .035em;
  text-transform: uppercase;
}

.planner-filter-options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

.planner-filter-options button {
  min-height: 32px;
  padding: 5px 9px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--page-field-bg);
  color: var(--page-text);
  font-size: .75rem;
  font-weight: 850;
  line-height: 1.05;
  cursor: pointer;
}

.planner-filter-options button.active {
  border-color: var(--page-primary-dark);
  background: color-mix(in srgb, var(--page-accent) 76%, #fff 24%);
  box-shadow: inset 0 -2px 0 color-mix(in srgb, var(--page-primary-dark) 28%, transparent);
}

.planner-item-selector {
  border-top: var(--ecodex-border) solid var(--page-border);
}

.planner-favorite-selection-card {
  display: grid;
  gap: 14px;
}

.planner-favorite-intro h3,
.planner-item-selector h3,
.planner-builder-result h3 {
  margin-top: 0;
}

#buildPlanner,
#analyzeFavorites {
  justify-self: start;
  margin: 0 2px;
}

.planner-builder-fields select,
.planner-item-choice,
.planner-favorite-choice,
.planner-result-card {
  background: var(--page-field-bg);
}

.planner-item-selector,
.planner-builder-result,
.planner-recommended-items {
  border-color: var(--page-border);
}

.planner-item-selector > p,
.planner-favorite-intro p,
.planner-favorite-empty,
.planner-builder-result > p,
.planner-area-preview p,
.planner-recommended-items > p,
.planner-nature-area-pool > p {
  color: var(--page-muted);
}

.planner-area-preview,
.planner-fish-tip {
  border-color: var(--page-border);
  background: color-mix(in srgb, var(--page-primary-light) 28%, transparent);
}

.planner-reading {
  padding: clamp(22px, 4vw, 42px);
}

.planner-reading > header,
.planner-reading > section {
  width: min(900px, 100%);
}

.planner-reading h2,
.planner-reading h3,
.planner-reading h4 {
  color: var(--page-primary-dark);
}

.planner-reading p {
  color: #352f2a;
  font-size: 1rem;
  line-height: 1.6;
}

/* Waarnemingen */
.observations-page {
  display: grid;
}

.observations-header {
  border-bottom-color: var(--page-border);
}

.observations-summary,
.observations-toolbar {
  padding: 12px;
  border: var(--ecodex-border) solid var(--page-border);
  border-radius: var(--ecodex-radius-md);
  background: var(--page-panel-bg);
  box-shadow: var(--ecodex-shadow-small);
}

.observations-view-tab.active,
.observation-map-filter.active {
  background: var(--page-primary-dark);
}

.observation-map-panel {
  background: var(--page-panel-bg);
}

/* Prestaties and shop */
.achievements-page {
  max-width: none;
  margin-inline: 0;
}

.achievements-hero {
  border-top-width: var(--ecodex-border);
}

.achievement-tab-panel {
  padding: var(--ecodex-panel-padding);
  border: var(--ecodex-border) solid var(--page-border);
}

.achievement-section-header {
  padding: 0;
}

.achievement-tab.active {
  background: var(--page-primary-dark);
}

.skill-tree-current,
.achievement-card,
.repeatable-card,
.unlockable-card {
  border-radius: var(--ecodex-radius-md);
  box-shadow: var(--ecodex-shadow-small);
}

/* Sociaal and settings */
.social-page,
.settings-page {
  background: var(--page-canvas-bg);
}

.social-profile-card,
.social-progress-card,
.social-section,
.social-shared-view,
.social-tab-panel,
.settings-section,
.settings-danger-zone {
  border-color: var(--page-border);
  border-radius: var(--ecodex-radius-md);
  background-color: var(--page-panel-bg);
  box-shadow: var(--ecodex-shadow-small);
}

.social-tab.active,
.social-page .primary-button {
  background: var(--page-primary-dark);
}

/* Over: long-form content uses the same panel stack instead of one unrelated
   article sheet. */
.about-page {
  display: grid;
  gap: var(--ecodex-page-gap);
  overflow: visible;
}

.about-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: center;
  justify-items: start;
}

.about-hero p:not(.kicker) {
  width: 100%;
  max-width: 880px;
  margin: 4px 0 0;
}

.about-hero .kicker {
  color: rgba(255, 255, 255, .92);
}

.about-flow {
  display: grid;
  gap: var(--ecodex-page-gap);
  padding: 0;
}

.about-section {
  padding: var(--ecodex-panel-padding);
  border: var(--ecodex-border) solid var(--page-border);
  border-radius: var(--ecodex-radius-md);
  background: var(--page-panel-bg);
  box-shadow: var(--ecodex-shadow-small);
}

.about-section h3 {
  margin: 0 0 12px;
  font-size: clamp(1.35rem, 2.5vw, 1.85rem);
  line-height: 1.08;
}

.about-section > .kicker,
.about-profile > div > .kicker {
  margin: 0 0 4px;
  color: var(--page-primary-dark);
}

.about-title-label,
.about-section a,
.about-contact span {
  color: var(--page-primary-dark);
}

.about-mission {
  background: color-mix(in srgb, var(--page-primary-light) 42%, var(--page-panel-bg));
}

/* Selected controls use both colour and depth. */
:is(.segment, .nature-filter-button, .observation-map-filter, .achievement-tab, .skill-tree-tab, .social-tab)[aria-pressed="true"],
:is(.segment, .nature-filter-button, .observation-map-filter, .achievement-tab, .skill-tree-tab, .social-tab).active {
  box-shadow: inset 0 -4px rgba(0, 0, 0, .17), 0 3px 0 var(--line);
}

/* Responsive density follows the collection page rather than inventing a new
   layout for every section. */
@media (max-width: 820px) {
  :root {
    --ecodex-page-gap: 12px;
    --ecodex-canvas-padding: 10px;
    --ecodex-panel-padding: 15px;
  }

  .topbar {
    height: 96px;
    min-height: 96px;
    padding: 14px 16px;
  }

  .topbar-title h1 {
    font-size: clamp(2.35rem, 9vw, 3.35rem);
  }

  :is(.phylogeny-header, .items-header, .nature-hero, .observations-header, .achievements-hero, .social-hero, .about-hero) {
    min-height: 0;
    align-items: start;
    padding: 18px;
  }

  :is(.phylogeny-header, .items-header, .nature-hero, .observations-header, .achievements-hero, .social-hero, .about-hero) h2,
  .planner-builder > header h2 {
    font-size: clamp(1.85rem, 7.5vw, 2.55rem);
  }

  .planner-builder-fields {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .planner-result-species {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .achievement-tab-panel {
    padding: 14px;
  }
}

@media (max-width: 620px) {
  :root {
    --ecodex-page-gap: 9px;
    --ecodex-shell-padding: 7px;
    --ecodex-canvas-padding: 7px;
    --ecodex-panel-padding: 12px;
  }

  .app-shell {
    padding-top: max(7px, env(safe-area-inset-top));
    padding-right: max(7px, env(safe-area-inset-right));
    padding-bottom: max(7px, env(safe-area-inset-bottom));
    padding-left: max(7px, env(safe-area-inset-left));
  }

  .topbar {
    height: 84px;
    min-height: 84px;
    border-width: 3px;
    border-radius: 7px 7px 10px 10px;
    padding-inline: 68px;
  }

  .topbar-title .kicker {
    font-size: .61rem;
  }

  .topbar-title h1 {
    font-size: clamp(2rem, 11vw, 2.8rem);
  }

  body[data-page-theme="nature"] .topbar-title h1,
  body[data-page-theme="observations"] .topbar-title h1,
  body[data-page-theme="friend-profile"] .topbar-title h1 {
    font-size: clamp(1.5rem, 7.5vw, 2rem);
    line-height: 1;
  }

  body[data-view="friend-profile"] .topbar {
    min-height: 84px;
    padding-left: 136px;
    padding-right: 12px;
  }

  body[data-view="friend-profile"] .topbar-title {
    min-width: 0;
    text-align: left;
  }

  body[data-view="friend-profile"] .topbar-title h1 {
    max-width: 100%;
    overflow-wrap: anywhere;
    font-size: clamp(1.05rem, 5.1vw, 1.4rem);
    line-height: 1.05;
  }

  .menu-toggle,
  .friend-profile-back {
    width: 46px;
    height: 46px;
    border-width: 3px;
  }

  main > #speciesGrid {
    padding: 6px;
    border-width: 3px;
    box-shadow:
      inset 0 0 0 1px color-mix(in srgb, var(--page-primary) 32%, transparent),
      var(--ecodex-shadow-small);
  }

  .controls .segments {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
  }

  .controls .segments .segment {
    min-height: 36px;
    padding: 5px 3px;
    font-size: .7rem;
    line-height: 1.05;
  }

  .controls .segments .segment:first-child {
    grid-column: 1 / -1;
  }

  .observations-page #observationsList {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .observations-page #observationsList .observation-card {
    min-width: 0;
    grid-template-rows: 108px auto auto;
    border-top-width: 6px;
    box-shadow: 0 4px 0 rgba(23, 24, 29, .18);
  }

  .observations-page #observationsList .observation-card-photo .creature-wrap {
    width: 100%;
  }

  .observations-page #observationsList .observation-card-photo .creature-image,
  .observations-page #observationsList .observation-card-photo .creature-svg {
    width: 100%;
    height: 100%;
    max-height: 104px;
  }

  .observations-page #observationsList .observation-card-copy {
    gap: 4px;
    padding: 8px;
  }

  .observations-page #observationsList .observation-card-copy h3 {
    font-size: .9rem;
    line-height: 1.05;
    overflow-wrap: anywhere;
  }

  .observations-page #observationsList :is(.observation-date, .observation-location, .observation-quantity) {
    font-size: .68rem;
    line-height: 1.2;
  }

  .observations-page #observationsList .observation-coordinates {
    font-size: .61rem;
    overflow-wrap: anywhere;
  }

  .observations-page #observationsList .observation-note {
    font-size: .68rem;
    line-height: 1.3;
  }

  .observations-page #observationsList .observation-card-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
    padding: 6px;
  }

  .observations-page #observationsList .observation-card-actions button {
    width: 100%;
    min-height: 30px;
    padding: 4px 2px;
    font-size: .64rem;
  }

  .observations-page #observationsList .observation-card-actions .observation-delete {
    grid-column: 1 / -1;
  }

  main > :is(.phylogeny-view, .items-page, .nature-page, .planner-page, .observations-page, .achievements-page, .social-page, .settings-page, .about-page),
  main > .collection-panel {
    border-width: 3px;
    border-radius: var(--ecodex-radius-md);
  }

  :is(.phylogeny-header, .items-header, .nature-hero, .observations-header, .achievements-hero, .social-hero, .about-hero) {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    padding: 14px;
  }

  :is(.items-counter, .nature-hero-card, .achievement-wallet, .tree-total) {
    min-width: 82px;
    min-height: 68px;
    padding: 8px;
  }

  :is(.items-counter, .nature-hero-card, .achievement-wallet, .tree-total) strong {
    font-size: 1.55rem;
  }

  .achievements-hero {
    grid-template-columns: minmax(0, 1fr);
  }

  .achievement-wallet {
    width: 100%;
    min-width: 0;
    min-height: 0;
    grid-template-columns: auto 1fr auto;
    justify-items: start;
    align-items: center;
    gap: 8px;
  }

  .achievement-wallet strong {
    justify-self: center;
  }

  .achievement-wallet small {
    justify-self: end;
  }

  .tree-actions,
  .observations-header .observation-add-button {
    grid-column: 1 / -1;
  }

  .item-usage-filter,
  .nature-view-tabs,
  .observations-view-tabs,
  .achievement-tabs {
    gap: 6px;
    padding: 7px;
  }

  .item-usage-filter button,
  .nature-view-tabs button,
  .observations-view-tab,
  .achievement-tab {
    min-height: 40px;
    padding: 7px;
    font-size: .76rem;
  }

  .planner-builder-fields {
    grid-template-columns: 1fr;
    gap: 7px;
    padding: 9px;
  }

  .planner-filter-group {
    grid-template-columns: 66px minmax(0, 1fr);
    align-items: center;
    gap: 3px;
    padding: 6px 7px;
  }

  .planner-filter-title {
    font-size: .65rem;
    white-space: nowrap;
  }

  .planner-filter-options {
    flex-wrap: nowrap;
    gap: 5px;
    overflow-x: auto;
    padding: 1px 1px 3px;
    overscroll-behavior-inline: contain;
    scrollbar-width: none;
    touch-action: pan-x pan-y;
  }

  .planner-filter-options::-webkit-scrollbar {
    display: none;
  }

  .planner-filter-options button {
    flex: 0 0 auto;
    min-height: 29px;
    padding: 4px 8px;
    font-size: .68rem;
  }

  .planner-mode-tabs {
    grid-template-columns: 1fr;
  }

  .planner-result-species {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .planner-reading {
    padding: 18px 15px;
  }

  .about-profile {
    grid-template-columns: 1fr;
  }

  .about-hero {
    grid-template-columns: 1fr;
  }

  .about-profile img {
    width: 128px;
  }

  .about-score-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* The family tree remains horizontally explorable on small screens, but its
   wide inner canvas must never determine the width of the complete page. */
@media (max-width: 700px) {
  .phylogeny-view {
    grid-template-columns: minmax(0, 1fr);
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .phylogeny-view > *,
  .phylogeny-header > *,
  .phylogeny-layout > * {
    min-width: 0;
  }

  .phylogeny-header,
  .tree-search,
  .phylogeny-layout {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .phylogeny-header {
    grid-template-columns: minmax(0, 1fr);
  }

  .phylogeny-header .page-intro-copy {
    max-width: 100%;
    overflow-wrap: anywhere;
  }

  .tree-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    min-width: 0;
  }

  .tree-actions button,
  .tree-search input {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .taxon-info {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .phylo-tree {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: auto;
    overscroll-behavior-x: contain;
  }
}

/* Stickerkeuze is op ieder formaat een echt uitklapblok onder het canvas. */
.profile-sticker-icon-button.profile-sticker-menu-toggle {
  display: grid;
  margin-top: auto;
  color: #fff;
  background: var(--profile-accent, #348b5d);
}

.profile-sticker-menu-toggle[aria-expanded="true"] {
  outline: 3px solid color-mix(in srgb, var(--profile-accent, #348b5d) 42%, white);
  outline-offset: 2px;
}

.profile-sticker-tray:not(.mobile-open) {
  display: none !important;
}

.profile-sticker-tray.mobile-open {
  position: static;
  display: grid !important;
  grid-template-columns: repeat(auto-fit, minmax(105px, 1fr));
  gap: 8px;
  width: 100%;
  max-height: none;
  margin: 12px 0 0;
  padding: 12px;
  overflow: visible;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--profile-secondary, #fff) 88%, #fff 12%);
  box-shadow: 0 5px 0 rgba(23, 24, 29, .18);
}

.profile-sticker-tray.mobile-open::before {
  grid-column: 1 / -1;
  margin: 0 2px 3px;
  content: "Kies een sticker";
  color: var(--ink);
  font-size: .76rem;
  font-weight: 950;
  letter-spacing: .04em;
  text-transform: uppercase;
}

@media (max-width: 700px) {
  .profile-sticker-tray.mobile-open {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    padding: 10px;
  }
}

/* Shared popup stage ------------------------------------------------------
   Content dialogs enter as a side panel on wide screens. The page remains
   visible and eases aside, so opening a species or editor keeps its context. */
:root {
  --popup-panel-width: clamp(480px, 48vw, 760px);
  --popup-panel-speed: 480ms;
  --popup-panel-ease: cubic-bezier(.22, .78, .2, 1);
}

.app-shell {
  transform: none;
  transform-origin: center top;
  transition: transform var(--popup-panel-speed) var(--popup-panel-ease), filter 360ms ease;
  will-change: auto;
}

body.popup-panel-open {
  overflow: hidden;
}

body.popup-panel-open .app-shell {
  transform: translate3d(0, -6px, 0) scale(.985);
  filter: saturate(.94);
}

/* Keep the viewport-anchored profile banner intact while the appearance
   editor is open. A transformed or filtered ancestor changes the containing
   block of fixed backgrounds, which caused the old enlarged banner crop to
   reappear until the next scroll event. The dialog itself still animates. */
body[data-view="profile"].profile-page-has-custom-banner.popup-panel-open .app-shell {
  transform: none;
  filter: none;
}

body.popup-panel-open :is(.field-actions, .scroll-top-button) {
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

body > dialog {
  position: fixed;
  inset: 50% auto auto 50%;
  box-sizing: border-box;
  width: var(--popup-panel-width) !important;
  max-width: calc(100vw - 48px) !important;
  height: auto;
  max-height: calc(100dvh - 48px) !important;
  margin: 0 !important;
  padding: 12px;
  overflow-x: hidden;
  overflow-y: auto;
  opacity: 0;
  transform: translate(-50%, calc(-50% + 22px)) scale(.97);
  transition:
    transform var(--popup-panel-speed) var(--popup-panel-ease),
    opacity 300ms ease,
    height 260ms var(--popup-panel-ease),
    max-height 260ms var(--popup-panel-ease),
    display var(--popup-panel-speed) allow-discrete,
    overlay var(--popup-panel-speed) allow-discrete;
}

body > dialog[open] {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

body > dialog::backdrop {
  background: rgba(20, 27, 31, .28);
  opacity: 0;
  backdrop-filter: blur(1.5px);
  transition:
    opacity var(--popup-panel-speed) ease,
    display var(--popup-panel-speed) allow-discrete,
    overlay var(--popup-panel-speed) allow-discrete;
}

body > dialog[open]::backdrop {
  opacity: 1;
}

@starting-style {
  body > dialog[open] {
    opacity: 0;
    transform: translate(-50%, calc(-50% + 22px)) scale(.97);
  }

  body > dialog[open]::backdrop {
    opacity: 0;
  }
}

body > dialog > :is(article, form),
body > dialog > :is(.detail-card, .account-card, .profile-style-dialog-card, .unknown-observations-card) {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

/* The guest gate and badge preview are div-based overlays, but move in the
   same way as native dialogs. */
.account-gate-overlay,
.achievement-badge-preview {
  place-items: center;
  padding: 24px;
  background: rgba(20, 27, 31, .28);
  backdrop-filter: blur(1.5px);
  transition: opacity var(--popup-panel-speed) ease;
}

.account-gate-overlay {
  opacity: 0;
  pointer-events: none;
}

.account-gate-overlay.is-panel-open {
  opacity: 1;
  pointer-events: auto;
}

.account-gate-panel,
.achievement-badge-preview-panel {
  box-sizing: border-box;
  width: var(--popup-panel-width);
  max-width: calc(100vw - 48px);
  height: auto;
  max-height: calc(100dvh - 48px);
  margin: 0;
  padding: 12px;
  overflow-x: hidden;
  overflow-y: auto;
  opacity: 0;
  transform: translate3d(0, 22px, 0) scale(.97);
  transition: transform var(--popup-panel-speed) var(--popup-panel-ease), opacity 300ms ease;
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.account-gate-panel::-webkit-scrollbar,
.achievement-badge-preview-panel::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

.account-gate-overlay.is-panel-open .account-gate-panel,
.achievement-badge-preview.is-open .achievement-badge-preview-panel {
  opacity: 1;
  transform: translate3d(0, 0, 0) scale(1);
}

.account-gate-panel .profile-guest-view {
  grid-template-columns: minmax(0, 1fr);
  min-height: 0;
  align-content: center;
}

.achievement-badge-preview-panel {
  align-content: center;
  justify-items: center;
  border-radius: 0;
}

/* Phones and tall aspect ratios keep the current page in the upper half and
   use a bottom sheet instead of a side panel. */
.popup-sheet-handle {
  display: none;
}

@media (max-width: 700px), (max-aspect-ratio: 4/5), (max-height: 500px) and (pointer: coarse) {
  :root {
    --mobile-popup-height: min(62dvh, 700px);
  }

  body.popup-panel-open .app-shell {
    transform: translate3d(0, clamp(-42px, -4vh, -20px), 0) scale(.985);
    transform-origin: center top;
  }

  body[data-view="profile"].profile-page-has-custom-banner.popup-panel-open .app-shell {
    transform: none;
    filter: none;
  }

  body > dialog {
    inset: auto 0 0;
    width: 100vw !important;
    max-width: 100vw !important;
    height: var(--mobile-popup-height);
    max-height: var(--mobile-popup-height) !important;
    padding: 8px 8px max(8px, env(safe-area-inset-bottom));
    transform: translate3d(0, calc(100% + 24px), 0);
  }

  body > dialog[open] {
    transform: translate3d(0, 0, 0);
  }

  @starting-style {
    body > dialog[open] {
      opacity: 0;
      transform: translate3d(0, calc(100% + 24px), 0);
    }
  }

  .account-gate-overlay,
  .achievement-badge-preview {
    place-items: end stretch;
    padding: 0;
  }

  .account-gate-panel,
  .achievement-badge-preview-panel {
    width: 100%;
    max-width: 100%;
    height: var(--mobile-popup-height);
    max-height: var(--mobile-popup-height);
    padding: 8px 8px max(8px, env(safe-area-inset-bottom));
    transform: translate3d(0, calc(100% + 24px), 0);
    -ms-overflow-style: none;
    scrollbar-width: none;
  }

  .account-gate-panel::-webkit-scrollbar,
  .achievement-badge-preview-panel::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
  }

  .account-gate-panel .profile-guest-view {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .account-gate-panel.mobile-sheet-panel,
  .mobile-draggable-sheet .account-gate-panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .account-gate-overlay.is-panel-open .account-gate-panel,
  .achievement-badge-preview.is-open .achievement-badge-preview-panel {
    transform: translate3d(0, 0, 0);
  }

  #detailDialog #closeDialog {
    display: none;
  }

  #detailDialog {
    overflow: hidden;
  }

  #detailDialog .detail-card {
    height: 100%;
    max-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -ms-overflow-style: none;
    scrollbar-width: none;
    touch-action: pan-y;
  }

  #detailDialog .detail-card::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
  }

  #detailDialog.sheet-dragging {
    transition: none !important;
  }

  #detailDialog .detail-sheet-handle {
    position: sticky;
    top: 0;
    z-index: 18;
    display: block;
    width: 100%;
    height: 30px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: color-mix(in srgb, var(--group, #348b5d) 18%, #fff 82%);
    box-shadow: none;
    cursor: ns-resize;
    touch-action: none;
  }

  #detailDialog .detail-sheet-handle::before {
    position: absolute;
    top: 9px;
    left: 50%;
    width: 58px;
    height: 6px;
    border-radius: 999px;
    content: "";
    background: color-mix(in srgb, var(--group, #348b5d) 58%, #343940 42%);
    transform: translateX(-50%);
  }

  .mobile-draggable-sheet.sheet-dragging,
  .mobile-draggable-sheet.sheet-dragging :is(.account-gate-panel, .achievement-badge-preview-panel) {
    transition: none !important;
  }

  .mobile-draggable-sheet .popup-sheet-handle {
    position: sticky;
    top: 0;
    z-index: 24;
    display: block;
    width: calc(100% + 16px);
    max-width: none;
    min-height: 32px;
    margin: -8px -8px 6px;
    padding: 0;
    border: 0;
    border-bottom: 2px solid color-mix(in srgb, var(--page-primary-dark, #285f43) 44%, transparent);
    border-radius: 8px 8px 0 0;
    background: color-mix(in srgb, var(--page-primary, #348b5d) 16%, #fff 84%);
    box-shadow: none;
    cursor: ns-resize;
    touch-action: none;
  }

  .mobile-draggable-sheet .account-gate-panel > .popup-sheet-handle {
    position: relative;
    top: auto;
    flex: 0 0 32px;
  }

  .mobile-draggable-sheet .popup-sheet-handle::before {
    position: absolute;
    top: 9px;
    left: 50%;
    width: 58px;
    height: 6px;
    border-radius: 999px;
    content: "";
    background: color-mix(in srgb, var(--page-primary-dark, #285f43) 62%, #343940 38%);
    transform: translateX(-50%);
  }

  .account-gate-panel .account-gate-close {
    display: none !important;
  }

  body > dialog.mobile-draggable-sheet,
  .mobile-draggable-sheet :is(.account-gate-panel, .achievement-badge-preview-panel) {
    height: var(--mobile-popup-height);
    max-height: var(--mobile-popup-height) !important;
  }

  #detailDialog .detail-nav { display: none; }
}

.detail-sheet-handle { display: none; }

@media (prefers-reduced-motion: reduce) {
  :where(*, *::before, *::after) {
    scroll-behavior: auto !important;
  }

  :is(.primary-button, .secondary-button, .danger-button, .segment, .nature-filter-button, .achievement-tab, .skill-tree-tab) {
    transition-duration: .01ms !important;
  }

  .app-shell,
  body > dialog,
  body > dialog::backdrop,
  .account-gate-overlay,
  .account-gate-panel,
  .achievement-badge-preview,
  .achievement-badge-preview-panel {
    transition-duration: .01ms !important;
  }
}

/* Interface-afwerking: één teksthiërarchie en ergonomie op alle pagina's. */
:where(button, input, select, textarea, summary, a.secondary-button) {
  font-family: inherit;
}

:where(button, [role="button"], summary, select, input[type="checkbox"], input[type="radio"]) {
  touch-action: manipulation;
}

:where(button, a, input, select, textarea, summary):focus-visible {
  outline: 3px solid color-mix(in srgb, var(--page-accent, #2876aa) 72%, #fff 28%);
  outline-offset: 3px;
}

.compact-page-intro .page-intro-copy {
  max-width: 72ch;
  line-height: 1.45;
}

:where(.page-view, .phylogeny-view) :where(h2, h3, h4, p, span, strong, small, button, label) {
  overflow-wrap: anywhere;
}

:where(.items-list, .nature-section-list, .observations-list, .achievement-grid, .achievement-shop-grid) > :empty {
  display: none;
}

/* Houd achievementvoortgang op ieder scherm compact: 0 / 2. */
.achievement-progress-unit {
  display: none;
}

@media (max-width: 700px) {
  :where(.page-view, .phylogeny-view) button,
  :where(.page-view, .phylogeny-view) .secondary-button,
  :where(.page-view, .phylogeny-view) .primary-button {
    min-height: 42px;
  }

  .compact-page-intro {
    gap: 12px;
  }

  .compact-page-intro .page-intro-copy {
    font-size: .94rem;
  }

  .compact-page-intro :where(.items-counter, .nature-hero-card, .achievement-wallet) {
    min-width: 76px;
  }

  :where(.planner-builder-fields, .observation-map-selects) {
    grid-template-columns: minmax(0, 1fr);
  }

  .profile-sticker-tray {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    width: 100%;
  }

  .profile-sticker-tray .profile-sticker-choice {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    width: 100%;
    min-width: 0;
    min-height: 62px;
    padding: 4px 3px;
    font-size: .66rem;
    line-height: 1.05;
    text-align: center;
  }

  .profile-sticker-tray .profile-sticker-choice span {
    width: 38px;
    height: 34px;
  }

  .profile-sticker-tray .profile-sticker-choice span img {
    width: 38px;
    height: 38px;
  }

  .profile-sticker-tray .profile-sticker-choice strong {
    max-width: 100%;
    overflow-wrap: anywhere;
  }

  /* Gewone achievements blijven op mobiel compact en staan twee per rij. */
  .achievement-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .achievement-card {
    min-width: 0;
    min-height: 0;
    padding: 10px 8px;
    gap: 7px 8px;
  }

  .achievement-card .achievement-badge-trigger {
    width: 54px;
    height: 54px;
  }

  .achievement-card h4 {
    font-size: .82rem;
    line-height: 1.12;
  }

  .achievement-card > p {
    font-size: .72rem;
    line-height: 1.3;
  }

  .achievement-progress-copy {
    gap: 4px;
    font-size: .68rem;
  }

}

/* Definitieve responsieve filterindeling; bewust onderaan om oudere regels te overschrijven. */
@media (min-width: 761px) {
  .planner-filter-group .planner-filter-options {
    display: grid;
    grid-template-rows: repeat(2, 38px);
    align-items: stretch;
    gap: 7px;
  }

  .planner-filter-group[data-planner-filter="season"] .planner-filter-options,
  .planner-filter-group[data-planner-filter="time"] .planner-filter-options {
    grid-template-columns: 83px repeat(2, minmax(0, 1fr));
  }

  .planner-filter-group[data-planner-filter="habitat"] .planner-filter-options,
  .planner-filter-group[data-planner-filter="group"] .planner-filter-options {
    grid-template-columns: 83px repeat(3, minmax(0, 1fr));
  }

  .planner-filter-group .planner-filter-options button {
    width: 100%;
    min-height: 38px;
    padding-inline: 7px;
    white-space: normal;
    line-height: 1.12;
    font-size: .78rem;
  }

  .planner-filter-group .planner-filter-options button:first-child {
    grid-row: 1 / span 2;
    width: 83px;
    height: 83px;
    min-height: 83px;
    aspect-ratio: 1;
    border-radius: 18px;
    align-self: stretch;
  }
}

@media (max-width: 760px) {
  .planner-filter-options {
    position: relative;
    flex-wrap: nowrap;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    scroll-padding-left: 48px;
    touch-action: pan-x pan-y;
  }

  .planner-filter-options button:first-child {
    position: sticky;
    left: 0;
    z-index: 3;
    box-shadow:
      -7px 0 0 7px var(--page-field-bg),
      4px 0 0 var(--page-field-bg);
  }

  .planner-filter-options button:first-child:not(.active) {
    background: var(--page-field-bg);
  }
}

@media (min-width: 701px) {
  .profile-sticker-tray.mobile-open {
    max-height: min(60vh, 520px);
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    scrollbar-gutter: stable;
    touch-action: pan-y;
  }
}
