/* knotwick.com: the front page's layout. Built from tokens.css and system.css. */

.skip {
  position: absolute;
  left: var(--gutter-left);
  top: -4rem;
  z-index: 50;
  background: var(--bench);
  padding: var(--s2) var(--s3);
}
.skip:focus { top: var(--s3); }

/* A pool of candlelight that follows the pointer over the dark bench. */
.candlelight {
  position: fixed;
  inset: 0;
  z-index: 40;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(22rem circle at var(--mx, 50%) var(--my, 50%), rgb(233 162 75 / 0.16), rgb(233 162 75 / 0.05) 45%, transparent 70%);
  mix-blend-mode: screen;
  transition: opacity 600ms linear;
}
.candlelight.is-lit { opacity: 1; }

.section { padding-block: var(--s9); position: relative; }

/* ---------- Masthead ---------- */

.masthead {
  position: absolute;
  inset: 0 0 auto 0;
  z-index: 20;
  padding-top: calc(env(safe-area-inset-top, 0px) + var(--s4));
}
.masthead__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s5);
}
.masthead__logo img { width: 8.5rem; filter: drop-shadow(0 4px 10px rgb(0 0 0 / 0.5)); }
.masthead__nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--s2) var(--s5);
  font-size: var(--text-small);
  text-shadow: 0 1px 8px rgb(0 0 0 / 0.8);
}
@media (max-width: 40rem) {
  .masthead__nav a:nth-child(n+3) { display: none; }
}

/* ---------- Hero ---------- */

.hero {
  position: relative;
  min-height: clamp(40rem, 94svh, 62rem);
  display: grid;
  align-items: end;
  overflow: hidden;
  isolation: isolate;
  background: var(--dusk-deep);
}
.hero__painting {
  position: absolute;
  inset: 0;
  z-index: -2;
}
.hero__painting img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 62% 30%;
  animation: hero-pan var(--pan) var(--ease-drift) infinite alternate;
  transform-origin: 55% 40%;
  will-change: transform;
}
@keyframes hero-pan {
  from { transform: scale(1.02); }
  to { transform: scale(1.1) translate3d(-1%, -1%, 0); }
}
/* Dusk settles into the bench at the bottom, and behind the words. */
.hero__painting::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(to top, var(--bench) 0%, rgb(17 31 40 / 0.86) 14%, rgb(17 31 40 / 0) 46%),
    linear-gradient(100deg, rgb(17 22 32 / 0.88) 0%, rgb(17 22 32 / 0.6) 34%, rgb(17 22 32 / 0) 62%);
}
/* The tower's lit windows breathe a little. */
.hero__glow {
  position: absolute;
  border-radius: 50%;
  background: radial-gradient(circle, rgb(233 162 75 / 0.55), rgb(233 162 75 / 0) 70%);
  mix-blend-mode: screen;
  animation: flicker 5.5s var(--ease-drift) infinite alternate;
  pointer-events: none;
}
.hero__glow--window { left: 53%; top: 18%; width: 22vmax; height: 22vmax; }
.hero__glow--lantern { left: 63%; top: 30%; width: 12vmax; height: 12vmax; animation-duration: 3.7s; }
@keyframes flicker {
  0% { opacity: 0.35; transform: scale(0.96); }
  40% { opacity: 0.6; }
  55% { opacity: 0.45; }
  100% { opacity: 0.7; transform: scale(1.04); }
}

.hero__inner { padding-block: 9rem var(--s8); }
.hero__copy {
  display: grid;
  justify-items: start;
  gap: var(--s4);
  max-width: 35rem;
}
.hero__eyebrow { --skin: 1.1; transform: rotate(-1.2deg); }
.hero__title { margin: 0 0 0 -0.6rem; }
.hero__title img {
  width: min(100%, 33rem);
  filter: drop-shadow(0 14px 22px rgb(0 0 0 / 0.55));
}
.hero__tagline { --skin: 1.2; padding: 0.1em 1.2em 0.2em; }
.hero__lead { text-shadow: 0 1px 12px rgb(0 0 0 / 0.7); }
.hero__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s4) var(--s5);
  margin-top: var(--s2);
}
.hero__soon { font-size: var(--text-small); }

/* The logo arrives like a label being pressed on. */
.js .hero__title img { animation: press-on 900ms var(--ease-set) both; }
.js .hero__eyebrow { animation: tag-on 700ms var(--ease-set) 250ms both; }
.js .hero__tagline, .js .hero__lead, .js .hero__actions, .js .hero__soon { animation: rise 700ms var(--ease-set) both; }
.js .hero__tagline { animation-delay: 380ms; }
.js .hero__lead { animation-delay: 480ms; }
.js .hero__actions { animation-delay: 580ms; }
.js .hero__soon { animation-delay: 680ms; }
@keyframes press-on {
  0% { transform: scale(1.18) rotate(-3deg); opacity: 0; }
  60% { transform: scale(0.985) rotate(0.4deg); opacity: 1; }
  100% { transform: none; opacity: 1; }
}
@keyframes tag-on {
  from { transform: rotate(-9deg) translateY(-10px); opacity: 0; }
  to { transform: rotate(-1.2deg); opacity: 1; }
}
@keyframes rise {
  from { transform: translateY(14px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

/* Loose knots. Each is three layers: the fall, the sway, the knot itself. */
.hero__loose {
  position: absolute;
  inset: 0 0 0 44%;
  z-index: -1;
  overflow: hidden;
}
.loose {
  position: absolute;
  top: -5rem;
  left: var(--x);
  width: var(--size);
  height: var(--size);
  animation: loose-fall var(--fall) linear var(--delay) infinite backwards;
  pointer-events: none;
}
.loose__sway {
  width: 100%;
  height: 100%;
  animation: loose-sway var(--sway) var(--ease-drift) var(--delay) infinite alternate;
}
.loose__knot {
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  filter: drop-shadow(0 6px 8px rgb(0 0 0 / 0.45));
  transition: transform var(--t-move) linear;
}
.loose__knot:hover { transform: scale(1.12); }
.loose__knot img { width: 100%; height: 100%; }
@keyframes loose-fall {
  from { transform: translate3d(0, 0, 0); }
  to { transform: translate3d(var(--drift), calc(100svh + 12rem), 0); }
}
@keyframes loose-sway {
  from { transform: translateX(-1.4rem) rotate(-3deg); }
  to { transform: translateX(1.4rem) rotate(3deg); }
}
/* Untied: the game's clear burst, 220 ms, from 0.55 to 1.1. */
.burst {
  position: absolute;
  width: 6rem;
  height: 6rem;
  margin: -3rem 0 0 -3rem;
  pointer-events: none;
  animation: burst var(--t-burst) ease-out forwards;
}
@keyframes burst {
  from { transform: scale(0.55); opacity: 1; }
  to { transform: scale(1.1); opacity: 0; }
}
.hero__count {
  position: absolute;
  right: var(--gutter-right);
  bottom: var(--s6);
  margin: 0;
  animation: rise 400ms var(--ease-set) both;
}

@media (max-width: 52rem) {
  .hero__painting img { object-position: 50% 20%; }
  .hero__painting::after {
    background: linear-gradient(to top, var(--bench) 0%, rgb(17 31 40 / 0.9) 34%, rgb(17 31 40 / 0.35) 62%, rgb(17 31 40 / 0) 82%);
  }
  .hero__glow--window { left: 40%; top: 12%; }
  .hero__glow--lantern { left: 62%; top: 22%; }
  .hero__inner { padding-block: 19rem var(--s7); }
  .hero__count { top: 5rem; bottom: auto; }
  /* On a phone the knots fall over the painting and fade before the words. */
  .hero__loose {
    inset: 0;
    -webkit-mask-image: linear-gradient(to bottom, #000 30%, transparent 46%);
    mask-image: linear-gradient(to bottom, #000 30%, transparent 46%);
  }
}

/* ---------- The board ---------- */

.play__grid {
  display: grid;
  grid-template-columns: minmax(0, 23rem) minmax(0, 1fr);
  gap: var(--s8);
  align-items: center;
}
.play__bench { display: grid; gap: var(--s3); justify-items: stretch; }
.play__copy { display: grid; gap: var(--s5); }

.board-hud {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr);
  gap: var(--s2);
  align-items: stretch;
}
.board-hud .hud-tag { min-width: 0; }
.board-hud .label { white-space: nowrap; }
.board-next {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s2);
  padding: 0 var(--s2);
  min-width: 0;
}
.board-next__pair { display: flex; flex: none; }
.board-next__pair img { width: 1.45rem; height: 1.45rem; }
.board-hud .hud-tag { padding-right: var(--s2); }

.board-frame {
  position: relative;
  border-style: solid;
  border-color: transparent;
  border-width: 14px;
  border-image: var(--skin-frame) 36 / 14px stretch;
}
.board {
  --cols: 8;
  --rows: 11;
  position: relative;
  aspect-ratio: 8 / 11;
  margin: -4px;
  background-color: var(--slate);
  background-image:
    linear-gradient(to right, var(--grid) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid) 1px, transparent 1px);
  background-size: calc(100% / var(--cols)) calc(100% / var(--rows));
  overflow: hidden;
  outline-offset: 6px;
  touch-action: manipulation;
}
.cell {
  position: absolute;
  left: 0;
  top: 0;
  width: calc(100% / var(--cols));
  height: calc(100% / var(--rows));
  transition: transform var(--t-move) linear;
  will-change: transform;
}
.cell img { width: 100%; height: 100%; }
.cell--knot img { animation: knot-flex var(--idle) var(--ease-drift) infinite alternate; }
.cell--falling { transition-duration: 160ms; transition-timing-function: cubic-bezier(0.5, 0, 0.9, 0.6); }
.cell--ghost { opacity: 0.28; transition: none; }
@keyframes knot-flex {
  from { transform: scale(1, 1); }
  to { transform: scale(1.015, 0.985); }
}
/* The flax cord between a capsule's halves, drawn behind them. The box is
   one cell, at the upper or left half; the bar bridges to the other. */
.cord {
  position: absolute;
  left: 0;
  top: 0;
  width: calc(100% / var(--cols));
  height: calc(100% / var(--rows));
  transition: transform var(--t-move) linear;
  z-index: 0;
}
.cord::before {
  content: "";
  position: absolute;
  background: var(--flax);
  box-shadow: 0 0 0 1px var(--cord-key);
  border-radius: 2px;
}
.cord--flat::before { left: 86%; top: 45%; width: 28%; height: 10%; }
.cord--tall::before { left: 45%; top: 86%; width: 10%; height: 28%; }
.cell { z-index: 1; }
.board .burst { z-index: 3; width: 22%; height: auto; aspect-ratio: 1; margin: 0; }
.chain-label {
  position: absolute;
  left: 50%;
  top: 38%;
  z-index: 4;
  translate: -50% -50%;
  white-space: nowrap;
  animation: chain var(--t-chain) var(--ease-set) forwards;
}
@keyframes chain {
  0% { transform: scale(0.7); opacity: 0; }
  25% { transform: scale(1.08); opacity: 1; }
  80% { transform: scale(1); opacity: 1; }
  100% { transform: scale(1) translateY(-10px); opacity: 0; }
}
.board-card {
  --pad: var(--s4);
  position: absolute;
  left: -1.25rem;
  right: -1.25rem;
  top: 50%;
  translate: 0 -50%;
  z-index: 6;
  display: grid;
  gap: var(--s4);
  justify-items: center;
  animation: rise 300ms var(--ease-set) both;
}
.board-card .voice { font-size: 1.25rem; }
.board-keys {
  display: flex;
  justify-content: space-between;
  gap: var(--s1);
}
.board-keys__gap { flex: 1; }
.board-status { font-size: var(--text-small); text-align: center; min-height: 1.6em; }

.rules { display: grid; gap: var(--s4); }
.rules li {
  display: grid;
  grid-template-columns: 2.25rem minmax(0, 1fr);
  gap: var(--s3);
  align-items: baseline;
  font-size: var(--text-lead);
  line-height: 1.35;
}
.rules__n {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--brass);
  border-radius: 50%;
  color: var(--brass);
  letter-spacing: 0;
}
.inks { display: flex; flex-wrap: wrap; gap: var(--s3) var(--s5); }

@media (max-width: 56rem) {
  .play__grid { grid-template-columns: minmax(0, 1fr); gap: var(--s7); }
  .play__bench { max-width: 23rem; margin-inline: auto; width: 100%; order: 2; }
}

/* ---------- Long Night ---------- */

.night__head { display: grid; gap: var(--s4); margin-bottom: var(--s7); }

/* The rooms stack like floors: each one slides up over the last. */
.rooms { display: grid; gap: var(--s7); }
.room {
  position: sticky;
  top: calc(var(--s7) + var(--n) * 1.1rem);
  display: grid;
}
.room__painting {
  aspect-ratio: 16 / 9;
  max-height: calc(100svh - 7rem);
  box-shadow: 0 -18px 40px rgb(4 10 14 / 0.55), var(--shadow-bench);
}
.room__painting img { transform: scale(1.04); }
.room__note {
  --pad: var(--s5);
  position: absolute;
  left: var(--s5);
  bottom: var(--s5);
  width: min(26rem, calc(100% - 2 * var(--s5)));
  display: grid;
  gap: var(--s2);
}
.room__note .voice { font-size: 1.3rem; }
.room__note .dim { font-size: var(--text-small); }

/* Where the browser can, a room dims and shrinks a little as the next covers it. */
@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    .room__painting {
      animation: room-under linear both;
      animation-timeline: view();
      animation-range: exit-crossing 0% exit-crossing 100%;
    }
    .room__painting img {
      animation: room-pan linear both;
      animation-timeline: view();
      animation-range: entry 0% cover 60%;
    }
  }
}
@keyframes room-under {
  to { filter: brightness(0.55); transform: scale(0.965); }
}
@keyframes room-pan {
  from { transform: scale(1.14) translateY(3%); }
  to { transform: scale(1.04); }
}

@media (max-width: 46rem) {
  .room { position: relative; top: auto; }
  .room__painting { aspect-ratio: 4 / 3; max-height: none; }
  .room__note {
    position: relative;
    left: auto;
    bottom: auto;
    width: auto;
    margin: -2.5rem var(--s3) 0;
  }
}

.stops { margin-top: var(--s9); display: grid; gap: var(--s6); }
.stops__list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr));
  gap: var(--s5) var(--s6);
}
.stop {
  display: grid;
  grid-template-columns: 4rem minmax(0, 1fr);
  gap: var(--s4);
  align-items: center;
}
.stop img { width: 4rem; height: 4rem; filter: drop-shadow(0 6px 8px rgb(0 0 0 / 0.45)); transition: transform 300ms var(--ease-set); }
.stop:hover img { transform: rotate(-4deg) scale(1.08); }
.stop .dim { font-size: var(--text-small); line-height: 1.4; margin-top: 2px; }
.stops__threads { justify-self: start; font-size: var(--text-small); }

/* ---------- The bracelet ---------- */

.bracelet__head { display: grid; gap: var(--s4); }
.bracelet__stage {
  position: relative;
  height: 24rem;
  margin-block: var(--s5) var(--s6);
  touch-action: pan-y;
}
#bracelet-canvas { width: 100%; height: 100%; cursor: grab; }
#bracelet-canvas.is-held { cursor: grabbing; }
.bracelet__grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 22rem);
  gap: var(--s7);
  align-items: start;
}
.drawer { display: grid; gap: var(--s4); }
.drawer__list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(4.75rem, 1fr));
  gap: var(--s3);
}
.drawer__charm {
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1;
  padding: var(--s2);
  border: 1px solid var(--grid);
  border-radius: var(--radius-small);
  background: var(--slate);
  cursor: pointer;
  transition: transform 200ms var(--ease-set), border-color var(--t-fade) linear, background-color var(--t-fade) linear;
  -webkit-tap-highlight-color: transparent;
}
.drawer__charm img { width: 100%; height: 100%; transition: transform 300ms var(--ease-set); }
.drawer__charm:hover img { transform: rotate(-6deg) scale(1.08); }
.drawer__charm[aria-pressed="true"] {
  border-color: var(--brass);
  background: var(--bench-lift);
  box-shadow: inset 0 0 0 1px var(--brass);
}
.drawer__charm.is-full { animation: nope 260ms linear; }
@keyframes nope {
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}
.charm-note { display: grid; gap: var(--s2); min-height: 13rem; align-content: start; }
.charm-note__count { font-size: var(--text-small); margin-top: var(--s2); }

@media (max-width: 52rem) {
  .bracelet__grid { grid-template-columns: minmax(0, 1fr); gap: var(--s5); }
  .bracelet__stage { height: 14rem; }
  .charm-note { min-height: 0; order: -1; }
}

/* ---------- Ways to play ---------- */

.ways__grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr);
  gap: var(--s8);
  align-items: center;
}
.ways__copy { display: grid; gap: var(--s5); }
.ways__list { display: grid; gap: var(--s3); }
.ways__list .plate { --skin: 1.2; padding: var(--s3) var(--s5) var(--s4); display: grid; gap: var(--s1); }
.ways__list h3 { font-size: 1.6rem; }
.ways__list .dim { font-size: var(--text-small); line-height: 1.45; }

.phones {
  --tx: 0;
  --ty: 0;
  position: relative;
  height: clamp(26rem, 46vw, 36rem);
  perspective: 1200px;
}
.phones .phone {
  position: absolute;
  top: 50%;
  left: 50%;
  height: 92%;
  transition: transform 500ms var(--ease-set);
}
.phones__a { transform: translate(-128%, -52%) rotate(-9deg) translate3d(calc(var(--tx) * -14px), calc(var(--ty) * -8px), 0); }
.phones__b { transform: translate(-50%, -50%) translate3d(calc(var(--tx) * 6px), calc(var(--ty) * 6px), 0) scale(1.04); z-index: 2; }
.phones__c { transform: translate(28%, -48%) rotate(8deg) translate3d(calc(var(--tx) * 18px), calc(var(--ty) * 10px), 0); }

@media (max-width: 56rem) {
  .ways__grid { grid-template-columns: minmax(0, 1fr); gap: var(--s7); }
  .phones { height: 26rem; }
}

/* ---------- Nell ---------- */

.nell { background: linear-gradient(to bottom, var(--bench), var(--dusk-deep) 55%, var(--bench)); }
.nell__grid {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1fr);
  gap: var(--s8);
  align-items: center;
}
.nell__portrait img {
  width: min(100%, 26rem);
  margin-inline: auto;
  filter: drop-shadow(0 30px 40px rgb(0 0 0 / 0.5));
}
.nell__copy { display: grid; gap: var(--s5); }
.nell__says { --skin: 1.3; display: grid; gap: var(--s4); padding: var(--s4) var(--s5) var(--s5); justify-items: start; }
.nell__says .nell-line { width: 100%; min-height: 5.5rem; }
#nell-face, #board-card-face { transition: opacity var(--t-fade) linear; }
.is-swapping { opacity: 0; }

@media (max-width: 52rem) {
  .nell__grid { grid-template-columns: minmax(0, 1fr); gap: var(--s6); }
  .nell__portrait img { width: min(70%, 18rem); }
}

/* ---------- Promises, and the end ---------- */

.kind__grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
  gap: var(--s8);
  align-items: center;
}
.kind__leaf { --skin: 1.3; --pad: var(--s6); display: grid; gap: var(--s4); transform: rotate(-0.8deg); }
.kind__leaf h2 { font-size: var(--text-h3); }
.kind__list { display: grid; gap: var(--s3); }
.kind__list li {
  position: relative;
  padding-left: 1.4em;
  line-height: 1.4;
}
.kind__list li::before {
  content: "";
  position: absolute;
  left: 0.2em;
  top: 0.5em;
  width: 0.5em;
  height: 0.5em;
  background: var(--oxblood);
  border-radius: 50% 45% 55% 40%;
}
.kind__end { display: grid; gap: var(--s4); }
.kind__end .painting { aspect-ratio: 16 / 10; }
.kind__end figcaption { text-align: center; }

.soon {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: var(--s5);
  align-items: center;
  margin-top: var(--s9);
  justify-content: center;
  max-width: 52rem;
}
.soon__icon { border-radius: 22%; box-shadow: var(--shadow-bench); }
.soon h2 { font-size: var(--text-h3); }

@media (max-width: 52rem) {
  .kind__grid { grid-template-columns: minmax(0, 1fr); gap: var(--s7); }
  .soon { grid-template-columns: auto minmax(0, 1fr); }
  .soon .store { grid-column: 1 / -1; justify-self: start; }
}

/* ---------- Foot ---------- */

.foot {
  position: relative;
  padding-block: var(--s8) calc(var(--s7) + env(safe-area-inset-bottom, 0px));
  background:
    linear-gradient(to bottom, var(--bench), rgb(17 31 40 / 0.72) 40%, rgb(17 31 40 / 0.9)),
    url("../img/workbench.webp") center bottom / cover no-repeat;
  display: grid;
  gap: var(--s5);
}
.foot__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--s4);
}
.foot__nav { display: flex; gap: var(--s5); }
.foot__small { font-size: var(--text-small); max-width: 40rem; }

/* ---------- Less motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .hero__painting img, .hero__glow, .cell--knot img { animation: none; }
  .js .hero__title img, .js .hero__eyebrow, .js .hero__tagline, .js .hero__lead, .js .hero__actions, .js .hero__soon { animation: none; }
  .hero__loose { display: none; }
  .candlelight { display: none; }
  .phones .phone, .stop img, .drawer__charm img { transition: none; }
  .cell, .cord { transition: none; }
}
