@font-face {
  font-family: 'Sofia Sans';
  src: url('fonts/sofia-sans-cyrillic-wght-normal.woff2') format('woff2');
  font-weight: 1 1000;
  font-display: swap;
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: 'Sofia Sans';
  src: url('fonts/sofia-sans-latin-wght-normal.woff2') format('woff2');
  font-weight: 1 1000;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122;
}

:root {
  --red: #bd1a24;
  --red-deep: #7c0c14;
  --red-ink: #5c0a10;
  --green: #14563f;
  --green-deep: #08301f;
  --cream: #fff8e9;
  --mustard: #eeb035;
  --mustard-light: #ffd06b;
  --mustard-deep: #a8701a;
  --dark: #1a0406;
  --gutter: 16px;
  --out: cubic-bezier(0.16, 1, 0.3, 1);
  color-scheme: only light;
}

* {
  box-sizing: border-box;
  margin: 0;
}

html {
  background: var(--green-deep);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: 'Sofia Sans', 'Segoe UI', system-ui, sans-serif;
  font-size: 18px;
  line-height: 1.4;
  color: var(--cream);
  background: var(--red);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

::selection {
  background: var(--mustard);
  color: var(--red-ink);
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}

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

[tabindex='-1']:focus {
  outline: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.noscript {
  position: fixed;
  inset: auto 16px 24px;
  padding: 16px;
  text-align: center;
  color: var(--red-ink);
  background: var(--cream);
}

/* ---------- The sweater ---------- */

.page {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  padding-top: var(--yoke, 150px);
  padding-bottom: var(--hem, 170px);
}

.knit {
  position: absolute;
  inset: 0;
  z-index: -2;
  width: 100%;
  height: 100%;
}

/* Deepens the fabric behind text and focuses the eye while it spins. */
.page::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background: radial-gradient(120% 60% at 50% 52%, rgb(60 2 8 / 0.34), rgb(60 2 8 / 0) 70%);
  transition: background-color 0.6s var(--out);
}

[data-state='spinning'] .page::before {
  background-color: rgb(30 1 4 / 0.5);
}

.snow {
  position: fixed;
  inset: 0;
  z-index: 5;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.lights {
  position: absolute;
  top: calc(var(--yoke, 150px) - 44px);
  left: 0;
  width: 100%;
  height: 70px;
  pointer-events: none;
}

.lights svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.wire {
  fill: none;
  stroke: #062a1b;
  stroke-width: 2.5;
  stroke-linecap: round;
  filter: drop-shadow(0 2px 1px rgb(0 0 0 / 0.35));
}

.bulb .cap {
  fill: #062a1b;
}

.bulb .glass {
  fill: var(--c);
}

.bulb .dim {
  fill: #33060b;
  opacity: 0.5;
  transition: opacity 0.45s ease-out;
}

.bulb .shine {
  fill: #fff;
  opacity: 0.35;
}

.bulb .halo {
  opacity: 0;
  transition: opacity 0.45s ease-out;
}

.bulb.on .dim {
  opacity: 0;
  transition-duration: 0.06s;
}

.bulb.on .halo {
  opacity: 0.75;
  transition-duration: 0.06s;
}

/* ---------- Views ---------- */

main {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.view {
  display: none;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 22px 0 6px;
}

[data-state='ready'] .view-draw,
[data-state='spinning'] .view-draw,
[data-state='result'] .view-result,
[data-state='lost'] .view-lost,
[data-state='failed'] .view-failed {
  display: flex;
}

/* ---------- Draw ---------- */

.label {
  position: relative;
  width: min(330px, calc(100% - 2 * var(--gutter)));
  padding: 11px 32px 12px;
  text-align: center;
  text-wrap: balance;
  line-height: 1.25;
  color: var(--red-ink);
  background:
    repeating-linear-gradient(90deg, rgb(140 100 40 / 0.07) 0 1px, transparent 1px 3px),
    linear-gradient(180deg, #fffdf6, #f5e8cf);
  border-radius: 3px;
  box-shadow: 0 4px 10px rgb(40 0 4 / 0.45);
  transform: rotate(-1.2deg);
  transition: opacity 0.4s var(--out);
}

.label::before,
.label::after {
  content: '';
  position: absolute;
  top: 9px;
  bottom: 9px;
  left: 11px;
  width: 2px;
  background: repeating-linear-gradient(180deg, var(--red) 0 6px, transparent 6px 10px);
}

.label::after {
  left: auto;
  right: 11px;
}

.hello {
  font-size: 27px;
  font-weight: 850;
  letter-spacing: -0.01em;
  line-height: 1.15;
}

.case {
  position: relative;
  width: 100%;
  margin-top: 60px;
}

.slit {
  position: relative;
  height: 220px;
  background: linear-gradient(180deg, #0c0203, #2c070b 45%, #1a0406);
  box-shadow: 0 6px 16px rgb(30 0 3 / 0.55);
}

.slit::before,
.slit::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  z-index: 1;
  height: var(--cord-h, 14px);
  background: var(--cord) 50% 0 / var(--cord-w, 70px) var(--cord-h, 14px) repeat-x;
  filter: drop-shadow(0 3px 4px rgb(0 0 0 / 0.5));
}

.slit::before {
  top: -4px;
}

.slit::after {
  bottom: -4px;
  filter: drop-shadow(0 -2px 4px rgb(0 0 0 / 0.45));
}

#strip {
  display: block;
  width: 100%;
  height: 100%;
}

/* A wooden needle. Drawn lying down with its knob on the left. */
.needle {
  --thick: 13px;
  position: absolute;
  height: var(--thick);
}

.needle .shaft {
  position: absolute;
  inset: 0 0 0 8px;
  background: linear-gradient(180deg, #f7d9a0, #dca75f 38%, #a86f2f 78%, #7c4c1c);
  clip-path: polygon(0 0, calc(100% - 30px) 0, calc(100% - 4px) 36%, 100% 50%, calc(100% - 4px) 64%, calc(100% - 30px) 100%, 0 100%);
}

.needle .knob {
  position: absolute;
  top: 50%;
  left: 0;
  width: 25px;
  height: 25px;
  border-radius: 50%;
  background: radial-gradient(circle at 36% 32%, #ffe3a6, var(--mustard) 42%, var(--mustard-deep));
  transform: translate(-50%, -50%);
}

.pointer {
  top: -50px;
  left: 50%;
  z-index: 2;
  width: 92px;
  margin-top: calc(var(--thick) / -2);
  transform-origin: 0 50%;
  transform: rotate(calc(90deg + var(--kick, 0deg)));
  filter: drop-shadow(5px -3px 4px rgb(30 0 3 / 0.5));
}

.action {
  position: relative;
  width: min(400px, calc(100% - 2 * var(--gutter)));
  margin-top: 26px;
}

.cta {
  position: relative;
  display: block;
  width: 100%;
  min-height: 68px;
  padding: 10px 18px 11px;
  font-size: clamp(17px, 5.5vw, 22px);
  font-weight: 850;
  letter-spacing: -0.005em;
  line-height: 1.15;
  color: #420709;
  background: linear-gradient(180deg, var(--mustard-light), var(--mustard) 55%, #dc9a22);
  border-radius: 18px;
  box-shadow:
    inset 0 1px 0 rgb(255 245 214 / 0.8),
    inset 0 -5px 8px -3px rgb(130 78 10 / 0.6),
    0 10px 20px rgb(30 0 3 / 0.5);
  transition:
    transform 0.18s var(--out),
    box-shadow 0.18s var(--out),
    opacity 0.35s var(--out);
}

.cta::after {
  content: '';
  position: absolute;
  inset: 6px;
  border: 2px dashed rgb(96 34 4 / 0.5);
  border-radius: 13px;
  pointer-events: none;
}

.cta:active {
  transform: translateY(3px) scale(0.99);
  box-shadow:
    inset 0 2px 5px rgb(130 78 10 / 0.5),
    0 4px 9px rgb(30 0 3 / 0.5);
}

@media (hover: hover) {
  .cta:hover {
    background: linear-gradient(180deg, #ffdc8b, #f5bd4b 55%, #e2a22c);
  }
}

.suspense {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 26px;
  font-weight: 800;
  opacity: 0;
  transform: translateY(8px);
  transition:
    opacity 0.5s 0.15s var(--out),
    transform 0.5s 0.15s var(--out);
  pointer-events: none;
}

.sound {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 44px;
  margin-top: 8px;
  padding: 0 14px;
  font-size: 17px;
  font-weight: 600;
  text-shadow: 0 1px 2px rgb(60 2 8 / 0.8);
  border-radius: 12px;
  transition: opacity 0.3s var(--out);
}

.sound svg {
  filter: drop-shadow(0 1px 1px rgb(60 2 8 / 0.8));
}

.sound .cross,
.sound[aria-pressed='false'] .waves {
  display: none;
}

.sound[aria-pressed='false'] .cross {
  display: inline;
}

[data-state='spinning'] .cta,
[data-state='spinning'] .sound {
  opacity: 0;
  pointer-events: none;
}

[data-state='spinning'] .label {
  opacity: 0.25;
}

[data-state='spinning'] .suspense {
  opacity: 1;
  transform: none;
}

[data-state='spinning'].landed .suspense {
  opacity: 0;
}

[data-state='spinning'].landed .label {
  opacity: 0;
}

.closing .slit {
  clip-path: inset(50% 0);
  transition: clip-path 0.45s cubic-bezier(0.7, 0, 0.3, 1);
}

.case .slit {
  clip-path: inset(-30px 0);
}

/* ---------- Result ---------- */

.lead {
  padding: 0 var(--gutter);
  max-width: 24ch;
  text-align: center;
  text-wrap: balance;
  font-size: clamp(27px, 8vw, 34px);
  font-weight: 850;
  letter-spacing: -0.015em;
  line-height: 1.1;
  text-shadow: 0 2px 5px rgb(50 1 6 / 0.75);
}

.hanging {
  position: relative;
  margin-top: 30px;
  transform-origin: 50% 0;
}

#piece {
  display: block;
  margin: 0 auto;
  filter: drop-shadow(0 10px 12px rgb(30 0 3 / 0.55));
}

.rod {
  top: -7px;
  left: -19px;
  width: calc(100% + 42px);
  transform-origin: 0 50%;
  filter: drop-shadow(0 5px 4px rgb(30 0 3 / 0.5));
}

.note {
  max-width: 34ch;
  margin-top: 16px;
  padding: 0 var(--gutter);
  text-align: center;
  text-wrap: balance;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.35;
  text-shadow: 0 1px 3px rgb(50 1 6 / 0.9);
}

.revealing .note {
  opacity: 0;
}

.note {
  transition: opacity 0.8s var(--out);
}

.revealing .lead {
  animation: lead-in 0.8s var(--out) both;
}

@keyframes lead-in {
  from {
    opacity: 0;
    filter: blur(6px);
    transform: translateY(10px);
  }
}

.hanging.sway {
  animation: sway 2.6s ease-in-out;
}

@keyframes sway {
  0% { transform: rotate(0); }
  16% { transform: rotate(1.5deg); }
  38% { transform: rotate(-1deg); }
  60% { transform: rotate(0.55deg); }
  80% { transform: rotate(-0.25deg); }
  100% { transform: rotate(0); }
}

/* ---------- Lost link ---------- */

#lost-mitten {
  margin-bottom: 22px;
  border-radius: 12px;
  box-shadow: 0 10px 18px rgb(30 0 3 / 0.5);
  transform: rotate(-4deg);
}

/* ---------- Short phones ---------- */

@media (max-height: 700px) {
  .view {
    padding-top: 14px;
  }
  .case {
    margin-top: 58px;
  }
  .action {
    margin-top: 20px;
  }
  .sound {
    margin-top: 4px;
  }
}

@media (max-height: 600px) {
  .label p:last-child {
    display: none;
  }
  .case {
    margin-top: 54px;
  }
  .slit {
    height: 176px;
  }
  .action {
    margin-top: 16px;
  }
  .cta {
    min-height: 60px;
  }
}

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