@import "../css/tokens.css";

/* ==========================================================================
   Tile Merge — Phone-First 2048 Styling & Animation Engine
   ========================================================================== */

:root {
  --color-brand: #F97316;
  --color-brand-hover: #EA580C;
  --color-brand-subtle: #FFF7ED;
  --board-bg: #bbada0;
  --board-padding: clamp(8px, 2.5vw, 14px);
  --board-gap: clamp(8px, 2.5vw, 14px);
  --tile-radius: clamp(6px, 2vw, 10px);
  --board-radius: clamp(10px, 3vw, 16px);
  --cell-bg: rgba(238, 228, 218, 0.38);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  background-color: var(--color-paper, #faf8f5);
  color: var(--color-ink, #282420);
  font-family: var(--font-body, "Plus Jakarta Sans", sans-serif);
  min-height: 100%;
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
  padding-bottom: env(safe-area-inset-bottom, 24px);
}

/* --------------------------------------------------------------------------
   Hub Navigation Bar
   -------------------------------------------------------------------------- */
.hub-bar {
  width: 100%;
  background: var(--color-paper-2, #ffffff);
  border-bottom: 1px solid var(--color-rule, rgba(0, 0, 0, 0.08));
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 1rem;
  font-size: var(--text-sm, 0.875rem);
  font-family: var(--font-label, "JetBrains Mono", monospace);
}

.hub-bar a {
  color: var(--color-ink, #282420);
  text-decoration: none;
  font-weight: 600;
  transition: color var(--dur-micro, 120ms) ease;
}

.hub-bar a:hover {
  color: var(--color-brand);
}

.hub-bar__title {
  color: var(--color-muted, #786f66);
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 0.5rem;
}

/* --------------------------------------------------------------------------
   Ad Rail
   -------------------------------------------------------------------------- */
.ad-rail {
  width: 100%;
  max-width: 728px;
  margin: 0.5rem auto 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 0.5rem;
}

.ad-well {
  width: 100%;
  min-height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-well, rgba(0, 0, 0, 0.02));
  border-radius: 8px;
  overflow: hidden;
}

.ad-empty {
  font-family: var(--font-label);
  font-size: var(--text-xs, 0.75rem);
  color: var(--color-dim, rgba(0, 0, 0, 0.35));
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* --------------------------------------------------------------------------
   Game App Container & HUD
   -------------------------------------------------------------------------- */
.game-container {
  width: 100%;
  max-width: 480px;
  padding: 1rem 1rem 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.game-hud {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.75rem;
  gap: 0.75rem;
}

.hud-brand {
  flex: 1;
}

.game-title {
  font-size: clamp(1.75rem, 6vw, 2.25rem);
  font-weight: 800;
  line-height: 1.1;
  color: var(--color-brand);
  letter-spacing: -0.02em;
}

.game-subtitle {
  font-size: var(--text-xs, 0.75rem);
  color: var(--color-muted, #786f66);
  margin-top: 0.2rem;
}

.game-subtitle strong {
  color: var(--color-ink, #282420);
}

.hud-scores {
  display: flex;
  gap: 0.5rem;
}

.score-card {
  position: relative;
  background: var(--board-bg);
  border-radius: 10px;
  padding: 0.4rem 0.75rem;
  min-width: 72px;
  text-align: center;
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.score-card__label {
  display: block;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: #f4eae0;
  line-height: 1;
  margin-bottom: 0.2rem;
}

.score-card__val {
  display: block;
  font-family: var(--font-label, "JetBrains Mono", monospace);
  font-size: clamp(1rem, 3.5vw, 1.25rem);
  font-weight: 700;
  line-height: 1.1;
}

.score-add {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.score-add__item {
  font-family: var(--font-label, "JetBrains Mono", monospace);
  font-size: 0.9rem;
  font-weight: 800;
  color: var(--color-brand);
  background: #ffffff;
  padding: 2px 6px;
  border-radius: 12px;
  box-shadow: 0 3px 8px rgba(0,0,0,0.15);
  animation: scoreFloat 650ms cubic-bezier(0.2, 0.8, 0.3, 1) forwards;
}

@keyframes scoreFloat {
  0% {
    opacity: 0;
    transform: translate(-50%, 0) scale(0.7);
  }
  20% {
    opacity: 1;
    transform: translate(-50%, -10px) scale(1.1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -32px) scale(0.9);
  }
}

/* --------------------------------------------------------------------------
   Toolbar Controls
   -------------------------------------------------------------------------- */
.game-toolbar {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  gap: 0.5rem;
}

.tool-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  background: var(--color-paper-2, #ffffff);
  color: var(--color-ink, #282420);
  border: 1px solid var(--color-rule, rgba(0, 0, 0, 0.12));
  border-radius: var(--radius-input, 12px);
  padding: 0.55rem 0.5rem;
  min-height: 44px;
  font-family: var(--font-body);
  font-size: var(--text-sm, 0.875rem);
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  transition: all var(--dur-micro, 120ms) ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
}

.tool-btn:hover:not(:disabled) {
  background: #fdfaf6;
  border-color: var(--color-brand);
  color: var(--color-brand);
}

.tool-btn:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow: none;
}

.tool-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  background: #f3efe9;
}

.tool-icon {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
}

.tool-btn[aria-pressed="false"] .tool-icon--sound-on {
  display: none;
}
.tool-btn[aria-pressed="false"] .tool-icon--sound-off {
  display: inline-block;
}
.tool-btn[aria-pressed="true"] .tool-icon--sound-on {
  display: inline-block;
}
.tool-btn[aria-pressed="true"] .tool-icon--sound-off {
  display: none;
}

/* --------------------------------------------------------------------------
   4x4 Grid Board
   -------------------------------------------------------------------------- */
.board-wrapper {
  width: 100%;
  display: flex;
  justify-content: center;
  position: relative;
}

.grid-board {
  position: relative;
  width: 100%;
  max-width: 440px;
  aspect-ratio: 1 / 1;
  background: var(--board-bg);
  border-radius: var(--board-radius);
  padding: var(--board-padding);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: var(--board-gap);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: 0 10px 30px -6px rgba(0, 0, 0, 0.15), inset 0 2px 4px rgba(255, 255, 255, 0.25);
  outline: none;
}

.grid-cell {
  background: var(--cell-bg);
  border-radius: var(--tile-radius);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.12);
}

.tile-layer {
  position: absolute;
  top: var(--board-padding);
  left: var(--board-padding);
  right: var(--board-padding);
  bottom: var(--board-padding);
  pointer-events: none;
  --cell-size: calc((100% - 3 * var(--board-gap)) / 4);
  --cell: var(--cell-px, var(--cell-size));
}

/* --------------------------------------------------------------------------
   Tile Styling & Transforms
   Position uses --cell-px (measured) so translate never sees a % — a % in
   transform is the tile's own box and bunches every piece at the origin.
   -------------------------------------------------------------------------- */
.tile {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--cell);
  height: var(--cell);
  border-radius: var(--tile-radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display, "Plus Jakarta Sans", sans-serif);
  font-weight: 800;
  text-align: center;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.12);
  box-sizing: border-box;
  z-index: 1;
  isolation: isolate;
  overflow: hidden;
  will-change: transform;
  transform: translate(
    calc(var(--col) * (var(--cell) + var(--board-gap))),
    calc(var(--row) * (var(--cell) + var(--board-gap)))
  );
  transition: transform 140ms cubic-bezier(0.2, 0.8, 0.25, 1);
}

.tile::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background-image: url("assets/tile-faces.svg");
  background-size: 400% 100%;
  background-repeat: no-repeat;
  background-position: 0 0;
  pointer-events: none;
  mix-blend-mode: soft-light;
  opacity: 0.95;
  z-index: 0;
}

.tile-2::before,
.tile-4::before { background-position: 0 0; }
.tile-8::before,
.tile-16::before { background-position: 33.334% 0; }
.tile-32::before,
.tile-64::before { background-position: 66.667% 0; }
.tile-128::before,
.tile-256::before,
.tile-512::before,
.tile-1024::before,
.tile-2048::before,
.tile-4096::before,
.tile-8192::before,
.tile-super::before { background-position: 100% 0; }

.tile--spawn {
  animation: tileSpawn 200ms cubic-bezier(0.2, 0.8, 0.25, 1) both;
}

.tile--merged {
  z-index: 2;
  animation: tilePop 240ms cubic-bezier(0.18, 0.89, 0.32, 1.28) both;
}

.tile--hot {
  animation: tilePop 240ms cubic-bezier(0.18, 0.89, 0.32, 1.28) both,
             tileFlash 420ms ease-out both;
}

.tile--merging {
  z-index: 0;
}

@keyframes tileSpawn {
  0% {
    opacity: 0;
    transform: translate(
      calc(var(--col) * (var(--cell) + var(--board-gap))),
      calc(var(--row) * (var(--cell) + var(--board-gap)))
    ) scale(0);
  }
  62% {
    opacity: 1;
    transform: translate(
      calc(var(--col) * (var(--cell) + var(--board-gap))),
      calc(var(--row) * (var(--cell) + var(--board-gap)))
    ) scale(1.14);
  }
  100% {
    opacity: 1;
    transform: translate(
      calc(var(--col) * (var(--cell) + var(--board-gap))),
      calc(var(--row) * (var(--cell) + var(--board-gap)))
    ) scale(1);
  }
}

@keyframes tilePop {
  0% {
    transform: translate(
      calc(var(--col) * (var(--cell) + var(--board-gap))),
      calc(var(--row) * (var(--cell) + var(--board-gap)))
    ) scale(0.78);
  }
  55% {
    transform: translate(
      calc(var(--col) * (var(--cell) + var(--board-gap))),
      calc(var(--row) * (var(--cell) + var(--board-gap)))
    ) scale(1.22);
  }
  100% {
    transform: translate(
      calc(var(--col) * (var(--cell) + var(--board-gap))),
      calc(var(--row) * (var(--cell) + var(--board-gap)))
    ) scale(1);
  }
}

@keyframes tileFlash {
  0% { filter: brightness(1.35); }
  100% { filter: brightness(1); }
}

/* --------------------------------------------------------------------------
   Pastel & Vibrant Tile Palettes
   -------------------------------------------------------------------------- */
.tile-2 {
  background: #ede4db;
  color: #5f4b32;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06);
  font-size: clamp(1.6rem, 6vw, 2.25rem);
}

.tile-4 {
  background: #ede0c8;
  color: #5f4b32;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06);
  font-size: clamp(1.6rem, 6vw, 2.25rem);
}

.tile-8 {
  background: #f59563;
  color: #ffffff;
  box-shadow: 0 3px 8px rgba(245, 149, 99, 0.35);
  font-size: clamp(1.6rem, 6vw, 2.25rem);
}

.tile-16 {
  background: #f67c5f;
  color: #ffffff;
  box-shadow: 0 3px 10px rgba(246, 124, 95, 0.4);
  font-size: clamp(1.5rem, 5.5vw, 2.1rem);
}

.tile-32 {
  background: #f65e3b;
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(246, 94, 59, 0.45);
  font-size: clamp(1.5rem, 5.5vw, 2.1rem);
}

.tile-64 {
  background: #edcf72;
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(237, 207, 114, 0.5);
  font-size: clamp(1.5rem, 5.5vw, 2.1rem);
}

.tile-128 {
  background: #edcc61;
  color: #ffffff;
  box-shadow: 0 0 16px rgba(237, 204, 97, 0.55), inset 0 0 0 1px rgba(255, 255, 255, 0.4);
  font-size: clamp(1.25rem, 4.8vw, 1.8rem);
}

.tile-256 {
  background: #edc850;
  color: #ffffff;
  box-shadow: 0 0 20px rgba(237, 200, 80, 0.65), inset 0 0 0 1px rgba(255, 255, 255, 0.5);
  font-size: clamp(1.25rem, 4.8vw, 1.8rem);
}

.tile-512 {
  background: #edc53f;
  color: #ffffff;
  box-shadow: 0 0 24px rgba(237, 197, 63, 0.75), inset 0 0 0 1.5px rgba(255, 255, 255, 0.6);
  font-size: clamp(1.25rem, 4.8vw, 1.8rem);
}

.tile-1024 {
  background: #e4b82d;
  color: #ffffff;
  box-shadow: 0 0 28px rgba(228, 184, 45, 0.8), inset 0 0 0 2px rgba(255, 255, 255, 0.7);
  font-size: clamp(0.95rem, 3.8vw, 1.45rem);
}

.tile-2048 {
  background: linear-gradient(135deg, #ffd700 0%, #ff8c00 100%);
  color: #ffffff;
  box-shadow: 0 0 32px rgba(255, 140, 0, 0.85), inset 0 0 0 2px rgba(255, 255, 255, 0.9);
  font-size: clamp(0.95rem, 3.8vw, 1.45rem);
}

.tile-4096 {
  background: linear-gradient(135deg, #a855f7 0%, #6366f1 100%);
  color: #ffffff;
  box-shadow: 0 0 32px rgba(168, 85, 247, 0.85), inset 0 0 0 2px rgba(255, 255, 255, 0.9);
  font-size: clamp(0.95rem, 3.8vw, 1.45rem);
}

.tile-8192 {
  background: linear-gradient(135deg, #ec4899 0%, #f43f5e 100%);
  color: #ffffff;
  box-shadow: 0 0 36px rgba(244, 63, 94, 0.9), inset 0 0 0 2px rgba(255, 255, 255, 0.9);
  font-size: clamp(0.95rem, 3.8vw, 1.45rem);
}

.tile-super {
  background: linear-gradient(135deg, #10b981 0%, #06b6d4 100%);
  color: #ffffff;
  box-shadow: 0 0 36px rgba(6, 182, 212, 0.9);
  font-size: clamp(0.8rem, 3.2vw, 1.2rem);
}

/* --------------------------------------------------------------------------
   Swipe Hint
   -------------------------------------------------------------------------- */
.swipe-hint {
  font-size: var(--text-xs, 0.75rem);
  color: var(--color-muted, #786f66);
  margin-top: 0.85rem;
  text-align: center;
}

.swipe-hint strong {
  color: var(--color-ink, #282420);
}

/* --------------------------------------------------------------------------
   Overlay Modals (Victory / Game Over)
   -------------------------------------------------------------------------- */
.overlay-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(40, 36, 32, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-short, 220ms) ease;
}

.overlay-modal[hidden] {
  display: none !important;
}

.overlay-modal:not([hidden]) {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: var(--color-paper-2, #ffffff);
  border-radius: var(--radius-card, 20px);
  padding: 1.75rem 1.5rem;
  width: 100%;
  max-width: 360px;
  text-align: center;
  box-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.3);
  transform: scale(0.9);
  transition: transform var(--dur-short, 220ms) var(--ease-spring);
}

.overlay-modal:not([hidden]) .modal-card {
  transform: scale(1);
}

.modal-badge {
  font-size: 2.5rem;
  line-height: 1;
  margin-bottom: 0.5rem;
}

.modal-title {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--color-ink, #282420);
  margin-bottom: 0.35rem;
}

.modal-desc {
  font-size: var(--text-sm, 0.875rem);
  color: var(--color-muted, #786f66);
  margin-bottom: 1.25rem;
  line-height: 1.4;
}

.modal-stats {
  display: flex;
  justify-content: center;
  gap: 1rem;
  background: var(--color-paper, #faf8f5);
  border: 1px solid var(--color-rule, rgba(0, 0, 0, 0.08));
  border-radius: 12px;
  padding: 0.75rem;
  margin-bottom: 1.25rem;
}

.modal-stat {
  flex: 1;
}

.modal-stat__label {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-muted);
  font-weight: 700;
  margin-bottom: 0.2rem;
}

.modal-stat__val {
  display: block;
  font-family: var(--font-label);
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--color-ink);
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.btn[hidden] {
  display: none !important;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1.25rem;
  min-height: 44px;
  border-radius: var(--radius-pill, 999px);
  font-family: var(--font-body);
  font-size: var(--text-md, 1rem);
  font-weight: 700;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: all var(--dur-micro, 120ms) ease;
}

.btn--primary {
  background: var(--color-brand);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(249, 115, 22, 0.35);
}

.btn--primary:hover {
  background: var(--color-brand-hover);
  box-shadow: 0 6px 16px rgba(249, 115, 22, 0.45);
}

.btn--primary:active {
  transform: translateY(1px);
}

.btn--secondary {
  background: var(--color-paper, #faf8f5);
  color: var(--color-ink, #282420);
  border: 1px solid var(--color-rule, rgba(0, 0, 0, 0.12));
}

.btn--secondary:hover {
  background: #f0eae1;
}

/* --------------------------------------------------------------------------
   Article / Below Section (SEO & Game Guide)
   -------------------------------------------------------------------------- */
.article-section {
  width: 100%;
  max-width: 680px;
  padding: 2rem 1.25rem;
  margin-top: 1rem;
  border-top: 1px solid var(--color-rule, rgba(0, 0, 0, 0.08));
}

.article-section h2 {
  font-size: clamp(1.25rem, 4vw, 1.5rem);
  font-weight: 800;
  color: var(--color-ink, #282420);
  margin: 1.75rem 0 0.75rem;
  letter-spacing: -0.01em;
}

.article-section h2:first-of-type {
  margin-top: 0;
}

.article-section p {
  font-size: var(--text-sm, 0.875rem);
  line-height: 1.65;
  color: var(--color-ink-2, #3c3630);
  margin-bottom: 1rem;
}

.guide-steps {
  list-style: none;
  counter-reset: guide-counter;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.guide-steps li {
  counter-increment: guide-counter;
  position: relative;
  padding-left: 2.25rem;
  font-size: var(--text-sm, 0.875rem);
  line-height: 1.5;
  color: var(--color-ink-2);
}

.guide-steps li::before {
  content: counter(guide-counter);
  position: absolute;
  left: 0;
  top: 0;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background: var(--color-brand-subtle);
  color: var(--color-brand);
  border: 1px solid var(--color-brand);
  font-family: var(--font-label);
  font-size: 0.75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.guide-steps strong {
  color: var(--color-ink);
}

.tips-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin: 1rem 0 1.5rem;
}

.tip-card {
  background: var(--color-paper-2, #ffffff);
  border: 1px solid var(--color-rule, rgba(0, 0, 0, 0.08));
  border-radius: 14px;
  padding: 1rem;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.03);
}

.tip-card h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--color-brand);
  margin-bottom: 0.4rem;
}

.tip-card p {
  font-size: 0.825rem;
  line-height: 1.5;
  color: var(--color-muted);
  margin-bottom: 0;
}

.faq-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin: 1rem 0 1.5rem;
}

.faq-item {
  background: var(--color-paper-2, #ffffff);
  border: 1px solid var(--color-rule, rgba(0, 0, 0, 0.08));
  border-radius: 12px;
  overflow: hidden;
}

.faq-item summary {
  padding: 0.85rem 1rem;
  font-size: var(--text-sm, 0.875rem);
  font-weight: 700;
  color: var(--color-ink);
  cursor: pointer;
  user-select: none;
}

.faq-item summary:hover {
  color: var(--color-brand);
}

.faq-body {
  padding: 0 1rem 0.85rem;
  font-size: 0.825rem;
  line-height: 1.55;
  color: var(--color-ink-2);
}

.faq-body code {
  font-family: var(--font-label);
  background: var(--color-paper);
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
  font-size: 0.8em;
}

/* --------------------------------------------------------------------------
   Footer
   -------------------------------------------------------------------------- */
.game-footer {
  width: 100%;
  max-width: 680px;
  text-align: center;
  padding: 1.5rem 1rem 2rem;
  border-top: 1px solid var(--color-rule, rgba(0, 0, 0, 0.08));
}

.footer-links {
  font-size: var(--text-sm, 0.875rem);
  margin-bottom: 0.5rem;
}

.footer-links a {
  color: var(--color-ink, #282420);
  text-decoration: none;
  font-weight: 600;
}

.footer-links a:hover {
  color: var(--color-brand);
}

.footer-copy {
  font-size: var(--text-xs, 0.75rem);
  color: var(--color-muted);
}

@media (prefers-reduced-motion: reduce) {
  .tile,
  .tile--merging,
  .overlay-modal,
  .modal-card,
  .tool-btn,
  .btn {
    transition: none;
  }
  .tile--spawn,
  .tile--merged,
  .tile--hot,
  .score-add__item {
    animation: none;
  }
}

/* --------------------------------------------------------------------------
   Feedback layer (2026-09-28): callouts, merge sparks, blocked-swipe nudge,
   armed restart, new-best pulse, richer end sheet, screen-reader status.
   -------------------------------------------------------------------------- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.grid-board:focus-visible {
  box-shadow: 0 0 0 3px var(--color-paper, #faf8f5), 0 0 0 6px var(--color-brand);
}

.fx-layer {
  position: absolute;
  top: var(--board-padding);
  left: var(--board-padding);
  right: var(--board-padding);
  bottom: var(--board-padding);
  pointer-events: none;
  z-index: 3;
  --cell-size: calc((100% - 3 * var(--board-gap)) / 4);
  --cell: var(--cell-px, var(--cell-size));
}

.spark {
  position: absolute;
  top: 0;
  left: 0;
  width: 8px;
  height: 8px;
  margin: -4px 0 0 -4px;
  border-radius: 50%;
  --cx: calc(var(--col) * (var(--cell) + var(--board-gap)) + var(--cell) / 2);
  --cy: calc(var(--row) * (var(--cell) + var(--board-gap)) + var(--cell) / 2);
  transform: translate(var(--cx), var(--cy));
  animation: sparkFly 600ms cubic-bezier(0.15, 0.7, 0.3, 1) forwards;
}

@keyframes sparkFly {
  0% { opacity: 1; transform: translate(var(--cx), var(--cy)) scale(1.2); }
  100% {
    opacity: 0;
    transform: translate(calc(var(--cx) + var(--dx)), calc(var(--cy) + var(--dy))) scale(0.3);
  }
}

.board-toast {
  position: absolute;
  top: 38%;
  left: 50%;
  z-index: 5;
  pointer-events: none;
  padding: 0.45rem 0.95rem;
  border-radius: 999px;
  background: rgba(40, 36, 32, 0.86);
  color: #fff;
  font-family: var(--font-display, "Plus Jakarta Sans", sans-serif);
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.85);
}

.board-toast.is-on {
  animation: toastPop 1100ms cubic-bezier(0.2, 0.9, 0.3, 1.2) forwards;
}

.board-toast.is-combo {
  background: linear-gradient(135deg, #f97316, #ea580c);
}

.board-toast.is-gold {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #2b1a02;
}

@keyframes toastPop {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.8); }
  14% { opacity: 1; transform: translate(-50%, -50%) scale(1.06); }
  24% { transform: translate(-50%, -50%) scale(1); }
  78% { opacity: 1; transform: translate(-50%, -58%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -72%) scale(0.96); }
}

.grid-board.nudge-left { animation: nudgeL 180ms ease-out; }
.grid-board.nudge-right { animation: nudgeR 180ms ease-out; }
.grid-board.nudge-up { animation: nudgeU 180ms ease-out; }
.grid-board.nudge-down { animation: nudgeD 180ms ease-out; }
@keyframes nudgeL { 40% { transform: translateX(-5px); } }
@keyframes nudgeR { 40% { transform: translateX(5px); } }
@keyframes nudgeU { 40% { transform: translateY(-5px); } }
@keyframes nudgeD { 40% { transform: translateY(5px); } }

.tool-btn.is-armed,
.tool-btn.is-armed:hover:not(:disabled) {
  background: var(--color-brand);
  border-color: var(--color-brand);
  color: #fff;
  animation: armPulse 900ms ease-in-out infinite;
}

@keyframes armPulse {
  50% { box-shadow: 0 0 0 4px rgba(249, 115, 22, 0.28); }
}

.score-card--best.is-record {
  animation: recordPulse 900ms ease-out;
}

@keyframes recordPulse {
  0% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.7); transform: scale(1); }
  30% { transform: scale(1.08); }
  100% { box-shadow: 0 0 0 14px rgba(245, 158, 11, 0); transform: scale(1); }
}

.modal-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.35rem;
  padding: 0.7rem 0.4rem;
  margin-bottom: 0.6rem;
}

.modal-stat__label {
  font-size: 0.6rem;
}

.modal-stat__val {
  font-size: 1.05rem;
  overflow-wrap: anywhere;
}

.modal-record {
  display: inline-block;
  margin: 0 auto 0.5rem;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #2b1a02;
  font-size: 0.8rem;
  font-weight: 800;
}

.modal-record[hidden] {
  display: none;
}

.modal-life {
  font-size: 0.72rem;
  color: var(--color-muted, #786f66);
  margin-bottom: 1rem;
}

.modal-life:empty {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  .board-toast.is-on {
    animation: none;
    opacity: 1;
    transform: translate(-50%, -50%);
  }
  .grid-board.nudge-left,
  .grid-board.nudge-right,
  .grid-board.nudge-up,
  .grid-board.nudge-down,
  .tool-btn.is-armed,
  .score-card--best.is-record,
  .spark {
    animation: none;
  }
  .spark { display: none; }
}
