/* ==========================================================================
   NaCho Blocks — styles.css

   1.  Colors & tokens        ✏️ edit the palette here
   2.  Base
   3.  Background shapes
   4.  Screens & cards
   5.  Buttons
   6.  Logo & main menu
   7.  Forms (nickname, settings)
   8.  How to play & leaderboard
   9.  Game layout — phones (default)
   10. Game layout — tablets & desktop
   11. Board, pop-ups, countdown
   12. Touch gesture guide
   13. Overlays (pause, game over)
   14. Animations & reduced motion
   ========================================================================== */

/* 1. COLORS & TOKENS -------------------------------------------------------- */
:root {
  --bg-1: #2b1478;
  --bg-2: #1a3aa8;
  --bg-3: #0b7fb3;
  --ink: #1a1240;
  --panel: rgba(22, 14, 70, 0.72);
  --panel-solid: #221657;
  --panel-border: rgba(255, 255, 255, 0.16);
  --text: #ffffff;
  --muted: rgba(255, 255, 255, 0.75);

  /* Block colors (match js/pieces.js) */
  --red: #ff4a5c;
  --orange: #ff8a26;
  --yellow: #ffd23a;
  --green: #2fd36b;
  --cyan: #19d3f5;
  --blue: #3a78ff;
  --purple: #a64dff;

  --radius: 18px;
  --radius-lg: 26px;
  --font: "Baloo 2", "Arial Rounded MT Bold", "Trebuchet MS", system-ui, sans-serif;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

/* 2. BASE -------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  position: fixed; /* stops iOS rubber-band scrolling */
  inset: 0;
  overflow: hidden;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(circle at 15% 10%, rgba(255, 74, 92, 0.45), transparent 40%),
    radial-gradient(circle at 90% 20%, rgba(25, 211, 245, 0.4), transparent 42%),
    radial-gradient(circle at 70% 95%, rgba(255, 210, 58, 0.35), transparent 45%),
    linear-gradient(160deg, var(--bg-1) 0%, var(--bg-2) 55%, var(--bg-3) 100%);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

:focus-visible {
  outline: 3px solid var(--yellow);
  outline-offset: 3px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.9rem;
}

kbd {
  display: inline-block;
  min-width: 1.8em;
  padding: 0 0.4em;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-bottom-width: 3px;
  font-family: var(--font);
  font-weight: 700;
  font-size: 0.85em;
  text-align: center;
}

.noscript {
  position: fixed;
  inset: auto 0 0;
  padding: 1rem;
  background: var(--red);
  text-align: center;
}

/* 3. BACKGROUND SHAPES ------------------------------------------------------- */
.bg-shapes {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.bg-shapes span {
  position: absolute;
  width: 70px;
  height: 70px;
  border-radius: 16px;
  opacity: 0.18;
  animation: drift 18s ease-in-out infinite;
}

.bg-shapes span:nth-child(1) { top: 8%; left: 6%; background: var(--red); }
.bg-shapes span:nth-child(2) { top: 18%; right: 8%; background: var(--cyan); width: 50px; height: 50px; animation-delay: -4s; }
.bg-shapes span:nth-child(3) { bottom: 14%; left: 10%; background: var(--yellow); animation-delay: -8s; }
.bg-shapes span:nth-child(4) { bottom: 8%; right: 14%; background: var(--purple); width: 90px; height: 90px; animation-delay: -2s; }
.bg-shapes span:nth-child(5) { top: 48%; left: -20px; background: var(--green); width: 56px; height: 56px; animation-delay: -11s; }
.bg-shapes span:nth-child(6) { top: 60%; right: -10px; background: var(--orange); width: 60px; height: 60px; animation-delay: -6s; }

/* 4. SCREENS & CARDS --------------------------------------------------------- */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: calc(16px + var(--safe-top)) calc(16px + var(--safe-right)) calc(16px + var(--safe-bottom)) calc(16px + var(--safe-left));
}

.screen.is-active {
  display: flex;
}

.panel-card,
.overlay-card {
  width: 100%;
  max-width: 480px;
  max-height: 100%;
  padding: clamp(18px, 4vw, 28px);
  border-radius: var(--radius-lg);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.panel-card--scroll {
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.screen-title {
  margin: 0 0 0.6rem;
  font-size: clamp(1.7rem, 6vw, 2.2rem);
  font-weight: 800;
  line-height: 1.1;
  text-align: center;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.25);
}

.corner-link {
  position: absolute;
  top: calc(12px + var(--safe-top));
  left: calc(14px + var(--safe-left));
  color: var(--muted);
  font-weight: 700;
  text-decoration: none;
  font-size: 0.95rem;
}

.corner-link:hover {
  color: #fff;
}

/* 5. BUTTONS ----------------------------------------------------------------- */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  width: 100%;
  min-height: 54px;
  padding: 0.6rem 1.2rem;
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--ink);
  font-weight: 800;
  font-size: 1.1rem;
  letter-spacing: 0.04em;
  box-shadow: 0 6px 0 rgba(10, 6, 40, 0.55);
  transition: transform 0.08s, box-shadow 0.08s, filter 0.15s;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.btn:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 rgba(10, 6, 40, 0.55);
}

.btn--play {
  min-height: 62px;
  font-size: 1.35rem;
  background: linear-gradient(180deg, #ffe46b 0%, var(--yellow) 45%, var(--orange) 100%);
}

.btn--small {
  min-height: 44px;
  font-size: 0.95rem;
}

.btn--danger {
  background: #ffe1e4;
  color: #8a1020;
}

.btn-row {
  display: flex;
  gap: 12px;
  margin-top: 1.2rem;
}

.icon-btn {
  display: grid;
  place-items: center;
  min-width: 44px;
  min-height: 44px;
  border: 2px solid var(--panel-border);
  border-radius: 14px;
  background: var(--panel);
  color: #fff;
  font-weight: 800;
  font-size: 1rem;
  letter-spacing: -0.1em;
  touch-action: manipulation;
}

/* 6. LOGO & MAIN MENU -------------------------------------------------------- */
.menu-card {
  width: 100%;
  max-width: 440px;
  text-align: center;
}

.logo {
  margin: 0 0 0.4rem;
  line-height: 1;
}

.logo-img {
  max-width: min(360px, 90%);
  height: auto;
  margin: 0 auto;
}

.logo-text {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
}

.logo-word--top {
  font-size: clamp(3rem, 16vw, 4.6rem);
  font-weight: 800;
  color: #fff;
  letter-spacing: 0.02em;
  -webkit-text-stroke: 3px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 6px 0 var(--ink), 0 10px 24px rgba(0, 0, 0, 0.35);
  transform: rotate(-3deg);
}

/* "Blocks" — each letter becomes a colored block tile (see ui.js) */
.logo-word--bottom {
  display: flex;
  gap: 0.18em;
  font-size: clamp(1.9rem, 10vw, 2.9rem);
  font-weight: 800;
}

.logo-tile {
  display: grid;
  place-items: center;
  width: 1.35em;
  height: 1.35em;
  border-radius: 0.28em;
  border: 3px solid var(--ink);
  color: #fff;
  -webkit-text-stroke: 2px var(--ink);
  paint-order: stroke fill;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.45), transparent 45%), var(--tile);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.18), 0 5px 0 var(--ink);
  animation: tile-bob 2.4s ease-in-out infinite;
  animation-delay: var(--delay, 0s);
}

.menu-hello {
  min-height: 1.6em;
  margin: 0.6rem 0 1rem;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--muted);
}

.menu-buttons {
  display: grid;
  gap: 12px;
}

.menu-best {
  margin: 1rem 0 0.8rem;
  font-weight: 700;
  color: var(--muted);
}

.menu-best strong {
  color: var(--yellow);
  font-size: 1.15rem;
}

/* 7. FORMS -------------------------------------------------------------------- */
.field input,
.field--row input,
.select select {
  width: 100%;
  min-height: 52px;
  padding: 0.5rem 0.9rem;
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
  font-weight: 700;
  font-size: 1.15rem; /* 16px+ stops iPhone from zooming in */
}

.field input:focus,
.select select:focus {
  outline: 3px solid var(--yellow);
  outline-offset: 2px;
}

.form-error,
.form-note {
  min-height: 1.3em;
  margin: 0.4rem 0 0;
  font-weight: 700;
  color: var(--yellow);
}

.settings-group {
  margin: 0 0 1rem;
  padding: 0.8rem 1rem 1rem;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  display: grid;
  gap: 0.75rem;
}

.settings-group legend {
  padding: 0 0.4rem;
  font-weight: 800;
  color: var(--yellow);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-size: 0.85rem;
}

.toggle,
.range,
.select,
.field--row {
  display: grid;
  gap: 0.35rem;
  font-weight: 700;
  font-size: 1.05rem;
}

.toggle {
  grid-template-columns: 1fr auto;
  align-items: center;
  min-height: 44px;
  cursor: pointer;
}

.toggle input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.toggle-ui {
  position: relative;
  width: 58px;
  height: 32px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.25);
  border: 2px solid rgba(255, 255, 255, 0.4);
  transition: background 0.2s;
}

.toggle-ui::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
}

.toggle input:checked + .toggle-ui {
  background: var(--green);
}

.toggle input:checked + .toggle-ui::after {
  transform: translateX(26px);
}

.toggle input:focus-visible + .toggle-ui {
  outline: 3px solid var(--yellow);
  outline-offset: 2px;
}

.range span {
  display: flex;
  justify-content: space-between;
}

.range input {
  width: 100%;
  height: 32px;
  accent-color: var(--yellow);
}

/* 8. HOW TO PLAY & LEADERBOARD ---------------------------------------------- */
.howto-list {
  margin: 0 0 1rem;
  padding-left: 1.2rem;
  display: grid;
  gap: 0.45rem;
  line-height: 1.4;
}

.howto-sub {
  margin: 1rem 0 0.5rem;
  font-size: 1.15rem;
  color: var(--yellow);
}

.keys {
  display: grid;
  gap: 0.35rem;
  margin: 0;
}

.keys div {
  display: grid;
  grid-template-columns: 8.5rem 1fr;
  align-items: center;
  gap: 0.6rem;
}

.keys dt {
  display: flex;
  gap: 0.25rem;
}

.keys dd {
  margin: 0;
  color: var(--muted);
}

.mini-btn {
  display: inline-grid;
  place-items: center;
  min-width: 2em;
  padding: 0 0.35em;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.16);
  font-weight: 800;
  font-size: 0.85rem;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 1rem;
  padding: 5px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.25);
}

.tab {
  flex: 1;
  min-height: 44px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.tab[aria-selected="true"] {
  background: #fff;
  color: var(--ink);
}

.score-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.score-row {
  display: grid;
  grid-template-columns: 2.4rem 1fr auto;
  grid-template-areas: "rank name points" "rank meta meta";
  align-items: center;
  column-gap: 0.6rem;
  padding: 0.55rem 0.8rem;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.08);
}

.score-row.is-you {
  background: rgba(255, 210, 58, 0.2);
  box-shadow: inset 0 0 0 2px var(--yellow);
}

.score-rank { grid-area: rank; font-weight: 800; font-size: 1.3rem; text-align: center; }
.score-name { grid-area: name; font-weight: 800; font-size: 1.1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score-points { grid-area: points; font-weight: 800; font-size: 1.2rem; color: var(--yellow); }
.score-meta { grid-area: meta; font-size: 0.85rem; color: var(--muted); }

.score-empty {
  padding: 1.5rem;
  text-align: center;
  color: var(--muted);
  font-weight: 700;
}

.your-best {
  min-height: 1.4em;
  margin: 1rem 0 0.2rem;
  font-weight: 800;
  text-align: center;
}

/* 9. GAME LAYOUT — PHONES (default) ------------------------------------------ */
.screen--game {
  padding: calc(8px + var(--safe-top)) calc(8px + var(--safe-right)) calc(8px + var(--safe-bottom)) calc(8px + var(--safe-left));
  align-items: stretch;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}

.game-layout {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 1100px;
  height: 100%;
  margin: 0 auto;
}

.play-area {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) 64px 46px;
  grid-template-rows: 62px minmax(0, 1fr);
  grid-template-areas:
    "hold stats next pause"
    "board board board board";
  gap: 8px;
}

.side {
  display: contents;
}

.box {
  position: relative;
  min-width: 0;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
}

.box--hold { grid-area: hold; }
.box--next { grid-area: next; }
.box--stats { grid-area: stats; }
.pause-btn { grid-area: pause; align-self: stretch; }
.board-wrap { grid-area: board; }
.key-help { display: none; }

.box-label {
  position: absolute;
  top: 3px;
  left: 0;
  right: 0;
  margin: 0;
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-align: center;
  color: var(--muted);
}

.mini-canvas {
  display: block;
  position: absolute;
  inset: 16px 4px 4px;
  width: calc(100% - 8px);
  height: calc(100% - 20px);
}

.box--stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto;
  align-content: center;
  padding: 4px 10px;
  column-gap: 8px;
}

.stat {
  display: flex;
  align-items: baseline;
  gap: 0.3rem;
  min-width: 0;
}

.stat--score {
  grid-column: 1 / -1;
  justify-content: space-between;
}

.stat-label {
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.stat-value {
  font-weight: 800;
  font-size: 1rem;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.stat--score .stat-value {
  font-size: 1.35rem;
  color: var(--yellow);
}

/* Narrow phones (iPhone SE, mini): tighter top bar */
@media (max-width: 400px) {
  .play-area {
    grid-template-columns: 58px minmax(0, 1fr) 58px 42px;
    gap: 6px;
  }

  .box--stats {
    padding: 4px 7px;
    column-gap: 4px;
  }

  .stat-label {
    font-size: 0.56rem;
    letter-spacing: 0.06em;
  }

  .stat-value {
    font-size: 0.92rem;
  }

  .stat--score .stat-value {
    font-size: 1.2rem;
  }
}

/* 10. GAME LAYOUT — TABLETS & DESKTOP ---------------------------------------- */
@media (min-width: 760px) and (min-height: 560px) {
  .screen--game {
    padding: calc(16px + var(--safe-top)) 20px calc(16px + var(--safe-bottom));
  }

  .play-area {
    grid-template-columns: minmax(150px, 210px) minmax(0, 1fr) minmax(150px, 210px);
    grid-template-rows: minmax(0, 1fr);
    grid-template-areas: "left board right";
    gap: 20px;
  }

  .side {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-height: 0;
  }

  .side--left { grid-area: left; }
  .side--right { grid-area: right; }

  .box {
    border-radius: var(--radius);
  }

  .box--hold {
    height: 120px;
    flex: none;
  }

  .box--next {
    flex: 1;
    max-height: 380px;
    min-height: 150px;
  }

  .box-label {
    top: 8px;
    font-size: 0.85rem;
  }

  .mini-canvas {
    inset: 32px 10px 10px;
    width: calc(100% - 20px);
    height: calc(100% - 42px);
  }

  .box--stats {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px 16px;
  }

  .stat {
    flex-direction: column;
    align-items: flex-start;
    gap: 0;
  }

  .stat-label {
    font-size: 0.8rem;
  }

  .stat-value {
    font-size: 1.6rem;
  }

  .stat--score .stat-value {
    font-size: 2rem;
  }

  .pause-btn {
    min-height: 52px;
    font-size: 1.1rem;
  }

  .key-help {
    display: block;
    padding: 12px 14px;
    border-radius: var(--radius);
    background: rgba(0, 0, 0, 0.2);
    font-size: 0.85rem;
    color: var(--muted);
  }

  .key-help p {
    margin: 0 0 0.35rem;
  }

  body.is-touch .key-help {
    display: none;
  }
}

/* 11. BOARD, POP-UPS, COUNTDOWN ---------------------------------------------- */
.board-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
}

.board-frame {
  position: relative;
  padding: 4px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--red), var(--orange), var(--yellow), var(--green), var(--cyan), var(--blue), var(--purple));
  box-shadow: 0 0 0 3px var(--ink), 0 18px 40px rgba(0, 0, 0, 0.45), 0 0 40px rgba(166, 77, 255, 0.35);
}

#board-canvas {
  display: block;
  border-radius: 12px;
}

.board-frame.is-danger {
  animation: danger-pulse 1s ease-in-out infinite;
}

.board-pops {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  padding-top: 28%;
  pointer-events: none;
  overflow: hidden;
}

.pop {
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: pop-rise 1.25s cubic-bezier(0.2, 0.9, 0.3, 1) forwards;
}

.pop-main {
  font-size: clamp(1.4rem, 6vw, 2.1rem);
  font-weight: 800;
  line-height: 1;
  color: #fff;
  -webkit-text-stroke: 2px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 4px 0 var(--ink);
  white-space: nowrap;
}

.pop-sub {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--yellow);
  -webkit-text-stroke: 1.5px var(--ink);
  paint-order: stroke fill;
}

.pop--mega .pop-main {
  font-size: clamp(1.8rem, 8vw, 2.6rem);
  background: linear-gradient(90deg, var(--yellow), #fff, var(--cyan));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-stroke: 0;
  text-shadow: none;
  filter: drop-shadow(0 3px 0 var(--ink)) drop-shadow(0 0 12px rgba(255, 210, 58, 0.8));
}

.pop--combo .pop-main {
  color: var(--yellow);
  font-style: italic;
}

.pop--level .pop-main {
  color: var(--cyan);
}

.countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  font-size: clamp(3rem, 18vw, 6rem);
  font-weight: 800;
  color: #fff;
  -webkit-text-stroke: 3px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 6px 0 var(--ink);
  opacity: 0;
}

.countdown.is-showing {
  animation: count-pop 0.45s ease-out forwards;
}

/* 12. TOUCH GESTURE GUIDE -------------------------------------------------- */
.gesture-guide {
  position: absolute;
  left: 50%;
  bottom: 8%;
  width: max-content;
  max-width: 92%;
  padding: 0.6rem 1rem;
  border-radius: 16px;
  background: rgba(10, 6, 34, 0.78);
  border: 1px solid var(--panel-border);
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.35;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, 10px);
  transition: opacity 0.25s, transform 0.25s;
}

.gesture-guide p {
  margin: 0;
}

.gesture-guide b {
  color: var(--yellow);
}

.gesture-guide.is-showing {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* 13. OVERLAYS --------------------------------------------------------------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(10, 6, 34, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fade-in 0.2s ease-out;
}

.overlay-card {
  max-width: 400px;
  text-align: center;
  animation: card-in 0.3s cubic-bezier(0.2, 0.9, 0.3, 1.2);
  overflow-y: auto;
}

.gameover-name {
  margin: 0;
  font-weight: 700;
  color: var(--muted);
}

.final-score {
  margin: 0.2rem 0 0.6rem;
  font-size: clamp(2.6rem, 12vw, 3.4rem);
  font-weight: 800;
  line-height: 1;
  color: var(--yellow);
  -webkit-text-stroke: 2px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 5px 0 var(--ink);
  font-variant-numeric: tabular-nums;
}

.final-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 0 0 1.1rem;
}

.final-stats div {
  padding: 0.4rem;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.1);
}

.final-stats dt {
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.final-stats dd {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 800;
}

.new-best {
  margin: 0 0 0.3rem;
  font-weight: 800;
  font-size: 1.15rem;
  color: var(--yellow);
  animation: glow 0.9s ease-in-out infinite alternate;
}

.overlay-card--gameover.is-new-best {
  box-shadow: 0 0 0 3px var(--yellow), 0 0 50px rgba(255, 210, 58, 0.5), 0 24px 60px rgba(0, 0, 0, 0.35);
}

.overlay-card--gameover.is-new-best .final-score {
  background: linear-gradient(90deg, var(--yellow), #fff, var(--orange), var(--yellow));
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-stroke: 0;
  text-shadow: none;
  filter: drop-shadow(0 4px 0 var(--ink));
  animation: shimmer 1.6s linear infinite;
}

/* 14. ANIMATIONS ------------------------------------------------------------- */
@keyframes drift {
  0%, 100% { transform: translate(0, 0) rotate(0deg); }
  50% { transform: translate(18px, -26px) rotate(25deg); }
}

@keyframes tile-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

@keyframes pop-rise {
  0% { opacity: 0; transform: scale(0.4); }
  15% { opacity: 1; transform: scale(1.15); }
  28% { transform: scale(1); }
  75% { opacity: 1; transform: translateY(-10px); }
  100% { opacity: 0; transform: translateY(-34px); }
}

@keyframes count-pop {
  0% { opacity: 0; transform: scale(2); }
  30% { opacity: 1; transform: scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: scale(0.9); }
}

@keyframes danger-pulse {
  0%, 100% { box-shadow: 0 0 0 3px var(--ink), 0 18px 40px rgba(0, 0, 0, 0.45), 0 0 18px rgba(255, 74, 92, 0.5); }
  50% { box-shadow: 0 0 0 3px var(--red), 0 18px 40px rgba(0, 0, 0, 0.45), 0 0 44px rgba(255, 74, 92, 0.95); }
}

.shake-small { animation: shake-small 0.22s linear; }
.shake-big { animation: shake-big 0.4s linear; }

@keyframes shake-small {
  0%, 100% { transform: translate(0, 0); }
  25% { transform: translate(0, 4px); }
  50% { transform: translate(0, -2px); }
  75% { transform: translate(0, 2px); }
}

@keyframes shake-big {
  0%, 100% { transform: translate(0, 0); }
  15% { transform: translate(-6px, 4px); }
  30% { transform: translate(5px, -4px); }
  45% { transform: translate(-4px, 3px); }
  60% { transform: translate(3px, -2px); }
  80% { transform: translate(-1px, 1px); }
}

.bump { animation: bump 0.25s ease-out; }
@keyframes bump {
  50% { transform: scale(1.18); }
}

@keyframes fade-in { from { opacity: 0; } }
@keyframes card-in { from { opacity: 0; transform: scale(0.85) translateY(20px); } }
@keyframes glow { from { text-shadow: 0 0 4px rgba(255, 210, 58, 0.4); } to { text-shadow: 0 0 16px rgba(255, 210, 58, 1); } }
@keyframes shimmer { to { background-position: -200% 0; } }

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .pop {
    animation: none;
    opacity: 1;
  }
}
