@font-face {
  font-family: "Cinzel";
  font-weight: 400 900;
  font-style: normal;
  font-display: block;
  src: url(../fonts/Cinzel-wght.ttf) format("truetype");
}

/* Scene colours are registered so that day can fade into night. */
@property --sky-top { syntax: "<color>"; inherits: true; initial-value: #dccdb2; }
@property --sky-low { syntax: "<color>"; inherits: true; initial-value: #f1e8d6; }
@property --orb { syntax: "<color>"; inherits: true; initial-value: #f8f2e6; }
@property --orb-rim { syntax: "<color>"; inherits: true; initial-value: #f1e8d6; }
@property --halo { syntax: "<color>"; inherits: true; initial-value: rgba(248, 242, 230, 0.8); }
@property --t1 { syntax: "<color>"; inherits: true; initial-value: #4a6656; }
@property --t2 { syntax: "<color>"; inherits: true; initial-value: #324a3d; }
@property --t3 { syntax: "<color>"; inherits: true; initial-value: #22362b; }
@property --glow { syntax: "<color>"; inherits: true; initial-value: rgba(248, 242, 230, 0); }
@property --edge { syntax: "<color>"; inherits: true; initial-value: rgba(248, 242, 230, 0.6); }
@property --craters { syntax: "<number>"; inherits: true; initial-value: 0; }

/* Three inks: the green of the pot, the red of the bowl, the cream inside it.
   Every other colour here is a mix or a shade of those. */
:root {
  --green: #324a3d;
  --red: #cf0206;
  --cream: #e5d6be;

  /* a snowy day */
  --sky-top: #dccdb2;
  --sky-low: #f1e8d6;
  --orb: #f8f2e6;
  --orb-rim: #f1e8d6;
  --halo: rgba(248, 242, 230, 0.8);
  --t1: #4a6656;
  --t2: #324a3d;
  --t3: #22362b;
  --glow: rgba(248, 242, 230, 0);
  --edge: rgba(248, 242, 230, 0.6);
  --craters: 0;
  --num: #22362b;
  --edge-shade: rgba(50, 74, 61, 0.16);
  color-scheme: light;

  transition: --sky-top 0.9s ease, --sky-low 0.9s ease, --orb 0.9s ease, --orb-rim 0.9s ease,
    --halo 0.9s ease, --t1 0.9s ease, --t2 0.9s ease, --t3 0.9s ease, --glow 0.9s ease,
    --edge 0.9s ease, --craters 0.9s ease;
}

/* a moonlit night */
:root[data-theme="dark"] {
  --sky-top: #09110d;
  --sky-low: #22392d;
  --orb: #f1e8d6;
  --orb-rim: #dccdb2;
  --halo: rgba(229, 214, 190, 0.3);
  --t1: #f8f2e6;
  --t2: #e5d6be;
  --t3: #c4b698;
  --glow: rgba(229, 214, 190, 0.36);
  --edge: rgba(10, 18, 14, 0.6);
  --craters: 1;
  --num: #f8f2e6;
  --edge-shade: rgba(5, 10, 8, 0.5);
  color-scheme: dark;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--sky-low);
  -webkit-tap-highlight-color: transparent;
}

/* ------------------------------------------------------------- scenery */

#stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
  animation: dawn 1.4s ease backwards;
}

@keyframes dawn {
  from { opacity: 0; }
}

.sky {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-low) 64%);
}

/* a little grain, so the sky does not band */
.sky::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.3;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.05  0 0 0 0 0.09  0 0 0 0 0.07  0 0 0 0.55 -0.2'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* the moon by night, a low winter sun by day, over the mountains */
#orb {
  position: absolute;
  border-radius: 50%;
  background: radial-gradient(circle at 42% 40%, var(--orb) 0 52%, var(--orb-rim) 100%);
  box-shadow: 0 0 calc(var(--r) * 0.6) calc(var(--r) * 0.16) var(--halo),
    0 0 calc(var(--r) * 3) calc(var(--r) * 0.9) var(--halo);
  filter: blur(calc(var(--r) * 0.035));
  will-change: transform;
}

#orb::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  opacity: var(--craters);
  background:
    radial-gradient(circle at 63% 31%, rgba(143, 148, 128, 0.3) 0 7%, transparent 11%),
    radial-gradient(circle at 34% 57%, rgba(143, 148, 128, 0.24) 0 11%, transparent 16%),
    radial-gradient(circle at 67% 68%, rgba(143, 148, 128, 0.2) 0 6%, transparent 9%),
    radial-gradient(circle at 45% 25%, rgba(143, 148, 128, 0.16) 0 4%, transparent 7%),
    radial-gradient(circle at 24% 36%, rgba(143, 148, 128, 0.14) 0 3%, transparent 5%);
}

/* The land: each distance is one layer, painted by
   scenery.js and stretched to the window. Day and night are two canvases
   that fade into one another. */
.land {
  position: absolute;
  left: -48px;
  top: 0;
  width: calc(100% + 96px);
  height: 100%;
  pointer-events: none;
  will-change: transform;
}

.land canvas {
  position: absolute;
  left: 0;
  width: 100%;
  display: block;
  transition: opacity 0.9s ease;
}

.land .night { opacity: 0; }
:root[data-theme="dark"] .land .night { opacity: 1; }
:root[data-theme="dark"] .land .day { opacity: 0; }

/* The northern lights, by night only: two paintings of them that swell and
   fade against one another, so the curtains seem to move. */
.land .lightsA,
.land .lightsB { opacity: 0; filter: blur(1.5px); }
:root[data-theme="dark"] .land .lightsA { opacity: 0.85; animation: lights 17s ease-in-out infinite alternate; }
:root[data-theme="dark"] .land .lightsB { opacity: 0.3; animation: lights 23s ease-in-out -9s infinite alternate-reverse; }

@keyframes lights {
  from { opacity: 0.9; transform: translate3d(-10px, 0, 0); }
  to { opacity: 0.2; transform: translate3d(14px, 0, 0); }
}

/* the drift in front of her lies over the fox */
#front { position: fixed; }

/* darker toward the edges, the way a lens draws */
.shade {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 78% 72% at 50% 58%, transparent 42%, var(--edge-shade) 100%);
}

/* ---------------------------------------------------------------- name */

#title,
#rule {
  position: fixed;
  left: 50%;
}

#title {
  top: 8vh;
  margin: 0;
  font-size: clamp(28px, 6vw, 88px);
  transform: translateX(-50%);
  white-space: nowrap;
  font-family: "Cinzel", "Trajan Pro", "Times New Roman", serif;
  font-weight: 600;
  letter-spacing: 0.16em;
  line-height: 1;
  filter: drop-shadow(0 0 0.3em var(--glow)) drop-shadow(0 0.035em 0.02em var(--edge));
}

#title span {
  display: inline-block;
  background: linear-gradient(180deg, var(--t1) 14%, var(--t2) 58%, var(--t3) 94%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

#title span:last-child { margin-right: -0.16em; }

#rule {
  height: 1px;
  transform: translateX(-50%);
  opacity: 0.8;
  background: linear-gradient(90deg, transparent, var(--t2) 24%, var(--t2) 44%, transparent 44%,
    transparent 56%, var(--t2) 56%, var(--t2) 76%, transparent);
}

#rule::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 7px;
  height: 7px;
  background: var(--t2);
  transform: translate(-50%, -50%) rotate(45deg);
}

/* how often she has been fed, pet and the rest */
#tally {
  position: fixed;
  left: 50%;
  margin: 0;
  width: max-content;
  max-width: min(90vw, 1100px);
  transform: translateX(-50%);
  text-align: center;
  text-wrap: balance;
  font-family: "Cinzel", "Times New Roman", serif;
  font-weight: 500;
  letter-spacing: 0.1em;
  line-height: 1.55;
  color: var(--t2);
  opacity: 0.92;
}

#tally b {
  display: inline-block;
  font-weight: 800;
  color: var(--num);
}

#tally b.pop { animation: pop 0.5s ease; }

@keyframes pop {
  35% { transform: scale(1.5); }
}

.ready #tally { animation: arrive 1.2s 1.5s ease backwards; }

@keyframes arrive {
  from { opacity: 0; }
}

/* the name waits for its font, then arrives a letter at a time */
.js body:not(.ready) #title,
body:not(.ready) #rule,
body:not(.ready) #tally { visibility: hidden; }

.ready #title span {
  animation: letter 1.2s cubic-bezier(0.2, 0.7, 0.2, 1) backwards;
  animation-delay: calc(0.3s + var(--i) * 90ms);
}

#title span:nth-child(1) { --i: 0; }
#title span:nth-child(2) { --i: 1; }
#title span:nth-child(3) { --i: 2; }
#title span:nth-child(4) { --i: 3; }
#title span:nth-child(5) { --i: 4; }
#title span:nth-child(6) { --i: 5; }
#title span:nth-child(7) { --i: 6; }
#title span:nth-child(8) { --i: 7; }

.ready #rule { animation: rule 1.3s 1.2s ease backwards; }

@keyframes letter {
  from { opacity: 0; transform: translateY(0.2em); filter: blur(0.1em); }
}

@keyframes rule {
  from { opacity: 0; transform: translateX(-50%) scaleX(0.3); }
}

/* ----------------------------------------------------------------- fox */

#fox {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: default;
}

.fallback {
  display: none;
  position: fixed;
  left: 50%;
  bottom: 0;
  width: min(70vw, 60vh);
  transform: translateX(-50%);
}

.nogl #fox { display: none; }
.nogl .fallback { display: block; }

/* The two controls share one look, which reads on trees and on snow alike. */
.knob {
  position: fixed;
  bottom: max(14px, env(safe-area-inset-bottom));
  width: 46px;
  height: 46px;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: rgba(18, 31, 24, 0.5);
  color: var(--cream);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.2s ease;
}

.knob:hover,
.knob:focus-visible { background: rgba(18, 31, 24, 0.72); }
.knob:active { transform: scale(0.94); }
.knob:focus-visible { outline: 2px solid var(--cream); outline-offset: 2px; }
.knob svg { display: block; }

#mode { right: max(14px, env(safe-area-inset-right)); }
#mode svg { width: 24px; height: 24px; }
#feed { left: max(14px, env(safe-area-inset-left)); touch-action: none; }
#feed svg { width: 32px; height: 32px; }

/* fixed pictures and pages without the fox have nobody to feed */
.still #feed,
.nogl #feed { display: none; }

/* the berry on its way to her */
#berry {
  position: fixed;
  left: -16px;
  top: -16px;
  width: 32px;
  height: 32px;
  display: none;
  pointer-events: none;
  will-change: transform;
}

#berry.out { display: block; }
#berry svg { display: block; width: 100%; height: 100%; }

/* a small "+1" where something was counted */
#floats span {
  position: fixed;
  transform: translate(-50%, -50%);
  font-family: "Cinzel", serif;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.04em;
  color: #f8f2e6;
  text-shadow: 0 1px 3px rgba(10, 18, 14, 0.75);
  pointer-events: none;
  animation: rise 1.1s ease-out forwards;
}

@keyframes rise {
  from { opacity: 0; transform: translate(-50%, -30%); }
  20% { opacity: 1; }
  to { opacity: 0; transform: translate(-50%, -260%); }
}
#mode .sun { display: none; }
:root[data-theme="dark"] #mode .sun { display: block; }
:root[data-theme="dark"] #mode .moon { display: none; }

/* a fixed picture: nothing fades or moves */
.still,
.still *,
.still *::before,
.still *::after {
  animation: none !important;
  transition: none !important;
}
