/* WP-PRACTICE-01: local practice demo styles. Light luxury surface (pearl, blush, peach, cream,
   soft gold, lavender) with raised, glossy game tiles (owner direction for this demo).
   Base colour values are the approved tokens in docs/DESIGN-SYSTEM.md; the --wp-* tints and
   shades are demo-local derivations of them. The primary gradient follows the approved
   reference image's violet-to-magenta "Play Now" button. No external fonts or images. All
   motion is cosmetic and disabled under prefers-reduced-motion. */
:root {
  --ac-bg-light: #FAFAFC;
  --ac-bg-dark: #0B1220;
  --ac-primary: #6C3BFF;
  --ac-accent: #EC4899;
  --ac-success: #14B8A6;
  --ac-premium: #D4AF37;
  --ac-text-dark: #1F2937;
  --ac-text-muted-light: #475569;
  --ac-border: #E5E7EB;
  --ac-stroke-signature: 1.5px;
  --ac-motion-fast: 160ms;
  --ac-motion-normal: 220ms;

  /* Demo-local palette */
  --wp-ink: #2A1B3D;            /* deep plum text */
  --wp-ink-muted: #5B4B6B;
  --wp-blush: #FDF2F8;
  --wp-blush-200: #FBCFE8;
  --wp-pink-deep: #DB2777;
  --wp-pink-ink: #BE185D;
  --wp-peach: #FFE4D6;
  --wp-cream: #FFF8EC;
  --wp-lavender: #EDE9FE;
  --wp-gold-soft: #FDF3D0;
  --wp-line: #E7D8EC;           /* premium tile/key outline */
  --wp-line-strong: #C9B2D6;
  --wp-tile-edge: #9C86AE;       /* empty tile outline: >= 3:1 vs tile face and board tray */
  --wp-tile-edge-filled: #7A6690;
  --wp-lip: #E3D0EA;            /* raised base under light tiles/keys */
  --wp-lip-strong: #CDB5DB;
  --wp-primary-gradient: linear-gradient(135deg, #6C3BFF 0%, #A133E8 48%, #DB2777 100%);

  /* Tile state faces: top / bottom / base lip / text */
  --wp-correct-top: #6EF0DC;
  --wp-correct-bottom: #14B8A6;
  --wp-correct-lip: #0B8C80;
  --wp-present-top: #FFE89A;
  --wp-present-bottom: #E8B530;
  --wp-present-lip: #B98714;
  --wp-absent-top: #8A9BB6;
  --wp-absent-bottom: #5E6E89;
  --wp-absent-lip: #435069;

  --wp-font: "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, "SF Pro Display", Roboto, "Noto Sans", Arial, sans-serif;
  --wp-ring: 0 0 0 2px #FFFFFF, 0 0 0 5px var(--wp-pink-deep), 0 0 0 10px rgba(236, 72, 153, 0.16);
  color-scheme: light;
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  display: flow-root;
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--wp-ink);
  font-family: var(--wp-font);
  line-height: 1.4;
  background:
    radial-gradient(1100px 620px at 0% 0%, #FFE6F1 0%, rgba(255, 230, 241, 0) 60%),
    radial-gradient(900px 600px at 100% 0%, #F1EBFF 0%, rgba(241, 235, 255, 0) 58%),
    radial-gradient(1000px 640px at 100% 100%, #FFF0CC 0%, rgba(255, 240, 204, 0) 60%),
    radial-gradient(900px 600px at 0% 100%, #FFE3D3 0%, rgba(255, 227, 211, 0) 58%),
    linear-gradient(160deg, #FFF9F6 0%, #FDF4F9 45%, #FBF6FF 70%, #FFFAF0 100%);
  background-attachment: fixed;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Ambient decoration (static, behind content) ---------- */
.ambient {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(40px);
}

.orb-peach {
  top: -120px;
  left: -100px;
  width: 420px;
  height: 420px;
  background: radial-gradient(circle, rgba(255, 190, 160, 0.55), rgba(255, 190, 160, 0) 70%);
}

.orb-pink {
  top: 30%;
  left: -160px;
  width: 380px;
  height: 380px;
  background: radial-gradient(circle, rgba(244, 114, 182, 0.30), rgba(244, 114, 182, 0) 70%);
}

.orb-lavender {
  top: -80px;
  right: -120px;
  width: 460px;
  height: 460px;
  background: radial-gradient(circle, rgba(196, 181, 253, 0.45), rgba(196, 181, 253, 0) 70%);
}

.orb-gold {
  right: -140px;
  bottom: -140px;
  width: 520px;
  height: 520px;
  background: radial-gradient(circle, rgba(250, 204, 21, 0.30), rgba(250, 204, 21, 0) 70%);
}

.dots {
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(190, 24, 93, 0.10) 1.2px, transparent 1.3px);
  background-size: 26px 26px;
  -webkit-mask-image: radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 30%, #000 85%);
  mask-image: radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 30%, #000 85%);
}

.deco-tile {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  border: 1.5px solid rgba(255, 255, 255, 0.9);
  border-radius: 18px;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.85), rgba(255, 255, 255, 0.35));
  color: rgba(190, 24, 93, 0.28);
  font-family: var(--wp-font);
  font-size: 30px;
  font-weight: 800;
  box-shadow: 0 6px 0 rgba(227, 208, 234, 0.6), 0 24px 40px -20px rgba(190, 24, 93, 0.35);
}

.deco-1 { top: 11%; left: 9%; rotate: -14deg; }
.deco-2 { top: 58%; left: 5%; width: 52px; height: 52px; font-size: 24px; rotate: 10deg; color: rgba(20, 184, 166, 0.32); }
.deco-3 { top: 16%; right: 8%; width: 56px; height: 56px; font-size: 26px; rotate: 12deg; color: rgba(185, 135, 20, 0.34); }
.deco-4 { bottom: 12%; right: 10%; rotate: -8deg; color: rgba(108, 59, 255, 0.24); }

.sparkle {
  position: absolute;
  width: 14px;
  height: 14px;
  background: linear-gradient(135deg, #FFD36E, #F59E0B);
  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
  opacity: 0.7;
}

.sparkle-1 { top: 26%; left: 17%; }
.sparkle-2 { top: 9%; right: 21%; width: 10px; height: 10px; background: linear-gradient(135deg, #F9A8D4, #EC4899); }
.sparkle-3 { bottom: 24%; right: 19%; width: 18px; height: 18px; }

@media (max-width: 720px) {
  .deco-tile,
  .sparkle {
    display: none;
  }
}

/* ---------- Game card ---------- */
.game {
  position: relative;
  z-index: 1;
  width: min(100%, 540px);
  height: 100vh;
  height: 100dvh;
  min-height: 560px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

@media (min-width: 560px) {
  .game {
    height: calc(100dvh - 28px);
    max-height: 920px;
    margin: 14px auto;
    padding: 20px 26px 18px;
    border: var(--ac-stroke-signature) solid rgba(255, 255, 255, 0.95);
    border-radius: 34px;
    background:
      linear-gradient(180deg, rgba(255, 255, 255, 0.94) 0%, rgba(255, 251, 253, 0.86) 100%);
    box-shadow:
      0 0 0 1px rgba(219, 39, 119, 0.10),
      inset 0 2px 0 rgba(255, 255, 255, 1),
      0 50px 90px -46px rgba(190, 24, 93, 0.45),
      0 22px 44px -28px rgba(42, 27, 61, 0.30);
  }

  /* Gradient accent strip along the top edge of the card */
  .game::before {
    content: "";
    position: absolute;
    top: -1px;
    left: 50%;
    width: 38%;
    height: 4px;
    border-radius: 0 0 6px 6px;
    background: linear-gradient(90deg, #F9A8D4, #EC4899 35%, #FB923C 65%, #F2C94C);
    transform: translateX(-50%);
  }
}

.game-header {
  text-align: center;
}

.eyebrow {
  margin: 0 0 4px;
  background: linear-gradient(90deg, var(--wp-pink-ink), #C2410C);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

h1 {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-size: clamp(1.6rem, 6vw, 2.05rem);
  font-weight: 800;
  letter-spacing: -0.025em;
  line-height: 1.1;
  color: var(--wp-ink);
}

.logo-tiles {
  display: inline-flex;
  gap: 3px;
}

.logo-tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.15em;
  height: 1.15em;
  border-radius: 0.28em;
  font-size: 0.68em;
  font-weight: 900;
  letter-spacing: 0;
  color: var(--wp-ink);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7), 0 3px 0 var(--lip), 0 6px 10px -6px rgba(42, 27, 61, 0.5);
}

.logo-tile-1 {
  --lip: var(--wp-correct-lip);
  background: linear-gradient(180deg, var(--wp-correct-top), var(--wp-correct-bottom));
  transform: rotate(-6deg);
}

.logo-tile-2 {
  --lip: var(--wp-present-lip);
  background: linear-gradient(180deg, var(--wp-present-top), var(--wp-present-bottom));
  transform: rotate(5deg) translateY(1px);
}

.header-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px 10px;
  margin: 8px 0 0;
}

.mode-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 11px;
  border: var(--ac-stroke-signature) solid var(--wp-blush-200);
  border-radius: 999px;
  background: linear-gradient(180deg, #FFFFFF, var(--wp-blush));
  color: var(--wp-pink-ink);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  box-shadow: 0 2px 6px -3px rgba(190, 24, 93, 0.35);
}

.demo-note {
  color: var(--wp-ink-muted);
  font-size: 0.8125rem;
}

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.length-picker {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin: 0;
  padding: 4px;
  border: var(--ac-stroke-signature) solid var(--wp-line);
  border-radius: 16px;
  background: linear-gradient(180deg, #FFFFFF, #FBF7FC);
  box-shadow: inset 0 1px 0 #FFFFFF, 0 3px 0 var(--wp-lip), 0 10px 18px -12px rgba(42, 27, 61, 0.35);
}

.length-legend {
  float: left;
  padding: 0 8px 0 10px;
  color: var(--wp-ink-muted);
  font-size: 0.8125rem;
  font-weight: 700;
}

.segment {
  position: relative;
  display: inline-flex;
}

.segment input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}

.segment span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  border-radius: 12px;
  color: var(--wp-ink);
  font-weight: 800;
  transition: background-color var(--ac-motion-fast) ease, color var(--ac-motion-fast) ease, box-shadow var(--ac-motion-fast) ease;
}

.segment input:checked + span {
  background: var(--wp-primary-gradient);
  color: #FFFFFF;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 2px 0 #5A22C9, 0 6px 12px -6px rgba(108, 59, 255, 0.7);
}

.segment input:focus-visible + span {
  box-shadow: var(--wp-ring);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 18px;
  border-radius: 14px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  transition: transform var(--ac-motion-fast) ease, box-shadow var(--ac-motion-fast) ease, filter var(--ac-motion-fast) ease;
}

.btn-icon {
  width: 18px;
  height: 18px;
}

.btn-secondary {
  border: var(--ac-stroke-signature) solid var(--wp-line);
  background: linear-gradient(180deg, #FFFFFF, #FBF7FC);
  color: var(--wp-ink);
  box-shadow: inset 0 1px 0 #FFFFFF, 0 3px 0 var(--wp-lip), 0 10px 18px -12px rgba(42, 27, 61, 0.35);
}

.btn-secondary .btn-icon {
  color: var(--wp-pink-deep);
}

.btn-primary {
  border: var(--ac-stroke-signature) solid rgba(255, 255, 255, 0.35);
  background: var(--wp-primary-gradient);
  color: #FFFFFF;
  text-shadow: 0 1px 1px rgba(42, 27, 61, 0.35);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 3px 0 #5A22C9, 0 12px 20px -12px rgba(108, 59, 255, 0.75);
}

.btn:active:not(:disabled) {
  transform: translateY(2px);
}

.btn-secondary:active:not(:disabled) {
  box-shadow: inset 0 1px 0 #FFFFFF, 0 1px 0 var(--wp-lip);
}

.btn-primary:active:not(:disabled) {
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 1px 0 #5A22C9;
}

.btn:disabled {
  border-color: var(--ac-border);
  background: #F1F1F4;
  color: #8A8F98;
  text-shadow: none;
  box-shadow: none;
  cursor: not-allowed;
}

@media (hover: hover) {
  .btn-secondary:hover:not(:disabled) {
    border-color: var(--wp-line-strong);
    transform: translateY(-1px);
  }

  .btn-primary:hover:not(:disabled) {
    filter: saturate(1.1) brightness(1.04);
    transform: translateY(-1px);
  }
}

:focus-visible {
  outline: none;
  box-shadow: var(--wp-ring);
}

/* ---------- Progress ---------- */
.progress {
  display: flex;
  align-items: center;
  gap: 10px;
}

.tries {
  margin: 0;
  color: var(--wp-ink-muted);
  font-size: 0.875rem;
  font-weight: 700;
}

.pips {
  display: inline-flex;
  gap: 5px;
}

.pip {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #FFFFFF;
  box-shadow: inset 0 0 0 1.5px var(--wp-blush-200);
}

.pip.used {
  background: linear-gradient(135deg, #EC4899, #FB923C);
  box-shadow: none;
  transform: scale(0.9);
}

/* "?" toggle for the colour key; only shown where the legend is hidden (see below). The
   ::after extends the 26px visual to a 44px touch target. */
.help-btn {
  position: relative;
  display: none;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: var(--ac-stroke-signature) solid var(--wp-line);
  border-radius: 50%;
  background: linear-gradient(180deg, #FFFFFF, #FBF7FC);
  color: var(--wp-pink-ink);
  box-shadow: inset 0 1px 0 #FFFFFF, 0 2px 0 var(--wp-lip);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
}

.help-btn::after {
  content: "";
  position: absolute;
  inset: -9px;
}

.help-btn[aria-expanded="true"] {
  border-color: var(--wp-pink-deep);
  background: var(--wp-blush);
}

/* ---------- Board ---------- */
.board-stage {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  container-type: size;
}

.board {
  --cols: 5;
  --gap: clamp(6px, 1.7vw, 9px);
  --pad: clamp(8px, 2.4vw, 14px);
  --lip: 5px;
  /* Sized from the space the board stage actually has (a size container), so the whole game
     fits one screen without scrolling. */
  --tile: max(26px, min(66px,
    calc((100cqw - 2 * var(--pad) - (var(--cols) - 1) * var(--gap)) / var(--cols)),
    calc((100cqh - 2 * var(--pad) - var(--lip) - 5 * var(--gap)) / 6)));
  display: grid;
  gap: var(--gap);
  padding: var(--pad) var(--pad) calc(var(--pad) + var(--lip));
  border: var(--ac-stroke-signature) solid rgba(255, 255, 255, 0.9);
  border-radius: 26px;
  background: linear-gradient(180deg, rgba(251, 244, 251, 0.95) 0%, rgba(253, 246, 240, 0.95) 100%);
  box-shadow:
    inset 0 2px 6px rgba(190, 24, 93, 0.08),
    inset 0 -1px 0 rgba(255, 255, 255, 0.9),
    0 0 0 1px rgba(219, 39, 119, 0.08);
  perspective: 900px;
}

.row {
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--tile));
  gap: var(--gap);
}

/* Raised tile: gradient face, glossy top sheen (::before), coloured base lip and soft drop. */
.tile {
  --face-top: #FFFFFF;
  --face-bottom: #FBF6FC;
  --edge: var(--wp-tile-edge);
  --lip-colour: var(--wp-lip);
  --text: var(--wp-ink);
  --sheen: 0.55;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--tile);
  height: var(--tile);
  border: 2px solid var(--edge);
  border-radius: calc(var(--tile) * 0.24);
  background: linear-gradient(180deg, var(--face-top) 0%, var(--face-bottom) 100%);
  color: var(--text);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.9),
    inset 0 -3px 6px rgba(42, 27, 61, 0.04),
    0 var(--lip) 0 var(--lip-colour),
    0 calc(var(--lip) + 8px) 14px -8px rgba(42, 27, 61, 0.28);
  font-size: calc(var(--tile) * 0.5);
  font-weight: 900;
  line-height: 1;
  text-transform: uppercase;
  user-select: none;
  transform-style: preserve-3d;
  transition: border-color var(--ac-motion-fast) ease, box-shadow var(--ac-motion-fast) ease;
}

.tile::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 8%;
  right: 8%;
  height: 42%;
  border-radius: calc(var(--tile) * 0.18) calc(var(--tile) * 0.18) 40% 40% / calc(var(--tile) * 0.18) calc(var(--tile) * 0.18) 22% 22%;
  background: linear-gradient(180deg, rgba(255, 255, 255, var(--sheen)) 0%, rgba(255, 255, 255, 0) 100%);
  pointer-events: none;
}

.tile .letter {
  position: relative;
}

.tile.filled {
  --edge: var(--wp-tile-edge-filled);
  --lip-colour: var(--wp-lip-strong);
}

.tile.filled .letter {
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.9);
}

.row.current .tile.next {
  --edge: var(--wp-pink-deep);
  --lip-colour: #F5B8D3;
  box-shadow:
    0 0 0 4px rgba(236, 72, 153, 0.16),
    inset 0 2px 0 rgba(255, 255, 255, 0.9),
    0 var(--lip) 0 var(--lip-colour),
    0 calc(var(--lip) + 8px) 14px -8px rgba(190, 24, 93, 0.35);
}

.tile.state-correct,
.tile.state-present,
.tile.state-absent {
  --edge: rgba(255, 255, 255, 0.55);
  --sheen: 0.6;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.55),
    inset 0 -4px 8px rgba(42, 27, 61, 0.12),
    0 var(--lip) 0 var(--lip-colour),
    0 calc(var(--lip) + 10px) 16px -8px rgba(42, 27, 61, 0.42);
}

.state-correct {
  --face-top: var(--wp-correct-top);
  --face-bottom: var(--wp-correct-bottom);
  --lip-colour: var(--wp-correct-lip);
  --text: var(--wp-ink);
  --state-top: var(--wp-correct-top);
  --state-bottom: var(--wp-correct-bottom);
  --state-text: var(--wp-ink);
}

.state-present {
  --face-top: var(--wp-present-top);
  --face-bottom: var(--wp-present-bottom);
  --lip-colour: var(--wp-present-lip);
  --text: var(--wp-ink);
  --state-top: var(--wp-present-top);
  --state-bottom: var(--wp-present-bottom);
  --state-text: var(--wp-ink);
}

.state-absent {
  --face-top: var(--wp-absent-top);
  --face-bottom: var(--wp-absent-bottom);
  --lip-colour: var(--wp-absent-lip);
  --text: #FFFFFF;
  --sheen: 0.35;
  --state-top: var(--wp-absent-top);
  --state-bottom: var(--wp-absent-bottom);
  --state-text: #FFFFFF;
}

.tile.state-correct .letter,
.tile.state-present .letter {
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.55);
}

.tile.state-absent .letter {
  text-shadow: 0 1px 1px rgba(20, 16, 40, 0.45);
}

/* Non-colour status cue: a small badge sitting on the tile's top-right corner, clear of the letter. */
.tile .mark {
  position: absolute;
  top: -6px;
  right: -6px;
  z-index: 1;
  display: none;
  align-items: center;
  justify-content: center;
  width: max(15px, calc(var(--tile) * 0.3));
  height: max(15px, calc(var(--tile) * 0.3));
  border: 1.5px solid #FFFFFF;
  border-radius: 50%;
  background: var(--wp-ink);
  color: #FFFFFF;
  font-size: max(9px, calc(var(--tile) * 0.17));
  font-weight: 900;
  line-height: 1;
  box-shadow: 0 2px 4px rgba(42, 27, 61, 0.35);
}

.tile.state-correct .mark,
.tile.state-present .mark,
.tile.state-absent .mark {
  display: inline-flex;
}

/* Letter entry pop */
.tile.pop {
  animation: tile-pop 150ms ease-out;
}

@keyframes tile-pop {
  0% { transform: scale(0.84); }
  60% { transform: scale(1.09); }
  100% { transform: scale(1); }
}

/* Sequential flip: the neutral face shows until the tile's turn, then the colour appears
   at the half-way point. */
.tile.reveal {
  animation: tile-flip 520ms ease-in-out both;
  animation-delay: calc(var(--i, 0) * 240ms);
}

.tile.reveal .mark {
  animation: mark-in 520ms ease-in-out both;
  animation-delay: calc(var(--i, 0) * 240ms);
}

@keyframes tile-flip {
  0% {
    transform: rotateX(0deg);
    border-color: var(--wp-tile-edge-filled);
    background: linear-gradient(180deg, #FFFFFF 0%, #FBF6FC 100%);
    color: var(--wp-ink);
    box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.9), 0 var(--lip) 0 var(--wp-lip-strong), 0 calc(var(--lip) + 8px) 14px -8px rgba(42, 27, 61, 0.28);
  }
  49.9% {
    transform: rotateX(90deg);
    border-color: var(--wp-tile-edge-filled);
    background: linear-gradient(180deg, #FFFFFF 0%, #FBF6FC 100%);
    color: var(--wp-ink);
    box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.9), 0 var(--lip) 0 var(--wp-lip-strong), 0 calc(var(--lip) + 8px) 14px -8px rgba(42, 27, 61, 0.28);
  }
  50% {
    transform: rotateX(90deg);
    border-color: rgba(255, 255, 255, 0.55);
    background: linear-gradient(180deg, var(--state-top) 0%, var(--state-bottom) 100%);
    color: var(--state-text);
  }
  100% {
    transform: rotateX(0deg);
    border-color: rgba(255, 255, 255, 0.55);
    background: linear-gradient(180deg, var(--state-top) 0%, var(--state-bottom) 100%);
    color: var(--state-text);
  }
}

@keyframes mark-in {
  0%, 50% { opacity: 0; transform: scale(0.4); }
  80% { opacity: 1; transform: scale(1.15); }
  100% { opacity: 1; transform: scale(1); }
}

/* Invalid guess */
.row.shake {
  animation: row-shake 420ms cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

@keyframes row-shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-7px); }
  40%, 60% { transform: translateX(7px); }
}

/* Solved row bounce */
.tile.win {
  animation: tile-win 600ms ease-out both;
  animation-delay: calc(var(--i, 0) * 90ms);
}

@keyframes tile-win {
  0%, 100% { transform: translateY(0) scale(1); }
  35% { transform: translateY(-16px) scale(1.04); }
  60% { transform: translateY(2px) scale(0.98); }
  80% { transform: translateY(-4px) scale(1); }
}

/* ---------- Toast ---------- */
/* Sits over the progress line so it never covers the row being typed. */
.toast {
  position: absolute;
  top: -34px;
  left: 50%;
  z-index: 3;
  padding: 9px 16px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 14px;
  background: linear-gradient(180deg, #3B2A4F, var(--wp-ink));
  color: #FFFFFF;
  font-size: 0.9375rem;
  font-weight: 800;
  white-space: nowrap;
  box-shadow: 0 14px 28px -12px rgba(42, 27, 61, 0.7);
  opacity: 0;
  transform: translate(-50%, -6px);
  transition: opacity var(--ac-motion-normal) ease, transform var(--ac-motion-normal) ease;
  pointer-events: none;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- Legend / result ---------- */
.below-board {
  position: relative;
  display: flex;
  justify-content: center;
  width: 100%;
  min-height: 56px;
  align-items: center;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 16px;
  color: var(--wp-ink-muted);
  font-size: 0.8125rem;
  font-weight: 700;
}

.legend[hidden],
.result[hidden] {
  display: none;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 7px;
  background: linear-gradient(180deg, var(--state-top) 0%, var(--state-bottom) 100%);
  color: var(--state-text);
  font-size: 0.75rem;
  font-weight: 900;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5), 0 2px 0 var(--lip-colour);
}

.result {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  width: min(100%, 440px);
  padding: 10px 10px 10px 18px;
  border: var(--ac-stroke-signature) solid var(--wp-line);
  border-radius: 18px;
  background: linear-gradient(180deg, #FFFFFF, #FBF7FC);
  box-shadow: inset 0 1px 0 #FFFFFF, 0 3px 0 var(--wp-lip), 0 14px 26px -16px rgba(42, 27, 61, 0.4);
  animation: result-in 340ms ease-out both;
}

.result.is-win {
  border-color: #F1D27A;
  background: linear-gradient(180deg, #FFFDF6 0%, var(--wp-gold-soft) 100%);
  box-shadow: inset 0 1px 0 #FFFFFF, 0 3px 0 #EBCB6A, 0 14px 26px -16px rgba(185, 135, 20, 0.55);
}

.result-title {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 900;
  letter-spacing: -0.01em;
}

.result-word {
  margin: 2px 0 0;
  color: var(--wp-ink-muted);
  font-size: 0.875rem;
}

.result-word strong {
  color: var(--wp-pink-ink);
  letter-spacing: 0.1em;
}

@keyframes result-in {
  from { opacity: 0; transform: translateY(8px) scale(0.97); }
  to { opacity: 1; transform: none; }
}

/* ---------- Keyboard ---------- */
.keyboard {
  display: flex;
  flex-direction: column;
  gap: 9px;
  width: 100%;
  margin-top: auto;
  padding: 10px 6px 8px;
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0) 0%, rgba(250, 241, 250, 0.7) 100%);
  transition: opacity var(--ac-motion-normal) ease;
}

.keyboard.is-done {
  opacity: 0.55;
}

.key-row {
  display: flex;
  justify-content: center;
  gap: clamp(4px, 1.3vw, 6px);
}

.key {
  --key-top: #FFFFFF;
  --key-bottom: #F7F0FA;
  --key-edge: var(--wp-line);
  --key-lip: var(--wp-lip);
  --key-text: var(--wp-ink);
  position: relative;
  flex: 1 1 0;
  max-width: 46px;
  min-width: 0;
  height: clamp(46px, 6.6dvh, 58px);
  padding: 0;
  border: var(--ac-stroke-signature) solid var(--key-edge);
  border-radius: 12px;
  background: linear-gradient(180deg, var(--key-top) 0%, var(--key-bottom) 100%);
  color: var(--key-text);
  box-shadow:
    inset 0 1.5px 0 rgba(255, 255, 255, 0.95),
    0 3px 0 var(--key-lip),
    0 8px 12px -8px rgba(42, 27, 61, 0.35);
  font: inherit;
  font-size: clamp(0.95rem, 3.6vw, 1.12rem);
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 90ms ease, box-shadow 90ms ease, filter var(--ac-motion-fast) ease;
}

.key:active,
.key.pressed {
  transform: translateY(3px);
  box-shadow: inset 0 1.5px 0 rgba(255, 255, 255, 0.95), 0 0 0 var(--key-lip), 0 2px 4px -2px rgba(42, 27, 61, 0.35);
}

/* Invisible tap extension: each key also owns half of the gap around it, so taps that land
   between keys still register on the nearest key. */
.key::after {
  content: "";
  position: absolute;
  inset: -4px -3px;
}

.keyboard {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.key-action {
  flex: 1.6 1 0;
  max-width: 74px;
}

.key-enter {
  --key-edge: rgba(255, 255, 255, 0.35);
  --key-lip: #5A22C9;
  --key-text: #FFFFFF;
  background: var(--wp-primary-gradient);
  text-shadow: 0 1px 1px rgba(42, 27, 61, 0.35);
  box-shadow: inset 0 1.5px 0 rgba(255, 255, 255, 0.35), 0 3px 0 var(--key-lip), 0 10px 16px -10px rgba(108, 59, 255, 0.8);
  font-size: clamp(0.8rem, 3vw, 0.95rem);
}

.key-back {
  --key-top: #FFF6F0;
  --key-bottom: #FFE4D6;
  --key-edge: #F8C9B0;
  --key-lip: #F0B596;
  --key-text: #C2410C;
}

.key-back svg {
  width: 24px;
  height: 24px;
}

.key.state-correct,
.key.state-present,
.key.state-absent {
  --key-top: var(--face-top);
  --key-bottom: var(--face-bottom);
  --key-edge: rgba(255, 255, 255, 0.5);
  --key-lip: var(--lip-colour);
  --key-text: var(--text);
}

.key.state-correct,
.key.state-present {
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
}

/* Darker slate on keys so 17px letters keep 4.5:1 contrast. */
.key.state-absent {
  --key-top: #66758B;
  --key-bottom: #556379;
  text-shadow: 0 1px 1px rgba(20, 16, 40, 0.4);
}

@media (hover: hover) {
  .key:hover {
    filter: brightness(1.03);
    border-color: var(--wp-line-strong);
  }

  .key-enter:hover,
  .key.state-correct:hover,
  .key.state-present:hover,
  .key.state-absent:hover {
    border-color: rgba(255, 255, 255, 0.6);
  }
}

@media (min-width: 560px) {
  .key {
    max-width: 48px;
  }

  .key-action {
    max-width: 80px;
  }
}

/* ---------- Celebration ---------- */
.confetti {
  position: fixed;
  inset: 0;
  z-index: 10;
  overflow: hidden;
  pointer-events: none;
}

.piece {
  position: absolute;
  top: -16px;
  left: var(--x);
  width: 9px;
  height: 14px;
  border-radius: 2px;
  background: var(--colour);
  animation: confetti-fall 1600ms cubic-bezier(0.22, 0.7, 0.4, 1) var(--delay) both;
}

.piece:nth-child(3n) {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

@keyframes confetti-fall {
  0% { opacity: 1; transform: translate(0, 0) rotate(0deg); }
  100% { opacity: 0; transform: translate(var(--drift), 92vh) rotate(var(--spin)); }
}

/* =====================================================================================
   MOTION SYSTEM (reference direction for AmzingCoupon games)
   - Success speaks in springs: hop up, pop, ring burst, cascade, confetti.
   - Failure speaks in denial: horizontal shake, recoil down, muted red flash. Never a bounce.
   - Neutral info (misplaced/absent) is calm: a curious wiggle or a soft downward settle.
   - Everything animates transform/opacity (or the individual translate/scale/rotate
     properties so effects can layer on top of each other) and is off under reduced motion.
   - Motion is cosmetic: the server response is applied first; animation never delays scoring.
   ===================================================================================== */
:root {
  --m-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --m-out: cubic-bezier(0.22, 1, 0.36, 1);
  --m-in: cubic-bezier(0.55, 0, 0.75, 0.2);
  --px: 0;
  --py: 0;
}

/* ---- Page load: card rises in, header and controls follow in a short stagger ---- */
.game {
  animation: card-in 720ms var(--m-out) both;
}

.game-header > *,
.toolbar,
.progress {
  animation: rise-in 560ms var(--m-out) both;
}

.eyebrow { animation-delay: 120ms; }
h1 { animation-delay: 180ms; }
.header-meta { animation-delay: 240ms; }
.toolbar { animation-delay: 300ms; }
.progress { animation-delay: 360ms; }
.key-row { animation: rise-in 520ms var(--m-out) both; }
.key-row:nth-child(1) { animation-delay: 420ms; }
.key-row:nth-child(2) { animation-delay: 480ms; }
.key-row:nth-child(3) { animation-delay: 540ms; }

.mode-badge {
  background-image: linear-gradient(105deg, rgba(255, 255, 255, 0) 35%, rgba(255, 255, 255, 0.95) 50%, rgba(255, 255, 255, 0) 65%), linear-gradient(180deg, #FFFFFF, var(--wp-blush));
  background-size: 250% 100%, 100% 100%;
  background-position: 120% 0, 0 0;
  animation: badge-shine 1100ms ease-out 900ms both;
}

.logo-tile {
  animation: logo-pop 620ms var(--m-spring) both, logo-idle 5.5s ease-in-out 2s infinite;
}

.logo-tile-2 {
  animation-delay: 300ms, 2.25s;
}

.logo-tile-1 {
  animation-delay: 220ms, 2s;
}

@keyframes card-in {
  from { opacity: 0; translate: 0 26px; scale: 0.97; }
  to { opacity: 1; translate: 0 0; scale: 1; }
}

@keyframes rise-in {
  from { opacity: 0; translate: 0 12px; }
  to { opacity: 1; translate: 0 0; }
}

@keyframes badge-shine {
  to { background-position: -40% 0, 0 0; }
}

@keyframes logo-pop {
  0% { opacity: 0; scale: 0.3; }
  70% { opacity: 1; scale: 1.18; }
  100% { opacity: 1; scale: 1; }
}

@keyframes logo-idle {
  0%, 82%, 100% { translate: 0 0; }
  88% { translate: 0 -4px; }
  94% { translate: 0 1px; }
}

/* ---- Living background: breathing glows, floating letters, twinkling sparkles, parallax ---- */
.orb {
  will-change: transform;
  animation: orb-breathe 11s ease-in-out infinite alternate;
}

.orb-pink { animation-duration: 13s; animation-delay: -4s; }
.orb-lavender { animation-duration: 15s; animation-delay: -7s; }
.orb-gold { animation-duration: 12s; animation-delay: -2s; }

@keyframes orb-breathe {
  from { scale: 1; opacity: 0.85; }
  to { scale: 1.18; opacity: 1; }
}

.deco-tile {
  --depth: 18px;
  translate: calc(var(--px) * var(--depth)) calc(var(--py) * var(--depth));
  transition: translate 600ms var(--m-out);
  animation: deco-float 7s ease-in-out infinite alternate;
}

.deco-2 { --depth: 28px; animation-duration: 8.5s; animation-delay: -3s; }
.deco-3 { --depth: 12px; animation-duration: 6.5s; animation-delay: -1.5s; }
.deco-4 { --depth: 24px; animation-duration: 9s; animation-delay: -5s; }

@keyframes deco-float {
  from { transform: translateY(0) rotate(0deg); }
  to { transform: translateY(-16px) rotate(4deg); }
}

.sparkle {
  animation: twinkle 2.8s ease-in-out infinite;
}

.sparkle-2 { animation-delay: -1s; animation-duration: 3.4s; }
.sparkle-3 { animation-delay: -2s; animation-duration: 2.4s; }

@keyframes twinkle {
  0%, 100% { opacity: 0.25; scale: 0.6; rotate: 0deg; }
  50% { opacity: 0.9; scale: 1.15; rotate: 45deg; }
}

.dots {
  inset: -26px;
  animation: dots-drift 24s linear infinite;
}

@keyframes dots-drift {
  to { translate: 26px 26px; }
}

/* ---- Board entrance and reset ---- */
.board.entering .tile {
  animation: tile-enter 480ms var(--m-spring) both;
  animation-delay: calc(var(--r, 0) * 55ms + var(--i, 0) * 28ms);
}

.board.leaving .tile {
  animation: tile-leave 200ms var(--m-in) both;
  animation-delay: calc(var(--i, 0) * 12ms);
}

@keyframes tile-enter {
  from { opacity: 0; scale: 0.45; translate: 0 12px; }
  to { opacity: 1; scale: 1; translate: 0 0; }
}

@keyframes tile-leave {
  to { opacity: 0; scale: 0.6; translate: 0 8px; }
}

/* ---- Typing: letter drop-in, backspace shrink, idle "ready" breathing on the next slot ---- */
.tile.pop .letter {
  animation: letter-drop 200ms var(--m-out);
}

.tile.unpop {
  animation: tile-unpop 180ms var(--m-out);
}

.row.current .tile.next {
  animation: next-breathe 1.6s ease-in-out infinite;
}

@keyframes letter-drop {
  from { opacity: 0.2; translate: 0 -10px; }
  to { opacity: 1; translate: 0 0; }
}

@keyframes tile-unpop {
  0% { scale: 0.86; }
  100% { scale: 1; }
}

@keyframes next-breathe {
  0%, 100% { scale: 1; }
  50% { scale: 1.045; }
}

/* ---- Reveal: flip, then a state-specific settle ---- */
/* Correct: springy hop + teal ring burst (reward language). */
.tile.reveal.state-correct {
  animation: tile-flip 520ms ease-in-out both, settle-correct 620ms var(--m-spring) both;
  animation-delay: calc(var(--i, 0) * 240ms), calc(var(--i, 0) * 240ms + 480ms);
}

/* Misplaced: a curious wiggle (calm, informative). */
.tile.reveal.state-present {
  animation: tile-flip 520ms ease-in-out both, settle-present 560ms ease-in-out both;
  animation-delay: calc(var(--i, 0) * 240ms), calc(var(--i, 0) * 240ms + 480ms);
}

/* Absent: a soft downward settle (muted, no bounce). */
.tile.reveal.state-absent {
  animation: tile-flip 520ms ease-in-out both, settle-absent 420ms var(--m-out) both;
  animation-delay: calc(var(--i, 0) * 240ms), calc(var(--i, 0) * 240ms + 480ms);
}

.tile.reveal.state-correct::after,
.tile.reveal.state-present::after {
  content: "";
  position: absolute;
  inset: -3px;
  border: 3px solid rgba(45, 212, 191, 0.9);
  border-radius: inherit;
  opacity: 0;
  pointer-events: none;
  animation: ring-burst 700ms var(--m-out) both;
  animation-delay: calc(var(--i, 0) * 240ms + 500ms);
}

.tile.reveal.state-present::after {
  border-color: rgba(232, 181, 48, 0.75);
  animation-name: ring-burst-soft;
}

@keyframes settle-correct {
  0% { translate: 0 0; scale: 1; }
  35% { translate: 0 -10px; scale: 1.12; }
  65% { translate: 0 2px; scale: 0.96; }
  100% { translate: 0 0; scale: 1; }
}

@keyframes settle-present {
  0%, 100% { rotate: 0deg; scale: 1; }
  25% { rotate: -6deg; scale: 1.06; }
  55% { rotate: 5deg; }
  80% { rotate: -2deg; }
}

@keyframes settle-absent {
  0% { translate: 0 0; scale: 1; }
  45% { translate: 0 4px; scale: 0.94; }
  100% { translate: 0 0; scale: 1; }
}

@keyframes ring-burst {
  0% { opacity: 0.95; scale: 0.92; }
  100% { opacity: 0; scale: 1.5; }
}

@keyframes ring-burst-soft {
  0% { opacity: 0.7; scale: 0.95; }
  100% { opacity: 0; scale: 1.28; }
}

/* ---- Rejection: shake + recoil + muted red flash on the typed row ---- */
.row.shake {
  animation: row-deny 460ms cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

@keyframes row-deny {
  0%, 100% { transform: translate(0, 0); }
  12% { transform: translate(-8px, 2px); }
  28% { transform: translate(8px, 3px); }
  44% { transform: translate(-6px, 2px); }
  60% { transform: translate(5px, 1px); }
  76% { transform: translate(-3px, 0); }
}

.row.deny .tile::after {
  content: "";
  position: absolute;
  inset: -2px;
  border: 2px solid #E11D48;
  border-radius: inherit;
  background: rgba(225, 29, 72, 0.10);
  pointer-events: none;
  animation: deny-flash 520ms ease-out both;
}

@keyframes deny-flash {
  0% { opacity: 0; }
  18% { opacity: 1; }
  100% { opacity: 0; }
}

/* ---- Loss: the board gives a heavy, muted wobble ---- */
.board.lost {
  animation: board-lost 760ms var(--m-out);
}

@keyframes board-lost {
  0%, 100% { translate: 0 0; rotate: 0deg; }
  20% { translate: -6px 4px; rotate: -0.8deg; }
  45% { translate: 5px 6px; rotate: 0.6deg; }
  70% { translate: -2px 3px; rotate: -0.2deg; }
}

/* ---- Win: bigger cascading hop across the solved row ---- */
/* (.row .tile.win outranks the reveal rules above so the win hop replaces the settle.) */
.row .tile.win {
  animation: tile-win 680ms var(--m-spring) both;
  animation-delay: calc(var(--i, 0) * 85ms);
}

@keyframes tile-win {
  0%, 100% { transform: translateY(0) scale(1) rotate(0deg); }
  30% { transform: translateY(-22px) scale(1.12) rotate(-4deg); }
  55% { transform: translateY(3px) scale(0.95) rotate(2deg); }
  78% { transform: translateY(-6px) scale(1.02) rotate(0deg); }
}

.piece.burst {
  top: var(--oy, 50vh);
  left: var(--ox, 50vw);
  width: 8px;
  height: 12px;
  animation: confetti-burst 1500ms var(--m-out) var(--delay) both;
}

@keyframes confetti-burst {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(0.4) rotate(0deg); }
  55% { opacity: 1; transform: translate(calc(-50% + var(--bx)), calc(-50% + var(--by))) scale(1) rotate(var(--spin)); }
  100% { opacity: 0; transform: translate(calc(-50% + var(--bx)), calc(-50% + var(--by) + 160px)) scale(0.8) rotate(calc(var(--spin) * 1.6)); }
}

/* ---- Result card: spring entrance; win shimmer + shining CTA; muted loss ---- */
.result {
  animation: result-spring 620ms var(--m-spring) both;
}

.result-title {
  animation: title-pop 520ms var(--m-spring) 160ms both;
}

.result-word strong {
  display: inline-block;
  animation: word-track 620ms var(--m-out) 260ms both;
}

.result.is-win {
  background-image:
    linear-gradient(105deg, rgba(255, 255, 255, 0) 30%, rgba(255, 255, 255, 0.85) 50%, rgba(255, 255, 255, 0) 70%),
    linear-gradient(180deg, #FFFDF6 0%, var(--wp-gold-soft) 100%);
  background-size: 260% 100%, 100% 100%;
  background-position: 130% 0, 0 0;
  animation: result-spring 620ms var(--m-spring) both, card-shimmer 1300ms ease-out 520ms both;
}

/* Shine sweep on the success CTA (a moving highlight, not a glow). */
.result.is-win .btn-primary {
  background-image:
    linear-gradient(105deg, rgba(255, 255, 255, 0) 38%, rgba(255, 255, 255, 0.45) 50%, rgba(255, 255, 255, 0) 62%),
    var(--wp-primary-gradient);
  background-size: 280% 100%, 100% 100%;
  animation: cta-shine 2.6s ease-in-out 900ms infinite;
}

.result.is-loss {
  border-color: #CBD3DF;
  background: linear-gradient(180deg, #FFFFFF, #F4F6FA);
  box-shadow: inset 0 1px 0 #FFFFFF, 0 3px 0 #D5DBE5, 0 14px 26px -16px rgba(42, 27, 61, 0.35);
  animation: result-loss 620ms var(--m-out) both;
}

.result.is-loss .result-title {
  color: #475569;
  animation: none;
}

@keyframes result-spring {
  0% { opacity: 0; translate: 0 28px; scale: 0.88; }
  60% { opacity: 1; translate: 0 -4px; scale: 1.03; }
  100% { opacity: 1; translate: 0 0; scale: 1; }
}

@keyframes result-loss {
  0% { opacity: 0; translate: 0 18px; }
  60% { opacity: 1; translate: 0 0; rotate: -1deg; }
  80% { rotate: 0.6deg; }
  100% { opacity: 1; rotate: 0deg; }
}

@keyframes title-pop {
  0% { opacity: 0; scale: 0.6; }
  100% { opacity: 1; scale: 1; }
}

@keyframes word-track {
  from { opacity: 0; letter-spacing: 0.5em; }
  to { opacity: 1; letter-spacing: 0.1em; }
}

@keyframes card-shimmer {
  to { background-position: -40% 0, 0 0; }
}

@keyframes cta-shine {
  0% { background-position: 130% 0, 0 0; }
  45%, 100% { background-position: -40% 0, 0 0; }
}

/* ---- Buttons: press-in, spring release, ripple, icon spin, segment pick ---- */
.btn {
  position: relative;
  overflow: hidden;
  transition: transform 260ms var(--m-spring), box-shadow var(--ac-motion-fast) ease, filter var(--ac-motion-fast) ease;
}

.btn:active:not(:disabled) {
  transform: translateY(2px) scale(0.96);
  transition-duration: 70ms;
}

.ripple {
  position: absolute;
  top: var(--ry);
  left: var(--rx);
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(219, 39, 119, 0.22) 0%, rgba(219, 39, 119, 0) 65%);
  pointer-events: none;
  animation: ripple-out 620ms var(--m-out) both;
}

.btn-primary .ripple {
  background: radial-gradient(circle, rgba(255, 255, 255, 0.5) 0%, rgba(255, 255, 255, 0) 65%);
}

@keyframes ripple-out {
  from { opacity: 1; scale: 0; }
  to { opacity: 0; scale: 1; }
}

.btn-icon {
  transform-box: fill-box;
  transform-origin: center;
}

.btn-icon.spin {
  animation: icon-spin 680ms var(--m-out);
}

@keyframes icon-spin {
  from { rotate: 0deg; }
  to { rotate: -360deg; }
}

.segment span.picked {
  animation: seg-pick 420ms var(--m-spring);
}

@keyframes seg-pick {
  0% { scale: 0.82; }
  60% { scale: 1.1; }
  100% { scale: 1; }
}

.help-btn {
  transition: rotate 300ms var(--m-spring), scale 300ms var(--m-spring), background-color var(--ac-motion-fast) ease;
}

.help-btn[aria-expanded="true"] {
  rotate: 12deg;
  scale: 1.08;
}

@media (hover: hover) {
  .help-btn:hover {
    rotate: -12deg;
    scale: 1.1;
  }
}

/* Focus ring grows in rather than snapping. */
.btn:focus-visible,
.help-btn:focus-visible,
.key:focus-visible,
.segment input:focus-visible + span {
  animation: focus-in 240ms var(--m-out);
}

@keyframes focus-in {
  from { box-shadow: 0 0 0 0 #FFFFFF, 0 0 0 0 var(--wp-pink-deep), 0 0 0 0 rgba(236, 72, 153, 0.16); }
  to { box-shadow: var(--wp-ring); }
}

/* ---- Keyboard: springy press, coloured-state pop wave, ready Enter, backspace nudge ---- */
.key {
  transition: transform 300ms var(--m-spring), box-shadow 120ms ease, filter var(--ac-motion-fast) ease, opacity var(--ac-motion-normal) ease;
}

.key:active,
.key.pressed {
  transform: translateY(3px) scale(0.93);
  transition-duration: 60ms;
}

@media (hover: hover) {
  .key:hover:not(:active):not(.pressed) {
    transform: translateY(-1px);
  }
}

.key.state-in {
  animation: key-state-in 520ms var(--m-spring) both;
  animation-delay: calc(var(--k, 0) * 35ms);
}

.key.state-correct.state-in {
  animation-name: key-state-in-correct;
}

@keyframes key-state-in {
  0% { scale: 0.7; }
  60% { scale: 1.1; }
  100% { scale: 1; }
}

@keyframes key-state-in-correct {
  0% { scale: 0.7; translate: 0 0; }
  45% { scale: 1.16; translate: 0 -5px; }
  75% { scale: 0.97; translate: 0 1px; }
  100% { scale: 1; translate: 0 0; }
}

.key-enter.ready {
  background-image:
    linear-gradient(105deg, rgba(255, 255, 255, 0) 38%, rgba(255, 255, 255, 0.5) 50%, rgba(255, 255, 255, 0) 62%),
    var(--wp-primary-gradient);
  background-size: 280% 100%, 100% 100%;
  animation: enter-breathe 1.3s ease-in-out infinite, cta-shine 1.9s ease-in-out infinite;
}

@keyframes enter-breathe {
  0%, 100% { scale: 1; }
  50% { scale: 1.06; }
}

.key-back.nudge {
  animation: back-nudge 300ms var(--m-out);
}

@keyframes back-nudge {
  0%, 100% { translate: 0 0; }
  35% { translate: -4px 0; }
  70% { translate: 2px 0; }
}

.keyboard {
  transition: opacity 320ms ease, translate 420ms var(--m-out), filter 320ms ease;
}

.keyboard.is-done {
  translate: 0 6px;
  filter: saturate(0.7);
}

/* ---- Progress: pip pop and tries-left bump ---- */
.pip {
  transition: background 300ms ease, scale 300ms var(--m-spring);
}

.pip.just-used {
  animation: pip-pop 460ms var(--m-spring);
}

@keyframes pip-pop {
  0% { scale: 0.3; }
  55% { scale: 1.5; }
  100% { scale: 0.9; }
}

.tries {
  display: inline-block;
}

.tries.bump {
  animation: tries-bump 420ms var(--m-spring);
}

@keyframes tries-bump {
  0% { scale: 1; color: var(--wp-ink-muted); }
  40% { scale: 1.14; color: var(--wp-pink-ink); }
  100% { scale: 1; color: var(--wp-ink-muted); }
}

/* ---- Toast: springy info entrance; error toast has its own wobble and rose tone ---- */
.toast.visible {
  animation: toast-in 380ms var(--m-spring);
}

.toast.is-error {
  background: linear-gradient(180deg, #BE123C, #9F1239);
  border-color: rgba(255, 255, 255, 0.2);
}

.toast.is-error::before {
  content: "!";
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  margin-right: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  font-size: 0.75rem;
  font-weight: 900;
  vertical-align: 1px;
}

.toast.is-error.visible {
  animation: toast-in 300ms var(--m-out), toast-deny 420ms ease-in-out 120ms;
}

@keyframes toast-in {
  from { scale: 0.7; }
  to { scale: 1; }
}

@keyframes toast-deny {
  0%, 100% { translate: 0 0; }
  25% { translate: -6px 0; }
  50% { translate: 5px 0; }
  75% { translate: -3px 0; }
}

/* ---- Colour key popover items cascade in ---- */
.legend.is-open .legend-item {
  animation: rise-in 320ms var(--m-spring) both;
}

.legend.is-open .legend-item:nth-child(2) { animation-delay: 60ms; }
.legend.is-open .legend-item:nth-child(3) { animation-delay: 120ms; }

/* ---------- Responsive priorities: the board is the hero ---------- */
/* Below 900px tall (most laptops and phones) the legend is hidden: it repeats each tile's
   badge and accessible label. After the round the result card takes the keyboard's place
   instead of shrinking the board. */
@media (max-height: 899px) {
  .game {
    gap: 6px;
  }

  .legend {
    display: none;
  }

  .help-btn {
    display: inline-flex;
  }

  /* Compact colour key: opened from the "?" button as a small card over the board's lower rows. */
  .legend.is-open {
    position: absolute;
    bottom: 6px;
    left: 0;
    right: 0;
    margin-inline: auto;
    z-index: 5;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    width: max-content;
    max-width: calc(100% - 16px);
    padding: 12px 16px;
    border: var(--ac-stroke-signature) solid var(--wp-line);
    border-radius: 16px;
    background: #FFFFFF;
    color: var(--wp-ink);
    font-size: 0.875rem;
    box-shadow: 0 3px 0 var(--wp-lip), 0 18px 34px -14px rgba(42, 27, 61, 0.45);
    animation: result-in 220ms ease-out both;
  }

  .legend.is-open .chip {
    width: 24px;
    height: 24px;
  }

  .below-board {
    min-height: 0;
  }

  .board {
    --pad: 7px;
    border-radius: 20px;
  }

  .keyboard {
    gap: 7px;
    padding: 4px 4px 2px;
  }

  .keyboard.is-done {
    display: none;
  }

  .result:not([hidden]) {
    margin-top: auto;
  }
}

@media (max-height: 899px) and (min-width: 560px) {
  .game {
    height: calc(100dvh - 16px);
    margin: 8px auto;
    padding: 14px 24px 12px;
  }
}

/* Short viewports (laptops with browser chrome, landscape phones). */
@media (max-height: 780px) {
  .eyebrow {
    margin: 0 0 2px;
    font-size: 0.6875rem;
  }

  h1 {
    font-size: 1.5rem;
  }

  .header-meta {
    margin-top: 4px;
  }

  .key {
    height: 44px;
  }
}

/* Very short viewports (e.g. 320×568). */
@media (max-height: 620px) {
  .eyebrow {
    display: none;
  }

  h1 {
    font-size: 1.3rem;
  }

  .header-meta {
    margin-top: 2px;
  }

  .demo-note {
    font-size: 0.75rem;
  }

  .btn,
  .segment span {
    min-height: 44px;
  }

  .length-picker {
    padding: 2px;
  }
}

/* Phones: squeeze side padding and key gaps so letter keys get as wide as QWERTY allows. */
@media (max-width: 480px) {
  .game {
    padding-left: 6px;
    padding-right: 6px;
  }

  .keyboard {
    padding-left: 0;
    padding-right: 0;
  }

  .key-row {
    gap: 4px;
  }

  .key {
    max-width: none;
  }

  .key-action {
    flex: 1.5 1 0;
    max-width: none;
  }
}

/* Narrow phones (320–360px): keep the toolbar on one line. */
@media (max-width: 360px) {
  .length-legend {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .toolbar {
    gap: 8px;
  }

  .btn {
    padding: 0 14px;
  }

  /* Small tiles: a little more air between tiles and a smaller badge pushed further onto
     the corner so it clears the letter. */
  .board {
    --gap: 7px;
  }

  .tile .mark {
    top: -7px;
    right: -7px;
    width: 13px;
    height: 13px;
    border-width: 1px;
    font-size: 8px;
  }

  .key-row {
    gap: 3px;
  }

  .key::after {
    inset: -4px -2px;
  }

  .header-meta {
    gap: 4px 8px;
  }
}

/* Focus ring wins over the raised-surface shadows above. */
.btn:focus-visible,
.help-btn:focus-visible,
.key:focus-visible,
.segment input:focus-visible + span {
  outline: none;
  box-shadow: var(--wp-ring);
}

/* ---------- Daily ranked (local) ---------- */
.mode-picker .segment span {
  padding: 0 12px;
  font-size: 0.875rem;
}

.ranked-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px 12px;
}

.ranked-panel[hidden],
.toolbar[hidden] {
  display: none;
}

.round-chips {
  display: flex;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.round-chip {
  min-width: 44px;
  min-height: 44px;
  border: var(--ac-stroke-signature) solid var(--wp-line);
  border-radius: 12px;
  background: linear-gradient(180deg, #FFFFFF, #FBF7FC);
  color: var(--wp-ink);
  box-shadow: 0 2px 0 var(--wp-lip);
  font: inherit;
  font-weight: 900;
  cursor: pointer;
}

.round-chip.is-locked {
  opacity: 0.45;
  cursor: not-allowed;
}

.round-chip.is-available,
.round-chip.is-active {
  border-color: var(--wp-pink-deep);
}

.round-chip.is-solved {
  background: linear-gradient(180deg, var(--wp-correct-top), var(--wp-correct-bottom));
  border-color: transparent;
}

.round-chip.is-exhausted,
.round-chip.is-expired,
.round-chip.is-void {
  background: linear-gradient(180deg, #66758B, #556379);
  border-color: transparent;
  color: #FFFFFF;
}

.round-chip[aria-current="step"] {
  box-shadow: var(--wp-ring);
}

.ranked-meta {
  display: flex;
  gap: 12px;
  margin: 0;
  color: var(--wp-ink-muted);
  font-size: 0.875rem;
  font-weight: 800;
}

#ranked-timer.is-low {
  color: #BE123C;
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
