/* ============================================================================
   Birthday Connections Card
   Machinery. You shouldn't need to edit this to change content — see puzzle.js
   ========================================================================= */

:root {
  /* NYT Connections difficulty colors */
  --lvl-0: #f9df6d;   /* yellow  */
  --lvl-1: #a0c35a;   /* green   */
  --lvl-2: #b0c4ef;   /* blue    */
  --lvl-3: #ba81c5;   /* purple  */

  --tile-bg:       #efefe6;
  --tile-fg:       #121212;
  --tile-selected: #5a594e;
  --ink:           #121212;
  --muted:         #767676;
  --hairline:      #d3d3d3;
  --paper:         #ffffff;

  --card-ink:  #2c2a4a;
  --card-gold: #b08d57;
  --linen:     #f4ece0;     /* the surface the card sits on */
  --card-face: #fffdfa;     /* the paper of the card itself */

  --gap: 8px;
  --radius: 6px;
  --pad: 12px;          /* gap between the card and the edge of the screen */

  /* Built for a phone: nothing gets wider than a phone-sized column. */
  --col: 430px;

  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

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

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--linen);
  color: var(--ink);
  font-family: "Libre Franklin", "Helvetica Neue", Helvetica, Arial, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;      /* stop iOS inflating text in landscape */
  overscroll-behavior-y: none;         /* no rubber-band on a card */
  overflow-x: clip;                    /* screen transitions must not pan sideways */
}

button {
  font: inherit;
  color: inherit;
  margin: 0;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;          /* kills the 300ms double-tap-zoom delay */
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

/* ---------------------------------------------------------------- screens -- */

.screen {
  min-height: 100svh;
  padding:
    calc(var(--sat) + var(--pad))
    calc(var(--sar) + var(--pad))
    calc(var(--sab) + var(--pad))
    calc(var(--sal) + var(--pad));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  justify-content: safe center;
}

/* ---------------------------------------------------------------- the card --
   Once the cover is open, everything stays inside a piece of card stock:
   warm paper, a gold keyline and a soft shadow, sitting on the linen page. */

.card-page {
  position: relative;
  z-index: 1;
  width: min(100%, calc(var(--col) + 40px));
  background: var(--card-face);
  border-radius: 10px;
  box-shadow:
    0 1px 2px rgba(0,0,0,.06),
    0 14px 34px -12px rgba(44, 42, 74, .26);
  padding: 14px;
}

/* The gold keyline, matching the cover's */
.card-page::after {
  content: "";
  position: absolute;
  inset: 8px;
  border: 1px solid rgba(176, 141, 87, .38);
  border-radius: 6px;
  pointer-events: none;
}

.card-page__inner {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px;
  width: 100%;
}

/* The note is prose, so it earns more breathing room than the game board. */
.screen--note .card-page { padding: 20px; }
.screen--note .card-page__inner { padding: 12px 10px; }

/* Slide-in used by note / puzzle / finale */
.screen--entering { animation: slide-in 460ms var(--ease-out) both; }

@keyframes slide-in {
  from { opacity: 0; transform: translateX(28px); }
  to   { opacity: 1; transform: none; }
}

/* ================================================================== COVER == */

.card-stage {
  position: relative;
  width: min(92vw, calc(var(--col) - 50px));
  aspect-ratio: 3 / 4.2;
  perspective: 1600px;
}

/* The "inside" of the card, revealed as the cover swings open. */
.card-inside {
  position: absolute;
  inset: 0;
  border-radius: 10px;
  background: #fbf8f1;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.06);
  display: grid;
  place-items: center;
}

.card-inside__hint {
  font-size: 13px;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--muted);
  opacity: 0;
}

.card-cover {
  position: absolute;
  inset: 0;
  width: 100%;
  border-radius: 10px;
  background: linear-gradient(160deg, #fffdf8 0%, #f6efe2 100%);
  box-shadow:
    0 1px 2px rgba(0,0,0,.08),
    0 12px 28px -8px rgba(44, 42, 74, .28),
    inset 0 0 0 1px rgba(176, 141, 87, .25);

  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 32px 24px;
  text-align: center;

  transform-origin: left center;
  transform-style: preserve-3d;
  will-change: transform;
  overflow: hidden;              /* keeps confetti inside the card edge */
}

/* ---- balloons ---- */

.balloons {
  width: min(88%, 300px);
  height: auto;
  margin-bottom: 2px;
  overflow: visible;
}

.balloon { transform-origin: 50% 100%; }

/* Each drifts at its own pace so the cluster never looks mechanical. */
.balloon--1 { animation: bob 4.2s ease-in-out infinite; }
.balloon--2 { animation: bob 5.1s ease-in-out infinite .4s; }
.balloon--3 { animation: bob 3.8s ease-in-out infinite .9s; }
.balloon--4 { animation: bob 4.8s ease-in-out infinite .2s; }
.balloon--5 { animation: bob 5.6s ease-in-out infinite .7s; }

@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50%      { transform: translateY(-7px) rotate(1.2deg); }
}

/* ---- light confetti scattered on the cover ---- */

.cover-confetti {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.cover-confetti i {
  position: absolute;
  display: block;
  width: 7px;
  height: 10px;
  opacity: .5;
  animation: drift 7s ease-in-out infinite;
}

@keyframes drift {
  0%, 100% { transform: translateY(0) rotate(var(--spin, 0deg)); }
  50%      { transform: translateY(-6px) rotate(calc(var(--spin, 0deg) + 12deg)); }
}

/* Gold inner keyline, like a letterpress card */
.card-cover::after {
  content: "";
  position: absolute;
  inset: 12px;
  border: 1px solid rgba(176, 141, 87, .45);
  border-radius: 5px;
  pointer-events: none;
}

.card-cover__deco {
  color: var(--card-gold);
  font-size: 18px;
  line-height: 1;
}

.card-cover__eyebrow {
  font-size: 12px;
  letter-spacing: .3em;
  text-transform: uppercase;
  color: var(--card-gold);
}

.card-cover__title {
  font-size: clamp(30px, 10vw, 44px);
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -.02em;
  color: var(--card-ink);
  max-width: 8ch;
}

.card-cover__rule {
  width: 44px;
  height: 1px;
  background: var(--card-gold);
}

.card-cover__cta {
  font-size: 13px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
  animation: breathe 2.4s ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% { opacity: .55; }
  50%      { opacity: 1; }
}

/* The open animation */
.card-stage.is-opening .card-cover {
  animation: card-open 900ms var(--ease-out) forwards;
}
.card-stage.is-opening .card-inside__hint {
  animation: fade-in 500ms 350ms ease-out forwards;
}

@keyframes card-open {
  0%   { transform: rotateY(0deg);   box-shadow: 0 1px 2px rgba(0,0,0,.08), 0 12px 28px -8px rgba(44,42,74,.28), inset 0 0 0 1px rgba(176,141,87,.25); }
  100% { transform: rotateY(-115deg); box-shadow: 0 1px 2px rgba(0,0,0,.04), 0 24px 40px -12px rgba(44,42,74,.18), inset 0 0 0 1px rgba(176,141,87,.25); }
}

@keyframes fade-in { to { opacity: 1; } }

/* =================================================================== NOTE == */

.screen--note { cursor: pointer; }

.note__body, .note__heading, .note__signoff { align-self: stretch; }

.note__heading {
  font-size: clamp(26px, 7vw, 36px);
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -.02em;
  margin: 0 0 20px;
  color: var(--card-ink);
}

.note__body p {
  font-size: 17px;
  line-height: 1.65;
  margin: 0 0 18px;
}

.note__signoff {
  font-size: 17px;
  font-style: italic;
  color: var(--muted);
  margin: 28px 0 0;
}

.advance {
  margin-top: 26px;
  width: 100%;
  min-height: 56px;
  padding: 16px 20px;
  border-radius: 999px;
  background: var(--card-ink);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: transform 120ms var(--ease-out), opacity 120ms;
}
.advance:active { transform: scale(.97); opacity: .9; }
.advance__chev { font-size: 20px; line-height: 1; }

/* ================================================================= PUZZLE == */

.screen--puzzle { justify-content: flex-start; gap: 0; }

.puzzle__header { text-align: center; margin: 4px 0 14px; }

.puzzle__title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.01em;
  margin: 0 0 14px;
}

.puzzle__instruction {
  font-size: 16px;
  margin: 0;
}

/* ---- toast ---- */
.toast {
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.toast__pill {
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  padding: 9px 14px;
  border-radius: 4px;
  animation: toast-in 180ms var(--ease-out);
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

/* ---- board ---- */
.board {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--gap);
}

.tile {
  position: relative;
  aspect-ratio: 4 / 3;
  min-height: 44px;              /* tap-target floor; see note below */
  border-radius: var(--radius);
  background: var(--tile-bg);
  color: var(--tile-fg);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: .01em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 4px 2px;
  overflow: hidden;
  /* Grid items default to min-width:auto, so the nowrap label's intrinsic width
     would widen the column and swallow the gaps before app.js can shrink it. */
  min-width: 0;
  user-select: none;
  -webkit-user-select: none;
  transition: background-color 120ms linear, color 120ms linear, transform 120ms var(--ease-out);
}

.tile:active { transform: scale(.96); }

.tile.is-selected {
  background: var(--tile-selected);
  color: #fff;
}

/* The label is measured and scaled by app.js so any word the user writes fits
   its tile. inline-block is what makes the measurement meaningful — a block
   would always report the tile's own width. */
.tile__label {
  display: inline-block;
  white-space: nowrap;
  line-height: 1.1;
}

/* Fallback for a word too long to fit even at the minimum size. */
.tile.is-wrapped .tile__label {
  display: block;
  width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.05;
}

.tile.is-bouncing { animation: tile-bounce 300ms var(--ease-out); }
@keyframes tile-bounce {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-11px); }
}

.tile.is-wrong { animation: tile-shake 420ms ease-in-out; }
@keyframes tile-shake {
  0%, 100%      { transform: translateX(0); }
  15%, 45%, 75% { transform: translateX(-6px); }
  30%, 60%, 90% { transform: translateX(6px); }
}

/* Tiles sliding into position after a correct guess (FLIP) */
.tile.is-flipping { transition: transform 450ms var(--ease-out); }

/* ---- solved group band ---- */
.band {
  grid-column: 1 / -1;
  border-radius: var(--radius);
  min-height: 62px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 8px;
  text-align: center;
  animation: band-in 320ms var(--ease-out);
}
@keyframes band-in {
  from { opacity: 0; transform: scale(.96); }
  to   { opacity: 1; transform: none; }
}

.band[data-level="0"] { background: var(--lvl-0); }
.band[data-level="1"] { background: var(--lvl-1); }
.band[data-level="2"] { background: var(--lvl-2); }
.band[data-level="3"] { background: var(--lvl-3); }

.band__title {
  font-size: 15px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .01em;
  line-height: 1.15;
  text-wrap: balance;        /* avoids a lonely last word on a wrapped title */
  overflow-wrap: anywhere;
}

.band__words {
  font-size: 15px;
  font-weight: 400;
  line-height: 1.2;
}

/* ---- mistakes ---- */
.mistakes {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 18px 0 16px;
  font-size: 15px;
  min-height: 20px;
}
.mistakes__dots { display: flex; gap: 8px; align-items: center; }

.dot {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--tile-selected);
  transition: transform 220ms var(--ease-out), opacity 220ms;
}
.dot.is-spent { transform: scale(0); opacity: 0; }

/* ---- controls ---- */
.controls {
  display: flex;
  gap: 7px;
  justify-content: center;
  flex-wrap: wrap;
  width: 100%;
}

.btn {
  min-height: 48px;
  padding: 0 13px;
  border-radius: 999px;
  border: 1px solid var(--ink);
  background: var(--paper);
  font-size: 16px;
  font-weight: 500;
  transition: transform 120ms var(--ease-out), opacity 120ms;
}
.btn:active { transform: scale(.96); }

.btn:disabled {
  border-color: var(--hairline);
  color: var(--hairline);
  cursor: default;
}
.btn:disabled:active { transform: none; }

.btn--primary:not(:disabled) {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.restart {
  margin-top: 20px;
  font-size: 13px;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 10px 14px;   /* keeps the tap target honest */
}

/* ================================================================= FINALE == */

.screen--finale {
  position: relative;
  overflow: hidden;
}

.finale__inner {
  position: relative;
  z-index: 1;
  text-align: center;
  width: 100%;
}

.finale__eyebrow {
  font-size: 12px;
  letter-spacing: .3em;
  text-transform: uppercase;
  color: var(--card-gold);
  margin: 0 0 14px;
}

.finale__heading {
  font-size: clamp(34px, 11vw, 56px);
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -.03em;
  color: var(--card-ink);
  margin: 0 0 22px;
}

.finale__body p {
  font-size: 17px;
  line-height: 1.6;
  margin: 0 0 14px;
}

.finale__replay {
  margin-top: 30px;
  font-size: 14px;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 10px 14px;
}

/* ---- confetti ---- */
.confetti { position: absolute; inset: 0; pointer-events: none; }

.confetti i {
  position: absolute;
  top: -12vh;
  width: 9px;
  height: 14px;
  opacity: 0;
  animation: confetti-fall linear forwards;
}

@keyframes confetti-fall {
  0%   { opacity: 1; transform: translateY(0) rotate(0deg); }
  100% { opacity: 0; transform: translateY(115vh) rotate(720deg); }
}

/* ============================================================ responsive == */

@media (max-width: 380px) {
  :root { --gap: 6px; --pad: 8px; }
  .card-page { padding: 10px; }
  .card-page__inner { padding: 4px; }
  .screen--note .card-page { padding: 14px; }
  .screen--note .card-page__inner { padding: 8px 6px; }
  /* Keep Shuffle / Deselect All / Submit on one row, as the real game does. */
  .controls { gap: 5px; }
  .btn { padding: 0 9px; font-size: 13.5px; }
}

/* Landscape on a phone: keep the whole board on screen */
@media (max-height: 560px) and (orientation: landscape) {
  .screen { justify-content: flex-start; }
  .tile { aspect-ratio: 5 / 2; }
  .band { min-height: 46px; }
  .puzzle__title { margin-bottom: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  .card-stage.is-opening .card-cover { opacity: 0; }
}
