@font-face {
  font-family: "Inter";
  src: url("./assets/typeface/Inter-VariableFont_opsz,wght.ttf") format("truetype");
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --page-bg-a: #f9f3e8;
  --page-bg-b: #dfecff;
  --page-bg-c: #f3dedb;
  --shell-bg: rgb(255 255 255 / 0.56);
  --shell-border: rgb(10 10 10 / 0.16);
  --shell-radius: 20px;
  --grid-bg: rgb(255 255 255 / 0.7);
  --cell-text: #111111;
  --line-color: #e1005b;
  --found-text: #1caa5d;
  --cell-size: clamp(22px, 5.4vmin, 40px);
  --grid-size: 12;
  --grid-gap: 2px;
  --stroke-width: 4px;
  --font-grid: "Inter", "Helvetica Neue", Arial, sans-serif;
  --cell-radius: 4px;
  --intro-fade-duration: 1400ms;
  --intro-offset-y: -24px;
  --found-reveal-duration: 1400ms;
  --popup-accent: #1ea4ff;
  --popup-accent-rgb: 30 164 255;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  color: var(--cell-text);
  font-family: var(--font-grid);
  background:
    radial-gradient(120vmax 120vmax at 0% 0%, var(--page-bg-a), transparent 42%),
    radial-gradient(100vmax 100vmax at 100% 100%, var(--page-bg-b), transparent 48%),
    linear-gradient(135deg, var(--page-bg-c), #faf7f3);
}

.site-overlay-header {
  position: fixed;
  inset: 0 0 auto 0;
  display: flex;
  justify-content: center;
  padding-top: calc(env(safe-area-inset-top, 0px) + clamp(8px, 2vh, 16px));
  z-index: 40;
  pointer-events: none;
}

.site-overlay-logo {
  width: clamp(24px, 3.4vmin, 34px);
  height: auto;
}

.app-shell {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: stretch;
}

.stage {
  min-width: 0;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  padding: clamp(16px, 2.8vmin, 30px);
  transition:
    padding 1100ms cubic-bezier(0.16, 1, 0.3, 1),
    filter 1100ms ease;
}

.puzzle-shell {
  padding: clamp(12px, 1.8vmin, 20px);
  opacity: 0;
  transform: translateY(var(--intro-offset-y));
  transition:
    opacity var(--intro-fade-duration) ease,
    transform var(--intro-fade-duration) cubic-bezier(0.22, 1, 0.36, 1),
    box-shadow 420ms ease;
  /* border-radius: var(--shell-radius);
  border: 1px solid var(--shell-border);
  background: var(--shell-bg);
  box-shadow:
    0 16px 34px rgb(9 14 20 / 0.1),
    inset 0 1px 0 rgb(255 255 255 / 0.68); */
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  will-change: opacity, transform;
}

.puzzle-shell.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.grid-wrap {
  position: relative;
  width: max-content;
  touch-action: none;
}

.crossword-grid {
  display: grid;
  grid-template-columns: repeat(var(--grid-size), var(--cell-size));
  grid-template-rows: repeat(var(--grid-size), var(--cell-size));
  gap: var(--grid-gap);
  padding: var(--grid-gap);
  /* border-radius: calc(var(--cell-radius) + 1px);
  background: var(--grid-bg); */
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  display: grid;
  place-items: center;
  color: var(--cell-text);
  font-size: clamp(0.78rem, 2.1vmin, 1.08rem);
  font-weight: 400;
  letter-spacing: 0;
  user-select: none;
  transition: color 180ms ease;
}

.cell-found {
  color: var(--found-text) !important;
}

.cell-found-intro {
  color: var(--cell-text);
  animation: found-cell-intro var(--found-reveal-duration) cubic-bezier(0.22, 1, 0.36, 1) both;
}

#draw-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: auto;
}

.word-popup-overlay {
  position: relative;
  min-width: 0;
  overflow: hidden;
  z-index: 80;
  pointer-events: none;
  visibility: hidden;
}

.word-popup-overlay[aria-hidden="true"] {
  visibility: hidden;
}

.word-popup-overlay.is-open {
  visibility: visible;
  pointer-events: auto;
}

.word-popup {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  background: transparent;
  box-shadow: none;
  opacity: 0;
  transform: translateX(34px);
  transition:
    opacity 880ms ease 260ms,
    transform 1120ms cubic-bezier(0.16, 1, 0.3, 1) 120ms;
}

.word-popup-overlay.is-open .word-popup {
  transform: translateX(0);
  opacity: 1;
}

.word-popup-close {
  position: fixed;
  left: 22vw;
  top: 50%;
  transform: translate(-50%, -50%) scale(0.96);
  opacity: 0;
  pointer-events: none;
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-size: clamp(0.78rem, 1.35vmin, 0.9rem);
  font-weight: 650;
  line-height: 1;
  color: #ffffff;
  background: var(--line-color);
  padding: 0.72rem 1.05rem;
  cursor: pointer;
  box-shadow: 0 12px 24px rgb(225 0 91 / 0.24);
  transition: opacity 220ms ease;
  z-index: 120;
}

body.popup-open .word-popup-close {
  pointer-events: auto;
  animation: popup-close-reveal 520ms cubic-bezier(0.16, 1, 0.3, 1) 1180ms both;
}

.word-popup-close:focus-visible {
  outline: 2px solid rgb(var(--popup-accent-rgb) / 0.56);
  outline-offset: 2px;
}

.word-popup-content {
  display: grid;
  gap: clamp(34px, 5.8vmin, 72px);
  padding: clamp(16px, 3vmin, 36px) clamp(18px, 6vmin, 86px) clamp(28px, 7vmin, 86px);
}

.word-popup-article {
  display: grid;
  gap: clamp(14px, 2.2vmin, 22px);
  max-width: 72ch;
}

.word-popup-reveal {
  opacity: 0;
  transform: translateY(-12px);
}

.word-popup-overlay.is-open .word-popup-reveal {
  animation: popup-content-reveal 820ms cubic-bezier(0.16, 1, 0.3, 1) both;
  animation-delay: calc(460ms + var(--reveal-index, 0) * 140ms);
}

.word-popup-heading {
  margin: 0;
  font-size: clamp(2rem, 5vmin, 4.2rem);
  font-weight: 650;
  line-height: 0.95;
  letter-spacing: 0;
  text-transform: uppercase;
  color: rgb(14 20 36 / 0.95);
}

.word-popup-description {
  margin: 0;
  max-width: 64ch;
  font-size: clamp(0.95rem, 1.9vmin, 1.15rem);
  line-height: 1.58;
  color: rgb(21 32 48 / 0.88);
}

.word-popup-gallery {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(10px, 2vmin, 16px);
  max-width: min(100%, 760px);
}

.word-popup-gallery-item {
  margin: 0;
  position: relative;
  overflow: hidden;
  border-radius: 0;
  min-height: clamp(140px, 22vmin, 250px);
  background: transparent;
  box-shadow: none;
}

.word-popup-gallery-image {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  filter: saturate(1.05) contrast(1.03);
  transition: transform 320ms ease;
}

.word-popup-gallery-item:hover .word-popup-gallery-image {
  transform: scale(1.04);
}

@media (min-width: 900px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr) minmax(0, 0fr);
    transition: grid-template-columns 1180ms cubic-bezier(0.16, 1, 0.3, 1);
  }

  body.popup-open .app-shell {
    grid-template-columns: minmax(0, 0.88fr) minmax(0, 1.12fr);
  }

  body.popup-open .stage {
    padding-left: clamp(10px, 2vmin, 18px);
    padding-right: clamp(8px, 1.4vmin, 12px);
    filter: blur(1.4px) saturate(0.92);
  }

  body.popup-open .puzzle-shell.is-visible {
    transform: translateY(0) scale(0.86);
  }

  body.popup-open .word-popup-close {
    left: 22vw;
  }
}

@media (max-width: 899px) {
  .stage {
    transition: filter 260ms ease;
  }

  body.popup-open .stage {
    filter: blur(1.6px) saturate(0.94);
  }

  .word-popup-overlay {
    position: fixed;
    inset: 0;
    opacity: 0;
    transition: opacity 720ms ease;
  }

  .word-popup-overlay.is-open {
    opacity: 1;
  }

  .word-popup {
    inset: 0;
    border-radius: 0;
    transform: translateY(24px);
    transition:
      opacity 720ms ease 160ms,
      transform 860ms cubic-bezier(0.16, 1, 0.3, 1) 100ms;
  }

  .word-popup-overlay.is-open .word-popup {
    transform: translateY(0);
  }

  body.popup-open .puzzle-shell.is-visible {
    transform: translateY(0) scale(0.88);
  }

  .word-popup-close,
  body.popup-open .word-popup-close {
    left: 50%;
    top: 50%;
  }

  .word-popup-content {
    padding:
      clamp(6px, 2vmin, 12px)
      clamp(14px, 4.5vmin, 20px)
      calc(env(safe-area-inset-bottom, 0px) + clamp(22px, 6vmin, 30px));
  }

  .word-popup-heading {
    font-size: clamp(1.9rem, 11vw, 2.8rem);
    line-height: 0.98;
  }

  .word-popup-description {
    font-size: clamp(0.94rem, 4.4vw, 1rem);
  }

  .word-popup-gallery {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: clamp(10px, 3vmin, 14px);
  }

  .word-popup-gallery-item:first-child {
    grid-column: 1 / -1;
    min-height: clamp(160px, 34vh, 240px);
  }
}

@keyframes found-cell-intro {
  0% {
    color: var(--cell-text);
  }
  100% {
    color: var(--found-text);
  }
}

@keyframes popup-content-reveal {
  0% {
    opacity: 0;
    transform: translateY(-12px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes popup-close-reveal {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.96);
  }
  100% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .puzzle-shell {
    opacity: 1;
    transform: translateY(0);
    transition: none;
  }

  .cell-found-intro {
    animation: none;
  }

  .app-shell,
  .stage,
  .word-popup-overlay,
  .word-popup,
  .word-popup-gallery-image {
    transition: none !important;
  }

  .word-popup-reveal {
    opacity: 1;
    transform: none;
    animation: none !important;
  }

  body.popup-open .puzzle-shell.is-visible {
    transform: translateY(0);
  }

  body.popup-open .word-popup-close {
    opacity: 1;
    transform: translate(-50%, -50%);
    animation: none;
  }
}
