/* ==========================================================================
   games.css — the look every game shares: the header (Help and Dashboard on
   the left, the title in the middle, Stats and Settings on the right), the
   dialogs, the end-of-round card, settings rows with their switches, the
   on-screen keyboard, the toast, the leaderboard list and the admin
   dashboards. Each game keeps its own board (tiles, timeline cards, quiz
   cards) in its own stylesheet. The Fun & Games hub loads it for the Player
   profile dialog.

   Colours come from the shell tokens in css/site.css (--ink, --c-good…),
   so every game follows the season, Menus & dialogs and True black from the
   ☰ menu, as every other page does. (The :not([class*="theme-"]) in a few
   selectors below is left from the old game themes; it always matches now,
   and is kept so those rules keep the weight the cascade was built around.)
   ========================================================================== */

/* ---------------------------------------------------------------- tokens */
:root {
  /* One "right answer" green and "wrong" red for every game: correct
     tiles, right answers, the end-of-round mood, placed cards. */
  --game-good: var(--c-good);
  --game-good-soft: rgba(29, 107, 58, .14);
  --game-bad: var(--c-bad);
  --game-warn: var(--c-warn);
  --game-warn-soft: rgba(138, 90, 30, .16);
  /* soft fill and hairline for stat tiles, help boxes, rows */
  --game-tint: rgba(47, 74, 114, .07);
  --game-line: rgba(47, 74, 114, .15);
}

/* ---------------------------------------------------------------- layout */
.game-container {
  max-width: 500px; margin: 0 auto;
  display: flex; flex-direction: column; min-height: 70vh;
  user-select: none; -webkit-user-select: none;
  background: var(--game-panel-bg, none); border: var(--game-panel-border, 0);
  border-radius: var(--radius-card); padding: var(--game-panel-pad, 0 0 2rem);
}
.shell:has(> .game-container) { padding-top: 1.5rem; }

/* Winter's night wash under The Seasons: the navy ink disappears into it, so
   what sits straight on the wash (StepWords' letters, 6Lets' tiles and keys,
   Timeline's category and counter, Ruff Times' pills) takes the season's light
   wash ink, as seasons.css does for page text. The white cards (Timeline's
   events, Ruff Times' question, answers and recap, the Score Sheet's sheet and
   leader board, Backgammon's and Set & Run's lobby cards) keep the brand navy. 6Lets
   resolves its tile tokens on :root, and Timeline its text tokens, so they are
   restated here. */
html[data-season="winter"][data-game]:not([class*="theme-"]) .game-container {
  --ink: var(--wash-ink);
  --ink-deep: var(--wash-ink-deep);
  --ink-soft: var(--wash-ink-soft);
  --sw-box-border: rgba(228, 238, 250, .38);
  --sw-goal-ink: rgba(242, 247, 253, .62);
  --sw-key-bg: rgba(228, 238, 250, .16);
  --sw-key-active: rgba(228, 238, 250, .32);
  --key-enter-bg: var(--wash-ink);
  --key-enter-color: #1d3153;
  --text-color: var(--wash-ink-deep);
  --tile-color-empty: var(--wash-ink-deep);
  --tile-bg-empty: rgba(228, 238, 250, .1);
  --board-empty-border: 2px solid rgba(228, 238, 250, .45);
  --text-primary: var(--wash-ink-deep);
  --text-secondary: var(--wash-ink-soft);
  color: var(--wash-ink-deep);
}
html[data-season="winter"][data-game]:not([class*="theme-"]) .game-container
  :is(.timeline-card, .active-card, .quiz__q, .quiz__opt, .quiz__hint, .quiz__fact, .recap, .sc-card, .bg-card, .sr-card, .sr-player, .swp-card, .swp-opp, .swp-coach) {
  --ink: #2f4a72;
  --ink-deep: #1d3153;
  --ink-soft: #4a6491;
  --text-primary: #1d3153;
  --text-secondary: #4a6491;
  color: #1d3153;
}

/* Tablets: each game is drawn larger, as the Android app draws it. The games
   keep their 500px phone column, small on a tablet's screen, so on a large
   screen the board, the dialogs and the toast are zoomed by one factor, the
   layout unchanged. The factor follows the app's (min(width / 480px, height /
   620px), at most 1.6), in steps, since CSS can't divide lengths. Widths and
   heights tied to the viewport are divided back by it. Phones are unchanged. */
@media (min-width: 600px) and (min-height: 775px) { html[data-game] { --gz: 1.25; } }
@media (min-width: 672px) and (min-height: 868px) { html[data-game] { --gz: 1.4; } }
@media (min-width: 768px) and (min-height: 992px) { html[data-game] { --gz: 1.6; } }
@media (min-width: 600px) and (min-height: 775px) {
  html[data-game] .game-container,
  html[data-game] .fw-modal .modal-content,
  html[data-game] .game-toast { zoom: var(--gz); }
  html[data-game] .game-container {
    max-width: min(500px, calc((100vw - 2.3rem) / var(--gz)));
    /* its 70vh too, or the zoomed column runs past the window's bottom and
       the keyboard pinned to its foot with it */
    min-height: calc(70vh / var(--gz));
  }
  html[data-game] .fw-modal .modal-content {
    width: min(30rem, calc((100vw - 2rem) / var(--gz)));
    max-height: calc((100svh - 2rem) / var(--gz));
  }
  html[data-game] .fw-modal.setdrawer > .modal-content {
    width: min(24rem, calc(92vw / var(--gz)));
    height: calc(100svh / var(--gz));
    max-height: none;
  }
}

/* ---------------------------------------------------------------- header */
.game-header {
  position: relative; display: flex; justify-content: center; align-items: center;
  text-align: center; margin-bottom: 2rem; min-height: 2.75rem;
}
.game-header__side {
  position: absolute; top: 50%; transform: translateY(-50%);
  display: flex; gap: .5rem;
}
.game-header__side--left { left: 0; }
.game-header__side--right { right: 0; }
.game-title {
  margin: 0; display: flex; align-items: center;
  font-family: inherit; font-weight: bold; color: var(--ink-deep);
  text-transform: uppercase; letter-spacing: 1px;
  font-size: clamp(1.2rem, 5vw, 1.6rem); line-height: 1.2;
}
/* A game's title in the site's blue bar (site.css .topbar__title), set
   like every page's bar title, and tappable, since StepWords' title
   changes the word length once the day is done. */
.topbar__title--game {
  pointer-events: auto; font-variant-numeric: tabular-nums;
  /* a game's bar is full (stats and settings beside the menu), so its
     title runs a little smaller than a tool page's */
  font-size: clamp(1.1rem, 5.2vw, 1.45rem);
}
.topbar__title--game .game-title__tag { margin-left: 0; padding: 0 .1rem; }
/* The small figure after the title: StepWords' word length, 6Lets' guesses. */
.game-title__tag { margin-left: .2rem; padding: .2rem .5rem; color: inherit; font-variant-numeric: tabular-nums; user-select: none; }

/* --------------------------------------------------------------- buttons */
/* .btn, .btn--ghost and .btn--go (green, for going on: Share, Copy, Next
   round) are the site's own, from css/site.css. */
.btn svg { vertical-align: -2px; }

/* --------------------------------------------------------------- dialogs */
/* Every game dialog is a .fw-modal shown with `show`, dressed exactly like
   the site's <dialog class="helpdlg">: the navy veil, the off-white card
   with an 18px corner, a serif title and the round close button. */
.fw-modal {
  display: none; position: fixed; inset: 0; width: 100%; height: 100%;
  background: rgba(20, 35, 60, .45); align-items: center; justify-content: center;
  padding: 1rem; z-index: 100;
}
.fw-modal.show { display: flex; }
.modal-content {
  position: relative;
  width: min(30rem, calc(100vw - 2rem)); max-height: calc(100svh - 2rem); overflow-y: auto;
  padding: 1.2rem 1.3rem 1.25rem;
  border-radius: var(--radius-card);
  background: var(--sw-modal-bg, #fdfcf8); color: var(--ink-deep, #2b3d5c);
  box-shadow: var(--shadow-lg);
  font-size: .9rem; line-height: 1.55; text-align: left;
  user-select: text; -webkit-user-select: text;
}
.modal-content h2 {
  font-family: var(--font-display); font-size: 1.2rem; line-height: 1.3;
  margin: 0 0 .5rem; padding-right: 2rem;
}
.modal-content h3 { font-family: var(--font-display); font-size: 1rem; margin: .9rem 0 .25rem; }
.modal-content p { margin: 0 0 .6rem; }
.modal-content ul { list-style: disc; padding-left: 1.2rem; display: grid; gap: .25rem; margin: 0; }
.close-modal:not(.btn) {
  position: absolute; top: .3rem; right: .35rem;
  width: 2.2rem; height: 2.2rem; padding: 0;
  border: 0; border-radius: 50%; background: none;
  font-size: 1.35rem; line-height: 1; color: var(--ink-soft, #4a6491); cursor: pointer;
}
.close-modal:not(.btn):hover { background: rgba(47, 74, 114, .08); }
/* A long dialog scrolls under its ×, which stays at the top (user, 2026-11-19: a
   leaderboard card was taller than the phone). */
.modal-content > .close-modal:not(.btn):first-child {
  position: sticky; float: right; top: -.9rem; margin: -.9rem -1rem 0 0; z-index: 2;
  background: var(--sw-modal-bg, #fdfcf8);
}
.modal-actions { display: flex; gap: .5rem; justify-content: center; margin-top: 1rem; }
.modal-actions .btn { flex: 1; }
.modal-content > .btn--block { margin-top: .6rem; }
/* The same right-aligned row as .helpdlg__btns, for Got it. */
.modal-content .helpdlg__btns { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }
/* A text field in a game dialog (display name, the dashboards' words). */
.game-input {
  display: block; width: 100%; padding: .65rem .75rem; margin: 0 0 .5rem;
  border: 1px solid rgba(47, 74, 114, .3); border-radius: var(--radius-sm);
  background: var(--sw-input-bg, #fff); color: inherit; font: inherit; font-size: 1rem;
}
.game-note { font-size: .85rem; color: var(--ink-soft); line-height: 1.45; margin: .75rem 0 0; }
.modal-content a, .game-note a { color: var(--ink); text-decoration: underline; font-weight: 600; }
button.linklike { border: 0; background: none; padding: 0; font: inherit; cursor: pointer; color: inherit; text-decoration: underline; font-weight: 600; }

/* Help: the "how it works" list and the plainer tips under it. */
.help-box { margin: .9rem 0; padding: .75rem 1rem .85rem; background: var(--game-tint); border-radius: var(--radius); }
.help-box h3:first-child, .help-more h3:first-child { margin-top: 0; }
.help-more { margin: .9rem 0 0; }
.help-origin { margin-top: 1rem; padding-top: .9rem; border-top: 1px solid var(--game-line); }
.help-center { text-align: center; }

/* ------------------------------------------------- end-of-round dialog */
/* `data-mood` picks the palette: green for a good round, amber for one to
   try again. */
.win-modal { --mood: var(--game-good); --mood-soft: var(--game-good-soft); }
.win-modal[data-mood="retry"] { --mood: var(--game-warn); --mood-soft: var(--game-warn-soft); }
/* Dark dialogs: --mood is worked out on .win-modal, outside the card, so it kept the page's dark
   green (or brown) on the navy. Inside the card it takes the dialog's own, as in the app. */
html[data-ui="dark"]:not([class*="theme-"]) .win-modal .modal-content { --mood: var(--c-good); }
html[data-ui="dark"]:not([class*="theme-"]) .win-modal[data-mood="retry"] .modal-content { --mood: var(--c-warn); }
.win-modal .modal-content, .modal-content.is-centered { text-align: center; }
.win-modal .modal-content { border-top: 6px solid var(--mood); }
.win-modal .modal-content h2 { padding: 0 2rem; }
.win-icon {
  width: 5.5rem; height: 5.5rem; margin: .5rem auto 1rem;
  display: grid; place-items: center;
  border-radius: 50%; background: var(--mood-soft); color: var(--mood);
  animation: win-icon-pop 420ms var(--ease);
}
.win-icon svg { width: 3.25rem; height: 3.25rem; }
@keyframes win-icon-pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-content .win-title { color: var(--mood); font-size: 1.9rem; margin-bottom: .5rem; }
.win-message { line-height: 1.55; }
.win-stats { display: flex; gap: .5rem; justify-content: center; margin: 1rem 0 .25rem; }
.win-stat { flex: 1; min-width: 0; padding: .6rem .25rem; border-radius: var(--radius-sm); background: var(--game-tint); text-align: center; }
.win-stat strong { display: block; font-size: 1.5rem; line-height: 1.1; color: var(--ink-deep); }
.win-stat small { display: block; font-size: .78rem; color: var(--ink-soft); margin-top: .2rem; }
.win-stat--mood { background: var(--mood-soft); }
.win-stat--mood strong { color: var(--mood); }
.win-stat--wide { grid-column: 1 / -1; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin: 1rem 0; }
.stat-grid .win-stat { padding: .8rem .25rem; }
.btn--mood { background: var(--mood); border-color: var(--mood); color: #fff; }
.btn--mood:hover { background: var(--mood); filter: brightness(1.08); }
/* "Next puzzle in" and its clock, the same on every game. */
.countdown { margin: 1rem 0; text-align: center; font-size: .95rem; color: var(--ink-soft); }
.countdown strong { display: block; font-size: 1.35rem; color: var(--ink-deep); font-variant-numeric: tabular-nums; }

/* ----------------------------------------------------------- leaderboard */
.modal-content .lb__title { margin: 1rem 0 .4rem; font-size: 1.05rem; text-align: center; }
.lb__list { list-style: none; display: block; margin: 0; padding: 0; text-align: left; font-size: .9rem; counter-reset: lb; }
.lb__row { display: flex; justify-content: space-between; gap: .75rem; padding: .3rem 0; border-bottom: 1px solid var(--game-line); counter-increment: lb; }
.lb__row::before { content: counter(lb) "."; width: 1.6rem; flex: 0 0 auto; opacity: .7; font-variant-numeric: tabular-nums; }
.lb__name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb__score { flex: 0 0 auto; font-variant-numeric: tabular-nums; opacity: .85; }
.lb__row--me { font-weight: bold; color: var(--mood, var(--ink-deep)); }
.lb__me { margin: .6rem 0 0; font-size: .9rem; opacity: .85; }

/* -------------------------------------------------------------- settings */
.setting-row {
  border-bottom: 1px solid var(--game-line); padding-bottom: .9rem; margin-bottom: .9rem;
  display: flex; justify-content: space-between; align-items: center; gap: 1rem; text-align: left;
}
.setting-row:not(:has(+ .setting-row)) { border-bottom: 0; margin-bottom: 0; padding-bottom: 0; }
label.setting-row { cursor: pointer; }
.setting-row__name { font-size: 1rem; font-weight: 600; }
.setting-row__note { color: var(--ink-soft); font-size: .85rem; }
.setting-row input[type="range"] { width: 8rem; accent-color: var(--ink); cursor: pointer; }
/* The games' switches are a checkbox inside .switch; they wear the site's
   .switch look (css/site.css): navy when on, a soft grey track when off. */
.switch:has(> input) { display: inline-block; background: none; cursor: pointer; }
.switch:has(> input)::after { content: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; border-radius: 999px; background: rgba(47, 74, 114, .25); transition: background 200ms var(--ease); }
.slider-btn {
  position: absolute; top: .2rem; left: .2rem; width: 1.4rem; height: 1.4rem;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3);
  pointer-events: none; transition: transform 200ms var(--ease);
}
input:checked + .slider { background: var(--ink); }
input:checked + .slider + .slider-btn { transform: translateX(1.3rem); }
input:focus-visible + .slider { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ------------------------------------------------------- on-screen keys */
/* StepWords' and 6Lets' keyboards: the same keys, rows and wide keys. */
.keyboard, #keyboard { flex-direction: column; gap: 6px; width: 100%; }
.key-row, .keyboard-row { display: flex; justify-content: center; gap: 5px; width: 100%; }
.key {
  flex: 0 1 9%; height: min(12vw, 3.4rem); padding: 0;
  display: flex; align-items: center; justify-content: center;
  border: var(--key-border, 0); border-radius: var(--key-radius, var(--radius-sm));
  background: var(--key-bg, var(--sw-key-bg, rgba(47, 74, 114, .12)));
  color: var(--key-color, var(--ink-deep));
  font-family: inherit; font-size: min(5.2vw, 1.3rem); font-weight: 600; text-transform: uppercase;
  cursor: pointer; user-select: none; -webkit-user-select: none;
  transition: filter 120ms, background 120ms;
}
.key:active { background: var(--key-active, var(--sw-key-active, rgba(47, 74, 114, .28))); }
.key.disabled { opacity: .5; pointer-events: none; }
.key svg { width: 1.4em; height: 1.4em; }
/* Enter and Delete: wider, Enter filled with the ink. */
.key--wide { flex: 0 1 13.5%; font-size: min(3.6vw, .95rem); text-transform: none; }
.key--enter { background: var(--key-enter-bg, var(--ink)); color: var(--key-enter-color, #fff); }
.key--enter:active { filter: brightness(.88); background: var(--key-enter-bg, var(--ink)); }

/* ----------------------------------------------------------------- toast */
/* The site's .toast (navy pill), at the top so the keyboard never hides it. */
.game-toast {
  position: fixed; top: calc(var(--topbar-h) + env(safe-area-inset-top, 0px) + .75rem); left: 50%;
  transform: translate(-50%, -.5rem);
  max-width: calc(100vw - 2rem); padding: .7rem 1.1rem;
  border-radius: 999px; box-shadow: var(--shadow-md);
  background: var(--sw-toast-bg, #23385c); color: var(--sw-toast-ink, #eef4ff);
  font-size: .87rem; text-align: center;
  opacity: 0; transition: opacity 250ms var(--ease), transform 250ms var(--ease);
  pointer-events: none; z-index: 1000;
}
.game-toast.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-5px); }
  40%, 80% { transform: translateX(5px); }
}

/* ------------------------------------------------------ admin dashboards */
/* StepWords', Timeline's and Ruff Times' dashboards (6Lets has its own
   word editor): a month calendar, then the chosen day. */
.modal-content.dashboard { width: min(34rem, calc(100vw - 2rem)); }
.modal-content.dashboard > h2 { text-align: center; padding: 0 2rem; }
.dash-lede { color: var(--ink-soft); font-size: .9rem; margin: 0 0 1.25rem; text-align: center; }
.calendar { max-width: 320px; margin: 0 auto; padding: 1rem; border-radius: var(--radius); background: var(--game-tint); border: 1px solid var(--game-line); }
.calendar__header { display: flex; align-items: center; justify-content: space-between; margin-bottom: .75rem; }
.calendar__header button { width: 32px; height: 32px; border: 0; border-radius: 50%; background: rgba(47, 74, 114, .1); color: inherit; font-size: 1.3rem; line-height: 1; cursor: pointer; }
.calendar__month { font-weight: 600; flex: 1; text-align: center; }
.calendar__weekdays, .calendar__days { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; gap: 4px; }
.calendar__weekdays span { font-size: .75rem; font-weight: 600; opacity: .7; margin-bottom: .25rem; }
.calendar__day { width: 34px; height: 34px; margin: 0 auto; display: flex; align-items: center; justify-content: center; border-radius: 50%; font-size: .9rem; cursor: pointer; border: 1px solid transparent; }
.calendar__day:hover:not(.is-empty):not(.is-before) { background: rgba(47, 74, 114, .14); }
.calendar__day.is-today { border-color: currentColor; }
.calendar__day.is-selected { background: var(--ink); color: #fff; font-weight: bold; }
/* Dark dialogs turn --ink light: the chosen day takes their gold instead. */
html[data-ui="dark"]:not([class*="theme-"]) .fw-modal .calendar__day.is-selected { background: var(--dlg-accent); color: var(--dlg-accent-ink); }
.calendar__day.is-empty { cursor: default; }
.calendar__day.is-before { opacity: .35; cursor: default; }
.dash-heading { margin: 1.5rem 0 .5rem; font-size: 1.05rem; }
.dash-heading__note { font-family: var(--font-body); font-weight: normal; font-size: .85rem; opacity: .7; margin-left: .35rem; }
.dash-message { margin-top: 1.25rem; padding: .6rem .8rem; border-radius: var(--radius-sm); text-align: center; font-size: .9rem; background: var(--game-tint); }
.dash-table-wrap { overflow-x: auto; font-size: .9rem; }
.dash-table { width: 100%; border-collapse: collapse; }
.dash-table th, .dash-table td { padding: .4rem .5rem; text-align: left; border-bottom: 1px solid var(--game-line); }
.dash-table th { font-size: .78rem; opacity: .75; }
.dash-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.dash-empty { text-align: center; opacity: .8; margin: .5rem 0; }

/* ------------------------------------------- Player profile (the hub) */
.profile__title { text-align: center; padding: 0 2rem; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.profile__section { padding: 1rem 0; border-bottom: 1px solid var(--game-line); }
.profile__section:not(:has(~ .profile__section:not([hidden]))) { border-bottom: 0; }
.profile__label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .4rem; }
.profile__row { display: flex; gap: .5rem; }
.profile__row .game-input { flex: 1; min-width: 0; margin: 0; }
.game-input--mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85rem; }
.profile__copy { flex: 0 0 auto; border: 1px solid rgba(47, 74, 114, .3); border-radius: var(--radius-sm); color: var(--ink); }
.profile__copy svg { width: 1.2rem; height: 1.2rem; }
.profile__or { display: flex; align-items: center; gap: .75rem; font-size: .8rem; color: var(--ink-soft); margin: 1rem 0; }
.profile__or::before, .profile__or::after { content: ""; flex: 1; height: 1px; background: currentColor; opacity: .3; }
.profile__admin h3 { text-align: center; margin: 0 0 1rem; }
.profile__admin h4 { margin: 0 0 .35rem; font-size: 1rem; }
.profile__error { color: var(--c-bad); font-size: .85rem; text-align: center; margin: 0 0 .75rem; }
.profile__note--center { text-align: center; margin: 0 0 1rem; }
.profile__pk { display: flex; align-items: center; gap: .75rem; padding: .5rem 0; border-bottom: 1px solid var(--game-line); }
.profile__pk-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile__pk-used { color: var(--ink-soft); font-size: .8rem; }
.profile__pk-remove { color: var(--c-bad); }
/* The tick on a game finished today (js/games-settings.js). */
.donemark { float: right; display: inline-grid; place-items: center; width: 1.3em; height: 1.3em; border-radius: 50%; background: var(--c-good); color: #fff; }
.donemark svg { width: .85em; height: .85em; }
