:root {
  --paper: #f4efe4;
  --paper-deep: #e7dcc8;
  --ink: #2c2118;
  --ink-soft: #6a5646;
  --brick: #e25b3a;
  --brick-deep: #c4472b;
  --teal: #1f9a8a;
  --mustard: #e8b931;
  --sky: #5ea9d6;
  --leaf: #6aab4d;
  --white: #fffaf3;
  --shadow: 0 10px 0 rgba(44, 33, 24, 0.12);
  --radius: 1.6rem;
  --tap: 7.5rem;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  color: var(--ink);
  font-family: "Avenir Next", "Segoe UI Rounded", "Trebuchet MS", "Segoe UI", sans-serif;
  background-color: var(--paper);
  background-image:
    radial-gradient(circle at 18% 22%, rgba(255, 255, 255, 0.45) 0 1.5px, transparent 2.2px),
    radial-gradient(circle at 72% 64%, rgba(44, 33, 24, 0.045) 0 1.2px, transparent 2px);
  background-size: 22px 22px, 16px 16px;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior: none;
}

body:has(.game-shell) {
  height: 100%;
  overflow: hidden;
}

img,
svg {
  -webkit-user-drag: none;
  pointer-events: none;
}

a,
button {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
}

.page {
  min-height: 100dvh;
  padding:
    calc(1.2rem + var(--safe-top))
    calc(1.2rem + var(--safe-right))
    calc(1.4rem + var(--safe-bottom))
    calc(1.2rem + var(--safe-left));
}

main.page {
  max-width: 72rem;
  margin: 0 auto;
}

.kicker {
  margin: 0;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ink-soft);
}

.site-title {
  margin: 0.35rem 0 0;
  font-size: clamp(2.2rem, 8vw, 4.2rem);
  line-height: 0.95;
  letter-spacing: -0.04em;
}

.lede {
  margin: 0.8rem 0 0;
  max-width: 28rem;
  font-size: clamp(1.05rem, 3vw, 1.35rem);
  color: var(--ink-soft);
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 17.5rem), 1fr));
  gap: 1rem;
  margin-top: 1.6rem;
}

@media (min-width: 960px) {
  .game-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.game-card {
  display: flex;
  flex-direction: column;
  min-height: 11.5rem;
  padding: 1.2rem;
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  background: var(--white);
  box-shadow: var(--shadow);
  text-decoration: none;
}

.game-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.game-card.playable {
  background: linear-gradient(180deg, #fffaf3 0%, #ffe7c2 100%);
}

.game-card.playable.sky-card {
  background: linear-gradient(180deg, #fffaf3 0%, #c5e9f8 100%);
}

.game-card.soon {
  opacity: 0.72;
}

.game-card h2 {
  margin: 0.4rem 0 0;
  font-size: 1.8rem;
  letter-spacing: -0.03em;
}

.game-card p {
  margin: 0.45rem 0 0;
  color: var(--ink-soft);
}

.badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.badge.soon {
  background: var(--ink-soft);
}

.thumb {
  width: 4.4rem;
  height: 4.4rem;
  margin-left: auto;
}

.game-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: 100%;
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  gap: 0.6rem;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 3.2rem;
  height: 3.2rem;
  flex: 0 0 auto;
  border: 3px solid var(--ink);
  border-radius: 1.1rem;
  background: var(--white);
  box-shadow: 0 5px 0 rgba(44, 33, 24, 0.12);
  text-decoration: none;
}

@media (min-width: 640px) {
  .icon-btn {
    width: 3.4rem;
    height: 3.4rem;
  }
}

.prompt {
  flex: 1;
  min-width: 0;
}

.prompt h1 {
  margin: 0;
  font-size: clamp(1.15rem, 3.8vw, 2.2rem);
  line-height: 1.15;
}

.count-pill {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  min-width: 3.6rem;
  width: 3.6rem;
  height: 3.6rem;
  padding: 0;
  border: 3px solid var(--ink);
  border-radius: 1.15rem;
  background: var(--mustard);
  font-size: 1.8rem;
  font-weight: 800;
}

@media (min-width: 640px) {
  .count-pill {
    min-width: 4.2rem;
    width: 4.2rem;
    height: 4.2rem;
    border-radius: 1.3rem;
    font-size: 2.2rem;
  }
}

.playfield {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: center;
  align-items: center;
  gap: clamp(0.35rem, 2cqi, 1.4rem);
  min-height: 0;
  padding: clamp(0.45rem, 2cqi, 1rem);
  border: 3px dashed color-mix(in srgb, var(--ink) 45%, transparent);
  border-radius: calc(var(--radius) + 0.4rem);
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--leaf) 18%, var(--paper)) 0%, var(--paper-deep) 100%);
  overflow: hidden;
  container-type: size;
}

.item {
  position: relative;
  width: min(11.5rem, 42vw, 30vh);
  height: min(11.5rem, 42vw, 30vh);
  flex: 0 0 auto;
  border: 0;
  padding: 0;
  background: transparent;
  filter: drop-shadow(0 8px 0 rgba(44, 33, 24, 0.08));
  transform: rotate(var(--tilt, 0deg));
  transition: transform 140ms ease;
}

.item:active {
  transform: rotate(var(--tilt, 0deg)) scale(0.92);
}

@supports (width: 1cqi) {
  .item {
    width: min(12rem, 46cqi, 46cqb);
    height: min(12rem, 46cqi, 46cqb);
  }

  .playfield[data-count="3"] .item {
    width: min(10.5rem, 30cqi, 42cqb);
    height: min(10.5rem, 30cqi, 42cqb);
  }

  .playfield[data-count="4"] .item {
    width: min(10rem, 40cqi, 42cqb);
    height: min(10rem, 40cqi, 42cqb);
  }

  .playfield[data-count="5"] .item {
    width: min(9rem, 36cqi, 28cqb);
    height: min(9rem, 36cqi, 28cqb);
  }
}

.item.counted {
  cursor: default;
}

.item .art {
  width: 100%;
  height: 100%;
}

.item .num {
  position: absolute;
  right: -0.15rem;
  top: -0.2rem;
  display: grid;
  place-items: center;
  width: 2.1rem;
  height: 2.1rem;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: var(--mustard);
  font-size: 1.15rem;
  font-weight: 800;
  opacity: 0;
  transform: scale(0.4);
}

.item.counted .num {
  opacity: 1;
  transform: scale(1);
  transition: transform 180ms cubic-bezier(0.2, 1.4, 0.3, 1);
}

.item.pop .art {
  animation: pop 420ms cubic-bezier(0.2, 1.4, 0.3, 1);
}

@keyframes pop {
  0% { transform: scale(1); }
  35% { transform: scale(1.18) rotate(-6deg); }
  100% { transform: scale(1) rotate(0deg); }
}

.celebrate {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: none;
  place-items: center;
  padding: clamp(0.4rem, 2cqi, 1rem);
  background: color-mix(in srgb, var(--paper) 82%, transparent);
  backdrop-filter: blur(4px);
}

.celebrate.show {
  display: grid;
}

.celebrate-card {
  display: grid;
  justify-items: center;
  gap: 0.15rem;
  width: min(22rem, 92%);
  max-height: 96%;
  padding: clamp(0.7rem, 2.4vh, 1.4rem) 1rem 1rem;
  overflow: auto;
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  background: var(--white);
  box-shadow: var(--shadow);
  text-align: center;
}

.celebrate-card .giant {
  font-size: clamp(3.2rem, 18vh, 8rem);
  line-height: 0.85;
  letter-spacing: -0.06em;
}

.celebrate-card .word {
  font-size: clamp(1.35rem, 5vh, 2.6rem);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--brick);
}

.celebrate-card .caption {
  margin: 0.25rem 0 0.7rem;
  color: var(--ink-soft);
  font-size: clamp(0.95rem, 2.4vh, 1.15rem);
}

.next-btn {
  width: 100%;
  min-height: 3.2rem;
  border: 3px solid var(--ink);
  border-radius: 1.2rem;
  background: var(--teal);
  color: var(--white);
  font-size: 1.35rem;
  font-weight: 800;
  box-shadow: 0 6px 0 var(--ink);
}

.next-btn:active {
  transform: translateY(3px);
  box-shadow: 0 3px 0 var(--ink);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.playfield.sky {
  background: linear-gradient(180deg, #9fd6f0 0%, #e7f3b8 100%);
  border-style: solid;
  border-color: color-mix(in srgb, var(--ink) 28%, transparent);
}

.color-word {
  color: var(--prompt-color, var(--brick));
}

.swatch-pill {
  background: var(--pill, var(--mustard));
  color: var(--pill-ink, var(--ink));
}

.balloon {
  position: absolute;
  left: var(--x);
  bottom: var(--y);
  z-index: 1;
  width: min(7.8rem, 28vw, 26vh);
  height: min(10.6rem, 38vw, 36vh);
  border: 0;
  padding: 0;
  background: transparent;
  filter: drop-shadow(0 10px 0 rgba(44, 33, 24, 0.08));
  animation: bob var(--bob, 3.6s) ease-in-out infinite;
  transform-origin: 50% 80%;
}

@supports (width: 1cqi) {
  .balloon {
    width: min(8.2rem, 26cqi, 34cqb);
    height: min(11rem, 34cqi, 46cqb);
  }
}

.balloon .art {
  width: 100%;
  height: 100%;
}

.balloon.wobble {
  animation: wobble 420ms ease;
}

.balloon.burst {
  pointer-events: none;
  animation: burst 380ms ease-out forwards;
}

@keyframes bob {
  0%,
  100% { transform: translate(0, 0) rotate(var(--tilt, 0deg)); }
  50% { transform: translate(var(--drift, 8px), -16px) rotate(calc(var(--tilt, 0deg) + 5deg)); }
}

@keyframes wobble {
  0%,
  100% { transform: translateX(0) rotate(var(--tilt, 0deg)); }
  25% { transform: translateX(-10px) rotate(-8deg); }
  75% { transform: translateX(10px) rotate(8deg); }
}

@keyframes burst {
  0% { transform: scale(1) rotate(var(--tilt, 0deg)); opacity: 1; }
  35% { transform: scale(1.22) rotate(var(--tilt, 0deg)); opacity: 1; }
  100% { transform: scale(0.15) rotate(18deg); opacity: 0; }
}

.giant-balloon {
  width: min(8.5rem, 28vw, 18vh);
  height: min(11rem, 36vw, 24vh);
}

.giant-balloon .art {
  width: 100%;
  height: 100%;
}

@media (min-width: 800px) and (min-height: 560px) {
  .balloon {
    width: min(9.2rem, 18vw, 32vh);
    height: min(12.4rem, 24vw, 42vh);
  }
}

@media (max-width: 720px), (max-height: 520px) {
  .playfield.sky {
    display: flex;
  }

  .balloon {
    position: relative;
    left: auto;
    bottom: auto;
    width: min(6.4rem, 28vw, 34vh);
    height: min(8.6rem, 38vw, 46vh);
  }

  @supports (width: 1cqi) {
    .balloon {
      width: min(6.8rem, 28cqi, 36cqb);
      height: min(9.2rem, 38cqi, 48cqb);
    }
  }
}

.game-card.playable.shape-card {
  background: linear-gradient(180deg, #fffaf3 0%, #e4d7f4 100%);
}

.game-card.playable.peek-card {
  background: linear-gradient(180deg, #fffaf3 0%, #f8d5c4 100%);
}

.swatch-pill .art {
  width: 2.2rem;
  height: 2.2rem;
}

@media (min-width: 640px) {
  .swatch-pill .art {
    width: 3.1rem;
    height: 3.1rem;
  }
}

.item.wobble {
  animation: wobble 420ms ease;
}

.item.found .art {
  animation: pop 420ms cubic-bezier(0.2, 1.4, 0.3, 1);
}

.giant-shape {
  width: min(8.5rem, 28vw, 18vh);
  height: min(8.5rem, 28vw, 18vh);
}

.giant-shape .art {
  width: 100%;
  height: 100%;
}

.playfield.room {
  background:
    linear-gradient(180deg, #f3c9a4 0 58%, #c9966c 58% 100%);
  border-style: solid;
  border-color: color-mix(in srgb, var(--ink) 28%, transparent);
  align-content: stretch;
}

.door-row {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: clamp(0.4rem, 2cqi, 1.4rem);
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 3% 2% 5%;
}

.door {
  position: relative;
  flex: 1 1 0;
  min-width: 4.5rem;
  max-width: 12.5rem;
  width: auto;
  height: auto;
  max-height: 100%;
  aspect-ratio: 2 / 4.2;
  padding: 0.45rem 0.45rem 0.3rem;
  border: 3px solid var(--ink);
  border-radius: 1.1rem 1.1rem 0.45rem 0.45rem;
  background: #8a4b2a;
  box-shadow: 0 8px 0 rgba(44, 33, 24, 0.12);
  perspective: 800px;
}

.door-inside {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 0.15rem;
  height: 100%;
  border-radius: 0.7rem;
  background: #f4efe4;
}

.door-inside .art {
  width: 84%;
  height: 64%;
}

.door-name {
  font-size: clamp(0.72rem, 2.4cqi, 1.25rem);
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  opacity: 0;
}

.door.open .door-name {
  opacity: 1;
}

.door-panel {
  position: absolute;
  inset: 0.45rem 0.45rem 0.3rem;
  transform-origin: left center;
  transition: transform 480ms ease;
  border-radius: 0.7rem;
  overflow: hidden;
  background:
    linear-gradient(#d08954, #d08954) 50% 20% / 72% 34% no-repeat,
    linear-gradient(#d08954, #d08954) 50% 78% / 72% 34% no-repeat,
    #c47a48;
}

.door-knob {
  position: absolute;
  top: 50%;
  right: 12%;
  width: clamp(0.9rem, 18%, 1.5rem);
  aspect-ratio: 1;
  translate: 0 -50%;
  border-radius: 50%;
  background: #e8b931;
  border: 3px solid var(--ink);
}

.door.open .door-panel {
  transform: rotateY(-108deg);
}

.door.open .door-inside .art {
  animation: pop 480ms cubic-bezier(0.2, 1.4, 0.3, 1);
}

.door.wiggle .door-inside .art {
  animation: pop 360ms cubic-bezier(0.2, 1.4, 0.3, 1);
}

.peek-row {
  display: flex;
  justify-content: center;
  gap: 0.35rem;
}

.peek-row .art {
  width: 3.4rem;
  height: 3.4rem;
}

@media (max-height: 500px) {
  .kicker {
    display: none;
  }

  .game-shell {
    gap: 0.3rem;
  }

  .page.game-shell {
    padding-top: calc(0.4rem + var(--safe-top));
    padding-right: calc(0.7rem + var(--safe-right));
    padding-bottom: calc(0.4rem + var(--safe-bottom));
    padding-left: calc(0.7rem + var(--safe-left));
  }

  .icon-btn,
  .count-pill {
    width: 44px;
    height: 44px;
    min-width: 44px;
    border-radius: 0.9rem;
    font-size: 1.35rem;
  }

  .door {
    height: 100%;
    width: auto;
    flex: 0 1 auto;
    aspect-ratio: 2 / 3.4;
  }

  .site-title {
    font-size: clamp(1.7rem, 7vw, 2.8rem);
  }

  .next-btn {
    min-height: 2.7rem;
    font-size: 1.15rem;
  }

  .door-row {
    padding: 2% 1% 3%;
    gap: 0.4rem;
  }
}

body.home {
  background-color: #e0dac8;
  background-image:
    radial-gradient(ellipse 90% 42% at 72% -8%, rgba(255, 250, 240, 0.7), transparent 62%),
    radial-gradient(circle at 18% 22%, rgba(255, 255, 255, 0.32) 0 1.4px, transparent 2.1px),
    radial-gradient(circle at 72% 64%, rgba(44, 33, 24, 0.035) 0 1.1px, transparent 2px);
  background-size: auto, 22px 22px, 16px 16px;
  background-repeat: no-repeat, repeat, repeat;
  background-position: top center, 0 0, 0 0;
}

.home-head {
  max-width: 34rem;
}

body.home .site-title {
  text-shadow: 0 1px 0 rgba(255, 250, 243, 0.65);
}

.shelf {
  margin-top: 1.6rem;
}

body.home .game-grid {
  margin-top: 0;
}

body.home .game-card {
  position: relative;
  min-height: 0;
  padding: 0;
  overflow: hidden;
  background: var(--white);
}

body.home .game-card.playable,
body.home .game-card.playable.sky-card,
body.home .game-card.playable.shape-card,
body.home .game-card.playable.peek-card {
  background: var(--white);
}

body.home .game-card .badge {
  position: absolute;
  top: 0.7rem;
  left: 0.7rem;
  z-index: 2;
}

.card-photo {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  object-position: center 38%;
}

.card-copy {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 1;
  padding: 2.4rem 1.05rem 0.85rem;
  background: linear-gradient(
    180deg,
    transparent 0%,
    rgba(255, 250, 243, 0.88) 42%,
    #fffaf3 78%
  );
}

body.home .game-card h2 {
  margin: 0;
  font-size: clamp(1.35rem, 3.4vw, 1.7rem);
}

body.home .game-card p {
  margin: 0.2rem 0 0;
  font-size: 0.95rem;
}

@media (max-height: 720px) {
  .card-photo {
    aspect-ratio: 16 / 10;
  }

  body.home .game-card p {
    display: none;
  }
}

body.home .game-card.playable:active {
  transform: translateY(3px);
  box-shadow: 0 6px 0 rgba(44, 33, 24, 0.12);
}

@media (prefers-reduced-motion: reduce) {
  .item.pop .art,
  .item .num,
  .item.found .art,
  .balloon,
  .door-panel,
  .door.open .door-inside .art,
  .door.wiggle .door-inside .art {
    animation: none;
    transition: none;
  }
}
