/* fiddlefinger shared shell. Needs /assets/tokens.css first. Usage: site/assets/README.md.
   Tokens only: no raw colours here except fallbacks where a custom property cannot reach (::backdrop). */

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; overscroll-behavior: none; background: var(--bg); }
body {
  margin: 0; min-height: 100vh; min-height: 100svh;
  background: var(--bg); color: var(--ink);
  font: var(--weight-body) var(--text-md)/var(--lh-body) var(--font-body);
  overscroll-behavior: none; -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, p, ul, ol { margin: 0; }
ul.ff-plain, ol.ff-plain { list-style: none; padding: 0; }
img, svg, canvas { display: block; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--link); text-underline-offset: .18em; }
:focus { outline: none; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.ff-vh { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ff-selectable { -webkit-user-select: text; user-select: text; -webkit-touch-callout: default; }
.ff-display { font-family: var(--font-display); font-weight: 400; font-variant-numeric: tabular-nums; }

/* ---------- page layout ----------
   Phone: .ff-screen is exactly one screen tall (header + play area + "More games" row); the footer sits below the fold.
   The whole screen is touch-locked while playing: swipes on the header, gutters, HUD or hint never scroll the page.
   Players reach the footer with the "More games" row (or the card link); the footer scrolls normally and has "Back to game".
   .ff-screen spans the full page width; its side padding centres a --page-max column, so the gutters belong to it too.
   Desktop (>= 920 px): the footer stands beside the game column. */
.ff-game, .ff-screen { --ff-more-row: 28px; --gutter-l: max(var(--space-4), env(safe-area-inset-left, 0px)); --gutter-r: max(var(--space-4), env(safe-area-inset-right, 0px)); }
.ff-screen {
  position: relative; height: 100vh; height: 100svh; width: 100%; margin: 0;
  display: flex; flex-direction: column;
  padding: 0 max(var(--gutter-r), calc((100% - var(--page-max)) / 2 + var(--space-4)))
    calc(var(--ff-more-row) + env(safe-area-inset-bottom, 0px)) max(var(--gutter-l), calc((100% - var(--page-max)) / 2 + var(--space-4)));
  touch-action: none; overscroll-behavior: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.ff-screen.ff-is-over { touch-action: pan-y; }   /* game-over card showing: the page may scroll to the footer */
.ff-play {
  position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; gap: var(--space-2);
  touch-action: none; overscroll-behavior: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.ff-play:focus { outline: none; }               /* focus target after a card or sheet closes (tabindex=-1), not a control */
.ff-play.ff-is-over { touch-action: pan-y; }     /* game not being played: let the page scroll to the footer */
.ff-stage { position: relative; flex: 1; min-height: 0; touch-action: none; }
.ff-stage canvas { width: 100%; height: 100%; touch-action: none; }
.ff-hint { text-align: center; font-size: var(--text-sm); line-height: 1.4; font-weight: var(--weight-strong); color: var(--muted); min-height: 1.4em; }
.ff-mode { display: flex; justify-content: center; }

/* "More games" row: sits in the reserved 28 px bottom padding of .ff-screen, so it never shifts the play area.
   The label sits low; the 44 px hit area reaches 16 px up over the (non-interactive) hint line. Net cost vs the old
   12 px bottom padding: 16 px of stage height. */
.ff-to-more {
  position: absolute; z-index: 2; left: 50%; bottom: env(safe-area-inset-bottom, 0px); transform: translateX(-50%);
  height: var(--tap-min); min-width: var(--tap-min); padding: 0 var(--space-4) 6px;
  display: inline-flex; align-items: flex-end; justify-content: center; gap: var(--space-1);
  font: var(--weight-heavy) var(--text-sm)/1 var(--font-body); color: var(--ink); text-decoration: none; white-space: nowrap;
  border-radius: var(--r-pill);
}
.ff-to-more svg, .ff-back svg { width: 20px; height: 20px; flex-shrink: 0; }
.ff-to-more:active { background: var(--panel); }
.ff-back { align-self: flex-start; padding-left: var(--space-4); }   /* footer "Back to game" (phones), a secondary .ff-btn */

@media (min-width: 920px) {
  body.ff-game { display: grid; grid-template-columns: minmax(0, var(--page-max)) 300px; justify-content: center; column-gap: var(--space-7); align-items: center; }
  body.ff-game .ff-screen { width: 100%; margin: 0; padding-bottom: max(var(--space-3), env(safe-area-inset-bottom, 0px)); }
  body.ff-game .ff-to-more, body.ff-game .ff-back { display: none; }
  body.ff-game .ff-footer { margin: 0; padding: var(--space-5) 0; max-width: none; border: 0; }
  body.ff-game .ff-tiles { grid-template-columns: 1fr 1fr; }
}

/* Landscape phone: friendly "turn upright" overlay. Touch-only (hover: none + coarse pointer), so desktop windows never see it. */
.ff-rotate {
  position: fixed; inset: 0; z-index: 100; display: none;
  flex-direction: column; align-items: center; justify-content: center; gap: var(--space-4);
  padding: var(--space-5) max(var(--space-5), env(safe-area-inset-right, 0px)) var(--space-5) max(var(--space-5), env(safe-area-inset-left, 0px));
  background: var(--bg); color: var(--ink); text-align: center; touch-action: none;
  -webkit-user-select: none; user-select: none;
}
.ff-rotate svg { width: 56px; height: 56px; color: var(--game-text, var(--ink)); }
.ff-rotate p { font: var(--weight-heavy) var(--text-xl)/var(--lh-snug) var(--font-body); max-width: 30ch; }
@media (hover: none) and (pointer: coarse) and (orientation: landscape) and (max-height: 499px) {
  .ff-rotate { display: flex; }
  dialog.ff-dialog, dialog.ff-dialog::backdrop { visibility: hidden; }   /* top-layer dialogs would sit above the overlay */
  .ff-rotate svg { animation: ff-rotate-hint 2.4s var(--ease-in-out) 0.4s 2 both; }
}
@keyframes ff-rotate-hint { 0%, 30% { transform: rotate(-90deg); } 60%, 100% { transform: rotate(0deg); } }

/* ---------- header ---------- */
.ff-header {
  min-height: 56px; display: flex; align-items: center; gap: var(--space-2);
  padding-top: env(safe-area-inset-top, 0px); flex-shrink: 0;
}
.ff-home { width: var(--tap); height: var(--tap); margin-left: -4px; display: grid; place-items: center; border-radius: var(--r-md); flex-shrink: 0; }
.ff-home img { width: 40px; height: 40px; transition: transform var(--dur-press) var(--ease-out); }
.ff-home:active img { transform: scale(.92); }
.ff-name {
  flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font: 400 var(--display-md)/var(--lh-tight) var(--font-display); letter-spacing: .01em;
  background: var(--game); color: var(--game-ink); padding: 5px 12px 7px; border-radius: var(--r-md);
  box-shadow: 0 3px 0 rgba(var(--shadow-rgb), .3);
  box-shadow: 0 3px 0 color-mix(in srgb, var(--game) 70%, #000);
}
.ff-header-end { margin-left: auto; display: flex; gap: var(--space-2); flex-shrink: 0; }
/* Long names (Pop Sheet) step down one display size when the chip would truncate; shell.js measures. */
.ff-name.ff-name--sm { font-size: var(--display-sm); padding: 8px 10px 10px; }
@media (max-width: 400px) {
  .ff-header, .ff-header-end { gap: 6px; }
  .ff-name { padding-left: 10px; padding-right: 10px; }
}

/* ---------- buttons ---------- */
.ff-icon-btn {
  width: var(--tap); height: var(--tap); padding: 0; border: 0; border-radius: 50%;
  display: grid; place-items: center; background: var(--panel); color: var(--ink);
  box-shadow: 0 3px 0 var(--panel-edge); transition: transform var(--dur-press) var(--ease-out), box-shadow var(--dur-press) var(--ease-out);
}
.ff-icon-btn svg { width: 22px; height: 22px; }
.ff-icon-btn:active { transform: translateY(2px) scale(.92); box-shadow: 0 1px 0 var(--panel-edge); }
.ff-icon-btn--flat { background: transparent; box-shadow: none; }

.ff-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  font: var(--weight-heavy) var(--text-md)/1.1 var(--font-body); min-height: var(--tap); padding: var(--space-2) var(--space-5);
  border: 0; border-radius: var(--r-md); text-decoration: none; text-align: center;
  background: var(--accent); color: var(--accent-ink); box-shadow: 0 var(--bevel) 0 var(--accent-edge);
  margin-bottom: var(--bevel); transform: translateY(0);
  transition: transform var(--dur-press) var(--ease-out), box-shadow var(--dur-press) var(--ease-out);
}
.ff-btn:active { transform: translateY(calc(var(--bevel) - var(--bevel-press))); box-shadow: 0 var(--bevel-press) 0 var(--accent-edge); }
.ff-btn svg { width: 20px; height: 20px; flex-shrink: 0; }
.ff-btn--secondary { background: var(--panel); color: var(--ink); box-shadow: 0 var(--bevel) 0 var(--panel-edge); }
.ff-btn--secondary:active { box-shadow: 0 var(--bevel-press) 0 var(--panel-edge); }
.ff-btn--block { display: flex; width: 100%; }
.ff-btn.is-good { color: var(--good); }

/* ---------- segmented control (mode switch, theme) ---------- */
.ff-seg { display: inline-flex; background: var(--panel); border-radius: var(--r-pill); padding: 3px; gap: 2px; }
.ff-seg button {
  border: 0; background: transparent; color: var(--muted); min-height: var(--tap-min); padding: 0 var(--space-4);
  font: var(--weight-heavy) var(--text-md)/1 var(--font-body); border-radius: var(--r-pill); white-space: nowrap;
  transition: background-color var(--dur-ui) var(--ease-out), color var(--dur-ui) var(--ease-out);
}
.ff-seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 2px 0 var(--surface-edge); }
.ff-seg--sm button { font-size: var(--text-sm); padding: 0 var(--space-3); }

/* ---------- HUD ---------- */
.ff-hud { display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; gap: var(--space-2); flex-shrink: 0; }
.ff-label { display: block; font-size: var(--text-sm); line-height: 1.4; font-weight: var(--weight-heavy); letter-spacing: var(--label-tracking); text-transform: uppercase; color: var(--muted); }
.ff-num { display: inline-block; font: 400 var(--display-lg)/var(--lh-tight) var(--font-display); font-variant-numeric: tabular-nums; transform-origin: left bottom; }
.ff-num-sm { display: inline-block; font: 400 var(--display-sm)/var(--lh-tight) var(--font-display); font-variant-numeric: tabular-nums; }
.ff-hud-end { grid-column: 3; text-align: right; }
.ff-hud-end .ff-num, .ff-hud-end .ff-num-sm { transform-origin: right bottom; }
.ff-badge {
  grid-column: 2; align-self: center; display: inline-flex; align-items: center; gap: var(--space-2);
  background: var(--accent); color: var(--accent-ink); font: var(--weight-heavy) var(--text-sm)/1 var(--font-body);
  padding: 7px 12px; border-radius: var(--r-pill); white-space: nowrap;
}
.ff-bump { animation: ff-bump var(--dur-pop) var(--ease-out); }
@keyframes ff-bump { 40% { transform: scale(1.13); } }

/* ---------- cards, sheets, dialogs ---------- */
.ff-card {
  background: var(--surface); color: var(--ink); border-radius: var(--r-lg);
  box-shadow: 0 var(--bevel-card) 0 var(--surface-edge), var(--shadow-card);
}
.ff-over {
  position: absolute; inset: 0; z-index: 20; display: grid; place-items: center; padding: var(--space-4);
  background: var(--scrim); touch-action: pan-y;
  animation: ff-fade var(--dur-ui) var(--ease-out);
}
.ff-over-card {
  width: 100%; max-width: 320px; max-height: 100%; overflow: auto; padding: var(--space-5) var(--space-5) var(--space-4);
  text-align: center; display: flex; flex-direction: column; gap: var(--space-2);
  animation: ff-pop var(--dur-pop) var(--ease-back);
}
/* FF.gameOver({ dock: 'bottom' }): a compact card docked at the bottom, light scrim, so the final board/tower stays visible */
.ff-over--dock { place-items: end center; background: linear-gradient(to bottom, transparent 40%, var(--scrim)); }
.ff-over--dock .ff-over-card { max-height: 62%; gap: var(--space-1); padding: var(--space-4) var(--space-4) var(--space-3); }
.ff-over--dock .ff-big { font-size: var(--display-lg, 40px); }
.ff-eyebrow { font: var(--weight-heavy) var(--text-sm)/1.4 var(--font-body); color: var(--game-text); }
.ff-kicker { font: var(--weight-heavy) var(--text-sm)/1.4 var(--font-body); letter-spacing: var(--label-tracking); text-transform: uppercase; color: var(--muted); }
.ff-big { font: 400 var(--display-xl)/var(--lh-tight) var(--font-display); font-variant-numeric: tabular-nums; }
.ff-meta { font: var(--weight-strong) var(--text-md)/1.4 var(--font-body); color: var(--muted); }
.ff-extra { font: var(--weight-heavy) var(--text-md)/1.4 var(--font-body); color: var(--ink); }   /* FF.gameOver({extra}) */
.ff-streak { display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2); font: var(--weight-heavy) var(--text-sm)/1.4 var(--font-body); color: var(--accent-text); }
.ff-streak svg { width: 20px; height: 20px; }
.ff-actions { display: flex; flex-direction: column; gap: var(--space-2); margin-top: var(--space-2); }
.ff-note { font-size: var(--text-sm); line-height: 1.4; color: var(--muted); }
.ff-note:empty { display: none; }
.ff-sharetext { margin: 0; padding: var(--space-3); border-radius: var(--r-sm); background: var(--bg); color: var(--ink); font: var(--weight-strong) var(--text-sm)/1.45 var(--font-body); white-space: pre-wrap; text-align: left; -webkit-user-select: all; user-select: all; }
.ff-msg-bad { color: var(--bad); font-weight: var(--weight-strong); }
.ff-card-link { font-size: var(--text-sm); font-weight: var(--weight-heavy); padding: var(--space-2); min-height: var(--tap-min); display: inline-flex; align-items: center; justify-content: center; align-self: center; }

dialog.ff-dialog {
  border: 0; padding: 0; color: var(--ink); background: var(--surface); max-width: min(440px, calc(100% - 32px)); width: 100%;
  border-radius: var(--r-lg); box-shadow: 0 var(--bevel-card) 0 var(--surface-edge), var(--shadow-card);
  overscroll-behavior: contain;
}
dialog.ff-dialog::backdrop { background: rgba(14, 19, 30, .6); background: var(--scrim, rgba(14, 19, 30, .6)); }
dialog.ff-dialog[open] { animation: ff-pop var(--dur-pop) var(--ease-out); }
.ff-dialog-body { padding: var(--space-5); display: flex; flex-direction: column; gap: var(--space-4); }
.ff-dialog-text { font: var(--weight-strong) var(--text-lg)/1.4 var(--font-body); max-width: 60ch; }

/* How-to-play: bottom sheet on phones, centred dialog on wider screens */
dialog.ff-sheet { margin: auto auto 0; max-width: var(--page-max); max-height: 88svh; border-radius: var(--r-lg) var(--r-lg) 0 0; box-shadow: var(--shadow-card); }
dialog.ff-sheet[open] { animation: ff-sheet-in var(--dur-sheet) var(--ease-out); }
.ff-sheet-body { padding: var(--space-5) var(--gutter-r, var(--space-4)) max(var(--space-5), env(safe-area-inset-bottom, 0px)) var(--gutter-l, var(--space-4)); display: flex; flex-direction: column; gap: var(--space-4); }
.ff-sheet-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin: calc(-1 * var(--space-2)) 0; }
.ff-sheet-title { font: var(--weight-heavy) var(--text-xl)/var(--lh-snug) var(--font-body); }
.ff-steps { display: flex; flex-direction: column; gap: var(--space-3); counter-reset: step; }
.ff-step { display: grid; grid-template-columns: 88px 1fr; align-items: center; gap: var(--space-4); }
.ff-step-pic { width: 88px; height: 64px; border-radius: var(--r-md); background: var(--board); color: var(--board-ink); display: grid; place-items: center; overflow: hidden; }
.ff-step-pic canvas, .ff-step-pic svg { width: 100%; height: 100%; }
.ff-step-num { font: 400 var(--display-sm)/1 var(--font-display); color: var(--accent); }
.ff-step-text { font: var(--weight-body) var(--text-md)/1.4 var(--font-body); max-width: 60ch; }
.ff-sheet-actions { display: flex; flex-direction: column; gap: var(--space-2); }
@media (min-width: 600px) {
  dialog.ff-sheet { margin: auto; border-radius: var(--r-lg); box-shadow: 0 var(--bevel-card) 0 var(--surface-edge), var(--shadow-card); }
  .ff-sheet-body { padding: var(--space-6); }
  .ff-step-text { font-size: var(--text-lg); }
  .ff-sheet-actions { flex-direction: row-reverse; }
  .ff-sheet-actions .ff-btn { flex: 1; }
}

/* ---------- toast ---------- */
.ff-toast {
  position: fixed; left: 50%; bottom: calc(var(--space-6) + env(safe-area-inset-bottom, 0px)); z-index: 60;
  width: max-content; max-width: calc(100% - 32px); transform: translateX(-50%); pointer-events: none;
  background: var(--ink); color: var(--bg); font: var(--weight-strong) var(--text-md)/1.35 var(--font-body);
  padding: var(--space-3) var(--space-4); border-radius: var(--r-md); box-shadow: var(--shadow-lift); text-align: center;
  opacity: 0; transition: opacity var(--dur-ui) var(--ease-out);
}
.ff-toast.is-on { opacity: 1; }

/* ---------- footer ---------- */
.ff-footer {
  max-width: var(--page-max); margin: 0 auto; padding: var(--space-6) var(--gutter-r, var(--space-4)) max(var(--space-6), env(safe-area-inset-bottom, 0px)) var(--gutter-l, var(--space-4));
  display: flex; flex-direction: column; gap: var(--space-5); border-top: 2px solid var(--line);
}
.ff-footer h2 { font: var(--weight-heavy) var(--text-xl)/var(--lh-snug) var(--font-body); margin-bottom: var(--space-3); }
.ff-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: var(--space-3) var(--space-3); list-style: none; padding: 0; margin: 0; }
.ff-tile {
  position: relative; display: flex; flex-direction: column; gap: 2px; min-height: 112px;
  padding: var(--space-3) var(--space-3) calc(var(--space-3) + var(--bevel)); border-radius: var(--r-md); text-decoration: none;
  background: var(--tile); color: var(--tile-ink); overflow: hidden;
  box-shadow: inset 0 calc(-1 * var(--bevel) - 2px) 0 rgba(var(--shadow-rgb), .3);
  box-shadow: inset 0 calc(-1 * var(--bevel) - 2px) 0 color-mix(in srgb, var(--tile) 70%, #000);
  transition: transform var(--dur-press) var(--ease-out);
}
.ff-tile::before { content: ""; position: absolute; left: 12%; top: 9%; width: 36%; height: 7px; border-radius: var(--r-pill); background: var(--highlight); }
.ff-tile:active { transform: scale(.96); }
.ff-tile-motif { align-self: flex-end; width: 34px; height: 34px; margin: -4px -4px auto 0; flex-shrink: 0; }
.ff-tile-motif svg { width: 100%; height: 100%; }
.ff-tile-name { font: 400 var(--display-sm)/1.05 var(--font-display); letter-spacing: .01em; }
.ff-tile-tag { font: var(--weight-strong) var(--text-sm)/1.3 var(--font-body); }
.ff-all { display: inline-flex; align-items: center; min-height: var(--tap-min); margin-top: var(--space-2); font-weight: var(--weight-heavy); }
.ff-theme { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); }
.ff-theme-label { font: var(--weight-heavy) var(--text-sm)/1.4 var(--font-body); color: var(--muted); }
.ff-small a, .ff-small span { white-space: nowrap; }
.ff-small { font-size: var(--text-sm); line-height: 1.4; color: var(--muted); font-weight: var(--weight-strong); }
.ff-small a { display: inline-block; padding: 13px 4px; margin: -13px 0; }

/* ---------- motion ---------- */
@keyframes ff-fade { from { opacity: 0; } }
@keyframes ff-pop { from { opacity: 0; transform: scale(.92); } }
@keyframes ff-sheet-in { from { transform: translateY(40%); opacity: .4; } }
@media (prefers-reduced-motion: reduce) {
  .ff-over-card, dialog.ff-dialog[open], dialog.ff-sheet[open] { animation: ff-fade var(--dur-sheet) linear; }
  .ff-bump { animation: none; }
  .ff-icon-btn:active, .ff-tile:active, .ff-home:active img { transform: none; filter: brightness(.92); }
  .ff-btn:active { transform: none; filter: brightness(.94); }
  .ff-rotate svg { animation: none !important; }
}

/* Game-over "Try next": the two related games as chips (>= 44 px) */
.ff-next { display: flex; flex-direction: column; gap: var(--space-1); align-items: stretch; }
.ff-next-h { font: var(--weight-heavy) var(--text-sm)/1.4 var(--font-body); letter-spacing: var(--label-tracking); text-transform: uppercase; color: var(--muted); }
.ff-next ul { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2); list-style: none; margin: 0; padding: 0; }
.ff-next-tile {
  display: flex; align-items: center; gap: var(--space-2); min-height: 48px; padding: var(--space-1) var(--space-3);
  border-radius: var(--r-md); background: var(--tile); color: var(--tile-ink); text-decoration: none;
  font: 400 var(--text-xl)/1.1 var(--font-display);
  box-shadow: inset 0 -4px 0 color-mix(in srgb, var(--tile) 70%, #000);
}
.ff-next-tile:active { transform: scale(.96); }
.ff-next-tile:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.ff-next-ico { width: 28px; height: 28px; flex-shrink: 0; }
.ff-next-ico svg { width: 100%; height: 100%; display: block; }
.ff-over--dock .ff-next-h { display: none; }
@media (prefers-reduced-motion: reduce) { .ff-next-tile:active { transform: none; filter: brightness(.94); } }

/* Static "About <game>" block: shipped in the page for crawlers, kept by the shell at the top of the footer */
.ff-about { max-width: 60ch; margin-bottom: var(--space-5); }
.ff-about p { font: var(--weight-body) var(--text-md)/1.5 var(--font-body); color: var(--ink); }
.ff-next-tile span:last-child { white-space: nowrap; }
.ff-over--dock .ff-next-tile { min-height: 44px; padding: 0 var(--space-2); font-size: var(--text-lg); }
.ff-over--dock .ff-next-ico { width: 22px; height: 22px; }
