/* The nest box (nestbox.js): Wren's home drawn in ink and in 3D, the
 * hedgerow and the sky around it. Colors are theme tokens (the page defines
 * --text, --accent, --warm…), so dark mode follows; every motion sits behind
 * prefers-reduced-motion: no-preference.
 */

.ik {
  --ik-wood: light-dark(#f5e9d5, #2b261e);
  --ik-wood-2: light-dark(#e9d6b8, #3a3228);
  --ik-roof: light-dark(#dcebe3, #16261f);
  --ik-roof-edge: light-dark(#bcd6c9, #21372d);
  --ik-plate: light-dark(#fffdf6, #1c231f);
  --ik-hole: light-dark(#2f2518, #050807);
  --ik-shadow: light-dark(#3b2b16, #000000);
  --ik-flag: var(--warm);
  --ik-arm: light-dark(#6b5537, #b59a72);
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.ik .ik-fill { stroke: none; }
.ik .ik-paper { fill: var(--surface); }
.ik .ik-wood { fill: var(--ik-wood); }
.ik .ik-roof { fill: var(--ik-roof); }
.ik .ik-roof-edge { fill: var(--ik-roof-edge); }
.ik .ik-plate { fill: var(--ik-plate); }
.ik .ik-hole { fill: var(--ik-hole); }
.ik .ik-rim { fill: var(--ik-wood-2); }
.ik .ik-glow { fill: url(#ik-glow-g); }
.ik .ik-glow-a { stop-color: light-dark(#fff3cc, #ffe7a6); }
.ik .ik-glow-b { stop-color: var(--warm); }
.ik .ik-glow-c { stop-color: light-dark(#b8741b, #c98a2a); }
.ik .ik-ground { fill: var(--ik-shadow); opacity: 0.07; }
.ik .ik-flag { fill: var(--ik-flag); }
.ik .ik-arm { fill: var(--ik-arm); }

/* A face turned from the light gets a little darker, as well as more hachure */
.ik .ik-shade { fill: var(--ik-shadow); }
.ik .ik-s1 { opacity: 0.05; }
.ik .ik-s2 { opacity: 0.11; }
.ik .ik-s3 { opacity: 0.19; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .ik .ik-s1 { opacity: 0.16; }
  :root:not([data-theme="light"]) .ik .ik-s2 { opacity: 0.28; }
  :root:not([data-theme="light"]) .ik .ik-s3 { opacity: 0.4; }
  :root:not([data-theme="light"]) .ik .ik-ground { opacity: 0.4; }
}
:root[data-theme="dark"] .ik .ik-s1 { opacity: 0.16; }
:root[data-theme="dark"] .ik .ik-s2 { opacity: 0.28; }
:root[data-theme="dark"] .ik .ik-s3 { opacity: 0.4; }
:root[data-theme="dark"] .ik .ik-ground { opacity: 0.4; }

.ik .ik-ink { fill: none; stroke: var(--text); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ik .ik-thin { stroke-width: 1.35; }
.ik .ik-grain { opacity: 0.5; }
.ik .ik-shingle { stroke: var(--accent-ink); opacity: 0.62; }
.ik .ik-hatch { fill: none; stroke: var(--warm-ink); stroke-width: 1.05; stroke-linecap: round; opacity: 0.38; }
.ik .ik-hatch.ik-green { stroke: var(--accent); opacity: 0.55; }
.ik .ik-hatch.ik-soft { stroke: var(--text); opacity: 0.35; }
.ik .ik-lip { fill: none; stroke: var(--warm); stroke-width: 1.6; stroke-linecap: round; opacity: 0.55; }
.ik .ik-nail { fill: var(--text); opacity: 0.7; }
.ik .ik-name { font-family: "Caveat", "Bradley Hand", "Segoe Print", cursive; font-weight: 700; fill: var(--text); }
.ik .ik-peg { fill: none; stroke: var(--ik-wood-2); stroke-linecap: round; }
.ik .ik-peg-end { fill: var(--ik-wood); stroke: var(--text); stroke-width: 1.2; }

/* Stamps pasted on the side: paper with perforated edges (dots in the wall's color bite into it) */
.ik .ik-stamp { fill: var(--ik-plate); }
.ik .ik-stamp-perf { fill: none; stroke: var(--ik-wood); stroke-width: 2.3; stroke-dasharray: 0 3.4; stroke-linecap: round; }
.ik .ik-stamp-frame { fill: none; stroke: var(--text); stroke-width: 0.7; opacity: 0.35; }

/* ------------------------------------------------------------------ over the box: the wren, friends, letters */

/* Pivots in the doodle's own units (its feet; the flying one's middle), never "fill-box": newer
   Safari mislocates fill-box origins on SVG groups */
.nb .nb-anim { transform-box: view-box; transform-origin: 50px 79px; }
.nb .nb-flying .nb-anim { transform-origin: 61px 51px; }
.nb .nb-flying.mirror .nb-anim { transform: scaleX(-1); }
.nb .nb-trail { fill: none; stroke: var(--accent); stroke-width: 1.7; stroke-linecap: round; stroke-dasharray: 1.5 7; }
.nb .nb-zzz text { font: 700 17px/1 "Caveat", cursive; fill: var(--accent-ink); opacity: 0; }
.nb .nb-huh { font: 700 34px/1 "Caveat", cursive; fill: var(--accent); }
.nb .nb-puff path { fill: none; stroke: var(--warm); stroke-width: 2; stroke-linecap: round; opacity: 0; }
.nb .nb-puff.big path { stroke-width: 2.6; }
.nb .nb-letter { pointer-events: none; }

@media (prefers-reduced-motion: no-preference) {
  .nb .nb-anim.hop { animation: nb-hop 0.62s cubic-bezier(0.3, 0.7, 0.4, 1) both; }
  .nb .nb-anim.tilt { animation: nb-tilt 1.4s ease-in-out both; }
  .nb .nb-anim.emerge { animation: nb-emerge 1.1s cubic-bezier(0.3, 0.7, 0.4, 1) both; }
  .nb .nb-bird.lands .nb-anim { animation: nb-land 0.9s calc(var(--i, 0) * 0.35s + 0.1s) cubic-bezier(0.3, 0.8, 0.4, 1) both; }
  .nb .nb-zzz text { animation: nb-z 3.6s ease-in infinite; }
  .nb .nb-zzz text:nth-child(2) { animation-delay: 1.2s; }
  .nb .nb-zzz text:nth-child(3) { animation-delay: 2.4s; }
  .nb .nb-huh { animation: nb-huh 1.7s cubic-bezier(0.3, 1.6, 0.5, 1) both; }
  .nb .nb-puff path { animation: nb-puff 0.85s ease-out both; }
}
@media (prefers-reduced-motion: reduce) {
  .nb .nb-zzz text:first-child { opacity: 0.8; }
}
@keyframes nb-hop { 0%, 100% { transform: none; } 35% { transform: translateY(-14px) rotate(-4deg); } 62% { transform: translateY(1px) scaleY(0.92); } }
@keyframes nb-emerge { 0% { opacity: 0; transform: translateY(190px) scale(0.35); } 25% { opacity: 1; transform: translateY(170px) scale(0.5); } 70% { transform: translateY(-16px) scale(1.03); } 100% { opacity: 1; transform: none; } }
@keyframes nb-tilt { 0%, 100% { transform: none; } 18%, 70% { transform: rotate(-11deg); } 40% { transform: rotate(-7deg); } }
@keyframes nb-land { 0% { opacity: 0; transform: translate(60px, -90px) scale(0.6) rotate(12deg); } 60% { opacity: 1; transform: translate(0, 3px) scaleY(0.9); } 100% { opacity: 1; transform: none; } }
/* These move by translation only, so there's no pivot for a browser to put in the wrong place */
@keyframes nb-z { 0% { opacity: 0; transform: translate(0, 0); } 20% { opacity: 0.9; } 100% { opacity: 0; transform: translate(14px, -34px); } }
@keyframes nb-huh { 0% { opacity: 0; transform: translateY(10px); } 18% { opacity: 1; transform: translateY(-2px); } 30% { transform: none; } 80% { opacity: 1; } 100% { opacity: 0; transform: translateY(-6px); } }
@keyframes nb-puff { 0% { opacity: 0; transform: translate(calc(var(--dx) * 0.15), calc(var(--dy) * 0.15)); } 25% { opacity: 1; } 100% { opacity: 0; transform: translate(var(--dx), var(--dy)); } }

/* ------------------------------------------------------------------ the hedgerow (hedgeSvg) */

/* Clipped to its box: the doodle class (.dk) lets drawings spill out, but a hedge or sky mustn't */
.dk.hg { display: block; width: 100%; height: 100%; overflow: hidden; }
.hg .hg-fill { stroke: none; }
.hg .hg-far .hg-fill { fill: light-dark(#dfe9e1, #142019); }
.hg .hg-near .hg-fill { fill: light-dark(#cfe2d6, #182a21); }
.hg .hg-ink { fill: none; stroke: var(--text); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.hg .hg-far .hg-ink { opacity: 0.45; stroke-width: 1.5; }
.hg .hg-ink.hg-clump { stroke-width: 1.3; opacity: 0.4; }
.hg .hg-far .hg-ink.hg-clump { opacity: 0.25; }
.hg .hg-leaf { fill: none; stroke: var(--accent); stroke-width: 1.3; stroke-linecap: round; opacity: 0.55; }
.hg .hg-far .hg-leaf { opacity: 0.3; }
.hg .hg-flower { fill: var(--warm); stroke: var(--text); stroke-width: 1; }

/* ------------------------------------------------------------------ the sky (skySvg) */

.dk.sk { display: block; width: 100%; height: 100%; overflow: hidden; }
.sk .sk-glow { fill: var(--warm-soft, #fbf0db); opacity: 0.8; }
.sk .sk-glow.night { fill: light-dark(#e7e9f1, #1a2030); opacity: 0.7; }
.sk .sk-sun { fill: var(--warm); }
.sk .sk-moon { fill: light-dark(#f4ecd4, #efe6c8); }
.sk .sk-ink { fill: none; stroke: var(--text); stroke-width: 1.7; stroke-linecap: round; }
.sk .sk-ray { fill: none; stroke: light-dark(#df8d2a, #eaa451); stroke-width: 2; stroke-linecap: round; }
.sk .sk-star { fill: none; stroke: light-dark(#8a96b4, #d9d4b4); stroke-width: 1.4; stroke-linecap: round; }
/* The rays turn with SMIL around the sun's own centre (skySvg), not a CSS origin */
@media (prefers-reduced-motion: no-preference) {
  .sk .sk-star { animation: sk-twinkle 3.2s ease-in-out infinite; animation-delay: calc(var(--d, 0s) * -1); }
}
@keyframes sk-twinkle { 50% { opacity: 0.25; } }
