@font-face {
  font-family: "Bagel Fat One";
  src: url("/fonts/bagel-fat-one.woff2") format("woff2");
  font-display: swap;
}
@font-face {
  font-family: "Nunito";
  src: url("/fonts/nunito-400.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Nunito";
  src: url("/fonts/nunito-800.woff2") format("woff2");
  font-weight: 800;
  font-display: swap;
}

:root {
  --pine: #16302a;
  --pine-deep: #0f231e;
  --wool: #f3e7d3;
  --cranberry: #c2413b;
  --mustard: #e3a63a;
  --frost: #a9cfcb;
  --plum: #6b3a5a;
  --display: "Bagel Fat One", "Arial Rounded MT Bold", system-ui, sans-serif;
  --body: "Nunito", system-ui, sans-serif;
  /* felt: fine fibre noise laid over every coloured surface */
  --felt: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .3 0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
}

* { box-sizing: border-box; }

html { background: var(--pine-deep); }

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--wool);
  font-family: var(--body);
  background:
    var(--felt),
    radial-gradient(120% 60% at 50% 0%, #1f4239 0%, var(--pine) 55%, var(--pine-deep) 100%);
  background-attachment: fixed;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  -webkit-tap-highlight-color: transparent;
}

.top {
  max-width: 520px;
  margin: 0 auto;
  padding: 28px 18px 18px;
}

h1 {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(2.1rem, 10.5vw, 3.1rem);
  line-height: .92;
  letter-spacing: -.01em;
  margin: 0;
  color: var(--wool);
  text-shadow: 0 3px 0 var(--pine-deep);
}
h1 span { color: var(--mustard); }

.status {
  margin: 12px 0 0;
  font-size: 1.02rem;
  line-height: 1.4;
  max-width: 30ch;
  color: color-mix(in srgb, var(--wool) 85%, transparent);
}
.status strong { color: var(--wool); font-weight: 800; }

/* ---------- the board ---------- */

.board {
  --gap: 9px;
  max-width: 520px;
  margin: 0 auto;
  padding: 0 14px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: calc((min(100vw, 520px) - 28px - 3 * var(--gap)) / 4);
  gap: var(--gap);
}

.tile {
  position: relative;
  border: 0;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
  background: none;
  cursor: pointer;
  container-type: size;
  rotate: var(--tilt, 0deg);
  transition: rotate .25s ease, scale .25s ease;
}
.tile:hover { scale: 1.02; }
.tile:focus-visible { outline: 3px solid var(--mustard); outline-offset: 3px; border-radius: 10px; }

/* a felt patch with a running stitch, sewn onto the board */
.patch {
  position: absolute;
  inset: 0;
  border-radius: 9px;
  background: var(--felt), var(--c);
  box-shadow: 0 2px 0 rgb(0 0 0 / .25), 0 8px 18px -8px rgb(0 0 0 / .55);
}
.patch::before {
  content: "";
  position: absolute;
  inset: 5px;
  border: 2px dashed var(--stitch, rgb(243 231 211 / .6));
  border-radius: 6px;
  pointer-events: none;
}

.num {
  position: absolute;
  font-family: var(--display);
  line-height: 1;
  color: var(--ink, var(--wool));
}
/* where the number sits varies from door to door, so the eye has to look */
.at-center { inset: 0; display: grid; place-items: center; font-size: 52cqmin; }
.at-corner { top: 12%; left: 14%; font-size: 30cqmin; }
.at-low { right: 13%; bottom: 10%; font-size: 36cqmin; }
.at-tilted { inset: 0; display: grid; place-items: center; font-size: 44cqmin; rotate: -14deg; }

.c-cranberry { --c: var(--cranberry); }
.c-mustard { --c: var(--mustard); --ink: var(--pine-deep); --stitch: rgb(15 35 30 / .45); }
.c-frost { --c: var(--frost); --ink: var(--pine-deep); --stitch: rgb(15 35 30 / .4); }
.c-plum { --c: var(--plum); }
.c-wool { --c: var(--wool); --ink: var(--cranberry); --stitch: rgb(194 65 59 / .5); }
.c-pine { --c: #2c5a4c; }

/* the flap swings open on its left edge */
.door { perspective: 700px; }
.door .flap {
  position: absolute;
  inset: 0;
  transform-origin: left center;
  transform-style: preserve-3d;
  z-index: 2;
}
.door .inside {
  position: absolute;
  inset: 0;
  border-radius: 9px;
  overflow: hidden;
  background: var(--pine-deep);
  box-shadow: inset 0 3px 10px rgb(0 0 0 / .6);
}
.door .inside img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.door .badge {
  position: absolute;
  left: 6px;
  top: 6px;
  min-width: 26px;
  height: 26px;
  padding: 0 6px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  font-family: var(--display);
  font-size: 14px;
  background: var(--wool);
  color: var(--cranberry);
  box-shadow: 0 2px 4px rgb(0 0 0 / .35);
}
.door .empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 800;
  color: var(--frost);
  text-align: center;
  padding: 8px;
}

.door:not(.is-open) .inside { visibility: hidden; }
.door.is-open .flap { display: none; }
.door.opening .inside { visibility: visible; }
.door.opening .flap { animation: swing .7s cubic-bezier(.3, .7, .3, 1) forwards; }

@keyframes swing {
  to { transform: rotateY(-118deg); opacity: .85; }
}

.door.nope { animation: nope .4s ease; }
@keyframes nope {
  20% { translate: -5px 0; }
  40% { translate: 5px 0; }
  60% { translate: -3px 0; }
  80% { translate: 3px 0; }
}

/* decoys: sewn-on things that are not doors */
.decoy svg {
  position: absolute;
  inset: 18%;
  width: 64%;
  height: 64%;
}
.decoy.wiggle { animation: nope .4s ease; }

.foot {
  max-width: 520px;
  margin: 22px auto 0;
  padding: 0 18px 36px;
  font-size: .9rem;
  color: color-mix(in srgb, var(--wool) 60%, transparent);
}

/* ---------- reveal ---------- */

dialog {
  border: 0;
  padding: 0;
  background: none;
  max-width: min(92vw, 480px);
  width: 100%;
  color: var(--pine-deep);
}
dialog::backdrop {
  background: rgb(10 22 19 / .78);
  backdrop-filter: blur(3px);
}
dialog[open] .sheet { animation: pop .35s cubic-bezier(.2, .9, .3, 1.2); }
@keyframes pop {
  from { scale: .85; opacity: 0; }
}

.sheet {
  position: relative;
  background: var(--felt), var(--wool);
  border-radius: 14px;
  padding: 18px 18px 16px;
  box-shadow: 0 20px 50px rgb(0 0 0 / .5);
}
.sheet::before {
  content: "";
  position: absolute;
  inset: 7px;
  border: 2px dashed rgb(194 65 59 / .5);
  border-radius: 9px;
  pointer-events: none;
}
.sheet h2 {
  font-family: var(--display);
  font-weight: 400;
  font-size: 1.9rem;
  margin: 2px 4px 12px;
  color: var(--cranberry);
}
.frame {
  border-radius: 8px;
  overflow: hidden;
  background: var(--pine-deep);
  aspect-ratio: var(--ratio, 1);
}
.frame video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: var(--wool);
}
.sheet form { margin: 14px 0 2px; text-align: right; }
.close {
  position: relative;
  font: 800 1rem var(--body);
  border: 0;
  border-radius: 999px;
  padding: 10px 20px;
  background: var(--pine);
  color: var(--wool);
  cursor: pointer;
}
.close:focus-visible { outline: 3px solid var(--mustard); outline-offset: 2px; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  translate: -50% 20px;
  max-width: min(90vw, 420px);
  width: max-content;
  padding: 12px 18px;
  border-radius: 12px;
  background: var(--felt), var(--wool);
  color: var(--pine-deep);
  font-weight: 800;
  box-shadow: 0 10px 30px rgb(0 0 0 / .45);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, translate .2s;
}
.toast.show { opacity: 1; translate: -50% 0; }

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