@font-face {
  font-family: "Cormorant Garamond";
  src: url("fonts/cormorant-garamond.woff2") format("woff2");
  font-weight: 300 700;
  font-display: swap;
}

@font-face {
  font-family: "Josefin Sans";
  src: url("fonts/josefin-sans.woff2") format("woff2");
  font-weight: 100 700;
  font-display: swap;
}

:root {
  --flax: #d8ccb3;
  --flax-light: #e8dfcb;
  --flax-shade: #b9aa8c;
  --sage: #8a9a7b;
  --sage-deep: #4f5b45;
  --woad: #4d6275;
  --woad-deep: #3d4f60;
  --thread: #ede3cc;
  --dawn: #f2b880;
  --graphite: #3b342a;
  --hoop: min(78vmin, 640px);
  /* main.js swaps this flat cross-weave for a generated linen tile. */
  --weave:
    repeating-linear-gradient(0deg, rgb(255 250 238 / .18) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, rgb(120 100 70 / .12) 0 1px, transparent 1px 3px);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  min-height: 100svh;
  background-color: var(--flax);
  background-image: var(--weave);
  background-size: 350px;
  color: var(--graphite);
  font-family: "Josefin Sans", "Avenir Next", "Segoe UI", sans-serif;
  overflow-x: hidden;
}

/* Morning light from the upper right, and the cloth falling into shade at the edges. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(120% 90% at 82% 8%, rgb(255 226 178 / .5), transparent 60%),
    radial-gradient(140% 120% at 50% 50%, transparent 55%, rgb(92 74 48 / .28));
}

.page {
  position: relative;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 48px 16px 96px;
}

.stage { position: relative; width: var(--hoop); }

/* The embroidery hoop: taut cloth inside, a beech ring and its brass screw on top. */
.hoop {
  position: relative;
  width: var(--hoop);
  aspect-ratio: 1;
  margin: 0;
  filter: drop-shadow(0 18px 22px rgb(70 52 30 / .22)) drop-shadow(0 2px 3px rgb(70 52 30 / .25));
}

.cloth {
  position: absolute;
  inset: 2.2%;
  border-radius: 50%;
  overflow: hidden;
  background-color: var(--flax-light);
  background-image:
    radial-gradient(circle at 50% 42%, rgb(255 251 240 / .55), transparent 70%),
    var(--weave);
  background-size: auto, 350px;
  box-shadow: inset 0 0 0 1px rgb(90 70 40 / .2), inset 0 6px 18px rgb(80 60 35 / .25);
}

.cloth canvas,
.cloth .drawing {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.cloth canvas {
  opacity: 0;
  transition: opacity 1.6s ease;
}

.hoop[data-scene="3d"] .cloth canvas.ready { opacity: 1; }
.hoop[data-scene="3d"] .drawing { display: none; }
.hoop[data-scene="dibujo"] canvas { display: none; }

.ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

/* The drawing: graphite lines on the cloth, watercolour washes under them. */
.ink {
  fill: none;
  stroke: var(--graphite);
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: .88;
}

.ink.faint { stroke-width: 1.6; opacity: .5; }

.wash { opacity: .5; mix-blend-mode: multiply; }
.wash-glow { opacity: .9; mix-blend-mode: normal; }
.wash-sun { opacity: .8; }
.wash-leaves { opacity: .42; }
.wash-trunk { opacity: .28; }
.wash-hills { opacity: .32; }
.wash-fabric { opacity: .55; }

.swing { transform-origin: 550px 314px; }
.rays { transform-origin: 730px 650px; }

/* main.js adds .drawing-in once it has set each line's order (--i). */
.drawing-in .ink {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  animation: draw .9s cubic-bezier(.45, .05, .35, 1) forwards;
  animation-delay: calc(var(--i, 0) * .32s + .3s);
}

.drawing-in .washes {
  opacity: 0;
  animation: soak 2.4s ease 4.6s forwards;
}

.drawing-in .sunrise { animation: rise 9s cubic-bezier(.25, .6, .3, 1) 4.4s both; }
.drawing-in .swing { animation: sway 3.6s ease-in-out 6.4s infinite alternate both; }
.drawing-in .rays { animation: turn 60s linear 6s infinite; }

@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes soak { to { opacity: 1; } }
@keyframes rise { from { transform: translateY(70px); } to { transform: translateY(-34px); } }
@keyframes sway { from { transform: rotate(-3.2deg); } to { transform: rotate(3.2deg); } }
@keyframes turn { to { transform: rotate(360deg); } }

/* The woven label sewn onto the linen, overlapping the hoop. */
.label {
  position: absolute;
  right: calc(var(--hoop) * -.14);
  bottom: calc(var(--hoop) * .02);
  margin: 0;
  padding: 18px 34px 16px;
  display: grid;
  gap: 4px;
  rotate: -2.5deg;
  color: var(--thread);
  font-weight: inherit;
  background-color: var(--woad);
  background-image:
    repeating-linear-gradient(45deg, rgb(255 255 255 / .07) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(-45deg, rgb(0 0 0 / .08) 0 1px, transparent 1px 4px);
  box-shadow: 0 1px 1px rgb(40 30 20 / .35), 0 6px 12px rgb(60 45 25 / .18);
  text-shadow: 0 1px 0 rgb(0 0 0 / .25);
}

/* Folded ends with their running stitch. */
.label::before,
.label::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 14px;
  background: var(--woad-deep);
  border-inline: 2px dashed rgb(237 227 204 / .55);
  border-block: 0;
  background-clip: padding-box;
}

.label::before { left: 0; border-left-color: transparent; }
.label::after { right: 0; border-right-color: transparent; }

.label-title {
  font-family: "Cormorant Garamond", "Iowan Old Style", Georgia, serif;
  font-weight: 600;
  font-size: clamp(2rem, 4.6vmin, 3rem);
  line-height: 1;
  letter-spacing: .01em;
}

.label-line {
  font-weight: 300;
  font-size: clamp(.95rem, 2vmin, 1.15rem);
  letter-spacing: .14em;
  padding-left: .15em;
}

.switch {
  position: fixed;
  right: 16px;
  bottom: 16px;
  padding: 10px 14px;
  border: 0;
  background: rgb(232 223 203 / .7);
  color: var(--graphite);
  font: 400 .95rem/1 "Josefin Sans", sans-serif;
  letter-spacing: .04em;
  text-decoration: underline dashed rgb(59 52 42 / .5);
  text-underline-offset: 5px;
  border-radius: 3px;
  cursor: pointer;
}

.switch:hover { background: rgb(232 223 203 / .95); }

.switch:focus-visible,
.label:focus-visible {
  outline: 2px solid var(--woad);
  outline-offset: 3px;
}

@media (max-width: 640px), (max-aspect-ratio: 3/4) {
  :root { --hoop: min(90vw, 58svh); }

  .page { padding-top: 32px; }

  .stage { display: grid; justify-items: center; }

  .label {
    position: relative;
    right: auto;
    bottom: auto;
    margin-top: calc(var(--hoop) * -.09);
    padding: 14px 30px 12px;
  }

  .switch { left: 50%; right: auto; translate: -50% 0; }
}

/* With reduced motion main.js never adds .drawing-in: the drawing stands finished. */
@media (prefers-reduced-motion: reduce) {
  .cloth canvas { transition: none; }
}
