@font-face {
  font-family: "Fell SC";
  src: url("fonts/im-fell-english-sc-latin.woff2") format("woff2");
  font-display: swap;
}
@font-face {
  font-family: "Fell";
  src: url("fonts/im-fell-english-latin.woff2") format("woff2");
  font-display: swap;
}

:root {
  --ink: #0a0b12;
  --gold: #e3bd6d;
  --gold-soft: #b8924a;
  --ivory: #f3e9d2;
  --ember: #ff8a3d;
  --blood: #7d1a22;
  --zoom: 1000ms;
  --swing: 3000ms;
  color-scheme: dark;
  scrollbar-gutter: stable;
}

* { box-sizing: border-box; }

html.zoomed { overflow: hidden; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--ink);
  color: var(--ivory);
  font-family: "Fell", Georgia, serif;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

.sky {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(ellipse 90% 60% at 50% 115%, rgba(125, 26, 34, .45), transparent 70%),
    radial-gradient(circle at 82% 12%, rgba(227, 189, 109, .10), transparent 30%),
    linear-gradient(180deg, #05060c 0%, #0b0e1c 55%, #170c12 100%);
}
.moon {
  position: absolute;
  top: 6vh;
  right: 9vw;
  width: clamp(56px, 9vw, 120px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 36%, #fff8e6 0%, #efe1bd 45%, #c9b48a 100%);
  box-shadow: 0 0 60px 14px rgba(243, 226, 180, .18), 0 0 160px 40px rgba(243, 226, 180, .07);
  opacity: .9;
}

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

.fog {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 45vh;
  z-index: 2;
  pointer-events: none;
  overflow: hidden;
  mask-image: linear-gradient(180deg, transparent, #000 60%);
}
.fog-a, .fog-b {
  position: absolute;
  bottom: -10vh;
  left: -50%;
  width: 200%;
  height: 100%;
  background:
    radial-gradient(ellipse 25% 40% at 20% 70%, rgba(190, 200, 220, .13), transparent 70%),
    radial-gradient(ellipse 30% 35% at 55% 80%, rgba(190, 200, 220, .11), transparent 70%),
    radial-gradient(ellipse 22% 45% at 85% 75%, rgba(190, 200, 220, .12), transparent 70%);
  filter: blur(6px);
  animation: drift 60s linear infinite;
}
.fog-b {
  bottom: -18vh;
  animation-duration: 90s;
  animation-direction: reverse;
  opacity: .8;
}
@keyframes drift {
  from { transform: translateX(0); }
  to { transform: translateX(25%); }
}

.scene {
  position: relative;
  z-index: 4;
  padding: clamp(20px, 5vh, 56px) 16px 72px;
}

.stage {
  max-width: 900px;
  margin: 0 auto;
  transform-origin: 50% 50%;
  transition: transform var(--zoom) cubic-bezier(.65, 0, .2, 1), filter var(--zoom) ease;
}

.title {
  margin: 0 0 clamp(14px, 3vh, 28px);
  text-align: center;
  font-family: "Fell SC", Georgia, serif;
  font-weight: 400;
  font-size: clamp(2.6rem, 9vw, 5.2rem);
  line-height: 1;
  letter-spacing: .06em;
  color: var(--gold);
  text-shadow: 0 0 22px rgba(255, 138, 61, .35), 0 2px 0 #3a1a08, 0 6px 24px rgba(0, 0, 0, .8);
}

.board {
  position: relative;
  padding: clamp(10px, 2.4vw, 22px);
  border-radius: 10px;
  background:
    repeating-linear-gradient(97deg, rgba(0, 0, 0, .10) 0 3px, transparent 3px 11px),
    repeating-linear-gradient(83deg, rgba(255, 255, 255, .025) 0 2px, transparent 2px 17px),
    linear-gradient(160deg, #3d1316, #24090d 60%, #1a0709);
  border: 2px solid var(--gold-soft);
  box-shadow:
    inset 0 0 0 5px #1a0709,
    inset 0 0 0 6px rgba(227, 189, 109, .45),
    inset 0 0 40px rgba(0, 0, 0, .6),
    0 30px 80px rgba(0, 0, 0, .75),
    0 0 120px rgba(125, 26, 34, .25);
}

.grid-box { container-type: inline-size; }

.grid {
  --cols: 7;
  --gap: clamp(5px, 1.4vw, 14px);
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  grid-auto-rows: calc((100cqi - (var(--cols) - 1) * var(--gap)) / var(--cols));
  gap: var(--gap);
}

.cell {
  position: relative;
  display: flex;
  min-width: 0;
  grid-row: var(--r) / span var(--rs);
  grid-column: var(--c) / span var(--cs);
}
@media (max-width: 560px) {
  .grid { --cols: 4; }
  .cell {
    grid-row: var(--nr) / span var(--rs);
    grid-column: var(--nc) / span var(--cs);
  }
}

.tone-red { --paper: #8a1f27; --paper-2: #5d1118; }
.tone-green { --paper: #1f4a36; --paper-2: #123022; }
.tone-night { --paper: #23305a; --paper-2: #151d3a; }
.tone-wood { --paper: #5a3d24; --paper-2: #3a2614; }

.door {
  position: relative;
  flex: 1;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: #050509;
  color: inherit;
  font: inherit;
  cursor: pointer;
  container-type: size;
  perspective: 3000px;
  transition: perspective var(--zoom) ease;
  box-shadow: inset 0 0 18px rgba(0, 0, 0, .9);
}
.door[aria-disabled="true"] { cursor: default; }
.door:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
}

.inside {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: 4px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: radial-gradient(circle at 50% 40%, #3a2412, #0c0706 75%);
}
.inside img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 20%;
}
.inside::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 45%, rgba(255, 190, 110, .85), rgba(255, 138, 61, .2) 45%, transparent 70%);
  opacity: 0;
  pointer-events: none;
}
.name {
  position: relative;
  z-index: 1;
  width: 100%;
  padding: 18cqh 6cqi 5cqh;
  text-align: center;
  font-size: clamp(6px, 12cqi, 40px);
  line-height: 1.1;
  color: var(--ivory);
  text-shadow: 0 1px 2px #000, 0 0 10px #000;
  background: linear-gradient(180deg, transparent, rgba(0, 0, 0, .85) 55%);
}
.cell.big .name { font-size: clamp(6px, 8cqi, 40px); }

.leaf {
  position: absolute;
  z-index: 2;
  inset: 0;
  transform-origin: 0 50%;
  transform-style: preserve-3d;
  transition: transform var(--swing) cubic-bezier(.6, 0, .3, 1.12);
}
.leaf.left { right: 50%; }
.leaf.right { left: 50%; transform-origin: 100% 50%; }

.face {
  position: absolute;
  inset: 0;
  border-radius: 4px;
}
.face.front {
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 30% 25%, rgba(255, 255, 255, .10), transparent 55%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Cg fill='%23f3e9d2' fill-opacity='.07'%3E%3Ccircle cx='6' cy='8' r='1.2'/%3E%3Ccircle cx='27' cy='5' r='.8'/%3E%3Ccircle cx='17' cy='22' r='1'/%3E%3Ccircle cx='35' cy='29' r='1.3'/%3E%3Ccircle cx='9' cy='34' r='.8'/%3E%3C/g%3E%3C/svg%3E"),
    linear-gradient(145deg, var(--paper), var(--paper-2));
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, .5),
    inset 0 0 0 4px rgba(0, 0, 0, .15),
    inset 0 -8px 16px rgba(0, 0, 0, .35),
    0 2px 6px rgba(0, 0, 0, .5);
}
.face.front::before {
  content: "";
  position: absolute;
  inset: max(4px, 6%);
  border: 1px dashed rgba(227, 189, 109, .35);
  border-radius: 3px;
}
.face.front::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 4px;
  background:
    repeating-linear-gradient(90deg, rgba(0, 0, 0, .06) 0 2px, transparent 2px 6px),
    linear-gradient(215deg, #d9c9a3, #9c845c);
  box-shadow: inset 0 0 12px rgba(0, 0, 0, .35);
  opacity: 0;
  transition: opacity 1ms linear calc(var(--swing) * .51);
}
.door.open .face.front::after { opacity: 1; }

.board.pictured {
  background: var(--bg) var(--bx, 50%) var(--by, 50%) / var(--bw, cover) var(--bh, auto) no-repeat, #1a0709;
}
.pictured .inside::before {
  content: "";
  position: absolute;
  inset: -16px;
  background: var(--bg) calc(var(--ix, 0px) + 16px) calc(var(--iy, 0px) + 16px) / var(--bw, cover) var(--bh, auto) no-repeat;
  filter: blur(6px) brightness(.9) saturate(1.2);
}
.pictured .face.front {
  background: var(--bg) var(--fx, 0) var(--fy, 0) / var(--bw, 0) var(--bh, 0) no-repeat, #1a0709;
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, .55),
    inset 1px 1px 0 1px rgba(255, 255, 255, .12),
    0 1px 3px rgba(0, 0, 0, .55);
}
.pictured .face.front::before {
  border: 1px dashed rgba(243, 233, 210, .45);
}
.pictured .num {
  color: var(--ivory);
  text-shadow: 0 1px 2px #000, 0 0 8px rgba(0, 0, 0, .9), 0 0 18px rgba(0, 0, 0, .7);
}

.num {
  position: relative;
  z-index: 1;
  font-family: "Fell", Georgia, serif;
  font-size: min(46cqi, 46cqh);
  line-height: 1;
  color: var(--gold);
  text-shadow: 0 1px 0 #2a1406, 0 0 14px rgba(255, 170, 80, .35);
  pointer-events: none;
}
.cell.big .num {
  position: absolute;
  z-index: 3;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 34cqi;
  transition: opacity 300ms ease;
}
.cell.big .leaf .face.front::before { inset: max(4px, 6%); }

.door:not([aria-disabled="true"]):hover .leaf { transform: rotateY(-12deg); }
.door:not([aria-disabled="true"]):hover .leaf.right { transform: rotateY(12deg); }

.door.open .leaf { transform: rotateY(-97deg); }
.cell.focus .door.open .leaf { transform: rotateY(-115deg); }
.door.open .leaf.right { transform: rotateY(97deg); }
.cell.focus .door.open .leaf.right { transform: rotateY(115deg); }
.door.open .num { opacity: 0; }
.cell:not(.focus) .door.open:hover .leaf { transform: rotateY(-93deg); }
.cell:not(.focus) .door.open:hover .leaf.right { transform: rotateY(93deg); }

.door.opening .inside::after { animation: glow var(--swing) ease-out; }
@keyframes glow {
  0% { opacity: 0; }
  25% { opacity: 1; }
  100% { opacity: 0; }
}

.door.locked-shake { animation: shake 420ms ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-3px) rotate(-1deg); }
  40% { transform: translateX(3px) rotate(1deg); }
  60% { transform: translateX(-2px); }
  80% { transform: translateX(2px); }
}

.cell:has(.door.open) { z-index: 1; }
.cell.focus { z-index: 5; }
.cell.focus .door { perspective: 700px; }
html.zoomed .cell:not(.focus) { filter: brightness(.35) blur(.4px); transition: filter var(--zoom) ease; }
.cell { transition: filter var(--zoom) ease; }
html.zoomed .title { opacity: 0; transition: opacity 400ms ease; }
.title { transition: opacity 600ms ease; }

.back {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 10;
  padding: 10px 20px;
  border: 2px solid var(--gold);
  border-radius: 999px;
  background: rgba(10, 11, 18, .8);
  color: var(--gold);
  font-family: "Fell SC", Georgia, serif;
  font-size: 1.15rem;
  cursor: pointer;
  opacity: 0;
  transition: opacity 400ms ease;
}
.back.show { opacity: 1; }
.back:hover { background: rgba(125, 26, 34, .6); }
.back:focus-visible { outline: 3px solid var(--ivory); outline-offset: 3px; }

.note {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 10;
  margin: 0;
  padding: 10px 20px;
  width: max-content;
  max-width: calc(100vw - 32px);
  transform: translate(-50%, 12px);
  border: 2px solid var(--gold);
  border-radius: 8px;
  background: rgba(10, 11, 18, .92);
  color: var(--ivory);
  font-size: 1.15rem;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 300ms ease, transform 300ms ease;
}
.note.show { opacity: 1; transform: translate(-50%, 0); }
.note.quiet { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

@media (prefers-reduced-motion: reduce) {
  :root { --zoom: 1ms; --swing: 1ms; }
  .fog-a, .fog-b { animation: none; }
  .door.opening .inside::after { animation: none; }
  .door.locked-shake { animation: none; }
}

.debug {
  position: fixed;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 12px;
  padding: 8px 12px;
  max-width: calc(100vw - 32px);
  background: rgba(10, 11, 18, .92);
  border: 1px solid #e3bd6d;
  border-radius: 8px;
  color: #f3e9d2;
  font: 15px/1.3 system-ui, sans-serif;
}
.debug input, .debug button {
  font: inherit;
  color: inherit;
  background: #191622;
  border: 1px solid #6b5a3a;
  border-radius: 6px;
  padding: 4px 8px;
}
.debug button { cursor: pointer; }
.debug a { color: #e3bd6d; }
.zoomed .debug { display: none; }

.credit {
  position: relative;
  z-index: 4;
  margin: -48px 0 0;
  padding: 0 16px 24px;
  text-align: center;
  font-size: .95rem;
  color: rgba(243, 233, 210, .6);
  transition: opacity 600ms ease;
}
.credit p { margin: 0; }
.credit a { color: var(--gold); }
.credit .legal { margin-top: 6px; font-size: .8rem; color: rgba(243, 233, 210, .45); }
html.zoomed .credit { opacity: 0; pointer-events: none; transition: opacity 400ms ease; }

.sound {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 10;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 2px solid var(--gold);
  border-radius: 50%;
  background: rgba(10, 11, 18, .8);
  color: var(--gold);
  cursor: pointer;
}
.sound[aria-pressed="false"] .on,
.sound[aria-pressed="true"] .off { display: none; }
.sound:focus-visible { outline: 2px solid var(--ivory); outline-offset: 3px; }
