/*
 * Mahjordle, in the colors of the Mahj On! app icon: a pale sky ground, white tiles
 * with jade-green edges, and the icon's jade, aqua, coral and blossom pink. No mat, no
 * texture. Tiles are the app's own art. Light, and a deep-teal night version for dark.
 */
:root {
  --sky: #ebf8fd;           /* the icon's ground */
  --sky-deep: #d6f0f7;
  --porcelain: #ffffff;     /* sheets, tray, buttons: the icon's white tiles */
  --ink: #1f3a2f;
  --muted: #4f6a60;
  --jade: #8fbb64;          /* the icon's lettering (AppPalette.jade); ink on it 7.2:1 */
  --jade-pressed: #779f50;
  --jade-ink: #4a7330;      /* AppPalette.jadeInk: words and outlines on white (5.2:1) */
  --jade-edge: #9cc67d;     /* the icon's tile edges */
  --aqua: #96d6dd;          /* the icon's bamboo and dots */
  --coral: #f6a088;         /* the icon's East wind (AppPalette.walnut) */
  --coral-pressed: #d9866f;
  --pink: #f6b6cb;          /* the icon's plum blossoms */
  --brass: #6fb7c0;         /* accent lines: the icon's aqua, deepened to show on white */
  --brass-light: #ffffff;
  --stone: #8c9c9e;         /* tiles not in the hand */
  --cloth: #ffffff;
  --rack-top: #a6d084;      /* racks: the jade of the icon's tile edges */
  --rack-bottom: #7aa957;
  --mark-g: var(--jade);
  --mark-y: var(--coral);
  --mark-x: var(--stone);
  --slot: rgb(255 255 255 / 0.75);
  --slot-edge: color-mix(in srgb, var(--aqua) 70%, transparent);
  --sheet-shadow: 0 18px 40px -24px rgb(40 110 120 / 0.45), 0 2px 6px -2px rgb(40 110 120 / 0.16);
  --tile-shadow: drop-shadow(0 1.5px 1.5px rgb(50 100 90 / 0.28));
  --serif: Charter, "Bitstream Charter", "Iowan Old Style", "Palatino Linotype", ui-serif, Georgia, serif;
  --sans: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --side: max(8px, env(safe-area-inset-left), env(safe-area-inset-right));
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --sky: #0e2327;
    --sky-deep: #12313a;
    --porcelain: #173339;
    --ink: #eef6f1;
    --muted: #a7c3bd;
    --jade-ink: #a9d27f;
    --jade-pressed: #a3cd7c;
    --brass: #5aa9b3;
    --brass-light: rgb(255 255 255 / 0.55);
    --stone: #55676a;
    --cloth: #12292e;
    --rack-top: #7fae5c;
    --rack-bottom: #4f7f37;
    --slot: rgb(255 255 255 / 0.05);
    --slot-edge: rgb(150 214 221 / 0.28);
    --sheet-shadow: 0 22px 48px -24px rgb(0 0 0 / 0.7);
    --tile-shadow: drop-shadow(0 1.5px 1.5px rgb(0 0 0 / 0.5));
  }
}

body.high-contrast {
  --mark-g: #f5793a;
  --mark-y: #85c0f9;
}

/* --- Base ----------------------------------------------------------------------------- */

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--sky) linear-gradient(180deg, var(--sky) 0%, var(--sky-deep) 100%) fixed;
  color: var(--ink);
  font: 17px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
@media (prefers-color-scheme: dark) {
  body { background-image: radial-gradient(ellipse at 50% 0%, #17393f 0%, var(--sky) 75%); }
}

a { color: var(--jade-ink); text-underline-offset: 0.18em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2.5px solid var(--jade-ink); outline-offset: 2px; border-radius: 6px; }
button { font: inherit; color: inherit; -webkit-tap-highlight-color: transparent; }
img { -webkit-user-drag: none; user-select: none; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}
.skip-link {
  position: absolute; left: 8px; top: -60px; z-index: 20;
  background: var(--porcelain); padding: 8px 14px; border-radius: 10px; box-shadow: var(--sheet-shadow);
}
.skip-link:focus { top: 8px; }

/* --- Header: the name spelled in the home screen's letter tiles ------------------------ */

.game-header {
  width: 100%;
  max-width: 64rem;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) var(--side) 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 6px;
}
.masthead { display: flex; flex-direction: column; align-items: center; }
.title { margin: 0; line-height: 0; }
.title-tiles { display: flex; gap: clamp(1px, 0.45vw, 4px); }
.title-tiles img {
  width: clamp(21px, 6.4vw, 40px);
  height: auto;
  filter: var(--tile-shadow);
  animation: drop-in 0.55s cubic-bezier(0.3, 1.4, 0.5, 1) backwards;
}
.title-tiles img:nth-child(1) { animation-delay: 0.05s; }
.title-tiles img:nth-child(2) { animation-delay: 0.1s; }
.title-tiles img:nth-child(3) { animation-delay: 0.15s; }
.title-tiles img:nth-child(4) { animation-delay: 0.2s; }
.title-tiles img:nth-child(5) { animation-delay: 0.25s; }
.title-tiles img:nth-child(6) { animation-delay: 0.3s; }
.title-tiles img:nth-child(7) { animation-delay: 0.35s; }
.title-tiles img:nth-child(8) { animation-delay: 0.4s; }
.title-tiles img:nth-child(9) { animation-delay: 0.45s; }
.title-tiles img:nth-child(odd) { rotate: -1.5deg; }
.title-tiles img:nth-child(even) { rotate: 1.5deg; translate: 0 1px; }
@keyframes drop-in { from { transform: translateY(-16px); opacity: 0; } }

.tagline {
  display: none;
  margin: 4px 0 0;
  font: italic 500 0.95rem/1.2 var(--serif);
  color: var(--muted);
  letter-spacing: 0.02em;
}
@media (min-height: 780px) { .tagline { display: block; } }

.header-actions { display: flex; gap: 4px; justify-self: end; }
#open-help { justify-self: start; }
.icon-button {
  border: 0; background: none; padding: 3px; cursor: pointer; border-radius: 8px; line-height: 0;
  touch-action: manipulation;
}
.icon-button img { width: clamp(26px, 7vw, 36px); height: auto; filter: var(--tile-shadow); transition: transform 0.15s; }
.icon-button:hover img { transform: translateY(-2px) rotate(-3deg); }
.icon-button:active img { transform: translateY(1px); }

/* --- Game area ------------------------------------------------------------------------ */

.game {
  flex: 1;
  width: 100%;
  max-width: 48rem;
  margin: 0 auto;
  padding: 8px var(--side) max(10px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  --tray: 0px;                         /* the tray's padding, where it shows */
}

.modes {
  display: inline-flex;
  padding: 3px;
  border-radius: 13px;
  background: var(--porcelain);
  box-shadow: 0 3px 0 var(--jade-edge), var(--sheet-shadow);
}
.modes button {
  border: 0;
  background: none;
  padding: 6px 18px;
  border-radius: 10px;
  font-weight: 650;
  font-size: 0.93rem;
  color: var(--muted);
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.2s, color 0.2s;
}
.modes button[aria-selected="true"] { background: var(--jade); color: #17251f; box-shadow: 0 2px 6px -2px rgb(74 115 48 / 0.6); }
.day-chip { margin: 0; align-items: center; gap: 10px; padding: 3px 14px 3px 3px; font-size: 0.93rem; color: var(--muted); }
.day-chip strong { background: var(--jade); color: #17251f; padding: 6px 16px; border-radius: 10px; font-weight: 700; }

/* The board sits on a porcelain tray where there is room for one. */
.tray { display: grid; justify-items: center; }
@media (min-width: 560px) {
  .game { --tray: 12px; }
  .tray {
    padding: var(--tray);
    background: var(--porcelain);
    border-radius: 18px;
    box-shadow: 0 5px 0 var(--jade-edge), var(--sheet-shadow);
  }
}

/* One row of fourteen tiles a guess. Columns line up from row to row. Width is what
   limits a tile in portrait, so the board runs nearly edge to edge with hairline gaps,
   and each tile fills its whole cell. */
.board {
  --gap: clamp(1.5px, 0.35vw, 4px);
  /* Fourteen across the width, and short enough that the board and keyboard fit the
     window together: measured, about 300 px of header, tabs and margins, 8.6 cells for
     the six rows and 7.6 keys for the racked keyboard. */
  --cell: min(
    calc((min(100vw, 48rem) - 2 * var(--side) - 2 * var(--tray) - 6px - 13 * var(--gap)) / 14),
    48px,
    calc((100dvh - 300px) / 19));
  display: grid;
  gap: calc(var(--gap) + 3px);
  padding: 3px;
  outline: none;
}
.row {
  display: grid;
  grid-template-columns: repeat(14, var(--cell));
  gap: var(--gap);
  border-radius: calc(var(--cell) * 0.2);
  outline: 2px solid transparent;
  outline-offset: 2px;
  transition: outline-color 0.3s;
}
.row.same-line { outline-color: var(--jade-ink); }
.row.done { cursor: zoom-in; }
.row.shake { animation: shake 0.4s; }
@keyframes shake {
  20%, 60% { transform: translateX(-5px); }
  40%, 80% { transform: translateX(5px); }
}

.cell {
  position: relative;
  width: var(--cell, 32px);
  aspect-ratio: 244 / 350;
  border-radius: calc(var(--cell, 32px) * 0.15);
  background: var(--slot);
  box-shadow: inset 0 0 0 1px var(--slot-edge);
  display: grid;
}
.cell.next { box-shadow: inset 0 0 0 2px var(--brass); animation: next 1.4s ease-in-out infinite; }
@keyframes next { 50% { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--brass) 35%, transparent); } }
.cell img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: var(--tile-shadow);
}
.cell.filled { box-shadow: none; background: none; }
.cell.typed img { animation: place 0.14s ease-out; }
@keyframes place { from { transform: translateY(-4px) scale(0.88); } }

/* A mark tints the tile itself, cut to the tile's own outline (every face shares the
   blank tile's silhouette), so the tile keeps its full size. Gray tiles go stone. */
.cell::after, .key::after {
  content: "";
  position: absolute;
  inset: 0;
  -webkit-mask: url("assets/tiles/blank.webp") center / contain no-repeat;
  mask: url("assets/tiles/blank.webp") center / contain no-repeat;
  mix-blend-mode: multiply;
  opacity: 0;
  pointer-events: none;
}
.mark-g::after { background: var(--mark-g); opacity: 0.68; }
.mark-y::after { background: var(--mark-y); opacity: 0.72; }
.mark-x::after { background: var(--mark-x); opacity: 0.55; }
.cell.mark-x img, .key.mark-x img { filter: grayscale(1); }

.cell.reveal { animation: flip 0.44s ease-in-out backwards; animation-delay: calc(var(--i) * 70ms); }
@keyframes flip {
  0% { transform: rotateX(0); }
  50% { transform: rotateX(90deg); }
  100% { transform: rotateX(0); }
}
.row.win .cell { animation: hop 0.5s cubic-bezier(0.3, 1.6, 0.5, 1) backwards; animation-delay: calc(var(--i) * 45ms + 1s); }
@keyframes hop { 40% { transform: translateY(-10px); } }

/* With a mouse, a tile on a finished row lifts and grows under the pointer. */
@media (hover: hover) and (pointer: fine) {
  .row.done .cell { transition: transform 0.15s ease-out; }
  .row.done .cell:hover { transform: scale(1.9) translateY(-8%); z-index: 3; }
}

/* --- The keyboard: tiles standing in racks -------------------------------------------- */

.controls { display: grid; gap: 12px; justify-items: center; margin-top: auto; width: 100%; }
.keyboard {
  --kgap: clamp(3px, 0.9vw, 6px);
  --key: min(
    calc((min(100vw, 48rem) - 2 * var(--side) - 16px - 8 * var(--kgap)) / 9),
    54px,
    calc((100dvh - 300px) / 14));
  display: grid;
  gap: calc(var(--kgap) + 2px);
  padding-top: 4px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.key-row { position: relative; display: flex; justify-content: center; gap: var(--kgap); }
.key-row.tiles { padding: 0 6px calc(var(--key) * 0.16); }
/* The rack: ink lacquer, a brass rail catching the light along its top edge. */
.key-row.tiles::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--key) * 0.34);
  border-radius: calc(var(--key) * 0.1);
  background: linear-gradient(180deg, var(--rack-top), var(--rack-bottom));
  box-shadow:
    inset 0 1.5px 0 color-mix(in srgb, var(--brass-light) 75%, transparent),
    inset 0 -2px 0 rgb(0 0 0 / 0.08),
    0 6px 10px -6px rgb(40 90 60 / 0.5);
}
.key {
  position: relative;
  z-index: 1;
  width: var(--key);
  aspect-ratio: 244 / 350;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
  line-height: 0;
  transition: transform 0.08s;
}
.key img { width: 100%; height: 100%; object-fit: contain; filter: var(--tile-shadow); pointer-events: none; }
@media (hover: hover) { .key:hover { transform: translateY(-2px); } }
.key:active { transform: translateY(1px) scale(0.95); }
.key.action {
  width: auto;
  aspect-ratio: auto;
  flex: 1;
  max-width: calc(var(--key) * 4.6);
  height: calc(var(--key) * 0.95);
  line-height: 1;
  border-radius: 14px;
  font-weight: 750;
  font-size: 1rem;
  letter-spacing: 0.02em;
  background: var(--porcelain);
  color: var(--ink);
  box-shadow: var(--sheet-shadow);
}
.key.action::after { content: none; }
.key.back { flex: none; width: calc(var(--key) * 1.5); font-size: 1.15rem; }
.key.enter { background: var(--jade); color: #17251f; box-shadow: 0 6px 14px -6px rgb(74 115 48 / 0.7); }
.key.enter:hover { background: var(--jade-pressed); }

/* A quiet pointer to the app, under the keyboard where a laptop has the room. */
.side-plug {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 8px 14px 8px 8px;
  border-radius: 14px;
  background: color-mix(in srgb, var(--porcelain) 80%, transparent);
  box-shadow: var(--sheet-shadow);
  color: var(--muted);
  text-decoration: none;
  font-size: 0.85rem;
  line-height: 1.3;
}
.side-plug img { border-radius: 8px; flex: none; }
.side-plug strong { display: block; color: var(--ink); font-size: 0.92rem; }
.side-plug:hover strong { color: var(--jade-ink); }

/* Short portrait phones (iPhone SE): the fern border is hidden there, so the height
   caps give the tiles back that room. */
@media (orientation: portrait) and (max-height: 700px) {
  .board { --cell: min(calc((min(100vw, 48rem) - 2 * var(--side) - 6px - 13 * var(--gap)) / 14), calc((100dvh - 218px) / 19)); }
  .keyboard { --key: min(calc((min(100vw, 48rem) - 2 * var(--side) - 16px - 8 * var(--kgap)) / 9), calc((100dvh - 218px) / 14)); }
}

/* Wide windows (phones on their side, laptops, desktops): the board on the left, as
   large as the height allows, and the keyboard beside it. The keyboard is promised keys
   of 30-46 px (3.4vw); the board takes the rest of the width. */
@media (orientation: landscape) and (min-aspect-ratio: 13/10) {
  .game {
    --chrome: 160px;     /* fern border, header and margins above and below the board */
    --colgap: clamp(14px, 3vw, 48px);
    --lgap: clamp(1.5px, 0.3vw, 4px);
    --kgap: clamp(2px, 0.5vw, 5px);
    --kmin: clamp(30px, 3.4vw, 46px);
    --lcell: min(
      calc((100dvh - var(--chrome) - 2 * var(--tray)) / 9.1),
      calc((100vw - 2 * var(--side) - var(--colgap) - 9 * var(--kmin) - 8 * var(--kgap) - 20px - 2 * var(--tray) - 13 * var(--lgap)) / 14),
      58px);
    --bw: calc(14 * var(--lcell) + 13 * var(--lgap) + 10px + 2 * var(--tray));
    max-width: none;
    display: grid;
    grid-template-columns: var(--bw) auto;
    grid-template-rows: auto 1fr;
    justify-content: center;
    align-items: start;
    column-gap: var(--colgap);
    row-gap: 12px;
  }
  .tray { grid-column: 1; grid-row: 1 / span 2; align-self: center; }
  .board { --gap: var(--lgap); --cell: var(--lcell); }
  .modes { grid-column: 2; grid-row: 1; justify-self: center; }
  .controls { grid-column: 2; grid-row: 2; align-self: center; margin-top: 0; }
  .keyboard {
    padding-top: 0;
    --key: min(
      calc((100dvh - var(--chrome) - 60px) / 7.7),
      calc((100vw - 2 * var(--side) - var(--bw) - var(--colgap) - 8 * var(--kgap) - 16px) / 9),
      54px);
  }
  .game-header { max-width: none; }
}
@media (orientation: landscape) and (min-aspect-ratio: 13/10) and (min-height: 700px) {
  .side-plug { display: flex; }
}

/* A phone on its side: the fern border, tagline and footer step aside so the game fits
   one screen. */
@media (orientation: landscape) and (max-height: 600px) {
  .site-footer, .tagline { display: none; }
  .game { --chrome: 62px; --tray: 0px; padding-top: 4px; row-gap: 8px; }
  .tray { padding: 0; background: none; box-shadow: none; outline: none; }
  .game-header { padding-top: max(4px, env(safe-area-inset-top)); }
  .title-tiles img { width: clamp(16px, 5dvh, 26px); }
  .icon-button img { width: clamp(20px, 6.2dvh, 30px); }
  .toast-stack { top: 6px; }
}

/* --- Toasts and confetti -------------------------------------------------------------- */

.toast-stack {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  gap: 8px;
  z-index: 30;
  pointer-events: none;
  width: max-content;
  max-width: calc(100vw - 32px);
}
.toast {
  background: var(--ink);
  color: var(--porcelain);
  padding: 10px 18px;
  border-radius: 12px;
  font-weight: 650;
  font-size: 0.95rem;
  text-align: center;
  box-shadow: 0 12px 28px -12px rgb(0 0 0 / 0.55);
  animation: toast-in 0.2s ease-out;
}
.toast.big { font: 700 1.25rem/1.2 var(--serif); padding: 12px 24px; }
.toast.out { opacity: 0; transform: translateY(-4px); transition: opacity 0.3s, transform 0.3s; }
@keyframes toast-in { from { transform: translateY(-8px); opacity: 0; } }

.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 25; overflow: hidden; }
.confetti i {
  position: absolute;
  top: -20px;
  width: 9px;
  height: 13px;
  border-radius: 2px;
  background: var(--c);
  left: var(--x);
  animation: fall var(--t) cubic-bezier(0.25, 0.4, 0.6, 1) var(--d) forwards;
  opacity: 0.95;
}
@keyframes fall {
  to { transform: translate(var(--dx), 110vh) rotate(var(--r)); opacity: 0.9; }
}

/* --- Dialogs: porcelain sheets laid on the mat ---------------------------------------- */

.sheet-dialog {
  width: calc(100% - 24px);
  max-width: 31rem;
  max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  padding: 28px clamp(20px, 5vw, 34px) 24px;
  border: 0;
  border-radius: 18px;
  background: var(--porcelain);
  color: var(--ink);
  box-shadow: 0 6px 0 var(--jade-edge), var(--sheet-shadow), 0 30px 80px -30px rgb(0 0 0 / 0.4);
  overscroll-behavior: contain;
}
.sheet-dialog::backdrop { background: rgb(14 50 56 / 0.45); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.sheet-dialog[open] { animation: sheet-in 0.26s cubic-bezier(0.25, 0.9, 0.3, 1); }
@keyframes sheet-in { from { transform: translateY(18px) scale(0.98); opacity: 0; } }
.sheet-dialog h2 { font: 700 1.6rem/1.2 var(--serif); margin: 0 0 0.6rem; padding-right: 32px; }
.sheet-dialog h3 { font: 700 1.05rem/1.3 var(--serif); margin: 1.3rem 0 0.55rem; }
.sheet-dialog p { margin: 0 0 0.8rem; }
.sheet-dialog ul { padding-left: 1.2rem; margin: 0 0 1rem; }
.sheet-dialog li + li { margin-top: 0.45rem; }
.sheet-dialog li::marker { color: var(--brass); }
.lead { font-size: 1.05rem; }
.close {
  position: absolute; top: 12px; right: 12px;
  width: 40px; height: 40px;
  border: 0; border-radius: 50%; background: none;
  font-size: 1.8rem; line-height: 1; cursor: pointer; color: var(--muted);
}
.close:hover { background: color-mix(in srgb, var(--brass) 15%, transparent); color: var(--ink); }
.fine { color: var(--muted); font-size: 0.88rem; }

.legend { display: grid; gap: 10px; margin: 1.1rem 0; }
.legend-row { display: grid; grid-template-columns: 40px 1fr; gap: 12px; align-items: center; }
.legend .cell { --cell: 34px; }
.legend-line { width: 34px; height: 48px; border-radius: 7px; outline: 2px solid var(--jade-ink); outline-offset: -2px; }
.portrait-only { display: none; }
@media (orientation: portrait) and (max-width: 600px) { .portrait-only { display: inline; } }
.keys-hint { display: none; font-size: 0.88rem; color: var(--muted); }
@media (hover: hover) and (pointer: fine) { .keys-hint { display: block; } }
kbd {
  display: inline-block; min-width: 1.5em; padding: 0 5px; text-align: center;
  font: 600 0.8rem/1.6 var(--sans); color: var(--ink);
  background: var(--cloth); border-radius: 5px; box-shadow: inset 0 -1.5px 0 var(--slot-edge), 0 0 0 1px var(--slot-edge);
}

/* The answer (and a guess up close), standing in a rack. */
.result { text-align: center; margin-bottom: 1.4rem; padding-bottom: 1.3rem; border-bottom: 1px solid color-mix(in srgb, var(--brass) 35%, transparent); }
.sheet-dialog .result h2 { padding: 0 32px; font-size: 2rem; margin-bottom: 0.2rem; }
.result-sub { color: var(--muted); }
.answer {
  --cell: min(calc((min(100vw, 31rem) - 110px) / 14.2), 30px);
  position: relative;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 7px;
  margin: 0.6rem auto 0.7rem;
}
.answer .group { display: flex; gap: 1px; }
/* Each set stands in its own short rack, so a hand that wraps onto two lines still sits
   on rails. */
.answer.rack { gap: 10px 6px; }
.answer.rack .group { position: relative; padding: 0 3px calc(var(--cell) * 0.2); }
.answer.rack .group::before {
  content: "";
  position: absolute; left: 0; right: 0; bottom: 0;
  height: calc(var(--cell) * 0.5);
  border-radius: calc(var(--cell) * 0.14);
  background: linear-gradient(180deg, var(--rack-top), var(--rack-bottom));
  box-shadow: inset 0 1.5px 0 color-mix(in srgb, var(--brass-light) 75%, transparent), 0 5px 9px -5px rgb(40 90 60 / 0.45);
}
.answer .cell { z-index: 1; }
.answer-meta { color: var(--muted); font-size: 0.92rem; }
.result-actions { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; margin: 1.1rem 0 0.7rem; }
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 0;
  background: var(--jade);
  color: #17251f;
  border-radius: 14px;
  padding: 12px 24px;
  font-weight: 750;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 6px 14px -6px rgb(74 115 48 / 0.65);
  transition: background 0.15s, transform 0.1s;
}
.button:hover { background: var(--jade-pressed); }
.button:active { transform: translateY(1px); }
.button.secondary { background: var(--coral); box-shadow: 0 6px 14px -6px rgb(190 100 80 / 0.6); }
.button.secondary:hover { background: var(--coral-pressed); }
.next { color: var(--muted); font-size: 0.92rem; margin: 0; }
.next strong { font-variant-numeric: tabular-nums; color: var(--ink); }

.zoom-dialog { text-align: center; max-width: 42rem; }
.answer.zoom-hand { --cell: min(calc((min(100vw, 42rem) - 100px) / 7.6), 58px); gap: 12px 12px; margin: 1rem auto 1.1rem; }
.answer.zoom-hand .group { gap: 2px; }

.stat-tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 0; }
.stat-tiles div { display: flex; flex-direction: column-reverse; align-items: center; }
.stat-tiles dd { margin: 0; font: 700 2rem/1.1 var(--serif); }
.stat-tiles dt { font-size: 0.78rem; color: var(--muted); }

.distribution { display: grid; gap: 6px; margin-bottom: 0.9rem; }
.dist-row { display: grid; grid-template-columns: 1.2em 1fr; gap: 8px; align-items: center; font-weight: 650; font-size: 0.9rem; }
.dist-bar {
  min-width: 2em;
  padding: 2px 9px;
  border-radius: 7px;
  background: var(--stone);
  color: #fff;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.dist-bar.current { background: var(--mark-g); color: #17251f; }

.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0;
  border-bottom: 1px solid color-mix(in srgb, var(--brass) 30%, transparent);
  cursor: pointer;
}
.setting > span { display: grid; gap: 2px; }
.setting input {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  margin: 0;
  width: 50px;
  height: 30px;
  border-radius: 15px;
  background: color-mix(in srgb, var(--stone) 45%, transparent);
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
}
.setting input::after {
  content: "";
  position: absolute; top: 3px; left: 3px;
  width: 24px; height: 24px; border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 4px rgb(0 0 0 / 0.3);
  transition: transform 0.2s;
}
.setting input:checked { background: var(--jade); }
.setting input:checked::after { transform: translateX(20px); }
.about { margin-top: 1rem; }

/* The pointer to the app, at the foot of each sheet. */
.plug {
  display: grid;
  grid-template-columns: 60px 1fr;
  gap: 14px;
  align-items: start;
  margin-top: 1.2rem;
  padding: 16px;
  border-radius: 14px;
  background: linear-gradient(160deg, color-mix(in srgb, var(--jade) 18%, var(--porcelain)), color-mix(in srgb, var(--pink) 22%, var(--porcelain)));
  border: 1px solid color-mix(in srgb, var(--jade) 35%, transparent);
  text-align: left;
}
.plug-icon { border-radius: 14px; box-shadow: 0 4px 10px -4px rgb(0 0 0 / 0.35); }
.plug-text { display: grid; gap: 4px; font-size: 0.9rem; color: var(--muted); line-height: 1.4; }
.plug-text strong { font: 700 1.05rem/1.25 var(--serif); color: var(--ink); }
.plug-button { justify-self: start; margin-top: 8px; padding: 9px 16px; font-size: 0.9rem; }

/* --- Footer --------------------------------------------------------------------------- */

.site-footer { background: var(--cloth); color: var(--muted); font-size: 0.86rem; box-shadow: 0 -1px 0 color-mix(in srgb, var(--aqua) 50%, transparent); }
.site-footer .inner {
  max-width: 64rem; margin: 0 auto; padding: 12px var(--side) max(16px, env(safe-area-inset-bottom));
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 20px;
}
.site-footer p { margin: 0; }
.site-footer a { color: var(--jade-ink); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .confetti { display: none; }
}

/* While the server checks a guess. */
body.checking #current-row { opacity: 0.6; transition: opacity 0.15s 0.1s; }
