/* --== Habitat Environment ==-- */

#habitatPage {
  --habitat-sky-top: #b9dcf1;
  --habitat-sky-bottom: #edf5dc;
  --habitat-ground: #abc990;
  --habitat-ground-deep: #88ae73;
  --habitat-light: rgba(255, 244, 209, 0.18);
  position: relative;
  width: 100vw;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  isolation: isolate;
  background: linear-gradient(to bottom, var(--habitat-sky-top) 0 44%, var(--habitat-sky-bottom) 44% 48%, var(--habitat-ground) 48% 100%);
  transition: background 2s ease, filter 2s ease;
}

#habitatPage[data-daypart="morning"] {
  --habitat-sky-top: #c7def0;
  --habitat-sky-bottom: #f5dfbd;
  --habitat-ground: #accb8f;
  --habitat-ground-deep: #86ad70;
  --habitat-light: rgba(255, 231, 183, 0.2);
}

#habitatPage[data-daypart="afternoon"] {
  --habitat-sky-top: #acd5ef;
  --habitat-sky-bottom: #eaf2d5;
  --habitat-ground: #a9ca86;
  --habitat-ground-deep: #82aa6a;
  --habitat-light: rgba(255, 247, 213, 0.16);
}

#habitatPage[data-daypart="evening"] {
  --habitat-sky-top: #a49dc8;
  --habitat-sky-bottom: #e8bda5;
  --habitat-ground: #879b72;
  --habitat-ground-deep: #687c5b;
  --habitat-light: rgba(255, 186, 144, 0.17);
}

#habitatPage[data-daypart="lateNight"],
#habitatPage[data-daypart="earlyMorning"] {
  --habitat-sky-top: #242a43;
  --habitat-sky-bottom: #4c5270;
  --habitat-ground: #536553;
  --habitat-ground-deep: #3d503f;
  --habitat-light: rgba(167, 190, 255, 0.08);
}

.habitat-environment,
.habitat-sky-layer,
.habitat-ground-layer,
.habitat-ambient-layer,
.habitat-light-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.habitat-environment { z-index: auto; }
.habitat-sky-layer { z-index: 0; overflow: hidden; }

.habitat-ground-layer {
  top: 46%;
  z-index: 1;
  background:
    radial-gradient(ellipse at 18% 64%, rgba(255,255,255,.08) 0 9%, transparent 10%),
    radial-gradient(ellipse at 78% 72%, rgba(70,93,59,.11) 0 10%, transparent 11%),
    linear-gradient(to bottom, transparent, rgba(41,67,44,.08));
}

.habitat-ground-layer::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: .28;
  background-image:
    repeating-linear-gradient(105deg, transparent 0 28px, rgba(54,82,49,.08) 29px 30px, transparent 31px 56px);
}

.habitat-light-layer {
  z-index: 95;
  background: var(--habitat-light);
  mix-blend-mode: soft-light;
  transition: background 2s ease;
}

.habitat-horizon {
  position: absolute;
  left: -5%;
  right: -5%;
  top: 39%;
  height: 12%;
  z-index: 2;
  border-radius: 50% 50% 0 0;
  background:
    radial-gradient(ellipse at 12% 100%, var(--habitat-ground-deep) 0 27%, transparent 28%),
    radial-gradient(ellipse at 37% 100%, color-mix(in srgb, var(--habitat-ground-deep) 86%, black) 0 31%, transparent 32%),
    radial-gradient(ellipse at 68% 100%, var(--habitat-ground-deep) 0 28%, transparent 29%),
    radial-gradient(ellipse at 94% 100%, color-mix(in srgb, var(--habitat-ground-deep) 90%, black) 0 29%, transparent 30%);
  opacity: .72;
}

.habitat-celestial {
  position: absolute;
  width: clamp(34px, 5vw, 62px);
  aspect-ratio: 1;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  transition: left 4s ease, top 4s ease, opacity 2s ease, background 2s ease, box-shadow 2s ease;
}

.habitat-celestial.sun {
  background: #fff1b0;
  box-shadow: 0 0 28px rgba(255, 223, 137, .65);
}

.habitat-celestial.moon {
  background: #e6e8f1;
  box-shadow: 0 0 22px rgba(210, 219, 255, .42);
}

.habitat-star {
  position: absolute;
  width: 2px;
  height: 2px;
  border-radius: 50%;
  background: rgba(255,255,255,.8);
  opacity: 0;
  transition: opacity 2s ease;
}

#habitatPage[data-daypart="lateNight"] .habitat-star,
#habitatPage[data-daypart="earlyMorning"] .habitat-star {
  opacity: var(--star-opacity, .6);
}

.habitat-cloud {
  position: absolute;
  width: 90px;
  height: 24px;
  border-radius: 999px;
  background: rgba(255,255,255,.33);
  opacity: .8;
  animation: habitat-cloud-drift var(--cloud-duration, 42s) linear infinite;
  transform: translateX(-140px) scale(var(--cloud-scale, 1));
}

.habitat-cloud::before,
.habitat-cloud::after {
  content: "";
  position: absolute;
  bottom: 5px;
  border-radius: 50%;
  background: inherit;
}

.habitat-cloud::before { width: 38px; height: 38px; left: 17px; }
.habitat-cloud::after { width: 48px; height: 48px; right: 13px; }

@keyframes habitat-cloud-drift {
  from { transform: translateX(-150px) scale(var(--cloud-scale, 1)); }
  to { transform: translateX(calc(100vw + 150px)) scale(var(--cloud-scale, 1)); }
}

.habitat-landmark {
  position: absolute;
  transform: translate(-50%, -50%);
  pointer-events: none;
  transition: filter .25s ease, transform .25s ease;
}

.habitat-landmark.active { filter: brightness(1.08); }

.habitat-tree {
  width: 108px;
  height: 166px;
  transform-origin: 50% 100%;
  transform: translate(-50%, -100%) scale(var(--tree-scale, 1));
}

.habitat-tree .trunk {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 21px;
  height: 79px;
  transform: translateX(-50%);
  border-radius: 8px 8px 3px 3px;
  background: #715d47;
}

.habitat-tree .canopy {
  position: absolute;
  left: 50%;
  top: 46px;
  width: 102px;
  height: 90px;
  transform: translate(-50%, -50%);
  border-radius: 48% 52% 46% 54%;
  background: var(--canopy, #66865c);
  box-shadow:
    -31px 13px 0 -10px var(--canopy-light, #718f64),
    31px 12px 0 -9px var(--canopy-dark, #58794f),
    3px -29px 0 -13px var(--canopy-top, #78956a);
  transition: background 2s ease, box-shadow 2s ease;
}

.habitat-pond {
  width: clamp(120px, 18vw, 230px);
  height: clamp(58px, 9vw, 115px);
  border-radius: 50%;
  background:
    radial-gradient(ellipse at 45% 42%, rgba(255,255,255,.22), transparent 28%),
    linear-gradient(155deg, #91c5c6, #638fa1);
  box-shadow:
    inset 0 0 0 5px rgba(63,91,71,.21),
    0 8px 14px rgba(26,55,50,.16);
}

.habitat-pond::after {
  content: "";
  position: absolute;
  left: 18%;
  top: 28%;
  width: 18%;
  height: 14%;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,.34);
  animation: habitat-ripple 3.5s ease-out infinite;
}

.habitat-pond.active::before {
  content: "";
  position: absolute;
  left: 62%;
  top: 48%;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.55);
  animation: habitat-ripple-active 1.4s ease-out infinite;
}

.habitat-skip-trail {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.habitat-skip {
  position: absolute;
  width: 10px;
  height: 5px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.7);
  transform: translate(-50%, -50%) scale(.3);
  opacity: 0;
  animation: habitat-skip .9s ease-out both;
}

@keyframes habitat-skip {
  0% { transform: translate(-50%, -50%) scale(.3); opacity: .9; }
  100% { transform: translate(-50%, -50%) scale(2.6); opacity: 0; }
}

.habitat-flower {
  transition: opacity .4s ease, transform .4s ease;
}

.habitat-flower.picked {
  opacity: 0;
}

@keyframes habitat-ripple {
  0% { transform: scale(.5); opacity: 0; }
  20% { opacity: .5; }
  100% { transform: scale(2.6); opacity: 0; }
}

@keyframes habitat-ripple-active {
  from { transform: scale(.4); opacity: .8; }
  to { transform: scale(3.2); opacity: 0; }
}

.habitat-bench { width: 88px; height: 54px; }

.habitat-bench .seat,
.habitat-bench .back {
  position: absolute;
  left: 0;
  width: 88px;
  height: 9px;
  border-radius: 3px;
  background: #866d55;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,.13);
}

.habitat-bench .back {
  top: 8px;
  height: 20px;
  background: repeating-linear-gradient(to bottom, #8c7359 0 5px, transparent 5px 8px);
}

.habitat-bench .seat { top: 30px; }

.habitat-bench .leg {
  position: absolute;
  top: 36px;
  width: 7px;
  height: 18px;
  background: #5f554d;
}

.habitat-bench .leg.left { left: 14px; }
.habitat-bench .leg.right { right: 14px; }

.habitat-picnic {
  width: 104px;
  height: 70px;
  border-radius: 9px;
  transform: translate(-50%, -50%) rotate(-4deg);
  background:
    conic-gradient(from 90deg, rgba(255,255,255,.22) 25%, transparent 0 50%, rgba(255,255,255,.22) 0 75%, transparent 0) 0 0 / 22px 22px,
    #b87979;
  box-shadow: 0 5px 10px rgba(50,40,36,.12);
}

.habitat-flower-patch { width: 120px; height: 72px; }

.habitat-flower {
  position: absolute;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--flower-color, #f5d7dc);
  box-shadow:
    6px 0 0 -1px var(--flower-color, #f5d7dc),
    -6px 0 0 -1px var(--flower-color, #f5d7dc),
    0 6px 0 -1px var(--flower-color, #f5d7dc),
    0 -6px 0 -1px var(--flower-color, #f5d7dc);
}

.habitat-flower::after {
  content: "";
  position: absolute;
  inset: 2px;
  border-radius: 50%;
  background: #e2bf69;
}

.habitat-grass {
  position: absolute;
  width: 18px;
  height: 18px;
  opacity: .42;
  background:
    linear-gradient(72deg, transparent 46%, #537349 47% 53%, transparent 54%) 3px 1px / 8px 18px no-repeat,
    linear-gradient(108deg, transparent 46%, #5f7d53 47% 53%, transparent 54%) 8px 2px / 8px 17px no-repeat;
}

.habitat-particle {
  position: absolute;
  pointer-events: none;
  z-index: 90;
  opacity: 0;
}

.habitat-particle.firefly {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #f6e89a;
  box-shadow: 0 0 7px #f6e89a;
  animation: habitat-firefly var(--particle-duration, 6s) ease-in-out infinite;
}

.habitat-particle.petal {
  width: 7px;
  height: 5px;
  border-radius: 70% 30% 70% 30%;
  background: rgba(242, 190, 207, .78);
  animation: habitat-petal var(--particle-duration, 9s) linear infinite;
}

@keyframes habitat-firefly {
  0%,100% { transform: translate(0,0); opacity: 0; }
  20% { opacity: .9; }
  50% { transform: translate(var(--particle-x, 16px), var(--particle-y, -22px)); opacity: .45; }
  75% { opacity: 1; }
}

@keyframes habitat-petal {
  0% { transform: translate(0,-20px) rotate(0deg); opacity: 0; }
  12% { opacity: .75; }
  100% { transform: translate(var(--particle-x, 70px), 120px) rotate(240deg); opacity: 0; }
}

@media (max-width: 768px) {
  .habitat-tree { transform: translate(-50%, -100%) scale(var(--tree-scale-mobile, 0.9)); }
  .habitat-bench { transform: translate(-50%, -50%) scale(.82); }
  .habitat-picnic { transform: translate(-50%, -50%) rotate(-4deg) scale(.8); }
  .habitat-flower-patch { transform: translate(-50%, -50%) scale(.82); }
}

/* --== Phase 1: Ground contact ==-- */
#habitatPage #mar-npc,
#habitatPage #mer-npc {
  height: 123px;
  transform-origin: 50% 100%;
  transform: translate(-50%, -100%);
}

#habitatPage .npc-ground-shadow {
  position: absolute;
  left: 50%;
  top: 100%;
  z-index: -1;
  width: 36px;
  height: 10px;
  border-radius: 50%;
  transform: translate(-50%, -48%);
  background: rgba(27, 41, 30, .29);
  filter: blur(3px);
  pointer-events: none;
}

#habitatPage .npc-food {
  transform: translate(-50%, -95%) scale(0);
}

#habitatPage .npc-food.spawned {
  transform: translate(-50%, -95%) scale(var(--npc-depth-scale, 1));
}

#habitatPage .npc-food.npc-food-half.spawned {
  transform: translate(-50%, -95%) scale(calc(var(--npc-depth-scale, 1) * .72));
}

#habitatPage .npc-food::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -3px;
  width: 18px;
  height: 5px;
  border-radius: 50%;
  background: rgba(27, 41, 30, .2);
  transform: translateX(-50%);
  filter: blur(2px);
  z-index: -1;
}

@media (prefers-reduced-motion: reduce) {
  #habitatPage .npc-food,
  #habitatPage .npc-food.spawned {
    transition: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .habitat-skip { animation-name: habitat-skip-fade; }
  .habitat-flower { transition: none; }
}

@keyframes habitat-skip-fade {
  0% { transform: translate(-50%, -50%) scale(1.4); opacity: .8; }
  100% { transform: translate(-50%, -50%) scale(1.4); opacity: 0; }
}

/* --== Phase 6: Weather and off-screen pausing ==-- */
#habitatPage.habitat-paused,
#habitatPage.habitat-paused *,
#habitatPage.habitat-paused *::before,
#habitatPage.habitat-paused *::after {
  animation-play-state: paused !important;
}

.habitat-rain-layer {
  position: absolute;
  inset: 0;
  z-index: 94;
  overflow: hidden;
  pointer-events: none;
  background: rgba(96, 112, 134, 0);
  transition: background 2.5s ease;
}

#habitatPage[data-weather="drizzle"] .habitat-rain-layer { background: rgba(96, 112, 134, .14); }
#habitatPage[data-weather="drizzle"] .habitat-cloud { background: rgba(226, 231, 240, .62); }
#habitatPage[data-weather="drizzle"] .habitat-celestial { opacity: .5; }

.habitat-raindrop {
  position: absolute;
  top: -8%;
  width: 1px;
  height: 14px;
  border-radius: 1px;
  background: linear-gradient(to bottom, transparent, rgba(232, 240, 250, .55));
  rotate: 9deg;
  animation: habitat-rain var(--rain-duration, .9s) linear infinite;
}

@keyframes habitat-rain {
  from { transform: translate(0, 0); }
  to { transform: translate(-12px, 112vh); }
}

.habitat-rain-ripple {
  position: absolute;
  width: 9px;
  height: 4px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .6);
  transform: translate(-50%, -50%);
  opacity: 0;
  animation: habitat-rain-ripple 2.1s ease-out infinite;
}

@keyframes habitat-rain-ripple {
  0% { transform: translate(-50%, -50%) scale(.4); opacity: .75; }
  100% { transform: translate(-50%, -50%) scale(2.8); opacity: 0; }
}

#habitatPage[data-weather="breezy"] .habitat-tree .canopy {
  transform-origin: 50% 85%;
  animation: habitat-sway 3.4s ease-in-out var(--sway-delay, 0s) infinite;
}

@keyframes habitat-sway {
  0%, 100% { rotate: -1.2deg; }
  50% { rotate: 2.6deg; }
}

@media (prefers-reduced-motion: reduce) {
  #habitatPage[data-weather="breezy"] .habitat-tree .canopy { animation: none; rotate: 1deg; }
  .habitat-rain-ripple { animation: none; opacity: .45; }
}

/* --== Phase 6: Seasons ==-- */
#habitatPage[data-season="spring"] {
  --canopy: #6d9061;
  --canopy-light: #7a9a69;
  --canopy-dark: #5d8053;
  --canopy-top: #83a172;
}

#habitatPage[data-season="summer"] {
  --canopy: #5c7f52;
  --canopy-light: #678a5b;
  --canopy-dark: #4d7045;
  --canopy-top: #6f9160;
}

#habitatPage[data-season="autumn"] {
  --canopy: #c27a3e;
  --canopy-light: #d49a4a;
  --canopy-dark: #a65a32;
  --canopy-top: #ddb053;
}

#habitatPage[data-season="winter"] {
  --canopy: #6f8471;
  --canopy-light: #7d9080;
  --canopy-dark: #5f7462;
  --canopy-top: #8a9c8d;
}

/* Spring blossoms and winter frost sit on the canopy, so they sway with it in a breeze. */
.habitat-tree .canopy::after {
  content: "";
  position: absolute;
  inset: 6% 8% 22%;
  border-radius: inherit;
  opacity: 0;
  pointer-events: none;
  transition: opacity 2s ease;
}

#habitatPage[data-season="spring"] .habitat-tree .canopy::after {
  opacity: .9;
  background:
    radial-gradient(circle at 22% 30%, #f6cad6 0 3px, transparent 4px),
    radial-gradient(circle at 64% 18%, #fbe0e8 0 3px, transparent 4px),
    radial-gradient(circle at 80% 52%, #f6cad6 0 2.5px, transparent 3.5px),
    radial-gradient(circle at 40% 62%, #fbe0e8 0 3px, transparent 4px),
    radial-gradient(circle at 12% 70%, #f2bccb 0 2.5px, transparent 3.5px),
    radial-gradient(circle at 55% 40%, #f2bccb 0 2px, transparent 3px);
}

#habitatPage[data-season="winter"] .habitat-tree .canopy::after {
  opacity: .85;
  inset: -4% 6% 58%;
  border-radius: 50% 50% 40% 40%;
  background: linear-gradient(to bottom, rgba(244, 248, 252, .92), rgba(232, 239, 246, .4));
}

/* Gentle ground tints: golden in autumn, pale and frosty in winter. */
.habitat-ground-layer::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 2s ease, background 2s ease;
}

#habitatPage[data-season="autumn"] .habitat-ground-layer::before {
  opacity: 1;
  background: linear-gradient(to bottom, rgba(214, 170, 92, .2), rgba(190, 132, 70, .12));
}

#habitatPage[data-season="winter"] .habitat-ground-layer::before {
  opacity: 1;
  background: linear-gradient(to bottom, rgba(236, 242, 248, .3), rgba(214, 226, 236, .16));
}

#habitatPage[data-season="winter"] .habitat-flower-patch { filter: saturate(.5) brightness(.96); }
#habitatPage[data-season="autumn"] .habitat-flower-patch { filter: saturate(.8); }

#habitatPage[data-season="winter"] .habitat-pond {
  box-shadow:
    inset 0 0 0 5px rgba(232, 240, 248, .55),
    0 8px 14px rgba(26,55,50,.16);
}

.habitat-season-detail {
  position: absolute;
  z-index: 3;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(var(--detail-scale, 1));
}

.habitat-leaf-litter {
  width: 70px;
  height: 18px;
  opacity: .85;
  background:
    radial-gradient(ellipse at 14% 50%, #c4622f 0 4px, transparent 5px),
    radial-gradient(ellipse at 30% 30%, #e3b04b 0 4px, transparent 5px),
    radial-gradient(ellipse at 46% 70%, #d9893f 0 4px, transparent 5px),
    radial-gradient(ellipse at 63% 36%, #b5552c 0 3.5px, transparent 4.5px),
    radial-gradient(ellipse at 78% 62%, #e3b04b 0 4px, transparent 5px),
    radial-gradient(ellipse at 90% 40%, #d9893f 0 3px, transparent 4px);
}

.habitat-snow-patch {
  width: 64px;
  height: 14px;
  border-radius: 50%;
  background: radial-gradient(ellipse at 50% 50%, rgba(246, 249, 252, .78), rgba(236, 242, 248, .3) 62%, transparent 72%);
}

.habitat-particle.leaf {
  width: 8px;
  height: 6px;
  border-radius: 0 70% 0 70%;
  background: var(--leaf-color, #d9893f);
  animation: habitat-petal var(--particle-duration, 9s) linear infinite;
}

.habitat-particle.flake {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: rgba(250, 252, 255, .9);
  animation: habitat-flake var(--particle-duration, 10s) linear infinite;
}

.habitat-particle.fluff {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: rgba(255, 252, 238, .85);
  box-shadow: 0 0 3px rgba(255, 252, 238, .8);
  animation: habitat-fluff var(--particle-duration, 10s) ease-in-out infinite;
}

@keyframes habitat-flake {
  0% { transform: translate(0, -20px); opacity: 0; }
  15% { opacity: .85; }
  100% { transform: translate(calc(var(--particle-x, 20px) * .5), 150px); opacity: 0; }
}

@keyframes habitat-fluff {
  0%, 100% { transform: translate(0, 0); opacity: 0; }
  25% { opacity: .8; }
  60% { transform: translate(var(--particle-x, 30px), var(--particle-y, -24px)); opacity: .6; }
}

@media (max-width: 768px) {
  .habitat-season-detail { transform: translate(-50%, -50%) scale(calc(var(--detail-scale, 1) * .82)); }
}

@media (prefers-reduced-motion: reduce) {
  .habitat-tree .canopy,
  .habitat-tree .canopy::after,
  .habitat-ground-layer::before { transition: none; }
}

/* --== Corner buttons ==-- */
.habitat-exit-button,
.habitat-sound-toggle {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 120;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, .7);
  border-radius: 50%;
  background: rgba(255, 255, 255, .55);
  color: #3d5340;
  box-shadow: 0 2px 8px rgba(27, 41, 30, .18);
  backdrop-filter: blur(4px);
  cursor: pointer;
  opacity: .78;
  transition: opacity .2s ease, background .2s ease, transform .2s ease;
  -webkit-tap-highlight-color: transparent;
}

.habitat-exit-button { right: auto; left: 12px; }

.habitat-exit-button:hover,
.habitat-exit-button:focus-visible,
.habitat-sound-toggle:hover,
.habitat-sound-toggle:focus-visible { opacity: 1; background: rgba(255, 255, 255, .78); }
.habitat-exit-button:focus-visible,
.habitat-sound-toggle:focus-visible { outline: 2px solid #3d5340; outline-offset: 2px; }
.habitat-exit-button:active,
.habitat-sound-toggle:active { transform: scale(.94); }

.habitat-sound-icon {
  position: relative;
  width: 20px;
  height: 20px;
}

.habitat-sound-icon::before {
  content: "\266A";
  position: absolute;
  inset: 0;
  font: bold 19px/20px system-ui, sans-serif;
  text-align: center;
}

/* Off: a diagonal slash through the note. */
.habitat-sound-toggle[aria-pressed="false"] .habitat-sound-icon::after {
  content: "";
  position: absolute;
  left: 50%;
  top: -1px;
  width: 2px;
  height: 22px;
  border-radius: 1px;
  background: currentColor;
  transform: translateX(-50%) rotate(45deg);
}

.habitat-sound-toggle[aria-pressed="false"] { opacity: .72; }

#habitatPage[data-daypart="lateNight"] .habitat-exit-button,
#habitatPage[data-daypart="earlyMorning"] .habitat-exit-button,
#habitatPage[data-daypart="lateNight"] .habitat-sound-toggle,
#habitatPage[data-daypart="earlyMorning"] .habitat-sound-toggle {
  background: rgba(32, 40, 62, .55);
  border-color: rgba(220, 228, 255, .35);
  color: #e4e8f7;
}

@media (max-width: 768px) {
  .habitat-exit-button,
  .habitat-sound-toggle { top: 8px; right: 8px; width: 44px; height: 44px; }
  .habitat-exit-button { right: auto; left: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .habitat-exit-button,
  .habitat-sound-toggle { transition: none; }
  .habitat-exit-button:active,
  .habitat-sound-toggle:active { transform: none; }
}

/* --== Phase 11: Tree swing ==-- */
/* Same box and scale as the shade tree, so the branch meets the trunk at every size. */
.habitat-swing {
  width: 108px;
  height: 166px;
  transform-origin: 50% 100%;
  transform: translate(-50%, -100%) scale(var(--tree-scale, 1));
  --swing-rope: #d8c39b;
  --swing-seat: #8b6b4d;
}

.habitat-swing-branch {
  position: absolute;
  width: 54px;
  height: 20px;
  overflow: visible;
  color: #715d47;
}

/* The rig's top-left corner is the pivot on the branch. */
.habitat-swing-rig {
  position: absolute;
  width: 0;
  height: 0;
  rotate: 0deg;
}

.habitat-swing-parts {
  position: absolute;
  left: -15px;
  top: 0;
  width: 30px;
  overflow: visible;
}

.habitat-swing-parts .rope { stroke: var(--swing-rope); stroke-width: 1.6; stroke-linecap: round; }
.habitat-swing-parts .knot { fill: var(--swing-rope); }
.habitat-swing-parts .seat { fill: var(--swing-seat); stroke: rgba(0, 0, 0, .18); stroke-width: .8; }

/* A finger-sized target around the seat for visitors to flick it. */
.habitat-swing-hit {
  position: absolute;
  left: -22px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  pointer-events: auto;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* One half swing per iteration, back of the arc to the front; the angle comes from --swing-angle. */
.habitat-swing-rig.riding {
  animation: habitat-swing-ride var(--swing-half, 1.1s) linear 0s infinite alternate;
}

@keyframes habitat-swing-ride {
  0% { rotate: var(--swing-angle, 18deg); }
  10% { rotate: calc(var(--swing-angle, 18deg) * .951); }
  20% { rotate: calc(var(--swing-angle, 18deg) * .809); }
  30% { rotate: calc(var(--swing-angle, 18deg) * .588); }
  40% { rotate: calc(var(--swing-angle, 18deg) * .309); }
  50% { rotate: 0deg; }
  60% { rotate: calc(var(--swing-angle, 18deg) * -.309); }
  70% { rotate: calc(var(--swing-angle, 18deg) * -.588); }
  80% { rotate: calc(var(--swing-angle, 18deg) * -.809); }
  90% { rotate: calc(var(--swing-angle, 18deg) * -.951); }
  100% { rotate: calc(var(--swing-angle, 18deg) * -1); }
}

#habitatPage[data-weather="breezy"] .habitat-swing-rig:not(.riding) {
  animation: habitat-swing-breeze 3.4s ease-in-out var(--sway-delay, 0s) infinite;
}

@keyframes habitat-swing-breeze {
  0%, 100% { rotate: 3deg; }
  50% { rotate: -5deg; }
}

#habitatPage[data-season="winter"] .habitat-swing { --swing-rope: #e3d8c6; }
#habitatPage[data-daypart="lateNight"] .habitat-swing,
#habitatPage[data-daypart="earlyMorning"] .habitat-swing { --swing-rope: #b7a888; --swing-seat: #6e5843; }

@media (max-width: 768px) {
  .habitat-swing { transform: translate(-50%, -100%) scale(var(--tree-scale-mobile, 0.9)); }
}

@media (prefers-reduced-motion: reduce) {
  .habitat-swing-rig.riding,
  #habitatPage[data-weather="breezy"] .habitat-swing-rig:not(.riding) { animation: none; }
}

/* --== Phase 11: Campfire ==-- */
/* The box is the stone ring; flames rise above it and the log seats sit --camp-seat px out on each side. */
.habitat-campfire {
  width: 64px;
  height: 28px;
  transform: translate(-50%, -50%) scale(var(--camp-scale, 1));
  --camp-stone: #a29d92;
  --camp-wood: #7a5638;
  --camp-coals: #4c4039;
}

.habitat-campfire-ring {
  position: absolute;
  inset: 0;
  overflow: visible;
}

.habitat-campfire-ring .stone { fill: var(--camp-stone); stroke: rgba(0, 0, 0, .2); stroke-width: .7; }
.habitat-campfire-ring .ash { fill: rgba(66, 54, 46, .55); }
.habitat-campfire-ring .wood { fill: var(--camp-wood); stroke: rgba(0, 0, 0, .22); stroke-width: .6; }
.habitat-campfire-ring .coals { fill: var(--camp-coals); transition: fill 1.6s ease; }

.habitat-campfire-log {
  position: absolute;
  top: calc(50% - 15px);
  width: 34px;
  height: 12px;
  overflow: visible;
}

.habitat-campfire-log.left { left: calc(50% - var(--camp-seat, 50px) - 23px); }
.habitat-campfire-log.right { left: calc(50% + var(--camp-seat, 50px) - 11px); }
.habitat-campfire-log .bark { fill: var(--camp-wood); stroke: rgba(0, 0, 0, .22); stroke-width: .8; }
.habitat-campfire-log .ring { fill: #c9a274; stroke: rgba(0, 0, 0, .18); stroke-width: .6; }

.habitat-campfire-flames {
  position: absolute;
  left: 50%;
  bottom: 46%;
  width: 30px;
  height: 42px;
  translate: -50% 0;
  transform-origin: 50% 100%;
  transform: scale(.2);
  opacity: 0;
  transition: transform .9s ease, opacity .9s ease;
}

.habitat-flame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform-origin: 50% 100%;
}

.habitat-flame.outer { fill: #f2913a; }
.habitat-flame.inner { fill: #ffd56b; inset: 22% 14% 0; width: 72%; height: 78%; }

.habitat-campfire-sparks {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 60%;
  height: 0;
}

.habitat-spark {
  position: absolute;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: #ffcf6e;
  opacity: 0;
  animation: habitat-spark var(--spark-duration, 1.8s) linear infinite;
}

@keyframes habitat-spark {
  0% { transform: translate(0, 0); opacity: 0; }
  12% { opacity: 1; }
  100% { transform: translate(var(--spark-x, 0px), -52px); opacity: 0; }
}

/* A tap target for stoking it, live only while it burns. */
.habitat-campfire-hit {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  transform: translate(-50%, -70%);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.habitat-campfire-glow {
  position: absolute;
  z-index: 94;
  width: 340px;
  height: 200px;
  border-radius: 50%;
  transform: translate(-50%, -62%) scale(var(--camp-scale, 1));
  background: radial-gradient(closest-side, rgba(255, 168, 82, .5), rgba(255, 140, 60, .2) 55%, transparent);
  mix-blend-mode: screen;
  opacity: 0;
  pointer-events: none;
  transition: opacity 1.6s ease;
}

#habitatPage[data-fire="lit"] .habitat-campfire-flames { transform: scale(1); opacity: 1; }
#habitatPage[data-fire="lit"] .habitat-flame { animation: habitat-flicker .85s ease-in-out infinite alternate; }
#habitatPage[data-fire="lit"] .habitat-flame.inner { animation-duration: .6s; animation-delay: -.3s; }
#habitatPage[data-fire="embers"] .habitat-campfire-flames { transform: scale(.32); opacity: .75; }
#habitatPage[data-fire="lit"] .habitat-campfire-ring .coals { fill: #ff7a2e; }
#habitatPage[data-fire="embers"] .habitat-campfire-ring .coals { fill: #c4522a; }
#habitatPage[data-fire="lit"] .habitat-campfire-hit,
#habitatPage[data-fire="embers"] .habitat-campfire-hit { pointer-events: auto; }
#habitatPage[data-fire="lit"] .habitat-campfire-glow { opacity: .55; }
#habitatPage[data-fire="lit"][data-daypart="lateNight"] .habitat-campfire-glow,
#habitatPage[data-fire="lit"][data-daypart="earlyMorning"] .habitat-campfire-glow { opacity: .85; }
#habitatPage[data-fire="embers"] .habitat-campfire-glow { opacity: .25; }
.habitat-campfire.flare .habitat-campfire-flames { transform: scale(1.32); opacity: 1; transition-duration: .25s; }
#habitatPage[data-fire] .habitat-campfire-glow.flare { opacity: 1; transition-duration: .3s; }

@keyframes habitat-flicker {
  0% { scale: 1 1; }
  35% { scale: .93 1.08; }
  70% { scale: 1.05 .95; }
  100% { scale: .97 1.05; }
}

#habitatPage[data-daypart="lateNight"] .habitat-campfire,
#habitatPage[data-daypart="earlyMorning"] .habitat-campfire { --camp-stone: #7a7872; --camp-wood: #5f4630; }
#habitatPage[data-season="winter"] .habitat-campfire { --camp-stone: #b8b6b0; }

@media (prefers-reduced-motion: reduce) {
  .habitat-campfire-flames,
  .habitat-campfire-glow,
  .habitat-campfire-ring .coals { transition: none; }
  #habitatPage[data-fire="lit"] .habitat-flame { animation: none; }
}

/* --== Phase 12: Garden ==-- */
/* The box is the wooden bed; crops rise out of each plot's soil, and the width comes from layoutGarden. */
.habitat-garden {
  width: 132px;
  height: 22px;
  transform: translate(-50%, -50%) scale(var(--garden-scale, 1));
  --garden-board: #9b7550;
  --garden-soil: #6e5039;
  --garden-soil-wet: #4c3526;
  --garden-leaf: #5f9a52;
  --garden-stem: #4f8545;
}

.habitat-garden-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.habitat-garden-frame .board { fill: var(--garden-board); stroke: rgba(0, 0, 0, .22); stroke-width: 1; vector-effect: non-scaling-stroke; }

.habitat-plot {
  position: absolute;
  top: 4px;
  width: 26px;
  height: 14px;
}

.habitat-plot.hidden { display: none; }

.habitat-plot .soil {
  position: absolute;
  inset: 0;
  border-radius: 3px;
  background: var(--garden-soil);
  box-shadow: inset 0 2px 3px rgba(0, 0, 0, .25);
  transition: background 1.2s ease;
}

.habitat-plot.wet .soil { background: var(--garden-soil-wet); }
.habitat-plot[data-stage="empty"] .soil { box-shadow: inset 0 2px 3px rgba(0, 0, 0, .25), inset 0 0 0 1px rgba(255, 244, 222, .18); }
.habitat-plot.choosing .soil { box-shadow: inset 0 2px 3px rgba(0, 0, 0, .25), 0 0 0 2px rgba(255, 246, 214, .85); }

/* The crop box's soil line (y 34 of 40) sits on the middle of the plot. */
.habitat-crop {
  position: absolute;
  left: 0;
  bottom: 2px;
  width: 26px;
  height: 40px;
  transform-origin: 50% 85%;
  transition: transform .8s ease, filter .8s ease;
}

.habitat-crop-art { width: 100%; height: 100%; overflow: visible; }
.habitat-crop-art .leaf { fill: var(--garden-leaf); }
.habitat-crop-art .stem { fill: none; stroke: var(--garden-stem); stroke-width: 1.6; stroke-linecap: round; }
.habitat-crop-art .mound { fill: #5b412e; }
.habitat-crop-art .seed { fill: #e9d7a8; }
.habitat-crop-art .bud { fill: #7db35e; }
.habitat-crop-art .petal { fill: #f4c542; }
.habitat-crop-art .seedhead { fill: #6a4a2c; }
.habitat-crop-art .blossom { fill: #fffaf0; }
.habitat-crop-art .root { fill: #ee8a32; stroke: rgba(0, 0, 0, .15); stroke-width: .5; }
.habitat-crop-art .berry { fill: #e0434f; stroke: rgba(0, 0, 0, .14); stroke-width: .4; }
.habitat-crop-art .gourd { fill: #e8892e; stroke: rgba(0, 0, 0, .16); stroke-width: .5; }
.habitat-crop-art .gourd.young { fill: #9fbf5a; }
.habitat-crop-art .ridge { fill: none; stroke: rgba(120, 60, 10, .45); stroke-width: .6; }

/* Dry plants droop and fade a little until someone waters them. */
.habitat-plot.dry:not([data-stage="seed"]) .habitat-crop { transform: rotate(-8deg) scaleY(.88); filter: saturate(.55) brightness(.95); }

.habitat-plot-drops {
  position: absolute;
  left: 3px;
  right: 3px;
  bottom: 6px;
  height: 22px;
  opacity: 0;
  pointer-events: none;
  background:
    radial-gradient(circle, #9fd0f0 0 1.2px, transparent 1.6px) 0 0 / 7px 8px,
    radial-gradient(circle, #9fd0f0 0 1.2px, transparent 1.6px) 3px 4px / 7px 8px;
}

.habitat-plot.watering .habitat-plot-drops { opacity: .9; animation: habitat-water-drops .5s linear infinite; }

@keyframes habitat-water-drops {
  from { background-position: 0 0, 3px 4px; }
  to { background-position: 0 8px, 3px 12px; }
}

.habitat-plot.rustle .habitat-crop { animation: habitat-rustle .45s ease-in-out 1; }

@keyframes habitat-rustle {
  0%, 100% { rotate: 0deg; }
  30% { rotate: -7deg; }
  65% { rotate: 6deg; }
}

/* One target over the bed and its crops; tapGarden works out which plot was meant. */
.habitat-garden-hit {
  position: absolute;
  left: -4px;
  right: -4px;
  top: -30px;
  bottom: -10px;
  pointer-events: auto;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

#habitatPage[data-daypart="lateNight"] .habitat-garden,
#habitatPage[data-daypart="earlyMorning"] .habitat-garden { --garden-board: #6f5640; --garden-leaf: #4b7a47; --garden-stem: #3f6a3c; }
#habitatPage[data-season="autumn"] .habitat-garden { --garden-leaf: #78964a; }

/* Winter: the bed sleeps under a layer of snow. */
.habitat-plot::after {
  content: "";
  position: absolute;
  inset: -2px -1px 2px;
  border-radius: 4px 4px 3px 3px;
  background: linear-gradient(#f6f9fc, #dfe8f1);
  opacity: 0;
  pointer-events: none;
  transition: opacity 1.2s ease;
}

#habitatPage[data-season="winter"] .habitat-plot::after { opacity: .92; }
#habitatPage[data-season="winter"] .habitat-crop { transform: scaleY(.55); filter: saturate(.3) brightness(1.1); opacity: .7; }

.habitat-seed-picker {
  position: absolute;
  z-index: 110;
  display: flex;
  gap: 6px;
  padding: 6px;
  border: 1px solid rgba(255, 255, 255, .75);
  border-radius: 28px;
  background: rgba(255, 252, 244, .86);
  box-shadow: 0 4px 14px rgba(27, 41, 30, .22);
  backdrop-filter: blur(4px);
  transform: translateY(-100%);
}

.habitat-seed-picker[hidden] { display: none; }

.habitat-seed {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid rgba(61, 83, 64, .2);
  border-radius: 50%;
  background: rgba(255, 255, 255, .9);
  font: 22px/1 system-ui, sans-serif;
  cursor: pointer;
  transition: transform .15s ease, background .15s ease;
  -webkit-tap-highlight-color: transparent;
}

.habitat-seed:hover,
.habitat-seed:focus-visible { background: #fff; transform: translateY(-2px); }
.habitat-seed:focus-visible { outline: 2px solid #3d5340; outline-offset: 2px; }

#habitatPage[data-daypart="lateNight"] .habitat-seed-picker,
#habitatPage[data-daypart="earlyMorning"] .habitat-seed-picker {
  background: rgba(32, 40, 62, .78);
  border-color: rgba(220, 228, 255, .35);
}

#habitatPage[data-daypart="lateNight"] .habitat-seed,
#habitatPage[data-daypart="earlyMorning"] .habitat-seed { background: rgba(228, 232, 247, .9); }

@media (prefers-reduced-motion: reduce) {
  .habitat-plot .soil,
  .habitat-crop,
  .habitat-plot::after,
  .habitat-seed { transition: none; }
  .habitat-plot.watering .habitat-plot-drops { animation: none; opacity: .7; }
  .habitat-plot.rustle .habitat-crop { animation: none; }
  .habitat-seed:hover,
  .habitat-seed:focus-visible { transform: none; }
}

/* --== Phase 12: Mailbox and notice board ==-- */
/* Anchored at the ground line, like the trees, so the posts stand on the grass at every scale. */
.habitat-mailbox {
  width: 64px;
  height: 56px;
  transform-origin: 50% 100%;
  transform: translate(-50%, -100%) scale(var(--mail-scale, 1));
  --mail-post: #7a6049;
  --mail-frame: #9b7550;
  --mail-cork: #c9a274;
  --mail-box: #7f9fb4;
  --mail-flag: #d9534f;
}

.habitat-mailbox-art { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.habitat-mailbox-art .post { fill: var(--mail-post); }
.habitat-mailbox-art .frame { fill: var(--mail-frame); stroke: rgba(0, 0, 0, .2); stroke-width: .6; }
.habitat-mailbox-art .cork { fill: var(--mail-cork); }
.habitat-mailbox-art .box { fill: var(--mail-box); stroke: rgba(0, 0, 0, .22); stroke-width: .7; }
.habitat-mailbox-art .door { fill: rgba(0, 0, 0, .16); }
.habitat-mailbox-art .snow { fill: #f4f8fc; opacity: 0; transition: opacity 1.2s ease; }

/* Down along the box, and up while a visitor's note waits. */
.habitat-mail-flag {
  position: absolute;
  width: 12px;
  height: 14px;
  overflow: visible;
  transform-origin: 1px 13px;
  transform: rotate(90deg);
  transition: transform .45s cubic-bezier(.3, 1.5, .5, 1);
}

.habitat-mail-flag .pole { fill: #5f554d; }
.habitat-mail-flag .flag { fill: var(--mail-flag); }
.habitat-mailbox.has-mail .habitat-mail-flag { transform: rotate(0deg); }
.habitat-mailbox.posted .habitat-mailbox-art { animation: habitat-mail-bump .4s ease-out 1; transform-origin: 75% 100%; }

@keyframes habitat-mail-bump {
  0%, 100% { transform: none; }
  40% { transform: translateY(-1.5px) rotate(-1.5deg); }
}

.habitat-mail-paper {
  position: absolute;
  width: 7.5px;
  height: 7px;
  border-radius: .8px;
  background: #fbf6ea;
  box-shadow: 0 .6px 0 rgba(0, 0, 0, .18);
  pointer-events: none;
}

.habitat-mail-paper.hidden { display: none; }
/* The ones they leave each other are blue lined paper; a visitor's has its stamp's colour in the corner. */
.habitat-mail-paper[data-kind="friend"] { background: repeating-linear-gradient(#eef4fb 0 1.4px, #b9cde2 1.4px 1.8px); }
.habitat-mail-paper[data-kind="visitor"]::after {
  content: "";
  position: absolute;
  right: .8px;
  top: .8px;
  width: 2.4px;
  height: 2.4px;
  border-radius: .5px;
  background: var(--stamp-color, #e8b93c);
}

.habitat-mail-paper[data-stamp="flower"],
.habitat-mail-stamp[data-stamp="flower"],
.habitat-stamp-art.flower { --stamp-color: #e58fb0; }
.habitat-mail-paper[data-stamp="leaf"],
.habitat-mail-stamp[data-stamp="leaf"],
.habitat-stamp-art.leaf { --stamp-color: #6aa45c; }
.habitat-mail-paper[data-stamp="moon"],
.habitat-mail-stamp[data-stamp="moon"],
.habitat-stamp-art.moon { --stamp-color: #9d8fd6; }

.habitat-mail-hit {
  position: absolute;
  inset: -10px -6px -4px;
  pointer-events: auto;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.habitat-mailbox.choosing .habitat-mailbox-art { filter: drop-shadow(0 0 2px rgba(255, 246, 214, .95)); }

#habitatPage[data-daypart="lateNight"] .habitat-mailbox,
#habitatPage[data-daypart="earlyMorning"] .habitat-mailbox { --mail-post: #5c4838; --mail-frame: #6f5640; --mail-cork: #8f7457; --mail-box: #5d7486; --mail-flag: #a8443f; }
#habitatPage[data-season="winter"] .habitat-mailbox-art .snow { opacity: .95; }

/* The note panel: built like the seed picker, with 44px targets and a night tint. */
.habitat-mail-panel {
  position: absolute;
  z-index: 110;
  box-sizing: border-box;
  width: min(300px, calc(100% - 16px));
  max-height: calc(100% - 16px);
  overflow-y: auto;
  padding: 8px 10px 10px;
  border: 1px solid rgba(255, 255, 255, .75);
  border-radius: 16px;
  background: rgba(255, 252, 244, .9);
  color: #3d5340;
  box-shadow: 0 4px 14px rgba(27, 41, 30, .22);
  backdrop-filter: blur(4px);
  font: 14px/1.3 system-ui, sans-serif;
}

.habitat-mail-panel[hidden] { display: none; }
.habitat-mail-head { display: flex; align-items: center; justify-content: space-between; }
.habitat-mail-title { margin: 0; font-weight: 600; }
.habitat-mail-title.small { margin-top: 8px; font-size: 12px; opacity: .8; }

.habitat-mail-close {
  width: 44px;
  height: 44px;
  margin: -6px -8px -6px 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  font: 24px/1 system-ui, sans-serif;
  cursor: pointer;
}

.habitat-mail-stamps { display: flex; gap: 6px; margin: 2px 0 8px; }

.habitat-mail-stamp,
.habitat-mail-note {
  border: 1px solid rgba(61, 83, 64, .2);
  background: rgba(255, 255, 255, .9);
  color: inherit;
  cursor: pointer;
  transition: transform .15s ease, background .15s ease;
  -webkit-tap-highlight-color: transparent;
}

.habitat-mail-stamp {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 10px;
}

.habitat-mail-stamp[aria-pressed="true"] { border-color: #3d5340; box-shadow: inset 0 0 0 1px #3d5340; background: #fff; }

.habitat-stamp-art { width: 20px; height: 20px; fill: var(--stamp-color, #e8b93c); }
.habitat-stamp-art .middle { fill: #f4d36b; }
.habitat-stamp-art .vein { fill: none; stroke: rgba(255, 255, 255, .7); stroke-width: 1; }

.habitat-mail-notes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }

.habitat-mail-note {
  min-height: 44px;
  padding: 6px 8px;
  border-radius: 12px;
  font: inherit;
  text-align: left;
}

.habitat-mail-note:disabled { opacity: .5; cursor: default; }

.habitat-mail-stamp:hover,
.habitat-mail-stamp:focus-visible,
.habitat-mail-note:not(:disabled):hover,
.habitat-mail-note:focus-visible { background: #fff; transform: translateY(-1px); }
.habitat-mail-stamp:focus-visible,
.habitat-mail-note:focus-visible,
.habitat-mail-close:focus-visible { outline: 2px solid #3d5340; outline-offset: 2px; }

.habitat-mail-status { margin: 6px 0 0; font-size: 12px; opacity: .8; }

.habitat-mail-board { margin: 4px 0 0; padding: 0; list-style: none; }

.habitat-mail-board li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 0;
  border-top: 1px solid rgba(61, 83, 64, .12);
  font-size: 13px;
}

.habitat-mail-board li.friend::before { content: ""; width: 14px; height: 14px; flex: none; border-radius: 2px; background: repeating-linear-gradient(#eef4fb 0 2.6px, #b9cde2 2.6px 3.4px); }
.habitat-mail-board .habitat-stamp-art { width: 14px; height: 14px; flex: none; }
.habitat-mail-board .text { flex: 1; }
.habitat-mail-board .from { font-size: 11px; opacity: .7; white-space: nowrap; }

#habitatPage[data-daypart="lateNight"] .habitat-mail-panel,
#habitatPage[data-daypart="earlyMorning"] .habitat-mail-panel {
  background: rgba(32, 40, 62, .86);
  border-color: rgba(220, 228, 255, .35);
  color: #e4e8f7;
}

#habitatPage[data-daypart="lateNight"] .habitat-mail-stamp,
#habitatPage[data-daypart="earlyMorning"] .habitat-mail-stamp,
#habitatPage[data-daypart="lateNight"] .habitat-mail-note,
#habitatPage[data-daypart="earlyMorning"] .habitat-mail-note { background: rgba(228, 232, 247, .12); border-color: rgba(220, 228, 255, .3); }
#habitatPage[data-daypart="lateNight"] .habitat-mail-panel :focus-visible,
#habitatPage[data-daypart="earlyMorning"] .habitat-mail-panel :focus-visible { outline-color: #e4e8f7; }
#habitatPage[data-daypart="lateNight"] .habitat-mail-stamp[aria-pressed="true"],
#habitatPage[data-daypart="earlyMorning"] .habitat-mail-stamp[aria-pressed="true"] { background: rgba(228, 232, 247, .3); border-color: #e4e8f7; box-shadow: inset 0 0 0 1px #e4e8f7; }

@media (prefers-reduced-motion: reduce) {
  .habitat-mail-flag,
  .habitat-mailbox-art .snow,
  .habitat-mail-stamp,
  .habitat-mail-note { transition: none; }
  .habitat-mailbox.posted .habitat-mailbox-art { animation: none; }
  .habitat-mail-stamp:hover,
  .habitat-mail-stamp:focus-visible,
  .habitat-mail-note:not(:disabled):hover,
  .habitat-mail-note:focus-visible { transform: none; }
}

/* --== Phase 13: Visitor controls and toys ==-- */
/* Round buttons beside the sound toggle, sharing its look and night tint. */
.habitat-controls {
  position: absolute;
  top: 12px;
  right: 60px;
  z-index: 120;
  display: flex;
  gap: 8px;
}

.habitat-control {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, .7);
  border-radius: 50%;
  background: rgba(255, 255, 255, .55);
  color: #3d5340;
  box-shadow: 0 2px 8px rgba(27, 41, 30, .18);
  backdrop-filter: blur(4px);
  cursor: pointer;
  opacity: .78;
  transition: opacity .2s ease, background .2s ease, transform .2s ease;
  -webkit-tap-highlight-color: transparent;
}

.habitat-control:hover,
.habitat-control:focus-visible { opacity: 1; background: rgba(255, 255, 255, .78); }
.habitat-control:focus-visible { outline: 2px solid #3d5340; outline-offset: 2px; }
.habitat-control:active { transform: scale(.94); }
/* Toy buttons can be pulled from, so a touch drag doesn't pan the page. */
.habitat-toy-button { touch-action: none; }
.habitat-control[aria-pressed="true"] { opacity: 1; box-shadow: 0 0 0 2px rgba(61, 83, 64, .35), 0 2px 8px rgba(27, 41, 30, .18); }

#habitatPage[data-daypart="lateNight"] .habitat-control,
#habitatPage[data-daypart="earlyMorning"] .habitat-control {
  background: rgba(32, 40, 62, .55);
  border-color: rgba(220, 228, 255, .35);
  color: #e4e8f7;
}

.habitat-ball-icon,
.habitat-ball-body {
  border-radius: 50%;
  background: conic-gradient(from 20deg, #e86a5a 0 90deg, #fbf3e4 0 180deg, #5aa2d6 0 270deg, #fbf3e4 0);
  box-shadow: inset -3px -3px 5px rgba(0, 0, 0, .22), inset 2px 2px 3px rgba(255, 255, 255, .5), 0 0 0 1px rgba(60, 50, 40, .25);
}

.habitat-ball-icon { width: 18px; height: 18px; }

/* Anchored at its ground contact; depth scale shrinks it toward the horizon like everything else. */
.habitat-toy {
  position: absolute;
  width: 0;
  height: 0;
  pointer-events: auto;
  touch-action: none;
  cursor: grab;
  transform: scale(var(--ball-scale, 1));
}

/* A finger-sized hit area around a small toy. */
.habitat-toy::before {
  content: "";
  position: absolute;
  left: -22px;
  top: -34px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
}

.habitat-toy.held { cursor: grabbing; }

.habitat-ball-body {
  position: absolute;
  left: -9px;
  top: -18px;
  width: 18px;
  height: 18px;
}

.habitat-toy-shadow {
  position: absolute;
  left: -8px;
  top: -4px;
  width: 16px;
  height: 6px;
  border-radius: 50%;
  background: rgba(30, 40, 25, .28);
}

/* The frisbee: a flat disc seen from the side, with a rim highlight that sweeps round while it glides. */
.habitat-frisbee-icon,
.habitat-frisbee-body {
  border-radius: 50%;
  background: radial-gradient(ellipse at 50% 30%, #ffe08a 0 30%, #f4b23f 32% 70%, #d9822b 72%);
  box-shadow: inset 0 -2px 0 rgba(150, 70, 20, .35), 0 0 0 1px rgba(80, 50, 20, .3);
}

.habitat-frisbee-icon { width: 22px; height: 9px; }

.habitat-frisbee-body {
  position: absolute;
  left: -12px;
  top: -10px;
  width: 24px;
  height: 8px;
  overflow: hidden;
}

.habitat-frisbee-body::after {
  content: "";
  position: absolute;
  top: 0;
  left: -40%;
  width: 30%;
  height: 100%;
  background: rgba(255, 255, 255, .55);
  opacity: 0;
}

.habitat-frisbee.gliding .habitat-frisbee-body::after { animation: habitat-frisbee-spin .32s linear infinite; }

@keyframes habitat-frisbee-spin {
  0% { left: -40%; opacity: .8; }
  100% { left: 110%; opacity: .8; }
}

.habitat-frisbee-shadow { left: -11px; width: 22px; }

/* The kite: lies flat on the grass, and flies from a rig pinned at the flyer's hand. The rig's arm sets the
   string's length and angle (from JS), and the sway inside it rotates the string and sail together. */
.habitat-kite-art { display: block; width: 100%; height: 100%; overflow: visible; }
.habitat-kite-icon { display: block; width: 16px; height: 26px; }
.habitat-kite-icon .habitat-kite-art { transform: rotate(-12deg); }

.habitat-kite-body {
  position: absolute;
  left: -10px;
  top: -22px;
  width: 20px;
  height: 33px;
}

.habitat-kite-body .habitat-kite-art { transform: translateY(9px) rotate(64deg) scaleY(.55); transform-origin: 50% 50%; }
.habitat-kite-shadow { left: -12px; width: 24px; }

.habitat-kite.falling {
  transition: left 1.1s cubic-bezier(.35, .1, .6, 1), top 1.1s cubic-bezier(.45, .05, .75, .9);
  pointer-events: none;
}
.habitat-kite.falling .habitat-kite-art { animation: habitat-kite-fall 1.1s ease-in both; }

@keyframes habitat-kite-fall {
  0% { transform: translateY(-30px) rotate(-10deg) scaleY(1); }
  35% { transform: translateY(-24px) rotate(28deg) scaleY(.95); }
  70% { transform: translateY(-8px) rotate(-14deg) scaleY(.8); }
  100% { transform: translateY(9px) rotate(64deg) scaleY(.55); }
}

.habitat-kite-rig {
  position: absolute;
  width: 0;
  height: 0;
  color: rgba(62, 52, 40, .55);
  pointer-events: none;
  transform: translateY(calc(var(--kite-hand, 30px) * -1));
}
.habitat-kite-rig.passing { transition: left .6s ease, top .6s ease; }

#habitatPage[data-daypart="lateNight"] .habitat-kite-rig,
#habitatPage[data-daypart="earlyMorning"] .habitat-kite-rig,
#habitatPage[data-daypart="evening"] .habitat-kite-rig { color: rgba(236, 232, 220, .55); }

.habitat-kite-arm {
  position: absolute;
  left: -5px;
  bottom: 0;
  width: 10px;
  height: 0;
  transform-origin: 50% 100%;
  transition: height var(--kite-ms, 0ms) cubic-bezier(.25, .7, .35, 1), transform var(--kite-ms, 0ms) ease;
}

.habitat-kite-sway {
  position: absolute;
  inset: 0;
  transform-origin: 50% 100%;
  animation: habitat-kite-sway 3.6s ease-in-out infinite alternate;
}
#habitatPage[data-weather="breezy"] .habitat-kite-sway { animation-duration: 2.2s; animation-name: habitat-kite-sway-breezy; }

.habitat-kite-string { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; transform: scaleX(var(--kite-wind, 1)); }

.habitat-kite-sail {
  position: absolute;
  left: 50%;
  top: 0;
  width: 24px;
  height: 40px;
  pointer-events: auto;
  touch-action: none;
  cursor: pointer;
  transform: translate(-50%, -22%) rotate(calc(var(--kite-wind, 1) * -10deg));
}

/* A finger-sized hit area around the sail. */
.habitat-kite-sail::before { content: ""; position: absolute; inset: -10px -10px 8px; border-radius: 50%; }
.habitat-kite-sail .habitat-kite-art { transform-origin: 50% 8%; animation: habitat-kite-flutter 1.3s ease-in-out infinite alternate; }

@keyframes habitat-kite-sway { from { transform: rotate(-2.5deg); } to { transform: rotate(2.5deg); } }
@keyframes habitat-kite-sway-breezy { from { transform: rotate(-5deg); } to { transform: rotate(4deg); } }
@keyframes habitat-kite-flutter { from { transform: rotate(-5deg); } to { transform: rotate(5deg); } }

.habitat-kite-rig.tug .habitat-kite-sway { animation: habitat-kite-tug .9s ease-in-out 1; }
.habitat-kite-rig.tug .habitat-kite-sail .habitat-kite-art { animation: habitat-kite-loop .9s ease-in-out 1; }

@keyframes habitat-kite-tug {
  0%, 100% { transform: rotate(0); }
  35% { transform: rotate(calc(var(--kite-wind, 1) * 14deg)); }
  70% { transform: rotate(calc(var(--kite-wind, 1) * -6deg)); }
}

@keyframes habitat-kite-loop {
  0% { transform: rotate(0); }
  100% { transform: rotate(calc(var(--kite-wind, 1) * 360deg)); }
}

@media (max-width: 768px) {
  .habitat-controls { top: 8px; right: 60px; }
  .habitat-control { width: 44px; height: 44px; }
  .habitat-ball-body { left: -10px; top: -20px; width: 20px; height: 20px; }
  .habitat-frisbee-body { left: -13px; top: -11px; width: 26px; height: 9px; }
  .habitat-controls { gap: 6px; }
  .habitat-kite-sail { width: 22px; height: 37px; }
}

@media (prefers-reduced-motion: reduce) {
  .habitat-control { transition: none; }
  .habitat-control:active { transform: none; }
  .habitat-frisbee.gliding .habitat-frisbee-body::after { animation: none; }
  .habitat-kite-sway, .habitat-kite-sail .habitat-kite-art,
  .habitat-kite-rig.tug .habitat-kite-sway, .habitat-kite-rig.tug .habitat-kite-sail .habitat-kite-art { animation: none; }
  .habitat-kite-rig.passing { transition: none; }
}

/* --== Phase 14: Photo mode ==-- */
.habitat-photo-icon { width: 22px; height: 22px; }

/* Presses pass through the frame to the scene; only the shutter takes them. */
.habitat-photo-frame {
  position: absolute;
  inset: 64px 16px 84px;
  z-index: 115;
  pointer-events: none;
}

.habitat-photo-frame[hidden] { display: none; }

.habitat-photo-corner {
  position: absolute;
  width: 28px;
  height: 28px;
  border: 0 solid rgba(255, 255, 255, .85);
  filter: drop-shadow(0 1px 2px rgba(27, 41, 30, .35));
}

.habitat-photo-corner.tl { top: 0; left: 0; border-width: 3px 0 0 3px; border-top-left-radius: 8px; }
.habitat-photo-corner.tr { top: 0; right: 0; border-width: 3px 3px 0 0; border-top-right-radius: 8px; }
.habitat-photo-corner.bl { bottom: 0; left: 0; border-width: 0 0 3px 3px; border-bottom-left-radius: 8px; }
.habitat-photo-corner.br { bottom: 0; right: 0; border-width: 0 3px 3px 0; border-bottom-right-radius: 8px; }

.habitat-photo-shutter {
  position: absolute;
  left: 50%;
  bottom: 10px;
  width: 58px;
  height: 58px;
  padding: 0;
  border: 4px solid rgba(255, 255, 255, .92);
  border-radius: 50%;
  background: rgba(255, 255, 255, .5);
  box-shadow: inset 0 0 0 3px rgba(61, 83, 64, .28), 0 2px 10px rgba(27, 41, 30, .25);
  transform: translateX(-50%);
  cursor: pointer;
  pointer-events: auto;
  transition: transform .15s ease, background .2s ease;
  -webkit-tap-highlight-color: transparent;
}

.habitat-photo-shutter:hover,
.habitat-photo-shutter:focus-visible { background: rgba(255, 255, 255, .8); }
.habitat-photo-shutter:focus-visible { outline: 2px solid #3d5340; outline-offset: 3px; }
.habitat-photo-shutter:active { transform: translateX(-50%) scale(.92); }
.habitat-photo-shutter[aria-busy="true"] { cursor: progress; opacity: .7; }
.habitat-photo-frame.developed .habitat-photo-shutter,
.habitat-photo-frame.developed .habitat-photo-corner { visibility: hidden; }

.habitat-photo-flash {
  position: fixed;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
}

.habitat-photo-frame.flash .habitat-photo-flash { animation: habitat-photo-flash .45s ease-out 1; }
@keyframes habitat-photo-flash { from { opacity: .85; } to { opacity: 0; } }

.habitat-photo-preview {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 125;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: min(560px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, .75);
  border-radius: 16px;
  background: rgba(255, 252, 244, .92);
  color: #3d5340;
  box-shadow: 0 6px 22px rgba(27, 41, 30, .3);
  backdrop-filter: blur(4px);
  font: 14px/1.3 system-ui, sans-serif;
  transform: translate(-50%, -50%);
  animation: habitat-photo-develop .35s ease-out 1;
}

.habitat-photo-preview[hidden] { display: none; }

@keyframes habitat-photo-develop {
  from { opacity: 0; transform: translate(-50%, -46%) rotate(-2deg); }
  to { opacity: 1; transform: translate(-50%, -50%); }
}

.habitat-photo-print {
  display: block;
  min-height: 0;
  max-width: 100%;
  max-height: calc(100vh - 220px);
  max-height: calc(100dvh - 220px);
  object-fit: contain;
  box-shadow: 0 2px 8px rgba(27, 41, 30, .25);
  transform: rotate(-1deg);
}

.habitat-photo-print[hidden],
.habitat-photo-message[hidden],
.habitat-photo-action[hidden] { display: none; }
.habitat-photo-message { margin: 4px 8px; text-align: center; }
.habitat-photo-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }

.habitat-photo-action {
  min-width: 76px;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid rgba(61, 83, 64, .35);
  border-radius: 22px;
  background: rgba(255, 255, 255, .7);
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.habitat-photo-action.primary { background: #3d5340; border-color: #3d5340; color: #fbf8f1; }
.habitat-photo-action:hover,
.habitat-photo-action:focus-visible { background: rgba(255, 255, 255, .95); }
.habitat-photo-action.primary:hover,
.habitat-photo-action.primary:focus-visible { background: #4c6650; }
.habitat-photo-action:focus-visible { outline: 2px solid #3d5340; outline-offset: 2px; }

#habitatPage[data-daypart="lateNight"] .habitat-photo-preview,
#habitatPage[data-daypart="earlyMorning"] .habitat-photo-preview { background: rgba(32, 40, 62, .9); border-color: rgba(220, 228, 255, .35); color: #e4e8f7; }
#habitatPage[data-daypart="lateNight"] .habitat-photo-action,
#habitatPage[data-daypart="earlyMorning"] .habitat-photo-action { background: rgba(228, 232, 247, .12); border-color: rgba(220, 228, 255, .3); }
#habitatPage[data-daypart="lateNight"] .habitat-photo-action.primary,
#habitatPage[data-daypart="earlyMorning"] .habitat-photo-action.primary { background: #e4e8f7; border-color: #e4e8f7; color: #242a43; }
#habitatPage[data-daypart="lateNight"] .habitat-photo-preview :focus-visible,
#habitatPage[data-daypart="earlyMorning"] .habitat-photo-preview :focus-visible { outline-color: #e4e8f7; }

/* -= Album =- */
.habitat-photo-album-button {
  position: absolute;
  left: calc(50% - 92px);
  bottom: 16px;
  width: 46px;
  height: 46px;
  padding: 3px;
  border: 2px solid rgba(255, 255, 255, .92);
  border-radius: 10px;
  background: #fbf8f1;
  box-shadow: 0 2px 8px rgba(27, 41, 30, .3);
  cursor: pointer;
  pointer-events: auto;
  transform: rotate(-4deg);
  -webkit-tap-highlight-color: transparent;
}

.habitat-photo-album-button[hidden],
.habitat-photo-frame.developed .habitat-photo-album-button { display: none; }
.habitat-photo-album-button:focus-visible { outline: 2px solid #3d5340; outline-offset: 3px; }
.habitat-photo-album-latest { display: block; width: 100%; height: 100%; border-radius: 6px; object-fit: cover; }

.habitat-photo-album { width: min(620px, calc(100% - 24px)); overflow-y: auto; overscroll-behavior: contain; }
.habitat-album-title { margin: 2px 0 0; font-size: 17px; font-weight: 600; }
.habitat-album-note { margin: 0; font-size: 13px; opacity: .8; text-align: center; }
.habitat-album-note[hidden] { display: none; }

.habitat-album-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  width: 100%;
}

.habitat-album-shot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 0;
  margin: 0;
}

.habitat-album-thumb {
  display: block;
  max-width: 100%;
  max-height: calc((100vh - 330px) / 2);
  max-height: calc((100dvh - 330px) / 2);
  min-height: 60px;
  object-fit: contain;
  box-shadow: 0 1px 5px rgba(27, 41, 30, .25);
}

.habitat-album-shot:nth-child(odd) .habitat-album-thumb { transform: rotate(-1.2deg); }
.habitat-album-shot:nth-child(even) .habitat-album-thumb { transform: rotate(1deg); }
.habitat-album-caption { max-width: 100%; font-size: 12px; text-align: center; overflow-wrap: anywhere; }
.habitat-album-actions { display: flex; gap: 6px; }

.habitat-album-action {
  min-width: 44px;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid rgba(61, 83, 64, .35);
  border-radius: 22px;
  background: rgba(255, 255, 255, .7);
  color: inherit;
  font: 13px/1 system-ui, sans-serif;
  cursor: pointer;
}

.habitat-album-action:hover,
.habitat-album-action:focus-visible { background: rgba(255, 255, 255, .95); }
.habitat-album-action:focus-visible { outline: 2px solid #3d5340; outline-offset: 2px; }
#habitatPage[data-daypart="lateNight"] .habitat-album-action,
#habitatPage[data-daypart="earlyMorning"] .habitat-album-action { background: rgba(228, 232, 247, .12); border-color: rgba(220, 228, 255, .3); }
#habitatPage[data-daypart="lateNight"] .habitat-album-action:hover,
#habitatPage[data-daypart="earlyMorning"] .habitat-album-action:hover,
#habitatPage[data-daypart="lateNight"] .habitat-album-action:focus-visible,
#habitatPage[data-daypart="earlyMorning"] .habitat-album-action:focus-visible { background: rgba(228, 232, 247, .24); }

@media (max-width: 768px) {
  .habitat-photo-frame { inset: 60px 10px 92px; }
  .habitat-photo-album-button { left: calc(50% - 84px); width: 42px; height: 42px; }
  .habitat-photo-album { max-height: calc(100% - 160px); }
  .habitat-album-grid { gap: 8px; }
  .habitat-album-thumb { max-height: calc((100vh - 430px) / 2); max-height: calc((100dvh - 430px) / 2); }
  .habitat-album-action { padding: 0 10px; }
  .habitat-photo-corner { width: 22px; height: 22px; }
  .habitat-photo-preview { padding: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .habitat-photo-shutter { transition: none; }
  .habitat-photo-shutter:active { transform: translateX(-50%); }
  .habitat-photo-frame.flash .habitat-photo-flash,
  .habitat-photo-preview { animation: none; }
  .habitat-photo-album-button, .habitat-album-thumb { transform: none !important; }
}
