/* Google Sans Flex is Google's open-source Material 3 Expressive face. The
   shipped file is the full variable font with roundness pinned to 100 (the
   soft, bouncy end of the ROND axis) and weight and optical size left live,
   so headings, body copy and numerals share one rounded voice. It keeps
   Latin-1 and Latin Extended-A so accented English, Spanish, French and
   German copy stays in the same face instead of falling back. */
@font-face {
  font-family: "Google Sans Flex";
  src: url("../fonts/google-sans-flex.woff2?v=5.0.2") format("woff2");
  font-weight: 100 1000;
  font-style: normal;
  font-display: swap;
}

/* Noto Sans Script families, subset to the glyphs used by each catalog. They
   sit behind Google Sans Flex in the locale-specific stacks below, so Latin
   brand names keep the app face while CJK, Devanagari and Arabic use a face
   designed for the script. All are OFL; see fonts/OFL-Noto.txt. */
@font-face {
  font-family: "Sixfold SC";
  src: url("../fonts/sixfold-sc.woff2?v=5.1.4") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Sixfold TC";
  src: url("../fonts/sixfold-tc.woff2?v=5.1.4") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Sixfold JP";
  src: url("../fonts/sixfold-jp.woff2?v=5.1.4") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Sixfold KR";
  src: url("../fonts/sixfold-kr.woff2?v=5.1.4") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Sixfold Devanagari";
  src: url("../fonts/sixfold-devanagari.woff2?v=5.1.4") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Sixfold Kannada";
  src: url("../fonts/sixfold-kannada.woff2?v=5.1.4") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Sixfold Arabic";
  src: url("../fonts/sixfold-arabic.woff2?v=5.1.4") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Sixfold Arabic Digits";
  src: url("../fonts/sixfold-arabic-digits.woff2?v=5.1.4") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0660-0669;
}
@font-face {
  font-family: "Sixfold Devanagari Digits";
  src: url("../fonts/sixfold-devanagari-digits.woff2?v=5.1.4") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0966-096F;
}

:root {
  --font-ui: "Google Sans Flex", ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  /* One family for display, UI and numeric labels. The locale blocks below add
     only the script fallbacks needed for glyphs Google Sans Flex does not ship. */
  color-scheme: light;

  /* page chrome — one flat colour, identical to the manifest and theme-color,
     so the phone's own status bar and navigation bar blend into the page */
  --page: #f6f1e8;
  --panel: #e4d9c7;
  --cell: rgba(255, 255, 255, 0.55);
  --ink: #3b3833;
  --muted: #6f665a;
  /* Used on the denser result card, where the regular muted tone is just
     below a comfortable reading contrast. */
  --muted-strong: #5b5348;
  --card: rgba(255, 255, 255, 0.8);
  --card-shadow: 0 1px 2px rgba(94, 76, 45, 0.1), 0 0 0 1px rgba(255, 255, 255, 0.7) inset;
  --ghost-bg: rgba(255, 255, 255, 0.75);
  --ghost-shadow: 0 1px 2px rgba(94, 76, 45, 0.12), 0 0 0 1px rgba(255, 255, 255, 0.8) inset;
  --btn-bg: #3b3833;
  --btn-ink: #fdfbf7;
  --btn-shadow: 0 8px 18px -10px rgba(59, 56, 51, 0.9);
  --board-shadow: 0 1px 0 rgba(255, 255, 255, 0.65) inset, 0 14px 30px -18px rgba(88, 66, 34, 0.55);
  --overlay: #f6f1e8db;
  --sheet-bg: #fbf7f0;
  /* The near-full warning stays red regardless of the tile palette. */
  --warn: #c94b35;
  --line: rgba(94, 76, 45, 0.12);
  --seg-bg: rgba(255, 255, 255, 0.6);

  /* tile colours — "Warm", the default palette */
  --t2: #f3ecdf;
  --t4: #f0e3c8;
  --t8: #efb07a;
  --t16: #ee9563;
  --t32: #ec7c55;
  --t64: #e85f3b;
  --t128: #e7c364;
  --t256: #e3b94a;
  --t512: #dcab30;
  --t1024: #cf9822;
  --t2048: #b9801a;

  /* Collection accents — one colour per cover piece, in cover order. */
  --g1: #e85f3b;
  --g2: #e3a92f;
  --g3: #8bbd54;
  --g4: #39a9a1;
  --g5: #5b8fd5;
  --g6: #9a6bb5;
  --six-1: var(--g1);
  --six-2: var(--t8);
  --six-3: var(--t256);
  --six-4: var(--g3);
  --six-5: var(--g4);
  --six-6: var(--g5);

  --ink-tile-low: #857a6b;
  --ink-tile-high: #fdfbf7;

  --pad: clamp(8px, 2.4vw, 13px);
  --gap: clamp(7px, 2vw, 11px);
}

html[lang="zh-Hans"] {
  --font-ui: "Google Sans Flex", "Sixfold SC", ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}
html[lang="zh-Hant"] {
  --font-ui: "Google Sans Flex", "Sixfold TC", ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}
html[lang="ja"] {
  --font-ui: "Google Sans Flex", "Sixfold JP", ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}
html[lang="ko"] {
  --font-ui: "Google Sans Flex", "Sixfold KR", ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}
html[lang="hi"] {
  --font-ui: "Google Sans Flex", "Sixfold Devanagari", "Sixfold Devanagari Digits", ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}
html[lang="kn"] {
  --font-ui: "Google Sans Flex", "Sixfold Kannada", ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}
html[lang="ar"] {
  --font-ui: "Google Sans Flex", "Sixfold Arabic", "Sixfold Arabic Digits", ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

/* Arabic joins letters; added tracking pulls the joins apart and reads as a
   rendering fault. Let the script set its own rhythm. */
html[lang="ar"] * { letter-spacing: normal !important; }

html[data-theme="dark"] {
  color-scheme: dark;
  --page: #1a1918;
  --panel: #302b25;
  --cell: rgba(255, 255, 255, 0.06);
  --ink: #f1eae0;
  --muted: #a2988a;
  --muted-strong: #b9afa1;
  --card: rgba(255, 255, 255, 0.07);
  --card-shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.07) inset;
  --ghost-bg: rgba(255, 255, 255, 0.09);
  --ghost-shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.08) inset;
  --btn-bg: #f1eae0;
  --btn-ink: #23211e;
  --btn-shadow: 0 8px 18px -10px rgba(0, 0, 0, 0.9);
  /* A crisp one-pixel hairline (zero blur) so the board reads as an object on
     the flat near-black page without bringing back any glow. */
  --board-shadow: 0 0 0 1px color-mix(in srgb, var(--ink) 16%, transparent), 0 1px 0 rgba(255, 255, 255, 0.06) inset, 0 16px 34px -20px rgba(0, 0, 0, 1);
  --overlay: #181715db;
  --sheet-bg: #24211d;
  /* A lighter red keeps the dot legible on a dark page. */
  --warn: #ff9b84;
  --line: rgba(255, 255, 255, 0.1);
  --seg-bg: rgba(255, 255, 255, 0.08);
}

* { box-sizing: border-box; }

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

html {
  height: 100%;
  overflow: hidden;
  background-color: var(--page);
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* The bundled face carries an fi/fl ligature that renders the i without its
   dot, so "finish" reads as "finſh". The copy is short UI text; the joined
   forms buy nothing and are not worth a broken letter. */
body {
  font-variant-ligatures: none;
}

body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  display: flex;
  /* The wordmark sits at the top left; the board and controls keep their
     balanced place in the space below it. */
  align-items: stretch;
  justify-content: center;
  /* Keep the content clear of the phone's system bars while the page colour
     fills the rest of the available screen. */
  padding: calc(var(--sa-top) + 22px) calc(var(--sa-right) + 16px) calc(var(--sa-bottom) + 18px) calc(var(--sa-left) + 16px);
  background-color: var(--page);
  color: var(--ink);
  font-family: var(--font-ui);
  font-weight: 500;
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
  /* No fade on the page colour: the phone's bar is repainted at the same moment,
     so a slow fade would read as the bar lagging behind the palette. */
  transition: color 160ms var(--ease-out);
}

/* A soft sheen behind the board, tinted by the chosen palette. It fades out well
   before every edge, so the top and bottom of the page stay exactly --page and the
   phone's own bars blend in. */
body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

body::before {
  background: radial-gradient(64% 48% at 50% 40%, rgba(255, 255, 255, 0.4), rgba(255, 255, 255, 0) 74%);
}

body::after {
  background: radial-gradient(68% 50% at 50% 44%, color-mix(in srgb, var(--panel) 44%, transparent), transparent 74%);
}

/* On a near-black page the broad tinted sheen reads as a cheap glow around the
   whole board, so dark mode drops it and keeps one flat page colour. The light
   theme keeps its soft highlight, where it reads as paper rather than a glow. */
html[data-theme="dark"] body::before,
html[data-theme="dark"] body::after {
  display: none;
}

.app {
  position: relative;
  z-index: 1;
  width: min(100%, 460px);
  display: flex;
  flex-direction: column;
  gap: clamp(10px, 2.2dvh, 22px);
}

/* ---------- header ---------- */

.header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

h1 {
  margin: 0;
  font-family: var(--font-ui);
  font-size: clamp(30px, 8.2vw, 38px);
  font-weight: 700;
  letter-spacing: 0.018em;
  line-height: 0.95;
  text-transform: uppercase;
}

.sub {
  margin: 6px 0 0;
  font-size: 12px;
  line-height: 1.35;
  color: var(--muted);
  max-width: 21ch;
}

.scores {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  /* Even and fixed, so the row keeps its shape as the numbers grow. */
  width: 180px;
  flex: none;
}

.score {
  min-width: 0;
  padding: 7px 8px 6px;
  border-radius: 10px;
  background: var(--card);
  box-shadow: var(--card-shadow);
  text-align: center;
}

.label {
  display: block;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.value {
  display: block;
  margin-top: 1px;
  font-size: 17px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

/* Five or six digits fit the same card by dropping a size, never by widening it. */
.value.is-long { font-size: 14px; }
.value.is-longer { font-size: 11.5px; }

/* A new personal best: the Best card pops once. The ring that used to travel
   through box-shadow repainted the card every frame; the pop alone is
   composited. */
@keyframes recordPop {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.18); }
  100% { transform: scale(1); }
}

.score.is-record .value { animation: recordPop 360ms cubic-bezier(0.2, 0.8, 0.2, 1); }

html[data-motion="reduced"] .score.is-record,
html[data-motion="reduced"] .score.is-record .value,
html[data-motion="reduced"] .hint.is-warning { animation: none; }

/* ---------- board ---------- */

.board {
  position: relative;
  width: min(100%, 70dvh);
  margin-inline: auto;
  aspect-ratio: 1 / 1;
  padding: var(--pad);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: var(--board-shadow);
  /* Let a two-finger pinch reach the browser for zoom, while single-finger
     swipes still go to the game. */
  touch-action: pinch-zoom;
}

.board:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--ink) 72%, transparent);
  outline-offset: 4px;
}

.grid,
.tiles {
  position: absolute;
  inset: var(--pad);
}

.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: var(--gap);
}

.cell {
  background: var(--cell);
  border-radius: 10px;
}

.tiles { pointer-events: none; }

.tile {
  position: absolute;
  top: 0;
  left: 0;
  border-radius: 10px;
  transition: transform 110ms cubic-bezier(0.25, 0.8, 0.35, 1);
  /* A merge or new tile is scaled on its face. Clipping the tile cell keeps
     that little pop inside its own square instead of covering the gap or
     the board's edge. */
  overflow: hidden;
}

.tile.instant { transition: none; }
.tiles.is-measuring .tile { transition: none; }

.face {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: inherit;
  font-weight: 800;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  color: var(--ink-tile-high);
  background: var(--t2048);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.28) inset;
}

.tile[data-v="2"] .face    { background: var(--t2); color: var(--ink-tile-low); }
.tile[data-v="4"] .face    { background: var(--t4); color: var(--ink-tile-low); }
.tile[data-v="8"] .face    { background: var(--t8); }
.tile[data-v="16"] .face   { background: var(--t16); }
.tile[data-v="32"] .face   { background: var(--t32); }
.tile[data-v="64"] .face   { background: var(--t64); }
.tile[data-v="128"] .face  { background: var(--t128); }
.tile[data-v="256"] .face  { background: var(--t256); }
.tile[data-v="512"] .face  { background: var(--t512); }
.tile[data-v="1024"] .face { background: var(--t1024); }
.tile[data-v="2048"] .face {
  background: var(--t2048);
  box-shadow: 0 0 0 2px rgba(255, 240, 200, 0.5) inset, 0 1px 0 rgba(255, 255, 255, 0.3) inset;
}

@keyframes appear {
  from { transform: scale(0.25); opacity: 0; }
  72%  { transform: scale(1.03); opacity: 1; }
  to   { transform: scale(1); opacity: 1; }
}

@keyframes bump {
  0%   { transform: scale(1); }
  45%  { transform: scale(1.08); }
  100% { transform: scale(1); }
}

.face.appear { animation: appear 150ms cubic-bezier(0.2, 0.9, 0.3, 1) both; }
.face.bump   { animation: bump 160ms ease-out; }

/* ---------- overlay ---------- */

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  border-radius: 16px;
  background: var(--overlay);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  animation: fade 180ms ease-out;
}

.overlay[hidden] { display: none; }

@keyframes fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.overlay-card {
  width: min(100%, 280px);
  padding: 18px 16px 16px;
  border-radius: 16px;
  text-align: center;
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  box-shadow: 0 20px 42px -26px rgba(0, 0, 0, 0.6), 0 0 0 1px color-mix(in srgb, var(--ink) 7%, transparent) inset;
}

.overlay-card h2 {
  margin: 0;
  font-size: 24px;
  letter-spacing: -0.02em;
}

/* The picture is the same file Share sends, kept small enough that the whole
   card still fits a short phone screen. */
.result-top {
  display: flex;
  align-items: center;
  gap: clamp(9px, 2.6vw, 12px);
}

.result-summary {
  flex: 1;
  min-width: 0;
}

.result-preview {
  flex: none;
  width: clamp(70px, 19vw, 80px);
  margin: 0;
}

/* Tall portrait phones have room for a clearer thumbnail; the shortest
   screens keep the compact size above. */
@media (min-height: 720px) and (min-width: 360px) and (max-width: 500px) {
  .result-preview {
    width: clamp(80px, 23vw, 92px);
  }
}

.result-preview[hidden] { display: none; }

.result-thumb {
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border-radius: 10px;
  background: var(--page);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--ink) 10%, transparent), 0 7px 16px -10px rgba(0, 0, 0, 0.45);
}

.result-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.result-thumb img[hidden] { display: none; }

/* A new theme's thumbnail fades in only after it is decoded, so the old one
   never disappears while the picture is being prepared. */
.result-thumb img.is-fresh { animation: previewIn 180ms ease-out; }

@keyframes previewIn {
  from { opacity: 0.35; }
  to   { opacity: 1; }
}

.result-preview figcaption {
  margin-top: 5px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: center;
}

.overlay-card p {
  margin: 0;
  font-size: 13px;
  line-height: 1.4;
  color: var(--muted-strong);
}

/* The finished round at a glance: big score, then size, moves and best. */
#overlay-score {
  margin-top: 3px;
  font-size: 34px;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

#overlay-meta {
  margin-top: 2px;
  font-size: 11.5px;
}

#overlay-text {
  margin-top: 7px;
  font-size: 12.5px;
}

.overlay-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 15px;
}

.overlay-actions .btn {
  padding: 10px 16px;
  font-size: 13.5px;
}

.overlay-actions [hidden] { display: none; }

/* An image of this card, kept under the two main choices. Small and quiet —
   Share already sends the picture where the phone allows it. */
.overlay-save {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  margin: 5px auto 0;
  padding: 0 10px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--muted-strong);
  font: inherit;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.01em;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.overlay-save:hover { color: var(--ink); }
.overlay-save[hidden] { display: none; }
.overlay-save:disabled { opacity: 0.65; cursor: default; }

/* ---------- footer ---------- */

.footer {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.controls #new-game { flex: 1; }

/* Tip, last result and the desktop keyboard cue travel together, so the
   landscape side column can centre them in its open middle. */
.status {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

/* The tip and the result shortcut share one fixed-height line. Keeping the
   line's height stable means opening or closing the result card never moves
   the board. */
.status-line {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 44px;
}

/* A quiet way back to the last result once its card has been put away. */
.result-again {
  position: relative;
  flex: none;
  height: 30px;
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 11px;
  line-height: 1;
  white-space: nowrap;
}

/* Keep a full-size tap target without making the visible chip taller. */
.result-again::after {
  content: "";
  position: absolute;
  inset: -7px -4px;
  border-radius: inherit;
}

.result-again[hidden] { display: none; }
.result-again.is-veiled { visibility: hidden; }

.sheet-block {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.sheet-block[hidden] { display: none; }

.sheet-block .sheet-label {
  margin-top: 0;
}

.install-btn {
  width: 100%;
  margin-top: 10px;
}

.hint {
  align-self: center;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 1 auto;
  min-width: 0;
  max-width: 100%;
  margin: 0;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 11.5px;
  line-height: 1.35;
  color: var(--muted);
  text-align: center;
  transition: color 200ms var(--ease-out), background-color 200ms var(--ease-out);
}

/* The near-full heads-up: a red warning pill, deliberately independent of
   the tile palette. It keeps its height in both states, so nothing moves. */
.hint.is-warning {
  color: var(--ink);
  font-weight: 700;
  background: color-mix(in srgb, var(--warn) 15%, transparent);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--warn) 30%, transparent) inset;
  animation: hintIn 240ms ease-out;
}

.hint.is-warning::before {
  content: "";
  width: 6px;
  height: 6px;
  flex: none;
  border-radius: 50%;
  background: var(--warn);
}

/* A small pointer-and-keyboard cue for the desktop layout. Hidden everywhere
   else, where the board is touched directly. */
.key-hint { display: none; }

.keycaps {
  display: inline-flex;
  gap: 4px;
}

.keycaps kbd {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: var(--ghost-bg);
  box-shadow: var(--ghost-shadow);
  color: var(--ink);
  font: inherit;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}

.version-note {
  margin-top: 14px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.08em;
}

@keyframes hintIn {
  from { transform: scale(0.94); opacity: 0.65; }
  to   { transform: scale(1); opacity: 1; }
}

.btn {
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  min-height: 44px;
  border: 0;
  border-radius: 11px;
  padding: 12px 20px;
  color: var(--btn-ink);
  background: var(--btn-bg);
  box-shadow: var(--btn-shadow);
  transition: transform 120ms var(--ease-out), opacity 150ms var(--ease-out);
  cursor: pointer;
}

.btn,
.seg button,
.palette,
.sheet-done { touch-action: manipulation; }

.btn:active { transform: translateY(1px) scale(0.985); }

/* Native-feeling press response on the small controls too. */
.seg button,
.palette,
.sheet-done { transition: transform 120ms var(--ease-out); }

.seg button:active,
.palette:active,
.sheet-done:active { transform: scale(0.97); }

/* A visible keyboard focus ring; taps don't show it. */
button:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--ink) 72%, transparent);
  outline-offset: 2px;
}

.btn.ghost {
  color: var(--ink);
  background: var(--ghost-bg);
  box-shadow: var(--ghost-shadow);
}

.btn.icon {
  width: 44px;
  height: 44px;
  padding: 0;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 12px;
}

.btn.icon svg {
  width: 21px;
  height: 21px;
  display: block;
}

/* The browser's native fullscreen resize is outside the page's control. Step
   the content back under a short fade, settle at the new size, then bring it
   back, so the board never snaps between two viewport layouts. */
html[data-motion="full"] .app {
    transition: opacity 160ms var(--ease-out), transform 240ms var(--ease-out);
  }

.btn.icon .slash { display: none; }
.btn.icon.is-off { color: var(--muted); }
.btn.icon.is-off .waves { display: none; }
.btn.icon.is-off .slash { display: block; }

/* ---------- appearance sheet ---------- */

html.sheet-open,
html.sheet-open body { overflow: hidden; }

.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet[hidden] { display: none; }

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(18, 16, 13, 0.44);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  animation: fade 160ms ease-out;
}

.sheet-card {
  position: relative;
  width: min(100%, 460px);
  max-height: calc(100dvh - var(--sa-top) - 16px);
  overflow-y: auto;
  /* `none`, not `contain`: the card must not hand the edge gesture to the page
     behind it, and it must not paint the WebView's own stretch over its copy
     either. The sheet slides; it does not deform. */
  overscroll-behavior: none;
  padding: 0 18px calc(var(--sa-bottom) + 20px);
  border-radius: 20px 20px 0 0;
  background: var(--sheet-bg);
  color: var(--ink);
  box-shadow: 0 -14px 44px -20px rgba(0, 0, 0, 0.6);
  animation: rise 220ms cubic-bezier(0.2, 0.9, 0.3, 1);
}

@keyframes rise {
  from { transform: translateY(16px); opacity: 0.6; }
  to   { transform: none; opacity: 1; }
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

/* A long panel (Look & feel is taller than a phone viewport) used to scroll its
   own Done button out of reach. Inside a sheet card the head travels with the
   top edge and paints over the copy that slides beneath it, so the way out is
   always visible; the card's own top padding moved into the head with it. It is
   kept as slim as a native app bar and fades into the copy below, so it reads
   as chrome instead of a band covering the settings. */
.sheet-card > .sheet-head {
  position: sticky;
  top: 0;
  z-index: 2;
  margin: 0 -18px;
  padding: 12px 18px 9px;
  background: var(--sheet-bg);
  /* The head travels with the top edge. A square head painted over the card's
     rounded top looked like the corners had gone flat as soon as the sheet
     scrolled to a colour control. */
  border-radius: 12px 12px 0 0;
}

.sheet-card > .sheet-head::after {
  content: "";
  position: absolute;
  top: 100%;
  right: 0;
  left: 0;
  height: 10px;
  pointer-events: none;
  background: linear-gradient(var(--sheet-bg), transparent);
}

.sheet-head h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: -0.02em;
}

.sheet-done {
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 9px;
  padding: 0 16px;
  color: var(--btn-ink);
  background: var(--btn-bg);
  cursor: pointer;
}

.sheet-label {
  margin: 20px 0 8px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  background: var(--seg-bg);
  box-shadow: var(--ghost-shadow);
}

/* Four language names do not fit comfortably on one 320px row. Two columns
   keep every label on one line without shrinking the tap targets. */
.seg--languages {
  grid-auto-flow: row;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.seg button {
  min-width: 0;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  padding: 9px 4px;
  overflow-wrap: anywhere;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.seg button[aria-pressed="true"] {
  background: var(--panel);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
}

html[data-theme="dark"] .seg button[aria-pressed="true"] {
  background: rgba(255, 255, 255, 0.16);
}

.palettes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.palette {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  padding: 11px 4px 9px;
  border: 0;
  border-radius: 12px;
  background: var(--seg-bg);
  box-shadow: var(--ghost-shadow);
  color: var(--ink);
  font: inherit;
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
}

.palette[aria-pressed="true"] {
  box-shadow: 0 0 0 2px var(--ink) inset;
}

.swatches { display: flex; }

.swatches span {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  margin-left: -4px;
  box-shadow: 0 0 0 1.5px var(--sheet-bg);
}

.swatches span:first-child { margin-left: 0; }

.sheet-note {
  margin: 8px 0 0;
  font-size: 11px;
  line-height: 1.35;
  color: var(--muted);
}

.contact-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  margin-top: 9px;
  padding: 0 14px;
  border: 0;
  border-radius: 10px;
  background: var(--seg-bg);
  box-shadow: var(--ghost-shadow);
  color: var(--ink);
  font: inherit;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  touch-action: manipulation;
  transition: transform 120ms var(--ease-out);
}

.contact-link:active { transform: scale(0.98); }

/* A link inside a sentence stays a sentence: the chip's 44px height and its
   own margins broke the release-notes line into three pieces. */
.contact-link--inline {
  display: inline;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  box-shadow: none;
  color: var(--ink);
  font-size: inherit;
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.contact-link--inline:active { transform: none; }

.contact-link:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--ink) 72%, transparent);
  outline-offset: 2px;
}

/* ---------- how to play ---------- */

/* Numbered like little tiles, so the three ideas are easy to take in at a glance. */
.steps {
  counter-reset: step;
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.steps li {
  counter-increment: step;
  position: relative;
  padding-inline-start: 30px;
  font-size: 13px;
  line-height: 1.45;
}

.steps li::before {
  content: counter(step);
  position: absolute;
  inset-inline-start: 0;
  top: 1px;
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: var(--seg-bg);
  box-shadow: var(--ghost-shadow);
  font-size: 11px;
  font-weight: 800;
}

@media (max-height: 620px) {
  .sub { display: none; }
  .app { gap: 10px; }
}

/* Small phones: slimmer cards, and if long numbers still don't fit beside the
   title the three cards drop onto their own line (right aligned) instead of
   pushing the page sideways. */
@media (max-width: 380px) {
  /* A little more room beside the result card so its 44px controls fit. */
  .overlay { padding: 12px; }
  .score { padding: 6px 7px 5px; }
  .value { font-size: 15px; }
  .value.is-long { font-size: 13.5px; }
  .value.is-longer { font-size: 11px; }
  .header { flex-wrap: nowrap; gap: 8px; }
  .scores { width: 150px; gap: 5px; margin-left: auto; }
  .sub { font-size: 11.5px; }
  #new-game { padding: 12px 10px; }
}

/* Long localized stat names (Spanish "Movimientos", German labels) need the
   full row width on phones. The three cards drop below the title rather than
   overflowing the header or clipping a word. */
@media (max-width: 480px) {
  .header { flex-wrap: wrap; }
  .scores { width: 100%; margin-top: 6px; margin-left: 0; }
  .label { font-size: 8.5px; letter-spacing: 0.08em; }
}

/* Keep every control at a comfortable native-sized 44px target on the
   narrowest phones by tightening the gaps instead of shrinking the buttons. */
@media (max-width: 340px) {
  .controls { gap: 5px; }
  #new-game { padding: 12px 8px; }
}

/* Only the title block moves: the board and controls stay balanced in the room
   between the header and the bottom of the screen. */
@media (orientation: portrait) {
  .board { margin-top: auto; }
  .footer { margin-bottom: auto; }
}

/* ---------- landscape ---------- */

/* Board on the left, title and controls stacked beside it, so a short screen
   never has to scroll or squeeze the board. */
@media (orientation: landscape) {
  body {
    align-items: center;
    padding: calc(var(--sa-top) + 8px) calc(var(--sa-right) + 14px) calc(var(--sa-bottom) + 8px) calc(var(--sa-left) + 14px);
  }

  .app {
    width: min(100%, 880px);
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto auto;
    grid-template-areas:
      "board header"
      "board footer";
    align-content: center;
    align-items: center;
    gap: 10px 20px;
  }

  .board {
    grid-area: board;
    width: min(48vw, 86dvh);
    margin-inline: 0;
  }

  .header { grid-area: header; align-self: end; }
  .footer { grid-area: footer; align-self: start; }

  /* The settings sheet becomes a centred dialog instead of a tall bottom sheet. */
  .sheet { align-items: center; }
  .sheet-card {
    border-radius: 20px;
    max-height: min(calc(100dvh - var(--sa-top) - 20px), 780px);
  }
}

@media (orientation: landscape) and (max-height: 620px) {
  .sub { display: none; }
}

/* Narrow landscape phones can squeeze the New game label until it breaks into
   two lines. Keep the row compact before falling back to the stacked layout
   below. */
@media (orientation: landscape) and (max-width: 760px) {
  .controls { gap: 5px; }
  .controls #new-game {
    padding-inline: 10px;
    font-size: 13px;
    white-space: nowrap;
  }
}

/* Only the shortest landscape phones need the text button on its own row. */
@media (orientation: landscape) and (max-height: 320px) {
  .controls {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 44px));
    gap: 6px;
    justify-content: start;
  }

  .controls .btn.icon { width: 100%; }

  .controls #new-game {
    grid-column: 1 / -1;
    width: 100%;
    min-width: 0;
    padding-inline: 10px;
  }
}

html[data-motion="reduced"] .tile { transition-duration: 0.01ms; }

html[data-motion="reduced"] .face.appear,
html[data-motion="reduced"] .face.bump { animation-duration: 0.01ms; }

html[data-motion="reduced"] .overlay,
html[data-motion="reduced"] .sheet-backdrop,
html[data-motion="reduced"] .sheet-card { animation: none; }

html[data-motion="reduced"] .result-thumb img.is-fresh { animation: none; }

html[data-motion="reduced"] .btn,
html[data-motion="reduced"] .seg button,
html[data-motion="reduced"] .palette,
html[data-motion="reduced"] .sheet-done { transition-duration: 0.01ms; }

/* ---------- motion system ---------- */

/* One set of curves and durations keeps every surface moving at the same
   cadence: quick feedback on taps, a soft settle on layout changes. */
:root {
  --ease-out: cubic-bezier(0.22, 0.61, 0.36, 1);
  --ease-spring: cubic-bezier(0.22, 1, 0.36, 1);
  /* Material 3's emphasized pair for a surface that crosses the screen edge:
     decelerate on the way in, accelerate on the way out. */
  --ease-emphasized-in: cubic-bezier(0.05, 0.7, 0.1, 1);
  --ease-emphasized-out: cubic-bezier(0.3, 0, 0.8, 0.15);
  --motion-fast: 140ms;
  --motion-base: 240ms;
  --motion-slow: 380ms;
}

/* The page colour is not faded: it lands in the same frame as the system bar,
   which has no transition of its own. A running background transition on these
   full-page layers is what could leave the WebView on the previous — or an
   in-between — colour after a switch. The content on top still cross-fades. */
body {
  transition: color 180ms var(--ease-out);
}

.board {
  transition: background-color var(--motion-slow) var(--ease-out);
}

.score {
  transition: background-color var(--motion-base) var(--ease-out);
}

.cell {
  transition: background-color var(--motion-base) var(--ease-out);
}

.tile {
  transition: transform 150ms var(--ease-out);
  backface-visibility: hidden;
}

.face {
  transition: background-color var(--motion-base) var(--ease-out), color 200ms var(--ease-out);
}

/* The board itself lifts in after the launch screen, rather than appearing
   underneath it with a hard cut. */
html[data-motion="full"].app-ready .header {
    animation: appRise 480ms var(--ease-out) 40ms both;
  }

html[data-motion="full"].app-ready .board {
    animation: boardReveal 560ms var(--ease-out) 80ms both;
  }

html[data-motion="full"].app-ready .footer {
    animation: appRise 480ms var(--ease-out) 150ms both;
  }

@keyframes appRise {
  from { opacity: 0; transform: translateY(7px); }
  to   { opacity: 1; transform: none; }
}

@keyframes boardReveal {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

/* Tiles land with a little more give, so a fast swipe feels physical rather
   than like four independent snap changes. */
@keyframes appear {
  0%   { transform: scale(0.55); opacity: 0; }
  72%  { transform: scale(1.035); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes bump {
  0%   { transform: scale(1); }
  42%  { transform: scale(1.12); }
  100% { transform: scale(1); }
}

.face.appear { animation: appear 190ms var(--ease-spring) both; }
.face.bump   { animation: bump 200ms var(--ease-spring); }

/* A gained score gets a quiet pulse; the Best card keeps its own record
   flourish so the two celebrations never compete. */
@keyframes scoreTick {
  0%   { transform: scale(1); }
  38%  { transform: scale(1.09); }
  100% { transform: scale(1); }
}

.score:not(.is-record).is-scoring .value {
  animation: scoreTick 260ms var(--ease-spring);
}

.hint {
  transition: color 200ms var(--ease-out), background-color var(--motion-base) var(--ease-out), transform 180ms var(--ease-out);
}

.hint.is-warning {
  animation: hintIn 260ms var(--ease-spring);
}

.btn {
  transition: transform var(--motion-fast) var(--ease-out), opacity 160ms var(--ease-out), background-color var(--motion-base) var(--ease-out), color var(--motion-base) var(--ease-out);
}

.seg button,
.palette,
.sheet-done,
.contact-link {
  transition: transform var(--motion-fast) var(--ease-out), background-color var(--motion-base) var(--ease-out), color var(--motion-base) var(--ease-out);
}

/* Result card: fade the dimmer, then let the card settle in from a small
   lift. The same path runs in reverse while it closes. */
.overlay {
  animation: none;
  opacity: 0;
  transition: opacity 220ms var(--ease-out);
}

.overlay.is-open {
  opacity: 1;
}

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

.overlay-card {
  opacity: 0;
  transform: translateY(10px) scale(0.97);
  transition: opacity 220ms var(--ease-out), transform 300ms var(--ease-spring), background-color var(--motion-base) var(--ease-out);
}

.overlay.is-open .overlay-card {
  opacity: 1;
  transform: none;
}

.overlay.is-closing .overlay-card {
  opacity: 0;
  transform: translateY(8px) scale(0.985);
  transition-duration: 180ms;
}

/* Sheets use the same language: a soft scrim and a card that rises, then
   leaves the same way instead of disappearing between frames. The blur is
   kept out of the opacity transition: a backdrop-filter inside a fading
   layer is rasterised late on phone GPUs, which made the sheet look as if it
   was waiting a beat before it blurred. The scrim is fully painted on open;
   only the card enters, and the scrim fades on close. */
.sheet {
  opacity: 1;
  visibility: hidden;
}

.sheet.is-open,
.sheet.is-closing {
  opacity: 1;
  visibility: visible;
}

.sheet.is-closing {
  pointer-events: none;
}

.sheet-backdrop {
  animation: none;
  opacity: 0;
  transition: opacity 220ms var(--ease-out);
}

.sheet.is-open .sheet-backdrop {
  opacity: 1;
  transition: none;
}

.sheet.is-closing .sheet-backdrop {
  opacity: 0;
  transition: opacity 220ms var(--ease-out);
}

/* A modal sheet slides: it does not fade, scale or deform. Material's own
   sheets cross the screen edge and keep their surface opaque, and a cross-fade
   made the card look like it was dissolving over the page. The transform-only
   path also means the whole entrance runs on the compositor. */
.sheet-card {
  animation: none;
  transform: translateY(100%);
  transition: transform 300ms var(--ease-emphasized-in), background-color var(--motion-base) var(--ease-out);
}

/* Promote the card only while it is actually travelling; a sheet sitting
   closed in the DOM must not hold a compositor layer. */
.sheet.is-closing .sheet-card {
  will-change: transform;
}

.sheet.is-open .sheet-card {
  transform: none;
}

.sheet.is-closing .sheet-card {
  transform: translateY(100%);
  transition: transform 200ms var(--ease-emphasized-out);
}

html[data-motion="reduced"].app-ready .header,
html[data-motion="reduced"].app-ready .board,
html[data-motion="reduced"].app-ready .footer,
html[data-motion="reduced"] .score:not(.is-record).is-scoring .value {
    animation: none;
  }

html[data-motion="reduced"] .tile,
html[data-motion="reduced"] .face,
html[data-motion="reduced"] .overlay,
html[data-motion="reduced"] .overlay-card,
html[data-motion="reduced"] .sheet,
html[data-motion="reduced"] .sheet-backdrop,
html[data-motion="reduced"] .sheet-card,
html[data-motion="reduced"] .btn,
html[data-motion="reduced"] .seg button,
html[data-motion="reduced"] .palette,
html[data-motion="reduced"] .sheet-done,
html[data-motion="reduced"] .contact-link,
html[data-motion="reduced"] .hint {
    transition-duration: 0.01ms;
  }

html[data-motion="reduced"] .face.appear,
html[data-motion="reduced"] .face.bump,
html[data-motion="reduced"] .hint.is-warning {
  animation: none;
}

/* Reduced removes movement, not every transition: an instant cut is its own
   little jolt, and opacity is not motion. Large surfaces stop lifting and
   sliding; they and their scrims fade in place. */
html[data-motion="reduced"] .overlay,
html[data-motion="reduced"] .sheet-backdrop,
html[data-motion="reduced"] .overlay-card,
html[data-motion="reduced"] .sheet-card {
  transition: opacity 160ms var(--ease-out);
}

/* The open sheet's scrim and the closing states carry more specific transition
   rules. Reduced keeps those surfaces in place but still fades them; without
   these the scrim cut in and the close hid the sheet before its fade ran. */
html[data-motion="reduced"] .sheet.is-open .sheet-backdrop,
html[data-motion="reduced"] .sheet.is-closing .sheet-backdrop,
html[data-motion="reduced"] .sheet.is-open .sheet-card,
html[data-motion="reduced"] .sheet.is-closing .sheet-card,
html[data-motion="reduced"] .overlay.is-closing,
html[data-motion="reduced"] .overlay.is-closing .overlay-card {
  transition: opacity 160ms var(--ease-out);
}

html[data-motion="reduced"] .overlay-card,
html[data-motion="reduced"] .overlay.is-closing .overlay-card,
html[data-motion="reduced"] .sheet-card,
html[data-motion="reduced"] .sheet.is-closing .sheet-card {
  transform: none;
}

/* ---------- desktop ---------- */

/* Wide screens get one calm composition: the wordmark and scores share a
   header line, then the board and its controls sit centred underneath. The
   board is capped so the header and controls always stay in view. */
@media (min-width: 900px) {
  body {
    align-items: center;
    padding: clamp(20px, 4vh, 40px) clamp(32px, 5vw, 64px);
  }

  /* A settings dialog on a desktop does not need the full window height: cap it
     at a comfortable panel so it reads as a dialog, not a second page. */
  .sheet-card { max-height: min(calc(100dvh - 24px), 780px); }

  .app {
    --pad: clamp(12px, 1.15vw, 16px);
    --gap: clamp(9px, 0.95vw, 13px);
    --play-width: min(100%, 63dvh, 600px);
    width: min(100%, 1040px);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: center;
    gap: clamp(16px, 2.4vh, 24px);
  }

  .header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    gap: clamp(28px, 4vw, 56px);
    width: 100%;
  }

  .title-block { min-width: 0; }

  h1 {
    font-size: clamp(42px, 4.2vw, 56px);
    line-height: 0.92;
    letter-spacing: 0.02em;
  }

  .sub {
    margin-top: 9px;
    max-width: 44ch;
    font-size: 14px;
    line-height: 1.45;
  }

  .scores {
    width: clamp(320px, 27vw, 368px);
    gap: 10px;
  }

  .score {
    padding: 11px 13px 10px;
    border-radius: 12px;
    text-align: left;
  }

  .label { font-size: 9.5px; }
  .value { margin-top: 2px; font-size: 22px; }
  .value.is-long { font-size: 18px; }
  .value.is-longer { font-size: 14px; }

  .board {
    width: var(--play-width);
    align-self: center;
    margin: 0;
    border-radius: 22px;
  }

  .grid,
  .tiles { inset: var(--pad); }

  .cell,
  .tile { border-radius: 12px; }

  .footer {
    width: var(--play-width);
    align-self: center;
    display: flex;
    flex-direction: column;
    gap: 9px;
  }

  .controls {
    display: flex;
    gap: 7px;
    width: 100%;
  }

  .controls #new-game {
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
    padding-inline: 12px;
    font-size: 14px;
    white-space: nowrap;
  }

  .btn { min-height: 46px; }

  .btn.icon {
    width: 46px;
    height: 46px;
  }

  .btn.icon svg {
    width: 22px;
    height: 22px;
  }

  .result-again {
    min-width: 0;
    height: 32px;
    min-height: 32px;
    padding: 0 12px;
    border-radius: 999px;
    font-size: 11.5px;
    line-height: 1;
  }

  .hint {
    align-self: center;
    justify-content: center;
    padding: 2px 0;
    text-align: center;
    font-size: 12px;
  }

  .hint.is-warning { padding-inline: 12px; }

  .overlay {
    padding: 28px;
    border-radius: 22px;
  }

  .overlay-card {
    width: min(100%, 360px);
    padding: 24px 22px 20px;
    border-radius: 20px;
  }

  .overlay-card h2 { font-size: 28px; }

  .result-top { gap: 16px; }

  .result-preview { width: 96px; }

  #overlay-score {
    margin-top: 4px;
    font-size: 42px;
  }

  #overlay-meta { font-size: 12px; }
  #overlay-text { font-size: 13.5px; }

  .overlay-card p { font-size: 14px; }

  .overlay-actions {
    gap: 10px;
    margin-top: 20px;
  }

  .overlay-actions .btn {
    min-height: 46px;
    padding: 11px 20px;
    font-size: 14px;
  }

  .overlay-save {
    margin-top: 8px;
    font-size: 12px;
  }

  .sheet {
    align-items: center;
    padding: 24px;
  }

  .sheet-card {
    width: min(100%, 520px);
    max-height: calc(100dvh - 48px);
    padding: 24px 24px 26px;
    border-radius: 24px;
  }

  .sheet-label { margin-top: 22px; }
  .sheet-note { font-size: 12px; line-height: 1.5; }
  .steps li { font-size: 14px; }
}

/* Short desktop windows (including small laptop screens) get a more compact
   header and a slightly smaller board before anything has to scroll. */
@media (min-width: 900px) and (max-height: 760px) {
  body { padding-block: 16px; }

  .app {
    --play-width: min(100%, 58dvh, 520px);
    gap: 12px;
  }

  h1 { font-size: 40px; }
  .sub { font-size: 13px; }
  .scores { width: 340px; }
  .footer { gap: 7px; }
}

/* With very little height, the controls and tip become a single compact row.
   The near-full warning stays visible. */
@media (min-width: 900px) and (max-height: 680px) {
  .sub { display: none; }

  .app { --play-width: min(100%, 52dvh, 460px); }

  .footer {
    width: min(100%, max(320px, var(--play-width)));
    gap: 7px;
  }

  .result-again {
    height: 30px;
    min-height: 30px;
    padding: 0 10px;
    font-size: 11px;
  }

  .controls { gap: 5px; }

  .controls .btn.icon {
    width: 42px;
    height: 42px;
    min-height: 42px;
    border-radius: 11px;
  }

  .controls .btn.icon svg {
    width: 20px;
    height: 20px;
  }

  .controls #new-game {
    min-height: 42px;
    padding-inline: 8px;
    font-size: 13px;
  }

  .hint { padding: 1px 0; }
  .key-hint { font-size: 10.5px; }
}

/* Large monitors get a little more board without loosening the header or
   letting the controls drop below the fold. */
@media (min-width: 1440px) and (min-height: 860px) {
  .app { --play-width: min(100%, 65dvh, 640px); }
}

/* A 1920-class display gets a substantial step up. The footer stays a little
   narrower than the board so the New game bar does not become a huge stripe. */
@media (min-width: 1800px) and (min-height: 1000px) {
  .app { --play-width: min(100%, 68dvh, 840px); }
  .footer { width: min(100%, 720px); max-width: var(--play-width); }
}

/* 1440p and 4K-class displays get the final size step, still comfortably
   inside the header width. */
@media (min-width: 2400px) and (min-height: 1300px) {
  .app { --play-width: min(100%, 68dvh, 960px); }
}

/* Landscapes use the board as the anchor: title and scores at the top of the
   side column, the live tip (or last result) in the open middle, and the
   controls at the bottom. The same rules apply in fullscreen. */
@media (orientation: landscape) {
  body {
    align-items: center;
    padding:
      calc(var(--sa-top) + 10px)
      calc(var(--sa-right) + 14px)
      calc(var(--sa-bottom) + 10px)
      calc(var(--sa-left) + 14px);
  }

  .app {
    width: min(100%, 1440px);
    height: 100%;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas:
      "board header"
      "board footer";
    align-content: stretch;
    align-items: stretch;
    gap: 12px clamp(16px, 2vw, 28px);
  }

  .board {
    grid-area: board;
    width: min(
      48vw,
      calc(100dvh - 32px - var(--sa-top) - var(--sa-bottom)),
      760px
    );
    margin: 0;
    align-self: center;
    justify-self: start;
  }

  .header {
    grid-area: header;
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    align-self: start;
    gap: 8px 16px;
    width: 100%;
  }

  .title-block { min-width: 0; flex: 1 1 190px; }
  .scores { margin-left: auto; }

  .footer {
    grid-area: footer;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
    grid-template-areas:
      "status"
      "controls";
    align-content: stretch;
    align-self: stretch;
    width: 100%;
    min-height: 0;
    gap: 10px;
  }

  .status {
    grid-area: status;
    align-self: center;
    justify-self: stretch;
    width: 100%;
    gap: 12px;
  }

  .controls {
    grid-area: controls;
    width: 100%;
  }

  .hint {
    max-width: min(100%, 46ch);
    padding: clamp(8px, 1.2vh, 12px) clamp(12px, 1.4vw, 18px);
    border-radius: 14px;
    background: var(--card);
    box-shadow: var(--card-shadow);
    font-size: clamp(12.5px, 1.15vw, 15px);
    line-height: 1.45;
    text-align: center;
  }

  .sub { display: block; }

  .sheet { align-items: center; }
  .sheet-card {
    border-radius: 20px;
    max-height: min(calc(100dvh - var(--sa-top) - 20px), 780px);
  }
}

/* Stack the score row beneath the wordmark in the narrower side columns. */
@media (orientation: landscape) and (max-width: 1100px) {
  .header {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
  }
}

/* Keep the result chip in the same line on the shortest landscape screens;
   it adds no height, so the warning and the board stay put. */
@media (orientation: landscape) and (max-height: 345px) {
  .status-line { gap: 6px; }
  .result-again { padding-inline: 10px; font-size: 10.5px; }
}

/* ---------- touch controls ---------- */

/* Fullscreen joins the footer on touch devices. The row stays flexible so
   devices without vibration support do not leave an empty control slot; New
   game only moves to its own line when the width is genuinely tight. */
@media (max-width: 899px) {
  .controls { gap: 6px; }

  .controls #new-game {
    min-width: 0;
    padding-inline: 10px;
    font-size: 13px;
    white-space: nowrap;
  }
}

/* Keep the five icon controls and New game on one row at the common narrow
   phone widths. Only the smallest screens fall back to a second row. */
@media (min-width: 351px) and (max-width: 380px) {
  .controls { flex-wrap: nowrap; gap: 4px; }

  .controls #new-game {
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
    padding-inline: 6px;
    font-size: 12.5px;
  }
}

@media (max-width: 350px) {
  .controls { flex-wrap: wrap; }

  .controls #new-game {
    flex: 1 0 100%;
    width: 100%;
    padding-inline: 10px;
    font-size: 14px;
  }
}

/* The landscape column beside the board can be narrower than the viewport. */
@media (orientation: landscape) and (max-width: 760px) {
  .controls { flex-wrap: wrap; }

  .controls #new-game {
    flex: 1 0 100%;
    width: 100%;
  }
}


/* Only mouse and pen devices get the grab cursor and keyboard cue. Touch
   tablets still use the same layout, with their familiar swipe gesture. */
@media (min-width: 900px) and (pointer: fine) {
  .board { cursor: grab; }
  .board.is-dragging { cursor: grabbing; }

  .key-hint {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
    margin: 1px 0 0;
    color: var(--muted);
    font-size: 11.5px;
    line-height: 1;
  }
}

/* Pointer feedback is intentionally absent on touch screens, where a hover
   state would linger after a tap. */
@media (hover: hover) and (pointer: fine) {
  .btn:hover:not(:active) { transform: translateY(-1px); }

  .btn.ghost:hover {
    background: color-mix(in srgb, var(--ghost-bg) 84%, var(--ink) 8%);
  }

  .btn:not(.ghost):hover {
    box-shadow: 0 12px 24px -12px color-mix(in srgb, var(--ink) 75%, transparent);
  }

  .seg button:not([aria-pressed="true"]):hover,
  .palette:hover {
    background: color-mix(in srgb, var(--seg-bg) 82%, var(--ink) 7%);
  }

  .sheet-done:hover {
    box-shadow: 0 10px 22px -12px color-mix(in srgb, var(--ink) 80%, transparent);
  }

  .overlay-save:hover { text-decoration-thickness: 2px; }
}

