/* ============================================================
   Snake — Notion design system (see DESIGN.md)
   Tokens below map 1:1 to DESIGN.md front matter.
   ============================================================ */

:root {
  /* Brand & accent */
  --primary: #0075de;
  --primary-active: #005bab;
  --secondary: #213183;
  --on-primary: #ffffff;

  /* Sticker palette (decorative only) */
  --accent-sky: #62aef0;
  --accent-purple: #d6b6f6;
  --accent-purple-deep: #391c57;
  --accent-pink: #ff64c8;
  --accent-orange: #dd5b00;
  --accent-teal: #2a9d99;
  --accent-green: #1aae39;

  /* Surface */
  --canvas: #ffffff;
  --canvas-soft: #f6f5f4;
  --surface: #ffffff;
  --hairline: #e6e6e6;

  /* Text */
  --ink: #000000;
  --ink-secondary: #31302e;
  --ink-muted: #615d59;
  --ink-faint: #a39e98;

  /* Radii */
  --rounded-xs: 4px;
  --rounded-sm: 5px;
  --rounded-md: 8px;
  --rounded-lg: 12px;
  --rounded-xl: 16px;
  --rounded-full: 9999px;

  /* Spacing */
  --xxs: 4px;
  --xs: 8px;
  --sm: 12px;
  --md: 16px;
  --lg: 24px;
  --xl: 28px;
  --xxl: 32px;

  /* Type */
  --font: "Notion Inter", "Inter", -apple-system, BlinkMacSystemFont, system-ui,
    "Segoe UI", Helvetica, Arial, sans-serif;

  /* Elevation — barely there, layered near-transparent stops */
  --shadow-1: 0 0.175px 1.041px rgba(0, 0, 0, 0.01),
    0 0.8px 2.925px rgba(0, 0, 0, 0.02),
    0 2.025px 7.847px rgba(0, 0, 0, 0.027),
    0 4px 18px rgba(0, 0, 0, 0.04);
  --shadow-2: 0 0.5px 1.5px rgba(0, 0, 0, 0.02),
    0 2px 6px rgba(0, 0, 0, 0.03),
    0 8px 20px rgba(0, 0, 0, 0.04),
    0 23px 52px rgba(0, 0, 0, 0.05);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--canvas-soft);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: var(--xxl) var(--md);
}

/* ─── Page ─────────────────────────────────────────────── */

.page {
  width: 100%;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  gap: var(--lg);
  transition: opacity 520ms ease, transform 520ms ease, filter 520ms ease;
}

/* Everything hides when the birthday finale takes over */
body.is-finale .page {
  opacity: 0;
  transform: scale(0.94);
  filter: blur(10px);
  pointer-events: none;
}

.page__header { display: flex; flex-direction: column; gap: var(--xs); }

.page__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sm);
}

/* Circular utility button (hairline + soft shadow) */
.icon-btn {
  width: 32px;
  height: 32px;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--hairline);
  border-radius: var(--rounded-full);
  background: var(--surface);
  color: var(--ink-secondary);
  cursor: pointer;
  box-shadow: var(--shadow-1);
  transition: background-color 120ms ease, color 120ms ease, transform 90ms ease;
}

.icon-btn:hover { background: var(--canvas-soft); color: var(--ink); }
.icon-btn:active { transform: scale(0.9); }
.icon-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.icon-btn__glyph { display: none; }
.icon-btn[aria-pressed="false"] .icon-btn__glyph--on { display: block; }
.icon-btn[aria-pressed="true"] .icon-btn__glyph--off { display: block; }
.icon-btn[aria-pressed="true"] { color: var(--ink-faint); background: var(--canvas-soft); }

/* Eyebrow — 12px / 600 / +0.125px tracking */
.eyebrow {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.33;
  letter-spacing: 0.125px;
  text-transform: uppercase;
  color: var(--ink-muted);
  display: flex;
  align-items: center;
  gap: var(--xs);
}

.eyebrow--center { justify-content: center; }

/* Decorative sticker dots */
.stickers { display: inline-flex; gap: 5px; }
.dot { width: 7px; height: 7px; border-radius: var(--rounded-full); display: inline-block; }
.dot--purple { background: var(--accent-purple); }
.dot--pink   { background: var(--accent-pink); }
.dot--orange { background: var(--accent-orange); }
.dot--teal   { background: var(--accent-teal); }
.dot--sky    { background: var(--accent-sky); }

/* Title — heavy 700, tight negative tracking */
.title {
  margin: 0;
  font-size: clamp(32px, 8vw, 40px);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -1px;
  color: var(--ink);
}

.title__score {
  color: var(--primary);
  display: inline-block;
  min-width: 1ch;
  transition: transform 160ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.title__score.is-bump { transform: scale(1.22); }

.subtitle {
  margin: 0;
  font-size: 15px;
  line-height: 1.33;
  color: var(--ink-secondary);
  max-width: 46ch;
}

.subtitle strong { font-weight: 600; color: var(--ink); }

.chip {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: var(--rounded-full);
  vertical-align: baseline;
  margin-right: 2px;
}
.chip--food { background: var(--accent-pink); }

/* ─── Board card ───────────────────────────────────────── */

.board-card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--rounded-xl);
  padding: var(--md);
  box-shadow: var(--shadow-1);
}

.board {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: var(--rounded-lg);
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--hairline);
}

.board canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* ─── Overlay (start / win / game over) ────────────────── */

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--lg);
  background: rgba(246, 245, 244, 0.88);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  transition: opacity 180ms ease, visibility 180ms ease;
}

.overlay.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.overlay__card {
  width: 100%;
  max-width: 320px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--rounded-xl);
  box-shadow: var(--shadow-2);
  padding: var(--lg);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sm);
}

.overlay__title {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  line-height: 1.23;
  letter-spacing: -0.625px;
  color: var(--ink);
}

.overlay__text {
  margin: 0;
  font-size: 15px;
  line-height: 1.33;
  color: var(--ink-muted);
}

.overlay__hint {
  margin: var(--xxs) 0 0;
  font-size: 14px;
  line-height: 1.43;
  color: var(--ink-faint);
}

/* ─── Buttons ──────────────────────────────────────────── */

.btn {
  font-family: inherit;
  font-size: 16px;
  font-weight: 500;
  line-height: 1.5;
  border: none;
  border-radius: var(--rounded-full);
  padding: 10px 22px;
  cursor: pointer;
  transition: background-color 120ms ease, transform 90ms ease, box-shadow 120ms ease;
}

.btn--primary {
  background: var(--primary);
  color: var(--on-primary, #fff);
  box-shadow: var(--shadow-1);
}

.btn--primary:hover { background: var(--primary-active); }
.btn--primary:active { background: var(--primary-active); transform: scale(0.9); }
.btn--primary:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ============================================================
   Birthday finale — full-bleed photo, pop-out greeting
   ============================================================ */

.finale {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  overflow: hidden;
  background: var(--secondary);
  opacity: 0;
  visibility: hidden;
  transition: opacity 620ms ease, visibility 620ms ease;
}

.finale.is-active { opacity: 1; visibility: visible; }

/* Blurred backdrop — fills the space around the fitted photo */
.finale__backdrop {
  position: absolute;
  inset: -10%;
  background-image: url('image.jpg');
  background-size: cover;
  background-position: center 30%;
  filter: blur(30px) saturate(1.3) brightness(0.88);
  transform: scale(1.08);
  opacity: 0;
  transition: opacity 700ms ease;
}

.finale.is-loaded .finale__backdrop { opacity: 1; }

.finale.is-active .finale__backdrop {
  animation: finaleZoom 26s cubic-bezier(0.2, 0.7, 0.2, 1) forwards;
}

@keyframes finaleZoom {
  0%   { transform: scale(1.16); }
  100% { transform: scale(1.02); }
}

/* The photo itself — always fits entirely on screen */
.finale__media {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  filter: drop-shadow(0 26px 60px rgba(0, 0, 0, 0.55));
  opacity: 0;
  transition: opacity 700ms ease;
}

.finale.is-loaded .finale__media { opacity: 1; }

/* Scrim — keeps the type legible over the photo */
.finale__scrim {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(9, 14, 40, 0.5) 0%, rgba(9, 14, 40, 0.12) 30%,
      rgba(9, 14, 40, 0.45) 62%, rgba(9, 14, 40, 0.86) 100%),
    radial-gradient(120% 80% at 50% 78%, rgba(9, 14, 40, 0.5) 0%, rgba(9, 14, 40, 0) 70%);
}

/* Confetti — the decorative sticker palette */
.finale__confetti {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 1;
}

.finale__confetti i {
  position: absolute;
  top: -12%;
  border-radius: 2px;
  animation-name: confettiFall;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
}

@keyframes confettiFall {
  0%   { transform: translate3d(0, -12vh, 0) rotate(0deg); opacity: 0; }
  8%   { opacity: 1; }
  100% { transform: translate3d(46px, 112vh, 0) rotate(720deg); opacity: 0; }
}

/* The message is anchored to the bottom of the photo itself, whatever the
   screen shape — the stage box is sized in JS to match the photo exactly. */
.finale__stage {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
  height: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 2;
  pointer-events: none;
}

.finale__content {
  width: 100%;
  padding: 0 5% 6%;
  text-align: center;
  pointer-events: auto;
}

.finale__msg {
  margin: 0;
  font-size: clamp(28px, min(7vw, 9vh), 76px);
  font-weight: 700;
  line-height: 1.12;
  letter-spacing: -2px;
  color: #fff;
  text-shadow: 0 2px 26px rgba(0, 0, 0, 0.55);
  opacity: 0;
  visibility: hidden;
  white-space: nowrap;   /* never break a word across lines */
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
}

/* Lets the greeting glide up to make room for the second line */
.finale__msg.is-shifting {
  transition: transform 620ms cubic-bezier(0.16, 0.9, 0.24, 1);
}

.finale__msg + .finale__msg { margin-top: 0.1em; }

.finale__msg.is-popping {
  visibility: visible;
  animation: msgSlideUp 780ms cubic-bezier(0.16, 0.9, 0.24, 1) forwards;
}

.finale__msg.is-leaving {
  visibility: visible;
  animation: msgSlideUpOut 620ms cubic-bezier(0.5, 0, 0.75, 0.2) forwards;
}

.finale__msg.is-hidden { display: none; }

/* Safety net — guarantees the finale is readable even when animations are
   frozen, throttled or disabled (reduced motion, background tabs, old engines). */
.finale__msg.is-settled { opacity: 1 !important; visibility: visible !important; filter: none !important; }
.finale__msg.is-settled .ch { opacity: 1 !important; transform: none !important; }
.finale.is-settled { opacity: 1 !important; visibility: visible !important; }
.finale.is-settled .finale__media,
.finale.is-settled .finale__backdrop { opacity: 1 !important; }

@keyframes msgSlideUp {
  0%   { opacity: 0; transform: translateY(72px); filter: blur(8px); }
  55%  { opacity: 1; transform: translateY(-8px); filter: blur(0); }
  100% { opacity: 1; transform: translateY(0); filter: blur(0); }
}

/* The first line leaves by sliding up and away, not by being replaced in place */
@keyframes msgSlideUpOut {
  0%   { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); }
  100% { opacity: 0; transform: translateY(-96px) scale(0.94); filter: blur(10px); }
}

/* Letter-by-letter slide up */
.finale__msg .ch { display: inline-block; }

.finale__msg.is-popping .ch {
  animation: chSlide 720ms cubic-bezier(0.16, 0.9, 0.24, 1) both;
  animation-delay: calc(var(--i) * 24ms);
}

@keyframes chSlide {
  0%   { opacity: 0; transform: translateY(0.62em); }
  60%  { opacity: 1; transform: translateY(-0.05em); }
  100% { opacity: 1; transform: translateY(0); }
}

/* White flash for the transition */
.flash {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: #fff;
  opacity: 0;
  pointer-events: none;
}

.flash.is-on { animation: flashOut 900ms ease-out forwards; }

@keyframes flashOut {
  0%   { opacity: 0; }
  6%   { opacity: 1; }
  100% { opacity: 0; }
}

/* Escape hatch back to the game — esc, or a tap once the second line is up */
.finale__hint {
  margin: 1.1em 0 0;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.43;
  letter-spacing: 0.125px;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.45);
  opacity: 0;
  visibility: hidden;
}

.finale__hint.is-visible {
  visibility: visible;
  animation: hintIn 700ms ease forwards;
}

@keyframes hintIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─── Footer ───────────────────────────────────────────── */

.page__footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sm);
}

.hint {
  margin: 0;
  font-size: 14px;
  line-height: 1.43;
  color: var(--ink-faint);
  text-align: center;
}

/* Directional pad — shown on touch devices */
.dpad {
  display: none;
  grid-template-areas: ". up ." "left down right";
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(2, 52px);
  gap: var(--xs);
}

.dpad__btn {
  border: 1px solid var(--hairline);
  background: var(--surface);
  color: var(--ink-secondary);
  border-radius: var(--rounded-md);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow-1);
  transition: background-color 120ms ease, transform 90ms ease;
}

.dpad__btn:active { background: var(--canvas-soft); transform: scale(0.94); }
.dpad__btn--up    { grid-area: up; }
.dpad__btn--left  { grid-area: left; }
.dpad__btn--down  { grid-area: down; }
.dpad__btn--right { grid-area: right; }

@media (pointer: coarse) {
  .dpad { display: grid; }
}

@media (max-width: 600px) {
  body { padding: var(--lg) var(--sm); }
  .page { gap: var(--md); }
  .board-card { padding: var(--sm); border-radius: var(--rounded-lg); }
  .dpad { display: grid; }
}

@media (prefers-reduced-motion: reduce) {
  .title__score { transition: none; }
  .finale__msg.is-popping,
  .finale__msg.is-popping .ch {
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
  }
  .finale__backdrop { animation: none !important; transform: scale(1.08); }
  .finale__confetti { display: none; }
  .flash.is-on { animation: none !important; }
}
