@font-face {
  font-family: 'Grenze Gotisch';
  src: url('/fonts/grenze-gotisch-latin-700-normal.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}
@font-face {
  font-family: 'Atkinson Hyperlegible';
  src: url('/fonts/atkinson-hyperlegible-latin-400-normal.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Atkinson Hyperlegible';
  src: url('/fonts/atkinson-hyperlegible-latin-700-normal.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --dusk: #0e2a30;
  --horizon: #2c5a5c;
  --walnut: #5a3419;
  --walnut-dark: #3a2010;
  --limewood: #d9b27c;
  --bollen: #c4242e;
  --bollen-light: #dc3a44;
  --snow: #f4f7f4;
  --snow-dim: #cfdcd6;
  --blaze: #f2c14e;
  --alert: #ffc2b8;
  --ink: #2a160b;
  --display: 'Grenze Gotisch', Georgia, serif;
  --body: 'Atkinson Hyperlegible', system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  font-size: 112.5%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--dusk);
  -webkit-tap-highlight-color: transparent;
  color: var(--snow);
  font-family: var(--body);
  line-height: 1.5;
  overflow-x: clip;
}

[hidden] {
  display: none !important;
}

/* ---- The forest, fixed behind everything ---- */

/* 100lvh stays put while a phone's address bar slides in and out. */
#scene {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 100vh;
  height: 100lvh;
  z-index: 0;
  overflow: hidden;
  background: linear-gradient(var(--dusk) 15%, var(--horizon) 62%);
  pointer-events: none;
}

#scene canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.ridge {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  transform: translateY(var(--drift, 0));
  animation: ridge-rise 1.5s cubic-bezier(0.2, 0.75, 0.25, 1) backwards;
}

/* Each layer has one height and keeps its proportions, centered and wider than any screen.
   Trees look the same on a small phone, a large phone and a desktop. */
.ridge svg {
  position: absolute;
  bottom: 0;
  left: 50%;
  display: block;
  height: 100%;
  width: auto;
  aspect-ratio: var(--ratio);
  max-width: none;
  transform: translateX(-50%);
}

.ridge--far {
  --ratio: 3600 / 300;
  height: clamp(13rem, 50%, 26rem);
}

.ridge--mid {
  --ratio: 3600 / 340;
  height: clamp(12rem, 41%, 24rem);
  animation-delay: 0.12s;
}

.ridge--near {
  --ratio: 3600 / 360;
  height: clamp(10rem, 29%, 20rem);
  animation-delay: 0.26s;
}

@keyframes ridge-rise {
  from {
    transform: translateY(70%);
  }
}

.fog {
  position: absolute;
  left: -40%;
  bottom: 12%;
  width: 180%;
  height: 26%;
  background:
    radial-gradient(ellipse 28% 42% at 22% 55%, rgb(220 235 230 / 0.2), transparent),
    radial-gradient(ellipse 34% 36% at 58% 45%, rgb(220 235 230 / 0.16), transparent),
    radial-gradient(ellipse 24% 44% at 84% 60%, rgb(220 235 230 / 0.2), transparent);
  animation: fog-drift 46s ease-in-out infinite alternate;
}

@keyframes fog-drift {
  to {
    transform: translateX(18%);
  }
}

/* ---- Page ---- */

main {
  position: relative;
  z-index: 1;
  width: min(100%, 30rem);
  margin: 0 auto;
  padding: max(1.5rem, env(safe-area-inset-top)) max(1.25rem, env(safe-area-inset-right)) max(4rem, env(safe-area-inset-bottom))
    max(1.25rem, env(safe-area-inset-left));
}

.masthead {
  display: flex;
  align-items: flex-end;
  gap: 0.9rem;
}

.masthead h1 {
  min-width: 0;
  overflow-wrap: anywhere;
}

h1,
h2 {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  text-wrap: balance;
}

h1 {
  font-size: clamp(2.7rem, 14.5vw, 4rem);
  line-height: 0.98;
}

h1:focus {
  outline: none;
}

h2 {
  font-size: 2.1rem;
  line-height: 1.05;
}

p {
  margin: 0;
}

.lead {
  margin-top: 0.6rem;
  color: var(--snow-dim);
}

section {
  margin-top: 2.5rem;
}

section > p {
  margin-top: 0.5rem;
}

section > form {
  margin-top: 0.75rem;
}

/* ---- Controls ---- */

button,
input,
textarea {
  font: inherit;
}

button {
  touch-action: manipulation; /* no double-tap zoom delay */
}

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

.button {
  display: inline-block;
  min-height: 3.25rem;
  padding: 0.65rem 1.5rem;
  border: 0;
  border-radius: 0.4rem;
  background: var(--bollen);
  color: var(--snow);
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, background-color 0.12s ease;
}

@media (hover: hover) {
  .button:hover {
    background: var(--bollen-light);
  }
}

.button:active {
  transform: translateY(2px);
}

.button:disabled {
  opacity: 0.6;
  cursor: wait;
}

.text-button {
  min-height: 2.75rem;
  padding: 0.4rem 0;
  border: 0;
  background: none;
  color: var(--snow);
  text-decoration: underline;
  text-underline-offset: 0.2em;
  cursor: pointer;
}

label {
  display: block;
  font-weight: 700;
}

input,
textarea {
  display: block;
  width: 100%;
  margin-top: 0.4rem;
  padding: 0.7rem 0.85rem;
  border: 2px solid var(--limewood);
  border-radius: 0.3rem;
  background: var(--snow);
  color: var(--ink);
}

.pin-input {
  max-width: 11rem;
  font-size: 1.6rem;
  letter-spacing: 0.25em;
}

.pin-input.is-wrong {
  animation: wrong-pin 0.4s ease;
}

@keyframes wrong-pin {
  20%,
  60% {
    transform: translateX(-8px);
  }
  40%,
  80% {
    transform: translateX(8px);
  }
}

textarea {
  min-height: 9rem;
  resize: vertical;
}

form .button {
  margin-top: 1rem;
}

.hint {
  margin-top: 0.4rem;
  color: var(--snow-dim);
  font-size: 0.9rem;
}

.error {
  margin-top: 0.75rem;
  color: var(--alert);
  font-weight: 700;
}

.error:empty,
.saved:empty {
  display: none;
}

.saved {
  margin-top: 0.6rem;
  color: var(--blaze);
  font-weight: 700;
}

.after-form {
  margin-top: 1.5rem;
}

/* ---- Who are you: a trail signpost ---- */

.trail {
  position: relative;
  margin: 1.1rem 0 0;
  padding: 0 0 2rem 0.9rem;
  list-style: none;
}

.trail::before {
  content: '';
  position: absolute;
  top: -0.9rem;
  bottom: 0;
  left: 0;
  width: 1rem;
  border-radius: 0.5rem 0.5rem 0 0;
  background: var(--walnut-dark);
}

.trail li {
  position: relative;
  width: max-content;
  max-width: 100%;
  margin-bottom: 0.4rem;
  filter: drop-shadow(0 3px 2px rgb(5 18 20 / 0.45));
  border-radius: 0.3rem;
  transform: rotate(var(--tilt, 0deg));
  transform-origin: 0 50%;
  animation: sign-swing 0.75s cubic-bezier(0.3, 1.5, 0.5, 1) backwards;
  animation-delay: var(--delay, 0s);
}

.trail li:has(:focus-visible) {
  outline: 3px solid var(--blaze);
  outline-offset: 2px;
}

@keyframes sign-swing {
  from {
    transform: rotate(calc(var(--tilt, 0deg) - 16deg)) scaleX(0.3);
    opacity: 0;
  }
}

.sign {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 11.5rem;
  max-width: 100%;
  min-height: 3rem;
  padding: 0.35rem 2.4rem 0.35rem 0.9rem;
  border: 0;
  background: repeating-linear-gradient(178deg, rgb(255 255 255 / 0.03) 0 3px, transparent 3px 9px), var(--walnut);
  clip-path: polygon(0 0, calc(100% - 1.6rem) 0, 100% 50%, calc(100% - 1.6rem) 100%, 0 100%);
  color: var(--snow);
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.1;
  text-align: left;
  cursor: pointer;
  transform-origin: 0 50%;
  transition: transform 0.35s cubic-bezier(0.3, 1.8, 0.5, 1), background-color 0.15s ease;
}

.sign:focus-visible {
  outline: none;
}

.sign:active {
  transform: rotate(3deg);
}

@media (hover: hover) {
  .sign:hover {
    transform: rotate(2.5deg);
  }
}

.sign::before {
  content: '';
  flex: none;
  width: 0.8rem;
  height: 0.8rem;
  background: var(--blaze);
  transform: rotate(45deg);
}

/* ---- The clock ---- */

/* Sized so the button below it stays on the first screen, even on small phones. */
.clock {
  position: relative;
  width: min(100%, clamp(9.5rem, calc((100svh - 15rem) * 0.6), 15.5rem));
  margin: 1.25rem auto 0;
  aspect-ratio: 240 / 400;
}

.clock--callable {
  cursor: pointer;
  transition: margin-bottom 0.2s ease;
}

.clock--callable.is-open {
  margin-bottom: calc(var(--plaque-overhang, 0px) + 1rem);
  transition: margin-bottom 0.5s ease 2.1s;
}

.clock--small {
  flex: none;
  width: 4.5rem;
  margin: 0;
}

.clock-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.clock-back {
  z-index: 1;
}

.clock-body {
  z-index: 3;
}

.pendulum {
  transform-box: view-box;
  transform-origin: 120px 236px;
  animation: pendulum 1.5s ease-in-out infinite alternate;
}

@keyframes pendulum {
  from {
    transform: rotate(-9deg);
  }
  to {
    transform: rotate(9deg);
  }
}

.hand {
  transform-box: view-box;
  transform-origin: 120px 170px;
  transition: transform 0.35s ease;
}

.hand--hour {
  transform: rotate(300deg);
}

.hand--minute {
  transform: rotate(60deg);
}

.is-open .hand {
  transition: transform 0.85s cubic-bezier(0.5, 0, 0.2, 1);
}

.is-open .hand--hour {
  transform: rotate(720deg);
}

.is-open .hand--minute {
  transform: rotate(1440deg);
}

.door {
  transform-box: view-box;
  transition: transform 0.18s ease;
}

.door--left {
  transform-origin: 97px 76px;
}

.door--right {
  transform-origin: 143px 76px;
}

.is-open .door {
  transform: scaleX(0.12);
  transition: transform 0.22s cubic-bezier(0.3, 1.4, 0.6, 1) 0.8s;
}

.bird {
  transform-box: view-box;
  transform-origin: 120px 84px;
  transform: translateX(14px) scale(0.3);
  opacity: 0;
  transition: transform 0.15s ease, opacity 0.1s linear 0.1s;
}

.is-open .bird {
  transform: translateX(6px) translateY(-6px) scale(1.15);
  opacity: 1;
  transition: transform 0.4s cubic-bezier(0.3, 1.8, 0.5, 1) 0.92s, opacity 0.01s linear 0.92s;
}

.bird-bow {
  transform-box: view-box;
  transform-origin: 124px 88px;
}

.bird-beak {
  transform-box: view-box;
  transform-origin: 94px 71px;
}

.is-open .bird-bow {
  animation: bird-bow 0.55s ease-in-out 1.15s 2;
}

.is-open .bird-beak {
  animation: bird-beak 0.55s ease-in-out 1.15s 2;
}

@keyframes bird-bow {
  35% {
    transform: rotate(-16deg);
  }
}

@keyframes bird-beak {
  35% {
    transform: rotate(-26deg);
  }
}

/* The plaque waits behind the clock's body, then drops on its chains. */

.plaque {
  position: absolute;
  z-index: 2;
  top: 69%;
  left: calc(50% - max(47%, 7.5rem));
  width: max(94%, 15rem); /* stays readable when the clock shrinks on a small phone */
  padding: 0.6rem 0.6rem 0.7rem;
  border: 3px solid var(--walnut-dark);
  border-radius: 0.3rem;
  background: var(--limewood);
  color: var(--ink);
  text-align: center;
  visibility: hidden;
  transform: translateY(-105%);
  transition: transform 0.2s ease-in, visibility 0s linear 0.2s;
}

.plaque::before,
.plaque::after {
  content: '';
  position: absolute;
  bottom: 100%;
  width: 3px;
  height: 2.2rem;
  background: repeating-linear-gradient(var(--walnut-dark) 0 5px, transparent 5px 7px);
}

.plaque::before {
  left: 18%;
}

.plaque::after {
  right: 18%;
}

.is-open .plaque {
  visibility: visible;
  transform: none;
  transition: transform 0.75s cubic-bezier(0.32, 1.65, 0.5, 1) 2.1s, visibility 0s linear 2.1s;
}

.plaque-label {
  font-weight: 700;
  font-size: 0.95rem;
}

/* Names use the plain face: this is the one word nobody may misread. */
.plaque-name {
  font-size: 2.5rem;
  font-weight: 700;
  line-height: 1.05;
  overflow-wrap: anywhere;
}

.plaque-name--long {
  font-size: 1.75rem;
}

.clock-action {
  display: block;
  width: min(100%, 15.5rem);
  margin: 1rem auto 0;
}

.event-note {
  margin-top: 1.5rem;
}

.wishes {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.receiver-wishes {
  animation: wishes-arrive 0.6s ease backwards;
}

@keyframes wishes-arrive {
  from {
    opacity: 0;
    transform: translateY(0.75rem);
  }
}

/* ---- Calm version: everything ends up in the same place, instantly ---- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
