/* The page is one full-screen painting. Layers, bottom to top:
   .lqip      a 48 px blurred copy of the painting, inlined in the HTML, for the first frame
   #poster    the flat painting, framed exactly like the live scene
   #scene     the WebGL scene, faded in over the poster once its textures are ready
   h1, .sound the name and the one control
   --daylight (1 golden hour, 0 night) is set by js/main.js and tints the ink. */

:root {
  --daylight: 1;
  --ink-t: 1;
  --ink-day: #262c3b;
  --ink-night: #e8e2d2;
  --ink: color-mix(in oklab, var(--ink-day) calc(var(--ink-t) * 100%), var(--ink-night));
  --ink-glow: transparent;
  --page: #c9c3b5;
  color-scheme: light;
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--page);
}
body {
  /* the scene handles every gesture itself: no page zoom, scroll or bounce */
  touch-action: none;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

.lqip, .poster, #scene {
  position: fixed;
  left: 0;
  top: 0;
  pointer-events: none;
}
.lqip {
  inset: -40px;
  background-size: cover;
  background-position: 59% 50%;
  filter: blur(18px);
}
.poster {
  /* before js/main.js places it exactly, cover framing biased like the scene's */
  width: 100vw;
  height: 100vh;
  object-fit: cover;
  object-position: 59% 50%;
  transform-origin: 0 0;
}
#scene {
  display: block;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  opacity: 0;
  transition: opacity 1.3s cubic-bezier(.3, .1, .2, 1);
}
.scene-live #scene { opacity: 1; }
.poster-gone .poster, .poster-gone .lqip { visibility: hidden; }

/* First paint already follows the clock: before the live scene arrives (and for
   good when WebGL is missing) the poster is toned toward dusk or night with a
   desaturation and a multiplied glaze, the way a watercolourist would glaze it,
   so reds go to dark wine instead of shifting hue. */
.lqip, .poster { transition: filter 1.2s ease; }
.glaze {
  position: fixed;
  inset: 0;
  pointer-events: none;
  mix-blend-mode: multiply;
  opacity: 0;
  transition: opacity 1.2s ease;
}
[data-phase="dusk"] .poster { filter: saturate(1.08) brightness(.9); }
[data-phase="dusk"] .lqip { filter: blur(18px) saturate(1.08) brightness(.9); }
[data-phase="dusk"] .glaze { opacity: .55; background: linear-gradient(180deg, #8f86c4 0%, #e9a27c 55%, #b98a72 100%); }
[data-phase="night"] .poster { filter: saturate(.42) brightness(.78) contrast(1.06); }
[data-phase="night"] .lqip { filter: blur(18px) saturate(.42) brightness(.78); }
[data-phase="night"] .glaze { opacity: 1; background: linear-gradient(180deg, #2a3768 0%, #4a5a8c 52%, #283454 100%); }
.scene-live .glaze { opacity: 0; }
#scene { z-index: 1; }

/* ---------- the name ---------- */
.name {
  position: fixed;
  z-index: 4;
  left: max(env(safe-area-inset-left), clamp(20px, 4.2vw, 84px));
  top: max(env(safe-area-inset-top), clamp(18px, 5.6vh, 76px));
  margin: 0;
  font-family: 'Cormorant Garamond', 'Cormorant', Garamond, 'Iowan Old Style', 'Times New Roman', serif;
  font-weight: 500;
  font-size: clamp(2.6rem, 4.5vw, 6rem);
  line-height: 0.95;
  letter-spacing: 0.005em;
  white-space: nowrap;
  color: var(--ink);
  text-shadow: 0 0 .5em var(--ink-glow);
  font-kerning: normal;
  text-rendering: optimizeLegibility;
}
/* portrait phones: the greeting is centred across the open sky. There it sits on the
   blue zenith, never on the pale horizon glow, so it is pale ink at every hour with a
   soft dark halo that keeps it legible over cloud and blue alike */
@media (max-aspect-ratio: 3/4) {
  .name {
    left: 0; right: 0; text-align: center;
    top: calc(env(safe-area-inset-top) + clamp(10px, 2.8vh, 36px));
    font-size: clamp(2.3rem, 11vw, 3.4rem);
    color: #f1ece0;
    text-shadow: 0 0 .28em rgb(18 24 46 / .5), 0 0 .9em rgb(18 24 46 / .3);
  }
}
/* behaviours reveal the name; until one does (or if none runs) it waits unseen */
.js .name { opacity: 0; }
.name-static .name { opacity: 1; transition: opacity 1.4s ease .3s; }

/* ---------- zoom fade: greeting and slider step aside when looking closely ---------- */
/* its own layer above the behaviours' canvases (z 2 and 3), so fading never drops the
   greeting beneath them */
.ui-fade { position: relative; z-index: 4; opacity: var(--ui-fade, 1); transition: opacity .45s ease; }
.ui-faded .ui-fade { pointer-events: none; }
.ui-faded .ui-fade * { pointer-events: none; }

/* ---------- controls along the bottom edge ---------- */
:root { --ui-bottom: max(env(safe-area-inset-bottom), clamp(10px, 2.6vh, 30px)); }

/* ---------- time slider ---------- */
.time {
  position: fixed;
  z-index: 5;
  left: 50%;
  bottom: var(--ui-bottom);
  transform: translateX(-50%);
  height: 48px;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  opacity: 0;
  transition: opacity 1.2s ease .6s;
  --p: .5;
  --sun: 1;
}
.time.is-ready { opacity: 1; }
/* a lifted, paler patch of paper behind the control (darker at night) so it reads
   over the meadow without a box around it */
.time::before {
  content: "";
  position: absolute;
  inset: -18px -44px;
  z-index: -1;
  border-radius: 50%;
  background: radial-gradient(farthest-side, color-mix(in oklab, #f3ead8 calc(var(--ink-t) * 100%), #141b30) 0%, color-mix(in oklab, #f3ead8 calc(var(--ink-t) * 100%), #141b30) 50%, transparent 100%);
  opacity: calc(.3 + .2 * var(--ink-t));
  filter: blur(10px);
  pointer-events: none;
}
.time-label {
  min-width: 4.4em;
  text-align: right;
  font-family: 'Cormorant Garamond', 'Cormorant', Garamond, 'Iowan Old Style', 'Times New Roman', serif;
  font-weight: 600;
  font-size: 1.08rem;
  line-height: 1;
  font-variant-numeric: tabular-nums lining-nums;
  white-space: nowrap;
  opacity: 1;
  transition: opacity .4s ease;
}
.time-strip {
  position: relative;
  width: clamp(280px, 24vw, 360px);
  height: 48px;
}
.time-track {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 12px;
  margin-top: -6px;
  border-radius: 7px;
  /* JS sets the sky gradient and the paper; the paper multiplies into the wash */
  background-color: #b9c3d6;
  background-size: 220px 220px, 100% 100%;
  background-blend-mode: multiply, normal;
  /* a wash, not a pill: a faint dried rim where the pigment pooled, and edges that
     feather out on all four sides */
  box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--ink) 16%, transparent);
  /* at night the painted day colours sink with the scene instead of glaring */
  filter: brightness(calc(.6 + .4 * var(--ink-t))) saturate(calc(.75 + .25 * var(--ink-t)));
  /* the ends fade like a wash running out of pigment */
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 6%, #000 94%, transparent), linear-gradient(180deg, rgb(0 0 0 / .15), #000 30%, #000 70%, rgb(0 0 0 / .15));
  -webkit-mask-composite: source-in;
  mask-image: linear-gradient(90deg, transparent, #000 6%, #000 94%, transparent), linear-gradient(180deg, rgb(0 0 0 / .15), #000 30%, #000 70%, rgb(0 0 0 / .15));
  mask-composite: intersect;
}
.time-thumb {
  position: absolute;
  top: 50%;
  left: calc(var(--p) * (100% - 30px));
  width: 30px;
  height: 30px;
  margin-top: -15px;
  pointer-events: none;
  overflow: visible;
  transition: transform .25s ease;
}
.time-thumb .sun { opacity: var(--sun); transition: opacity .5s ease; }
.time-thumb .moon { opacity: calc(1 - var(--sun)); transition: opacity .5s ease; }
.time-strip:hover .time-thumb, .time-input:active + .time-thumb { transform: scale(1.08); }
.time-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  opacity: 0;
  cursor: pointer;
  touch-action: none;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
}
.time-input::-webkit-slider-thumb { -webkit-appearance: none; width: 30px; height: 48px; cursor: grab; }
.time-input::-moz-range-thumb { width: 30px; height: 48px; border: 0; cursor: grab; }
.time-input:active::-webkit-slider-thumb { cursor: grabbing; }
.time-strip:has(.time-input:focus-visible) .time-track { box-shadow: 0 0 0 1.5px var(--ink); }

/* touch: a thumb-sized grab area */
@media (pointer: coarse) {
  .time-input::-webkit-slider-thumb { width: 44px; }
  .time-input::-moz-range-thumb { width: 44px; }
  .time-thumb { width: 34px; height: 34px; margin-top: -17px; left: calc(var(--p) * (100% - 44px) + 5px); }
}
@media (max-width: 600px) {
  /* phones: nearly the full width, ending before the sound button */
  .time {
    left: max(16px, env(safe-area-inset-left));
    right: 72px;
    transform: none;
    gap: 10px;
  }
  .time-strip { width: auto; flex: 1; }
  .time-label { min-width: 4.1em; font-size: 1rem; }
}

/* ---------- small life in the controls ---------- */
.time-thumb .rays { transform-box: view-box; transform-origin: 16px 16px; animation: rays-turn 48s linear infinite; }
@keyframes rays-turn { to { transform: rotate(360deg); } }
.sound[aria-pressed="true"] .waves { transform-box: view-box; transform-origin: 21px 16px; animation: sound-breathe 4.8s ease-in-out infinite; }
@keyframes sound-breathe { 0%, 100% { opacity: .55; transform: scale(.94); } 50% { opacity: 1; transform: scale(1.04); } }
@media (prefers-reduced-motion: reduce) {
  .time-thumb .rays, .sound[aria-pressed="true"] .waves { animation: none; }
}

/* ---------- sound toggle ---------- */
.sound {
  position: fixed;
  z-index: 5;
  right: max(env(safe-area-inset-right), clamp(10px, 2.4vw, 36px));
  bottom: var(--ui-bottom);
  width: 48px;
  height: 48px;
  padding: 10px;
  margin: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink);
  opacity: 0.78;
  cursor: pointer;
  transition: opacity .35s ease, transform .35s ease;
}
/* the same lifted patch of paper the slider sits on */
.sound::before {
  content: "";
  position: absolute;
  inset: -10px;
  z-index: -1;
  border-radius: 50%;
  background: radial-gradient(closest-side, color-mix(in oklab, #f6efe0 calc(var(--ink-t) * 100%), #141b30) 0%, color-mix(in oklab, #f6efe0 calc(var(--ink-t) * 100%), #141b30) 40%, transparent 100%);
  opacity: calc(.42 + .28 * var(--ink-t));
  filter: blur(6px);
  pointer-events: none;
}
.sound svg path { stroke-width: 1.7px; }
.sound .hush { transform-box: view-box; transform-origin: 24.1px 16px; transform: scale(1.2); }
.sound:hover { opacity: 0.95; }
.sound:active { transform: scale(.94); }
.sound:focus-visible { outline: 1.5px solid currentColor; outline-offset: 2px; opacity: 0.9; }
.sound svg { display: block; width: 100%; height: 100%; overflow: visible; }
.sound .waves, .sound .hush { transition: opacity .4s ease; }
.sound .waves { opacity: 0; }
.sound[aria-pressed="true"] .waves { opacity: 1; }
.sound[aria-pressed="true"] .hush { opacity: 0; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  #scene { transition-duration: .6s; }
}

/* ---------- restore: appears only once the visitor has broken something ---------- */
/* stacked above the sound toggle so the slider's phone layout never has to share the row */
.heal { bottom: calc(var(--ui-bottom) + 54px); opacity: 0; transform: translateY(6px); transition: opacity .6s ease, transform .6s ease; }
.heal.is-shown { opacity: 0.78; transform: none; }
.heal.is-shown:hover { opacity: 0.95; }
.heal[hidden] { display: block; visibility: hidden; pointer-events: none; }
.heal .leaf-l, .heal .leaf-r { transform-box: view-box; transform-origin: 16px 17px; transition: transform .5s ease; }
.heal:hover .leaf-l { transform: rotate(-8deg); }
.heal:hover .leaf-r { transform: rotate(8deg); }
/* the wash that covers the scene while the world is restored */
.heal-wash { position: fixed; inset: 0; z-index: 20; background: #f5efe3; opacity: 0; pointer-events: none; transition: opacity .7s ease; }
.heal-wash.is-on { opacity: 1; }
