/* Bird Mahjong app shell — sunny woodland palette, mobile first. */

:root {
  color-scheme: light;

  /* Palette */
  --ivory: #fbf6e8;
  --ivory-deep: #f2e8cf;
  --paper: #fffdf7;
  --bark: #2f2a20;          /* body text */
  --bark-soft: #5f5645;     /* secondary text (6.7:1 on ivory) */
  --leaf: #3d7a35;          /* primary actions */
  --leaf-dark: #2b5d25;
  --leaf-tint: #e2eed8;
  --sky: #4f97c7;           /* decorative sky */
  --sky-ink: #235f87;       /* sky used for text / secondary actions */
  --sky-tint: #dcecf6;
  --cardinal: #b3312b;      /* restrained accent: brand word, focus, danger */
  --rim: #d9bf86;           /* tile-rim gold, borders only */

  /* Shape & rhythm */
  --radius: 18px;
  --radius-sm: 12px;
  --gutter: 16px;
  --shadow: 0 1px 2px rgb(47 42 32 / 0.08), 0 8px 24px rgb(47 42 32 / 0.08);
  --font: "Avenir Next", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --tap: 48px;
}

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

html { -webkit-text-size-adjust: 100%; background: var(--ivory-deep); }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font);
  color: var(--bark);
  background:
    radial-gradient(120% 60% at 50% -10%, var(--sky-tint) 0%, transparent 70%),
    linear-gradient(180deg, #f4f5ea 0%, var(--ivory) 45%, var(--ivory-deep) 100%);
  line-height: 1.45;
  overflow-x: hidden;
}

img { display: block; max-width: 100%; height: auto; }

button, input { font: inherit; color: inherit; }

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

h1, h2 { font-family: var(--font-display); line-height: 1.1; margin: 0; }
p { margin: 0; }

.eyebrow {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--leaf-dark);   /* small text: needs AA even over the sky-tinted top of the page */
}

.brand {
  font-size: clamp(2.6rem, 12vw, 4.5rem);
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--leaf-dark);
}
.brand span { color: var(--cardinal); }

/* ---------- Floating background tiles ---------- */

.sky-tiles {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  transition: opacity 600ms ease;
}
.sky-tiles[hidden] { display: none; }
body[data-screen="game"] .sky-tiles { opacity: 0.45; }

.float-tile {
  position: absolute;
  left: var(--x);
  top: 100%;
  width: var(--size);
  opacity: var(--alpha, 0.2);
  filter: saturate(0.85) drop-shadow(0 6px 10px rgb(47 42 32 / 0.15));
  animation: float-up var(--dur) linear var(--delay) infinite;
  will-change: transform;
}
.float-tile img { width: 100%; animation: sway var(--sway-dur) ease-in-out infinite alternate; }

@keyframes float-up {
  from { transform: translate3d(0, 0, 0) rotate(var(--rot)); }
  to   { transform: translate3d(var(--drift), calc(-100dvh - 100% - 40px), 0) rotate(calc(var(--rot) * -1)); }
}
@keyframes sway {
  from { transform: translateX(-10px) rotate(-3deg); }
  to   { transform: translateX(10px) rotate(3deg); }
}

/* Reduced motion: tiles rest, scattered, and screen fades are dropped.
   "system" follows the OS; the Settings screen can force either way. */
html[data-motion="reduce"] .float-tile,
html[data-motion="reduce"] .float-tile img { animation: none; }
html[data-motion="reduce"] .float-tile { top: var(--y); transform: rotate(var(--rot)); }
html[data-motion="reduce"] .screen.is-active { animation: none; }
html[data-motion="reduce"] .start-prompt { animation: none; }

@media (prefers-reduced-motion: reduce) {
  html[data-motion="system"] .float-tile,
  html[data-motion="system"] .float-tile img { animation: none; }
  html[data-motion="system"] .float-tile { top: var(--y); transform: rotate(var(--rot)); }
  html[data-motion="system"] .screen.is-active { animation: none; }
  html[data-motion="system"] .start-prompt { animation: none; }
  html[data-motion="system"] * { transition: none !important; }
}
html[data-motion="reduce"] * { transition: none !important; }

/* ---------- Screens ---------- */

.app { position: relative; z-index: 1; }

.screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding:
    max(var(--gutter), env(safe-area-inset-top))
    max(var(--gutter), env(safe-area-inset-right))
    max(var(--gutter), env(safe-area-inset-bottom))
    max(var(--gutter), env(safe-area-inset-left));
}
.screen[hidden] { display: none; }
.screen:focus { outline: none; }
.screen.is-active { animation: screen-in 280ms ease-out; }

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

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  min-height: var(--tap);
  padding: 0.7em 1.4em;
  border: 2px solid var(--rim);
  border-radius: 999px;
  background: var(--paper);
  color: var(--bark);
  font-weight: 700;
  font-size: 1.05rem;
  cursor: pointer;
  box-shadow: 0 2px 0 rgb(47 42 32 / 0.08);
  transition: transform 120ms ease, background-color 160ms ease, border-color 160ms ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.btn:hover:not(:disabled) { border-color: var(--leaf); background: #fff; }
.btn:active:not(:disabled) { transform: translateY(1px) scale(0.99); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

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

.btn--sky { background: var(--sky-tint); border-color: var(--sky); color: var(--sky-ink); }
.btn--sky:hover:not(:disabled) { background: #cfe5f3; border-color: var(--sky-ink); }

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

.btn--quiet {
  background: transparent;
  border-color: transparent;
  color: var(--cardinal);
  box-shadow: none;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.btn--quiet:hover:not(:disabled) { background: transparent; border-color: transparent; }

.btn-back, .icon-btn {
  min-height: 44px;
  min-width: 44px;
  border: 2px solid transparent;
  border-radius: 999px;
  background: rgb(255 253 247 / 0.7);
  color: var(--leaf-dark);
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn-back { padding: 0.4em 1em; align-self: flex-start; }
.btn-back:hover, .icon-btn:hover { border-color: var(--rim); }
.icon-btn { font-size: 1.1rem; line-height: 1; }

/* ---------- Start ---------- */

.screen--start {
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  text-align: center;
  cursor: pointer;
}
.start-card { margin: auto 0; display: grid; justify-items: center; gap: clamp(4px, 1.6vh, 12px); }
.screen--start .brand { font-size: clamp(2.4rem, min(12vw, 11vh), 4.5rem); }
.start-prompt {
  margin-top: clamp(4px, 2.5vh, 20px);
  padding: 0.6em 1.2em;
  border-radius: 999px;
  background: rgb(255 253 247 / 0.75);
  color: var(--bark-soft);
  font-weight: 600;
  font-size: clamp(0.85rem, 3.6vw, 1rem);
  text-wrap: balance;
  animation: breathe 2.8s ease-in-out infinite;
}
@keyframes breathe { 50% { transform: scale(1.035); box-shadow: 0 0 0 6px rgb(61 122 53 / 0.12); } }
.byline {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  color: var(--bark-soft);
  font-size: 0.85rem;
  letter-spacing: 0.12em;
}
/* The INSPIRE logo (black outline, white letters): reads on ivory and dark. */
.brand-logo { display: block; width: auto; height: 100%; }
.byline .brand-logo { height: clamp(28px, 6vh, 40px); }

.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;
}

/* ---------- INSPIRE intro ----------
   Full-bleed black (the video's own background), the video letterboxed to
   fit, and a Skip button that's always on screen. */
.screen--intro {
  position: fixed;
  inset: 0;
  z-index: 50;
  padding: 0;
  background: #000;
  align-items: center;
  justify-content: center;
}
.screen--intro.is-active { animation: none; }
.intro-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  pointer-events: none;
}
.intro-skip {
  position: absolute;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  min-height: 48px;
  padding: 0.5em 1.4em;
  border: 1px solid rgb(255 255 255 / 0.55);
  background: rgb(0 0 0 / 0.55);
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.intro-skip:hover { background: rgb(255 255 255 / 0.14); }
.intro-skip:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }

.hero-tiles, .menu-hero, .results-tiles {
  display: flex;
  justify-content: center;
  align-items: flex-end;
}
.hero-tiles img, .menu-hero img, .results-tiles img {
  width: clamp(56px, min(22vw, 20vh), 140px);
  filter: drop-shadow(0 8px 14px rgb(47 42 32 / 0.22));
}
.hero-tiles { margin-bottom: 8px; }
.hero-tiles img, .menu-hero img, .results-tiles img { position: relative; }
.hero-tiles img:nth-child(1) { transform: rotate(-9deg) translate(14px, 8px); }
.hero-tiles img:nth-child(2) { transform: translateY(-6px); z-index: 1; }
.hero-tiles img:nth-child(3) { transform: rotate(9deg) translate(-14px, 8px); }

/* ---------- Main menu ---------- */

.screen--menu { justify-content: center; }
.menu-layout {
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  display: grid;
  gap: 20px;
}
.menu-hero img { width: clamp(64px, 19vw, 96px); }
.menu-hero img:nth-child(1) { transform: rotate(-7deg) translate(10px, 6px); }
.menu-hero img:nth-child(2) { transform: translateY(-4px); z-index: 1; }
.menu-hero img:nth-child(3) { transform: rotate(7deg) translate(-10px, 6px); }

.menu-content { display: grid; gap: 8px; text-align: center; }
.menu-nav { display: grid; gap: 12px; margin-top: 20px; }
.menu-footer {
  display: flex;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 20px;
  font-size: 0.85rem;
  color: var(--bark-soft);
  letter-spacing: 0.06em;
}
.menu-footer { align-items: center; }
.menu-footer a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 8px; color: var(--sky-ink); }

/* ---------- Panel screens (difficulty, help, settings) ---------- */

.panel-header {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 640px;
  margin: 0 auto 20px;
}
.panel-header h1 { font-size: clamp(1.8rem, 7vw, 2.4rem); color: var(--leaf-dark); }

.panel-body {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 20px;
  border-radius: var(--radius);
  background: rgb(255 253 247 / 0.9);
  border: 1px solid rgb(217 191 134 / 0.6);
  box-shadow: var(--shadow);
}

.difficulty-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.difficulty-option {
  width: 100%;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 4px 14px;
  min-height: 72px;
  padding: 12px 16px;
  text-align: left;
  border: 2px solid var(--ivory-deep);
  border-radius: var(--radius-sm);
  background: var(--paper);
  cursor: pointer;
  transition: border-color 160ms ease, transform 120ms ease;
}
.difficulty-option:hover { border-color: var(--leaf); }
.difficulty-option:active { transform: scale(0.99); }
.difficulty-option img { grid-row: span 3; width: 44px; }
.difficulty-option strong { font-size: 1.15rem; color: var(--leaf-dark); }
.difficulty-option strong small { display: block; font-weight: 700; font-size: 0.75rem; color: var(--sky-ink); letter-spacing: 0.12em; text-transform: uppercase; }
.difficulty-option span { font-size: 0.9rem; color: var(--bark-soft); }

/* How to Play */
.prose h2 { font-size: 1.35rem; color: var(--leaf-dark); margin: 24px 0 8px; }
.prose p { color: var(--bark-soft); }
.steps { margin: 0; padding-left: 1.3em; display: grid; gap: 10px; }
.steps li::marker { color: var(--leaf); font-weight: 700; }
.lookalikes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.lookalikes figure {
  margin: 0;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: var(--sky-tint);
  display: grid;
  justify-items: center;
  gap: 8px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--bark-soft);
}
.lookalikes img { width: 84px; }
.lookalikes strong { display: block; color: var(--bark); font-size: 0.95rem; }

/* Settings */
.settings { display: grid; gap: 8px; }
.setting { border: 0; margin: 0; padding: 14px 0; border-bottom: 1px solid var(--ivory-deep); }
.setting legend { font-weight: 700; padding: 0; margin-bottom: 2px; }
.setting-hint { display: block; font-size: 0.85rem; color: var(--bark-soft); font-weight: 400; margin-bottom: 8px; }
.setting--toggle { display: flex; align-items: center; justify-content: space-between; gap: 16px; cursor: pointer; }
.setting--toggle .setting-hint { margin: 2px 0 0; }

.segmented { display: flex; flex-wrap: wrap; gap: 8px; }
.segmented label { flex: 1 1 auto; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: block;
  min-height: 44px;
  padding: 10px 14px;
  text-align: center;
  border: 2px solid var(--ivory-deep);
  border-radius: 999px;
  background: var(--paper);
  font-weight: 600;
  cursor: pointer;
}
.segmented input:checked + span { background: var(--leaf-tint); border-color: var(--leaf); color: var(--leaf-dark); }
.segmented input:focus-visible + span { outline: 3px solid var(--cardinal); outline-offset: 2px; }

input[role="switch"] {
  appearance: none;
  flex: none;
  width: 52px;
  height: 30px;
  border-radius: 999px;
  background: #cfc6b1;
  position: relative;
  cursor: pointer;
  transition: background-color 160ms ease;
}
input[role="switch"]::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.25);
  transition: transform 160ms ease;
}
input[role="switch"]:checked { background: var(--leaf); }
input[role="switch"]:checked::after { transform: translateX(22px); }

#btn-reset-settings { justify-self: start; margin-top: 8px; padding-left: 0; }

/* ---------- Game ---------- */

/* A compact brand footer under the board: one short line, so the board and
   controls keep their room on the narrowest phones. */
.game-footer {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 20px;
  color: var(--bark-soft);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}
.game-footer .brand-logo { height: 18px; }

/* The game screen is exactly one viewport tall; the board scrolls inside its
   own frame so the page itself never scrolls or zooms during play. */
.screen--game {
  gap: 10px;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}
.game-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
}
.game-title { text-align: center; min-width: 0; }
.game-title h1 { font-size: 1.35rem; color: var(--leaf-dark); }
.game-title p { font-size: 0.8rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--sky-ink); }

.game-layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  grid-template-areas: "stats" "message" "board" "tools";
  gap: 8px;
}
/* On phones the side column dissolves into the grid rows above/below the board. */
.game-side { display: contents; }
.game-stats { grid-area: stats; }
.game-message { grid-area: message; }
.board-area { grid-area: board; }
.game-tools { grid-area: tools; }

.game-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 0;
}
.game-stats div, .results-metrics div {
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  background: rgb(255 253 247 / 0.9);
  border: 1px solid rgb(217 191 134 / 0.55);
  text-align: center;
}
.game-stats dt, .results-metrics dt {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--bark-soft);
}
.game-stats dd, .results-metrics dd {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* Fixed two-line height so messages never shift the board. */
.game-message {
  height: 2.6em;
  line-height: 1.3;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  text-align: center;
  text-wrap: balance;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--bark-soft);
}
.game-message[data-tone="good"] { color: var(--leaf-dark); }
.game-message[data-tone="good"]::before { content: "✓ "; }
.game-message[data-tone="warn"] { color: var(--bark); }
.game-message[data-tone="warn"]::before { content: "• "; color: var(--cardinal); }

/* The board and its stuck panel share one area. */
.board-area {
  position: relative;
  display: flex;
  min-height: 0;
  min-width: 0;
}
.board-viewport {
  position: relative;
  flex: 1;
  min-width: 0;
  isolation: isolate;       /* keep tile z-indexes inside the board */
  display: flex;          /* auto margins centre the board without clipping it */
  overflow: auto;
  overscroll-behavior: contain;
  touch-action: pan-x pan-y; /* scroll to pan; no page pinch-zoom or double-tap zoom */
  border-radius: var(--radius);
  background:
    radial-gradient(90% 70% at 50% 40%, rgb(255 253 247 / 0.55), transparent 75%),
    repeating-linear-gradient(90deg, rgb(61 122 53 / 0.05) 0 1px, transparent 1px 22px),
    var(--leaf-tint);
  border: 1px solid rgb(61 122 53 / 0.25);
  box-shadow: inset 0 2px 10px rgb(47 42 32 / 0.08);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  scrollbar-width: thin;
}
.board-viewport.is-pannable { cursor: grab; }
.board-viewport.is-dragging { cursor: grabbing; }
.board-viewport.is-dragging .tile { cursor: grabbing; }

.board-surface {
  position: relative;
  flex: none;
  margin: auto;
  /* Transient decorations (lifted tiles, "+points" tags) must never grow the
     scroll area: a brief scrollbar would make the whole board jump. The
     board's padding leaves room for the lift and the focus ring. */
  overflow: hidden;
  overflow: clip;
}

/* ---------- Tiles ---------- */

.tile {
  --edge: calc(var(--tile-w, 48px) * 0.06);
  position: absolute;
  padding: 0;
  border: 0;
  border-radius: 11% / 9%;
  background: #e9d6a6;
  color: var(--bark);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  /* Thickness on the bottom-right edge, then a soft drop shadow. */
  box-shadow:
    var(--edge) var(--edge) 0 #b8955a,
    calc(var(--edge) + 1px) calc(var(--edge) + 2px) 4px rgb(47 42 32 / 0.28);
  transition: transform 140ms ease, filter 140ms ease, box-shadow 140ms ease;
}
.tile img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
  border-radius: inherit;
  pointer-events: none;
  -webkit-user-drag: none;
}
.tile[hidden] { display: none; }
.tile:focus-visible { outline: 3px solid var(--cardinal); outline-offset: 2px; }

/* Free: full colour; lifts a touch under a mouse. */
@media (hover: hover) {
  .tile.is-free:hover { transform: translateY(-3%); }
}

/* Blocked: faded AND striped, so it doesn't depend on colour perception. */
.tile.is-blocked { cursor: not-allowed; }
.tile.is-blocked img { filter: saturate(0.4) brightness(0.8) contrast(0.9); }
.tile.is-blocked::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: repeating-linear-gradient(
    135deg,
    rgb(47 42 32 / 0.26) 0 2px,
    transparent 2px 7px
  );
  pointer-events: none;
}

/* Selected: lifted, thick double ring AND a ✓ badge. */
.tile.is-selected {
  transform: translateY(-9%);
  box-shadow:
    0 0 0 3px var(--paper),
    0 0 0 6px var(--leaf-dark),
    var(--edge) calc(var(--edge) + 6px) 10px rgb(47 42 32 / 0.35);
}

/* Hint: dashed ring AND a "?" badge (plus a slow pulse when motion is on). */
.tile.is-hint {
  outline: 3px dashed var(--sky-ink);
  outline-offset: 3px;
  animation: hint-pulse 1.6s ease-in-out infinite;
}
@keyframes hint-pulse { 50% { outline-offset: 6px; } }

.tile-badge {
  display: none;
  position: absolute;
  top: -8%;
  right: -10%;
  width: max(20px, calc(var(--tile-w, 48px) * 0.42));
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px solid var(--paper);
  box-shadow: 0 2px 4px rgb(47 42 32 / 0.3);
  font: 800 max(12px, calc(var(--tile-w, 48px) * 0.24)) / 1 var(--font);
  place-items: center;
  pointer-events: none;
}
.tile.is-selected .tile-badge { display: grid; background: var(--leaf-dark); color: #fff; }
.tile.is-selected .tile-badge::before { content: "✓"; }
.tile.is-hint:not(.is-selected) .tile-badge { display: grid; background: var(--sky-ink); color: #fff; }
.tile.is-hint:not(.is-selected) .tile-badge::before { content: "?"; }

/* Optional bird-name labels (Settings). */
.tile-label {
  display: none;
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: 7%;
  padding: 1px 2px;
  border-radius: 4px;
  background: rgb(255 253 247 / 0.92);
  font: 700 max(8px, calc(var(--tile-w, 48px) * 0.15)) / 1.15 var(--font);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}
html[data-tile-labels="on"] .tile-label { display: block; }

/* Gentle feedback: a matched pair lifts a little and fades (280ms, matching
   REMOVE_MS in js/ui/game-controller.js); blocked taps wiggle. Only transform
   and opacity animate, so it stays smooth on phones. */
.tile.is-removing {
  pointer-events: none;
  z-index: 5000 !important;
  will-change: transform, opacity;
  animation: tile-lift 280ms cubic-bezier(0.25, 0.7, 0.35, 1) forwards;
}
@keyframes tile-lift {
  0% { transform: translateY(-9%); opacity: 1; }
  45% { transform: translateY(-18%) scale(1.03); opacity: 0.9; }
  100% { transform: translateY(-26%) scale(0.97); opacity: 0; }
}

/* The woodland accent over each cleared tile: four specks of leaf, gold and
   sky drifting out, and one small feather floating up. ~0.5s, no input. */
.match-sparkle {
  position: absolute;
  z-index: 5500;
  width: 0;
  height: 0;
  pointer-events: none;
}
.match-sparkle .spark {
  position: absolute;
  left: -4px;
  top: -4px;
  width: 8px;
  height: 8px;
  border-radius: 50% 0 50% 0;   /* a tiny leaf */
  box-shadow: 0 0 4px 1px rgb(255 253 247 / 0.7);
  opacity: 0;
  animation: spark-drift 500ms ease-out forwards;
}
.match-sparkle .spark:nth-child(2n) { border-radius: 50%; width: 6px; height: 6px; left: -3px; top: -3px; animation-delay: 40ms; }
@keyframes spark-drift {
  0% { opacity: 0; transform: translate(0, 0) scale(0.6) rotate(0); }
  30% { opacity: 0.95; }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(1) rotate(90deg); }
}
.match-sparkle .match-feather {
  position: absolute;
  left: -4px;
  top: -10px;
  width: 8px;
  height: 20px;
  border-radius: 50% 50% 50% 50% / 70% 70% 30% 30%;
  background: linear-gradient(to right, var(--paper) 45%, var(--rim) 55%);
  box-shadow: 0 0 0 1px rgb(47 42 32 / 0.12);
  opacity: 0;
  animation: feather-up 520ms ease-out forwards;
}
@keyframes feather-up {
  0% { opacity: 0; transform: translate(0, 0) rotate(0); }
  25% { opacity: 0.9; }
  100% { opacity: 0; transform: translate(var(--sway, 0px), calc(var(--size, 48px) * -0.7)) rotate(var(--turn)); }
}
.tile.is-nudge { animation: nudge 280ms ease-in-out; }
@keyframes nudge {
  25% { transform: translateX(-4%); }
  75% { transform: translateX(4%); }
}

.reduce-motion .tile,
.reduce-motion .tile.is-hint,
.reduce-motion .tile.is-nudge { animation: none; transition: none; }
.reduce-motion .tile.is-removing { animation: none; opacity: 0; }
.reduce-motion .match-sparkle { display: none; }

.game-tools {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}
.zoom-controls { display: flex; gap: 6px; }
.zoom-controls[hidden] { display: none; }
.btn--icon { min-width: 44px; padding-inline: 0.6em; font-size: 1.2rem; line-height: 1; }

/* How to Play legend: real tile states at a fixed size. */
.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.legend li { display: grid; grid-template-columns: 52px 1fr; align-items: center; gap: 14px; }
.legend strong { display: block; color: var(--bark); }
.legend li > span:last-child { color: var(--bark-soft); font-size: 0.92rem; }
.legend-tile.tile {
  --tile-w: 44px;
  position: relative;
  display: block;
  width: 44px;
  height: 56px;
  margin: 8px 0 0 2px;
  cursor: default;
}
.legend-tile.is-hint { animation: none; }

/* Pause dialog */
.dialog {
  width: min(92vw, 360px);
  padding: 24px;
  border: 0;
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--bark);
  box-shadow: 0 20px 60px rgb(47 42 32 / 0.3);
  text-align: center;
}
.dialog::backdrop { background: rgb(47 42 32 / 0.35); backdrop-filter: blur(2px); }
.dialog form { display: grid; gap: 12px; }
.dialog h2 { font-size: 2rem; color: var(--leaf-dark); margin-bottom: 8px; }

/* ---------- Results ---------- */

.screen--results { align-items: center; justify-content: center; }
.results-card {
  width: 100%;
  max-width: 440px;
  display: grid;
  gap: 8px;
  justify-items: center;
  text-align: center;
  padding: 24px 20px;
  border-radius: var(--radius);
  background: rgb(255 253 247 / 0.92);
  border: 1px solid rgb(217 191 134 / 0.6);
  box-shadow: var(--shadow);
}
.results-tiles { margin-top: -8px; margin-bottom: 4px; }
.results-tiles img { width: clamp(64px, 18vw, 88px); }
.results-tiles img:nth-child(1) { transform: rotate(-8deg) translateX(8px); }
.results-tiles img:nth-child(2) { transform: rotate(8deg) translateX(-8px); }
.results-card h1 { font-size: clamp(2.2rem, 10vw, 3rem); color: var(--leaf-dark); }
.results-difficulty { font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; font-size: 0.85rem; color: var(--sky-ink); }
.results-metrics {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 12px 0 4px;
}
.results-note { font-size: 0.8rem; color: var(--bark-soft); }
.results-actions { width: 100%; display: grid; gap: 10px; margin-top: 12px; }

.noscript { position: relative; z-index: 1; padding: 24px; text-align: center; }

/* ---------- Tablet (≥ 700px) ---------- */

@media (min-width: 700px) {
  :root { --gutter: 32px; }

  .panel-header { flex-direction: row; align-items: center; gap: 20px; }
  .panel-header .btn-back { align-self: center; }
  .panel-body { padding: 28px 32px; }

  .difficulty-list { gap: 16px; }
  .difficulty-option { min-height: 96px; }
  .difficulty-option img { width: 52px; }

  .lookalikes img { width: 110px; }


  .results-card { padding: 32px; }
  .results-metrics { grid-template-columns: repeat(4, 1fr); }
  .results-actions { grid-template-columns: 1fr 1fr; }
}

/* ---------- Desktop (≥ 1024px) ---------- */

@media (min-width: 1024px) {
  .menu-layout {
    max-width: 960px;
    grid-template-columns: 1.1fr 1fr;
    align-items: center;
    gap: 56px;
  }
  .menu-hero img { width: 150px; }
  .menu-hero img:nth-child(1) { transform: rotate(-8deg) translate(24px, 12px); }
  .menu-hero img:nth-child(3) { transform: rotate(8deg) translate(-24px, 12px); }
  .menu-content { text-align: left; justify-items: stretch; }
  .menu-footer { justify-content: flex-start; }

  .screen--game { max-width: 1400px; width: 100%; margin: 0 auto; }
}

/* ---------- Wide game layout: desktop, and landscape phones ----------
   Stats and tools move to a side column so the board gets the full height. */

@media (min-width: 1024px), (orientation: landscape) and (max-height: 560px) {
  .game-layout {
    grid-template-columns: minmax(150px, 210px) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "side message" "side board";
    gap: 8px 16px;
  }
  .game-side {
    grid-area: side;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
    overflow-y: auto;
  }
  .game-stats { grid-template-columns: 1fr; }
  .game-stats div { display: flex; justify-content: space-between; align-items: baseline; text-align: left; padding: 8px 12px; }
  .game-tools { flex-direction: column; align-items: stretch; }
  .zoom-controls { justify-content: space-between; }
  .zoom-controls .btn { flex: 1; }
}

@media (min-width: 1024px) {
  .game-stats div { display: block; padding: 12px 16px; }
  .game-stats dd { font-size: 1.6rem; }
}

/* Landscape phones: every pixel of height counts. Tools sit in a 2-column
   grid (zoom on its own row) so the whole side column fits in ~300px. */
@media (orientation: landscape) and (max-height: 560px) {
  .screen--game { gap: 6px; padding-top: max(8px, env(safe-area-inset-top)); padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .game-title h1 { font-size: 1.05rem; }
  .game-title p { font-size: 0.75rem; }
  .game-layout { grid-template-columns: minmax(176px, 220px) minmax(0, 1fr); gap: 6px 12px; }
  .game-side { gap: 8px; }
  .game-stats { gap: 4px; }
  .game-stats div { padding: 3px 10px; }
  .game-stats dd { font-size: 1rem; }
  .game-tools { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
  .game-tools .btn--small { padding-inline: 0.4em; font-size: 0.9rem; }
  .zoom-controls { grid-column: 1 / -1; }
  .game-message { height: 2.6em; font-size: 0.85rem; }
}

/* Narrow phones: keep header and stats to one line each so the board keeps its height. */
.game-title p { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 380px) {
  .game-stats dt { letter-spacing: 0.02em; white-space: nowrap; }
  .game-stats div { padding-inline: 6px; }
  .game-stats dd { font-size: 1.1rem; }
  .game-title h1 { font-size: 1.15rem; }
  .game-tools { gap: 5px; }
  .game-tools .btn--small { padding-inline: 0.6em; font-size: 0.88rem; }
}

/* ---------- Scores ---------- */

.difficulty-option .difficulty-best {
  grid-column: 2;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--leaf-dark);
}

.results-score { margin-top: 4px; font-weight: 700; color: var(--bark-soft); }
.results-score-value {
  display: block;
  font-family: var(--font-display);
  font-size: clamp(2.6rem, 12vw, 3.4rem);
  line-height: 1;
  color: var(--bark);
  font-variant-numeric: tabular-nums;
}
.results-best { font-weight: 600; color: var(--bark-soft); }
.results-best[data-new-best="true"] {
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--leaf-tint);
  color: var(--leaf-dark);
}
.results-best[data-new-best="true"]::before { content: "★ "; }

/* ---------- Game controls: header spacer, stuck panel, dialogs ---------- */

.header-spacer { width: 44px; height: 44px; }

.board-area.is-stuck .board-viewport { filter: saturate(0.7); }
.board-area.is-stuck .board-viewport::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgb(251 246 232 / 0.35);
  pointer-events: none;
}

.stuck-panel {
  position: absolute;
  z-index: 2;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  width: min(calc(100% - 24px), 380px);
  max-height: calc(100% - 24px);
  overflow-y: auto;
  display: grid;
  gap: 8px;
  padding: 16px 18px;
  text-align: center;
  border-radius: var(--radius);
  background: var(--paper);
  border: 2px solid var(--rim);
  box-shadow: 0 12px 36px rgb(47 42 32 / 0.28);
  animation: stuck-in 260ms ease-out;
}
.stuck-panel[hidden] { display: none; }
.stuck-panel h2 { font-size: 1.35rem; color: var(--leaf-dark); }
.stuck-panel p:not(.eyebrow) { font-size: 0.9rem; color: var(--bark-soft); }
.stuck-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 4px; }
.stuck-actions .btn { min-height: 46px; padding-inline: 0.8em; font-size: 0.95rem; white-space: nowrap; }
.stuck-actions .btn[hidden] { display: none; }
@keyframes stuck-in { from { opacity: 0; transform: translate(-50%, 12px); } }
.reduce-motion .stuck-panel { animation: none; }

/* Phones and short screens: the board area is too small to hold the offer,
   so it becomes a bottom sheet over the lower part of the screen. */
@media (max-width: 699px), (max-height: 560px) {
  .stuck-panel {
    position: fixed;
    bottom: max(12px, env(safe-area-inset-bottom));
    max-height: calc(100dvh - 24px);
    z-index: 20;
  }
}

.dialog-text { color: var(--bark-soft); margin: -4px 0 4px; }

/* ---------- Saving ---------- */

.btn--continue { flex-direction: column; gap: 0; line-height: 1.2; }
.continue-detail { font-size: 0.78rem; font-weight: 600; color: var(--bark-soft); }
.continue-detail:empty { display: none; }
.difficulty-note {
  margin: 0 0 14px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--sky-tint);
  color: var(--sky-ink);
  font-size: 0.9rem;
  font-weight: 600;
}
.difficulty-note[hidden], .storage-note[hidden] { display: none; }
.storage-note {
  margin: 8px 0 0;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border-left: 4px solid var(--cardinal);
  background: var(--ivory);
  font-size: 0.88rem;
  color: var(--bark);
}

/* ---------- Polish: focus, feedback, celebration, controls ---------- */

/* A focused tile is always drawn above its neighbours so the ring shows. */
.tile:focus-visible {
  z-index: 4500 !important;
  outline: 3px solid var(--cardinal);
  outline-offset: 3px;
  box-shadow:
    0 0 0 6px var(--paper),
    var(--edge) var(--edge) 0 #b8955a;
}

/* "+120" floating up from a matched pair. */
.score-float {
  position: absolute;
  z-index: 6000;
  transform: translate(-50%, 0);
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--paper);
  border: 1px solid var(--rim);
  color: var(--leaf-dark);
  font: 800 0.9rem/1.3 var(--font);
  pointer-events: none;
  animation: score-float 850ms ease-out forwards;
}
@keyframes score-float {
  0% { opacity: 0; transform: translate(-50%, 6px); }
  20% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -34px); }
}

/* Board cleared: a soft glow and a dozen feathers drifting up, ~1.5s. */
.celebration {
  position: absolute;
  inset: 0;
  z-index: 3;
  overflow: hidden;
  pointer-events: none;
  border-radius: var(--radius);
  background: radial-gradient(60% 50% at 50% 55%, rgb(255 253 247 / 0.85), transparent 70%);
  animation: glow 1500ms ease-out forwards;
}
.feather {
  position: absolute;
  left: var(--x);
  bottom: 18%;
  width: 10px;
  height: 26px;
  border-radius: 50% 50% 50% 50% / 70% 70% 30% 30%;
  opacity: 0;
  animation: feather 1300ms ease-out var(--delay) forwards;
}
@keyframes glow { 0% { opacity: 0; } 25% { opacity: 1; } 100% { opacity: 0.2; } }
@keyframes feather {
  0% { opacity: 0; transform: translate(0, 0) rotate(0); }
  20% { opacity: 0.9; }
  100% { opacity: 0; transform: translate(var(--drift), -160px) rotate(var(--turn)); }
}
.reduce-motion .score-float,
.reduce-motion .celebration { display: none; }

/* Settings: a volume slider with a comfortable 44px touch area. */
.setting--range { display: grid; gap: 4px; }
.setting--range input[type="range"] {
  width: 100%;
  min-height: 44px;
  margin: 0;
  accent-color: var(--leaf);
  cursor: pointer;
}
.setting--range input[type="range"]:disabled { opacity: 0.45; cursor: not-allowed; }

/* How to Play */
.prose h2.first { margin-top: 0; }
.steps--plain { list-style: none; padding-left: 0; }
.keys { display: grid; gap: 8px; margin: 12px 0; }
.keys div { display: grid; grid-template-columns: minmax(120px, auto) 1fr; gap: 12px; align-items: baseline; }
.keys dt { font-weight: 700; }
.keys dd { margin: 0; color: var(--bark-soft); }
kbd {
  display: inline-block;
  min-width: 1.8em;
  padding: 1px 6px;
  border: 1px solid var(--rim);
  border-bottom-width: 2px;
  border-radius: 6px;
  background: var(--paper);
  font: 700 0.85rem/1.4 var(--font);
  text-align: center;
  color: var(--bark);
}

/* ---------- Install and updates ---------- */

.update-banner {
  position: fixed;
  z-index: 100;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(calc(100% - 24px), 440px);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--paper);
  border: 2px solid var(--rim);
  box-shadow: 0 12px 36px rgb(47 42 32 / 0.28);
  color: var(--bark);
  font-weight: 600;
}
.update-banner[hidden] { display: none; }
.update-actions { display: flex; gap: 8px; }
#btn-install[hidden] { display: none; }

/* During play, a downward swipe must not trigger Android's pull-to-refresh
   (or iOS rubber-banding) and yank the board. */
html:has(body[data-screen="game"]),
body[data-screen="game"] { overscroll-behavior: none; }
.setting-note { margin: 8px 0 0; }
