/* Games: shared shell + Dagens ord + Sudoku */

.game {
  max-width: 560px;
  margin: 0 auto;
  padding: 0 16px;
  text-align: center;
}
.game h1 { font-size: 30px; }
.game-meta { margin: 0 0 24px; }

#toast[hidden] { display: none; }
#toast {
  position: fixed; left: 50%; top: 88px; transform: translateX(-50%);
  z-index: 40; background: var(--ink); color: var(--bg);
  padding: 12px 20px; border-radius: var(--r-pill);
  font-size: 17px; font-weight: 600;
}

/* ---------- Dagens ord ---------- */

#board { display: grid; gap: 8px; justify-content: center; margin-bottom: 32px; }
.row { display: grid; grid-template-columns: repeat(5, 60px); gap: 8px; }

.tile {
  position: relative;
  display: grid; place-items: center;
  height: 60px;
  border: 2px solid var(--line);
  border-radius: var(--r-tile);
  background: var(--surface);
  font: 600 30px/1 var(--sans);
  color: var(--ink);
  text-transform: uppercase;
  transition: background-color .18s ease-out, border-color .18s ease-out;
}
.row.active .tile { border-color: var(--accent); }
.row.active .tile.cursor { border-width: 3px; }

/* Colour is never the only signal — every resolved tile carries a mark. */
.tile[data-mark]::after {
  content: attr(data-mark);
  position: absolute; top: 2px; right: 5px;
  font: 700 14px/1 var(--sans);
  opacity: .85;
}
.tile.ok {
  border: 3px solid var(--ok); background: var(--ok); color: var(--ok-ink);
}
.tile.near {
  border: 3px dashed var(--near); background: var(--near-soft); color: var(--near-ink);
}
.tile.absent {
  border: 2px solid var(--line); background: var(--absent-fill); color: var(--absent);
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}
.row.shake { animation: shake .16s ease-in-out; }

#keyboard { display: grid; gap: 8px; margin-bottom: 16px; }
/* The top row is 11 keys (qwertyuiopå). At a 30px floor plus 6px gaps that row
   could not compress below 390px, so on a 320-390px phone it was wider than
   the screen and pushed the page sideways. Keys shrink to fit instead: the row
   is never wider than its container, and 44px stays the cap so they do not
   sprawl on a tablet. Around 26px on the narrowest phone is what the OS
   keyboard does too — 11 keys at the 48px control minimum would need 528px,
   which no phone in portrait has. */
.krow { display: flex; gap: 4px; justify-content: center; max-width: 100%; }
.key {
  min-width: 0; flex: 1 1 0; max-width: 44px; height: 52px;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface); color: var(--ink);
  font: 600 17px/1 var(--sans); text-transform: uppercase;
  cursor: pointer;
}
.key.wide { flex: 0 0 52px; max-width: 56px; font-size: 17px; }
.key[data-key="gå"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.key.outline { background: transparent; }
/* The same ✓ → × the tiles carry. The keyboard is the summary a player reads
   instead of re-checking every past guess, so it is the wrong place to make
   someone rely on fill tone: `near` had a dashed border, but `ok` and `absent`
   were told apart by colour alone. Small, because it reinforces a fill and a
   border rather than carrying the state by itself. */
.key { position: relative; }
.key[data-mark]::after {
  content: attr(data-mark);
  position: absolute; top: 2px; right: 3px;
  font: 700 10px/1 var(--sans); opacity: .9;
}
.key.ok { background: var(--ok); color: var(--ok-ink); border-color: var(--ok); }
.key.near { background: var(--near-soft); color: var(--near-ink); border: 2px dashed var(--near); }
.key.absent { background: var(--absent-fill); color: var(--absent); }

.kbd-hint { display: none; }
@media (min-width: 760px) {
  .row { grid-template-columns: repeat(5, 72px); gap: 10px; }
  .tile { height: 72px; font-size: 34px; }
  #keyboard { display: none; }
  .kbd-hint { display: block; }
}

#result[hidden] { display: none; }
#result {
  margin-top: 32px; padding: 24px;
  background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-panel);
}
#result h2 { margin-top: 0; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 24px 0; }
.stat { padding: 12px 8px; border: 1px solid var(--line); border-radius: var(--r-card); }
.stat b { display: block; font: 600 30px/1.1 var(--serif); }
.stat span { font-size: 15px; color: var(--muted); }
.streakline { margin: 0 0 20px; font-size: 18px; color: var(--muted); }
.result-actions { display: grid; gap: 12px; }

/* ---------- Sudoku ---------- */

#sudoku {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  width: min(100%, 520px);
  margin: 0 auto 24px;
  background: var(--surface);
  border: 3px solid var(--block);
  border-radius: 4px;
}
.cell {
  aspect-ratio: 1;
  display: grid; place-items: center;
  position: relative;
  border: 1px solid var(--grid);
  background: transparent;
  font: 500 22px/1 var(--sans);
  color: var(--accent);
  cursor: pointer;
  padding: 0;
}
.cell:nth-child(9n+1) { border-left: 0; }
.cell:nth-child(-n+9) { border-top: 0; }
.cell.b-right { border-right: 2px solid var(--block); }
.cell.b-bottom { border-bottom: 2px solid var(--block); }
.cell.given { font-weight: 700; color: var(--ink); }
.cell.peer { background: var(--sel); }
.cell.sel { background: var(--sel); box-shadow: inset 0 0 0 3px var(--accent); }
.cell.bad {
  background: var(--error-fill); color: var(--error);
  box-shadow: inset 0 0 0 3px var(--error-border);
}
.cell.bad::after {
  content: '△'; position: absolute; right: 2px; bottom: 0;
  font-size: 11px; line-height: 1;
}
.marks {
  display: grid; grid-template-columns: repeat(3, 1fr);
  width: 100%; height: 100%;
  font: 400 10px/1 var(--mono); color: var(--muted);
}
.marks span { display: grid; place-items: center; }

.pad { display: grid; grid-template-columns: repeat(9, 1fr); gap: 6px; margin: 16px auto; }
.pad button {
  height: 64px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--ink);
  font: 600 22px/1 var(--sans); cursor: pointer;
}
.pad button:hover { border-color: var(--accent); }
.controls { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 16px 0; }
.controls button {
  min-height: 48px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--ink);
  font: 600 17px/1 var(--sans); cursor: pointer;
}
.controls button.is-on {
  border: 2px solid var(--accent); background: var(--sel); color: var(--accent);
}
.diffs { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-bottom: 16px; }

@media (min-width: 760px) {
  .cell { font-size: 30px; }
  .marks { font-size: 13px; }
  .pad { grid-template-columns: repeat(9, 1fr); }
}

/* ---------- shared: result panel for the new games ---------- */

.result[hidden] { display: none; }
.result {
  margin-top: 32px; padding: 24px;
  background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-panel);
  text-align: center;
}
.result .icon {
  width: 44px; height: 44px; margin: 0 auto 12px;
  display: grid; place-items: center; border-radius: 999px;
  font-size: 22px; font-weight: 700;
}
.result.win .icon { background: var(--ok-soft); color: var(--ok); border: 2px solid var(--ok); }
.result.loss .icon { background: var(--error-fill); color: var(--error); border: 2px solid var(--error-border); }
.result h2 { margin: 0 0 4px; }
.result .sub { color: var(--muted); font-size: 18px; }

/* ---------- shared: zoom frame ---------- */

.frame {
  border: 2px solid var(--line); border-radius: 12px;
  background: var(--felt);
  overflow: auto; -webkit-overflow-scrolling: touch;
  max-height: 62vh; padding: 4px;
  position: relative;
}
.zoomctl { display: flex; gap: 8px; justify-content: center; margin: 12px 0; }
.zoomctl button {
  min-width: 48px; height: 48px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: var(--r-pill);
  background: var(--surface); color: var(--ink);
  font: 600 17px/1 var(--sans); cursor: pointer;
}

/* ---------- shared: segmented mode switch ---------- */

.seg {
  display: grid; grid-auto-flow: column; gap: 4px;
  padding: 4px; margin: 0 auto 16px; max-width: 320px;
  background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-pill);
}
.seg button {
  min-height: 48px; border: 0; border-radius: var(--r-pill);
  background: transparent; color: var(--ink);
  font: 600 18px/1 var(--sans); cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

/* ---------- Minsvepare ---------- */

#mineboard { display: grid; gap: 2px; justify-content: center; margin: 0 auto; }

.mcell {
  display: grid; place-items: center; padding: 0;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface); color: var(--ink);
  font-weight: 600; font-family: var(--sans);
  box-shadow: inset 0 -3px 0 var(--edge);      /* raised — a shape, not a shadow */
  cursor: pointer; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.mcell.cursor { outline: 3px solid var(--accent); outline-offset: 2px; z-index: 1; }
.mcell.open {
  background: var(--bg); border-color: var(--grid);
  box-shadow: none;                             /* sunken */
  cursor: default;
}
.mcell.flagged { border: 2px solid var(--accent); background: var(--sel); color: var(--accent); }
.mcell.unknown { border: 2px dashed var(--muted); color: var(--muted); }
.mcell.mine { background: var(--error-fill); border: 3px solid var(--error-border); color: var(--error); }
.mcell.boom { background: var(--error); border: 3px solid var(--error); color: #fff; }
.mcell.wrongflag {
  background: var(--absent-fill); color: var(--absent);
  border: 2px solid var(--absent); text-decoration: line-through;
}
.mcell.goodflag { background: var(--ok-soft); border: 2px solid var(--ok); color: var(--ok); }

/* Digit colours are reinforcement only — the numeral carries the meaning,
   so the board stays readable in greyscale. */
.mcell.n1 { color: var(--num-1); } .mcell.n2 { color: var(--num-2); }
.mcell.n3 { color: var(--num-3); } .mcell.n4 { color: var(--num-4); }
.mcell.n5 { color: var(--num-5); } .mcell.n6 { color: var(--num-6); }
.mcell.n7 { color: var(--num-7); } .mcell.n8 { color: var(--num-8); }

.only-desktop { display: none; }
@media (min-width: 1024px) { .only-desktop { display: inline; } }

/* ---------- Mahjong ---------- */

#mjboard { position: relative; margin: 0 auto; }

.mjtile {
  position: absolute; padding: 0;
  display: grid; place-items: center;
  background: var(--card-face); color: var(--ink);
  border: 2px solid var(--ink); border-radius: 6px;
  box-shadow: inset 0 -7px 0 var(--edge);     /* raised = free */
  font-family: var(--sans); font-weight: 600;
  cursor: pointer; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
/* Blocked differs by border weight, a flat face and a hatch — never by
   brightness alone. */
.mjtile.blocked {
  border: 1px solid var(--line);
  box-shadow: none;
  cursor: not-allowed;
  background-image: repeating-linear-gradient(45deg,
    var(--hatch) 0 4px, transparent 4px 9px);
}
.mjtile.sel {
  border: 3px solid var(--accent); background: var(--sel);
  box-shadow: inset 0 -8px 0 var(--edge);
}
.mjtile.hint { border: 3px dashed var(--accent); }
.mjtile.shakeit { animation: shake .16s ease-in-out; }

.pip {
  display: grid; place-items: center; line-height: 1;
  width: 66%; height: 66%;
}
.pip svg { display: block; }
.pip .cjk { font-size: 1.5em; line-height: 1; }

.gamectl { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 16px 0; }
.gamectl button {
  min-height: 48px; padding: 0 20px;
  border: 1px solid var(--line); border-radius: var(--r-pill);
  background: var(--surface); color: var(--ink);
  font: 600 17px/1 var(--sans); cursor: pointer;
}
.gamectl button:hover { border-color: var(--accent); }

/* ---------- Patiens ---------- */

.pattop { display: grid; grid-template-columns: auto auto 1fr; gap: 10px; align-items: start; margin-bottom: 16px; }
#foundations { display: flex; gap: 6px; justify-content: flex-end; }
/* Foundations need a real card width, or four of them collapse into stamps. */
.pslot { position: relative; width: 56px; flex: none; }
#stockpile, #wastepile { width: 56px; }

#patboard { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; align-items: start; }
.pcol { position: relative; min-height: 92px; }

.pcard {
  position: relative;
  width: 100%; aspect-ratio: .72;
  background: var(--card-face); color: var(--ink);
  border: 1px solid var(--ink); border-radius: 6px;
  display: grid; align-content: start; justify-items: center;
  padding: 3px 0; gap: 1px;
  font-family: var(--sans); font-weight: 600; line-height: 1;
  cursor: pointer; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.pcol .pcard { position: absolute; left: 0; right: 0; }
.pcard .rank { font-size: 17px; }
.pcard .suit { font-size: 19px; }

/* Red suits do not rely on colour alone — the rank is underlined too. */
.pcard.red { color: var(--error); }
.pcard.red .rank { text-decoration: underline; text-underline-offset: 2px; }

.pcard.down {
  background-image: repeating-linear-gradient(45deg,
    var(--hatch) 0 4px, transparent 4px 9px);
  background-color: var(--surface);
  border-color: var(--line);
}
.pcard.empty {
  background: transparent; border: 1px dashed var(--edge);
  color: var(--absent);
}
.pcard.empty .ghost { font-size: 22px; }
.pcard.sel {
  border: 3px solid var(--accent); background: var(--sel);
  transform: translateY(-6px); z-index: 5;
}
.pcard.target { border: 2px dashed var(--accent); }
.pcard.target::after {
  content: '▾'; position: absolute; bottom: 0; left: 0; right: 0;
  text-align: center; color: var(--accent); font-size: 15px; line-height: 1;
}

#patstatus {
  min-height: 44px; display: grid; align-items: center;
  padding: 10px 14px; margin: 12px 0;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-card); font-size: 17px; color: var(--muted);
  text-align: left;
}

@media (min-width: 1024px) {
  .pcard .rank { font-size: 22px; }
  .pcard .suit { font-size: 28px; }
  .pcol { min-height: 124px; }
  .pslot, #stockpile, #wastepile { width: 88px; }
}

/* ---------- Minnesspel ---------- */

#memboard { display: grid; gap: 10px; max-width: 460px; margin: 0 auto; }
.memcard {
  aspect-ratio: .82; min-height: 76px; padding: 0;
  display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--ink);
  box-shadow: inset 0 -4px 0 var(--edge);
  background-image: repeating-linear-gradient(45deg,
    var(--hatch) 0 4px, transparent 4px 9px);
  font-size: 30px; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.memcard.up {
  border: 3px solid var(--accent); background: var(--sel);
  background-image: none; color: var(--accent); box-shadow: none;
}
/* A matched pair keeps its tick permanently — not just a tint. */
.memcard.matched {
  border: 2px solid var(--ok); background: var(--ok-soft);
  background-image: none; color: var(--ok); box-shadow: none;
  cursor: default; position: relative;
}
.memcard.matched::after {
  content: '✓'; position: absolute; top: 3px; right: 6px; font-size: 14px;
}
.memcard.bad {
  border: 3px solid var(--error-border); background: var(--error-fill);
  background-image: none; color: var(--error); position: relative;
}
.memcard.bad::after {
  content: '△'; position: absolute; top: 3px; right: 6px; font-size: 14px;
}
@media (min-width: 1024px) { #memboard { max-width: 560px; } .memcard { font-size: 36px; } }

/* ---------- 2048 ---------- */

#g2048 {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
  max-width: 420px; margin: 0 auto; padding: 8px;
  background: var(--grid); border-radius: 12px;
  touch-action: none;
}
.tile2048 {
  aspect-ratio: 1; display: grid; place-items: center;
  border-radius: 8px; background: var(--absent-fill);
  font: 600 34px/1 var(--sans); color: var(--ink);
}
.tile2048.three { font-size: 28px; }
.tile2048.four { font-size: 22px; }
.tile2048.v2    { background: #FFFFFF; }
.tile2048.v4    { background: #F3EADA; }
.tile2048.v8    { background: #E9C89A; }
.tile2048.v16   { background: #DDA265; }
.tile2048.v32   { background: #C97A42; color: #fff; }
.tile2048.v64   { background: #B4531F; color: #fff; }
.tile2048.v128  { background: #8E3F14; color: #fff; }
.tile2048.v256  { background: #7A3510; color: #fff; }
.tile2048.v512  { background: #4C6B3C; color: #fff; }
.tile2048.v1024 { background: var(--ok-soft); color: var(--ok); }
.tile2048.v2048 { background: #4C6B3C; color: #fff; }
/* The two milestones also take a border, so they read without colour. */
.tile2048.milestone { border: 3px solid var(--ok); }
@media (min-width: 1024px) { #g2048 { max-width: 480px; } }

/* ---------- Minsvepare: the board gets the full measure ----------

   Cells never go below a 40 px tap target, so an expert field is 30 x 42 px =
   1260 px wide. In the shared 560 px game column that hid over half the board
   and needed a minimap to navigate. Widening the column shows nearly all of it
   and the minimap stops being necessary. Only the board wants the extra room —
   the controls and the result panel stay at the narrow measure. */

.game-wide { max-width: 1180px; }
.game-wide .frame { max-height: 78vh; }
.game-wide .result { max-width: 560px; margin-left: auto; margin-right: auto; }

/* ---- Kungen (FreeCell) ------------------------------------------------- */

/* One row of eight wherever the card can stay usably big, two banks of four
   below that.

   The handoff split the board in two so a 46 px card would fit at 320 px, on
   the grounds that side-scrolling hides half the board while the player is
   planning. That reasoning condemns stacking too — a board you scroll is a
   board you cannot plan on, whichever way you scroll. But eight columns below
   ~390 px drives the card to 33 px wide, under the 40 px floor this site holds
   everywhere else, and the audience skews 45+.

   So: one row from 390 px up, which covers most phones in portrait; two banks
   only on genuinely small screens, where a readable card matters more than
   seeing all eight at once. */
/* Keyed to the board's own width, not the window's. A viewport media query
   cannot see the padding, the sidebar or a future embed, so it guesses wrong
   about how much room the cards actually have. */
.kboardwrap { container-type: inline-size; container-name: kboard; }

#kboard { display: block; }
/* A hard floor, not a suggestion. If the threshold above is ever set wrong the
   board will overflow visibly here rather than quietly rendering a 29 px card
   that a 45+ audience cannot hit — a loud failure beats a silent one. */
#kboard .pcol { min-width: 40px; }
.kbank { display: grid; grid-template-columns: repeat(4, 1fr); gap: 3px; align-items: start; }
.kbanklabel { font: 400 15px/1 var(--mono); color: var(--muted); margin: 16px 0 6px; letter-spacing: .08em; }
.kbanklabel:first-child { margin-top: 0; }

/* 376 px is derived, not chosen: eight columns plus seven 3 px gaps leaves
   (376 - 21) / 8 = 44 px per card, the narrowest that still fits a 17 px rank
   beside a 19 px suit — and 17 px is this site's floor for product text. Move
   the type floor and this number moves with it. */
@container kboard (min-width: 376px) {
  #kboard { display: grid; grid-template-columns: repeat(8, 1fr); gap: 3px; align-items: start; }
  .kbank { display: contents; }
  .kbanklabel { display: none; }
}

.ktop { display: grid; gap: 12px; margin-bottom: 12px; }
.kcells, .kfound { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.kgroup > .mono { margin: 0 0 6px; color: var(--muted); font-size: 15px; letter-spacing: .08em; }

/* Free cells are sunken wells; foundations are bordered and rounder. The two
   must never be told apart by colour alone. */
.kcell {
  border-radius: 4px;
  box-shadow: inset 0 3px 0 var(--edge);
  background: var(--surface); border: 1px solid var(--line);
}
.kfound .pcard.empty { border-radius: 10px; }
.kcells.full { outline: 2px solid var(--near); outline-offset: 4px; border-radius: 6px; }
.kcells.stuck { outline: 2px solid var(--error); outline-offset: 4px; border-radius: 6px; }

/* The supermove meter. Permanent, never hidden, never abbreviated — a player
   who cannot see the limit reads a refused move as a broken game. */
.kmeter {
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); padding: 10px 12px; margin-bottom: 12px;
}
.kmeter b { font: 600 19px/1.3 var(--sans); display: block; }
.kmeter span { font: 400 15px/1.4 var(--mono); color: var(--muted); letter-spacing: .04em; }

/* In a fanned column only the top strip of a covered card shows, and the
   shared .pcard stacks rank above suit — so the suit fell outside the strip
   and ♠ could not be told from ♣ on any covered card. Lay it out horizontally
   here so both read at a glance. */
#kboard .pcol .pcard {
  grid-auto-flow: column; justify-content: center; align-content: start;
  gap: 4px; padding-top: 5px;
}
/* 8 columns means one card is ~12cqw. The rank and suit grow with it and stop
   at 17/19 px, which is this site's floor for product text — that floor, not
   the pixel width, is what decides when eight columns stop fitting. */
#kboard .pcol .pcard .rank { font-size: clamp(17px, 4.6cqw, 22px); }
#kboard .pcol .pcard .suit { font-size: clamp(19px, 5.4cqw, 28px); }
#kboard .pcol .pcard.empty { grid-auto-flow: row; }

/* Cards past the movable limit while a run is selected. Same hatch as a
   face-down card elsewhere, so "not available" reads the same everywhere. */
.pcard.beyond {
  background-image: repeating-linear-gradient(45deg,
    var(--hatch) 0 4px, transparent 4px 9px);
}
.pcard.bad { border: 3px solid var(--error); background: var(--error-fill); }
@media (prefers-reduced-motion: no-preference) {
  .pcard.bad { animation: kshake .16s linear; }
}
@keyframes kshake {
  0%, 100% { transform: translateX(0); } 25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

@container kboard (min-width: 700px) {
  #kboard { gap: 8px; }
}

@media (min-width: 700px) {
  .ktop { grid-template-columns: auto auto; justify-content: start; gap: 24px; }
  .kgroup + .kgroup { border-left: 1px solid var(--line); padding-left: 24px; }
}
