/* ── Bored? — Zufallsspiel-Seite ────────────────────────────────────────────
   Token-Layer oben, danach Shell (Topbar/Stage/Statusbar/Picker), danach
   generische Spiel-Bausteine (Overlay, Boards, Bildschirmtastatur).
   Einzelne Spiele bringen ihre Feinheiten in .game-<id>-Blöcken mit.        */

:root {
  --bg:        #0e1016;
  --bg-2:      #161a24;
  --bg-3:      #1e2431;
  --line:      #2a3241;
  --fg:        #e8ecf4;
  --fg-dim:    #97a1b4;
  --fg-faint:  #626d80;
  --accent:    #5ac8fa;
  --accent-2:  #7c5cff;
  --good:      #4ade80;
  --warn:      #fbbf24;
  --bad:       #f87171;
  --radius:    14px;
  --radius-sm: 9px;
  --shadow:    0 10px 30px rgb(0 0 0 / 45%);
  --topbar-h:  56px;
  --status-h:  38px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  overflow: hidden;                 /* die Stage scrollt, nicht die Seite */
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

button { font-family: inherit; font-size: inherit; }

/* ── Topbar ───────────────────────────────────────────────────────────── */

.topbar {
  flex: 0 0 auto;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 max(10px, env(safe-area-inset-left)) 0 max(10px, env(safe-area-inset-right));
  background: linear-gradient(180deg, var(--bg-2), var(--bg));
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  flex: 0 1 auto;
  min-width: 0;
  padding: 7px 11px 7px 9px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--fg);
  font-size: 1.02rem;
  font-weight: 650;
  letter-spacing: -0.01em;
  cursor: pointer;
}
.brand:hover  { background: var(--bg-3); border-color: var(--line); }
.brand-name   { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-caret  { color: var(--fg-faint); font-size: 0.8em; }
.brand-dot {
  flex: 0 0 auto;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgb(90 200 250 / 18%);
}

.topbar-actions { margin-left: auto; display: flex; gap: 8px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-3);
  color: var(--fg);
  font-size: 0.9rem;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s, transform .06s;
}
.btn:hover  { background: #26303f; border-color: #384356; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .brand:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-primary {
  background: linear-gradient(180deg, var(--accent), #38b6ee);
  border-color: #7ad4fb;
  color: #062330;
  font-weight: 680;
}
.btn-primary:hover { background: linear-gradient(180deg, #74d3fb, #45bef2); }

.btn-ghost { background: none; border-color: transparent; color: var(--fg-dim); }
.btn-ghost:hover { background: var(--bg-3); color: var(--fg); }

/* ── Stage ────────────────────────────────────────────────────────────── */

.stage {
  flex: 1 1 auto;
  position: relative;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  overflow: hidden;
}
.stage:focus { outline: none; }

/* Canvas-Spiele: Größe wird in JS gesetzt (siehe engine.makeCanvas). */
.game-canvas {
  display: block;
  border-radius: var(--radius);
  background: #0a0c12;
  box-shadow: var(--shadow);
  touch-action: none;
}

/* Gemeinsame Hülle, mittig, nie größer als die Stage.
   `height: 100%` ist wichtig: nur so kann ein Kind mit `flex: 1` (z. B. der
   Canvas-Halter bei Snake) überhaupt Höhe bekommen — mit auto-Höhe
   kollabiert es auf 0 und das Canvas wird unsichtbar. */
.game-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  height: 100%;
  max-width: 100%;
  overflow: auto;
  padding: 2px;
}

/* Halter für ein Canvas, das den Restplatz einnehmen soll. */
.canvas-fill {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Statusbar ────────────────────────────────────────────────────────── */

/* Schmale Bildschirme: der Spielname hat Vorrang vor den Button-Texten. */
@media (max-width: 520px) {
  .topbar { gap: 6px; padding: 0 8px; }
  .btn { padding: 8px 11px; }
  .btn-label { display: none; }
  .btn-primary .btn-icon { font-size: 1.05rem; }
  .brand { flex: 1 1 auto; padding-left: 4px; }
}

.statusbar {
  flex: 0 0 auto;
  min-height: var(--status-h);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 4px max(12px, env(safe-area-inset-left)) max(4px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--bg-2);
  font-size: 0.84rem;
}
.status { color: var(--fg); font-variant-numeric: tabular-nums; font-weight: 550; }
.hint   { margin-left: auto; color: var(--fg-faint); text-align: right; }
@media (max-width: 560px) {
  .hint { display: none; }
}

/* ── Picker (Overlay mit allen Spielen) ───────────────────────────────── */

.picker {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 16px;
  background: rgb(6 8 12 / 72%);
  backdrop-filter: blur(3px);
}
.picker[hidden] { display: none; }

.picker-panel {
  width: min(680px, 100%);
  max-height: 100%;
  margin-top: min(8vh, 60px);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-2);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.picker-head {
  display: flex;
  align-items: center;
  padding: 12px 12px 12px 18px;
  border-bottom: 1px solid var(--line);
}
.picker-head h2 { margin: 0; font-size: 1rem; font-weight: 650; }
.picker-head .btn { margin-left: auto; }

.picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px;
  padding: 14px;
  overflow: auto;
}
.picker-card {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-3);
  color: var(--fg);
  text-align: left;
  cursor: pointer;
}
.picker-card:hover { border-color: var(--accent); background: #26303f; }
.picker-card[aria-current="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.picker-card .pc-top  { display: flex; align-items: center; gap: 8px; font-weight: 620; }
.picker-card .pc-emoji { font-size: 1.15rem; }
.picker-card .pc-sub  { color: var(--fg-dim); font-size: 0.8rem; }
.picker-card .pc-best { color: var(--accent); font-size: 0.76rem; font-variant-numeric: tabular-nums; }

/* ── Overlay im Spiel (Game Over / Sieg / Pause) ──────────────────────── */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 20px;
  text-align: center;
  background: rgb(9 11 16 / 82%);
  backdrop-filter: blur(2px);
  animation: fade .16s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.overlay-title { margin: 0; font-size: clamp(1.4rem, 5vw, 2rem); font-weight: 720; letter-spacing: -0.02em; }
.overlay-sub   { margin: 0; color: var(--fg-dim); max-width: 34ch; }
.overlay-sub b  { color: var(--fg); }
.overlay .btn  { margin-top: 8px; padding: 11px 20px; font-size: 1rem; }
.overlay.win  .overlay-title { color: var(--good); }
.overlay.lose .overlay-title { color: var(--bad); }

/* ── Bildschirmtastatur (Wordle, Hangman) ─────────────────────────────── */

.keyboard {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: min(520px, 100%);
}
.kb-row { display: flex; justify-content: center; gap: 5px; }
.kb-key {
  flex: 1 1 auto;
  min-width: 0;
  height: 46px;
  padding: 0 2px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--bg-3);
  color: var(--fg);
  font-size: 0.95rem;
  font-weight: 620;
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.kb-key:hover:not(:disabled) { background: #2b3646; }
.kb-key:disabled { opacity: .45; cursor: default; }
.kb-key.wide { flex: 1.6 1 auto; font-size: 0.82rem; }
.kb-key.state-correct { background: var(--good); border-color: var(--good); color: #06230f; }
.kb-key.state-present { background: var(--warn); border-color: var(--warn); color: #2a1c00; }
.kb-key.state-absent  { background: #232a36; border-color: #232a36; color: var(--fg-faint); }
@media (max-width: 420px) {
  .kb-key { height: 42px; font-size: 0.86rem; }
}

/* ── Mobile Steuerkreuz (Snake u. a.) ─────────────────────────────────── */

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(2, 52px);
  gap: 6px;
  justify-content: center;
}
.dpad button {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-3);
  color: var(--fg);
  font-size: 1.1rem;
  cursor: pointer;
}
.dpad button:active { background: var(--accent); color: #062330; }
.dpad .d-up    { grid-area: 1 / 2; }
.dpad .d-left  { grid-area: 2 / 1; }
.dpad .d-down  { grid-area: 2 / 2; }
.dpad .d-right { grid-area: 2 / 3; }
@media (hover: hover) and (pointer: fine) {
  .dpad { display: none; }               /* Maus/Tastatur braucht kein Kreuz */
}

.noscript {
  padding: 24px;
  color: var(--warn);
  text-align: center;
}

/* ── 2048 ─────────────────────────────────────────────────────────────── */

.g2048-board {
  --gap: 9px;
  --n: 4;                        /* Spalten/Zeilen, wird in JS gesetzt */
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  grid-template-rows: repeat(var(--n), 1fr);
  gap: var(--gap);
  width: min(500px, 92vw, 62vh);
  aspect-ratio: 1;
  padding: var(--gap);
  border-radius: var(--radius);
  background: var(--bg-3);
  touch-action: none;
}
.g2048-cell { border-radius: var(--radius-sm); background: rgb(255 255 255 / 4%); }
.g2048-tile {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  width:  calc((100% - (var(--n) + 1) * var(--gap)) / var(--n));
  height: calc((100% - (var(--n) + 1) * var(--gap)) / var(--n));
  border-radius: var(--radius-sm);
  font-size: clamp(1.1rem, 6.5vw, 2rem);
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  color: #1b1205;
  background: #eee4da;
  transition: left .1s ease-out, top .1s ease-out;
  will-change: left, top;
}
.g2048-board[style*="--n: 5"] { --gap: 7px; }
.g2048-board[style*="--n: 5"] .g2048-tile { font-size: clamp(.9rem, 5vw, 1.6rem); }
.g2048-board[style*="--n: 3"] .g2048-tile { font-size: clamp(1.4rem, 9vw, 2.6rem); }
.g2048-tile[data-len="3"] { font-size: clamp(.95rem, 5.4vw, 1.7rem); }
.g2048-tile[data-len="4"] { font-size: clamp(.8rem, 4.4vw, 1.4rem); }
.g2048-tile[data-len="5"] { font-size: clamp(.7rem, 3.6vw, 1.15rem); }
.g2048-score { display: flex; gap: 10px; }
.g2048-score .chip { font-size: 0.9rem; color: var(--fg); }
.g2048-tile.spawn { animation: pop .14s ease-out; }
.g2048-tile.merged { animation: bump .16s ease-out; }
@keyframes pop  { from { transform: scale(.4); opacity: 0; } }
@keyframes bump { 50% { filter: brightness(1.25); } }

/* ── Memory ───────────────────────────────────────────────────────────── */

.memory-board {
  display: grid;
  gap: 8px;
  width: min(480px, 92vw, 60vh);
}
.memory-board[data-cols="5"] { width: min(560px, 94vw, 62vh); gap: 7px; }
.memory-board[data-cols="6"] { width: min(620px, 96vw, 66vh); gap: 6px; }
.memory-board[data-cols="6"] .memory-face { font-size: clamp(1.1rem, 5vw, 1.7rem); }

/* Kurz aufblitzen, wenn eine Karte den Platz gewechselt hat. */
.memory-card.swapped .memory-back { animation: swapGlow .5s ease-out; }
@keyframes swapGlow {
  0%, 100% { box-shadow: none; }
  40% { box-shadow: 0 0 0 3px var(--warn); }
}
.memory-card {
  aspect-ratio: 1;
  border: 0;
  padding: 0;
  border-radius: var(--radius-sm);
  background: none;
  cursor: pointer;
  perspective: 600px;
}
.memory-inner {
  position: relative;
  width: 100%; height: 100%;
  transition: transform .28s;
  transform-style: preserve-3d;
}
.memory-card.flipped .memory-inner { transform: rotateY(180deg); }
.memory-face {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  backface-visibility: hidden;
  font-size: clamp(1.4rem, 7vw, 2.2rem);
}
.memory-back  { background: linear-gradient(140deg, var(--accent-2), #4a3ad0); }
.memory-front { background: var(--bg-3); border: 1px solid var(--line); transform: rotateY(180deg); }
.memory-card.done .memory-front { background: #14351f; border-color: var(--good); }
.memory-card.done { cursor: default; }

/* ── Minesweeper ──────────────────────────────────────────────────────── */

.mine-board {
  display: grid;
  gap: 3px;
  padding: 8px;
  border-radius: var(--radius);
  background: var(--bg-3);
  width: min(480px, 94vw, 62vh);
  touch-action: manipulation;
}
/* Größere Bretter brauchen mehr Breite und dürfen enger stehen. */
.mine-board[data-size="mittel"] { width: min(620px, 96vw, 72vh); gap: 2px; }
.mine-board[data-size="profi"]  { width: min(900px, 97vw, 108vh); gap: 2px; padding: 6px; }
.mine-board[data-size="profi"] .mine-cell,
.mine-board[data-size="mittel"] .mine-cell { border-radius: 3px; }
.mine-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #313b4c;
  border-radius: 4px;
  background: #29323f;
  color: var(--fg);
  font-size: clamp(.7rem, 2.6vw, 1rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  padding: 0;
  user-select: none;
}
.mine-cell:hover:not(.open) { background: #35404f; }
.mine-cell.open  { background: #171c25; border-color: #202836; cursor: default; }
.mine-cell.flag  { background: #3a2a12; border-color: var(--warn); }
.mine-cell.boom  { background: var(--bad); border-color: var(--bad); }
.mine-cell.n1 { color: #74b9ff; } .mine-cell.n2 { color: #4ade80; }
.mine-cell.n3 { color: #fbbf24; } .mine-cell.n4 { color: #c084fc; }
.mine-cell.n5 { color: #fb923c; } .mine-cell.n6 { color: #22d3ee; }
.mine-cell.n7 { color: #f9a8d4; } .mine-cell.n8 { color: #e5e7eb; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}
.toolbar .chip {
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-2);
  color: var(--fg-dim);
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.toolbar .chip.on { border-color: var(--accent); background: rgb(90 200 250 / 14%); color: var(--fg); }
.toolbar .chip.static { cursor: default; }

/* Stufen-Auswahl: zusammenhängende Chip-Gruppe. */
.levels { display: inline-flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.levels .chip {
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-2);
  color: var(--fg-dim);
  font-size: 0.82rem;
  cursor: pointer;
}
.levels .chip:hover { color: var(--fg); border-color: #384356; }
.levels .chip.on { border-color: var(--accent); background: rgb(90 200 250 / 14%); color: var(--fg); }

/* ── Wordle ───────────────────────────────────────────────────────────── */

.wordle-grid {
  --len: 5;
  display: grid;
  gap: 6px;
  /* Breite wächst mit der Wortlänge, bleibt aber im Bild. */
  width: min(92vw, calc(var(--len) * 62px));
}
.wordle-row {
  display: grid;
  grid-template-columns: repeat(var(--len), 1fr);
  gap: 6px;
}
.wordle-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--line);
  border-radius: 7px;
  font-size: clamp(1.1rem, 4.6vw, 1.7rem);
  font-weight: 720;
  text-transform: uppercase;
}
.wordle-cell.filled { border-color: #445067; }
.wordle-cell.state-correct { background: var(--good); border-color: var(--good); color: #06230f; }
.wordle-cell.state-present { background: var(--warn); border-color: var(--warn); color: #2a1c00; }
.wordle-cell.state-absent  { background: #232a36; border-color: #232a36; color: var(--fg-dim); }
/* Bei 7 Buchstaben wird es eng — Schrift mitschrumpfen lassen. */
.wordle-grid[style*="--len: 6"] .wordle-cell { font-size: clamp(1rem, 4vw, 1.5rem); }
.wordle-grid[style*="--len: 7"] .wordle-cell { font-size: clamp(.9rem, 3.4vw, 1.35rem); }
.wordle-row.shake { animation: shake .3s; }
@keyframes shake {
  25% { transform: translateX(-6px); } 75% { transform: translateX(6px); }
}
.wordle-cell.reveal { animation: flip .3s ease-in; }
@keyframes flip { 0% { transform: rotateX(-90deg); } }

/* ── Hangman ──────────────────────────────────────────────────────────── */

.hangman-wrap { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.hangman-svg { width: min(190px, 38vw); height: auto; }
.hangman-svg .hm-part { stroke: var(--fg); stroke-width: 4; stroke-linecap: round; fill: none; }
.hangman-svg .hm-frame { stroke: var(--fg-faint); stroke-width: 5; stroke-linecap: round; fill: none; }
.hangman-word {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  justify-content: center;
  font-family: var(--mono);
  font-size: clamp(1.5rem, 7vw, 2.3rem);
  font-weight: 700;
  letter-spacing: .04em;
}
.hm-slot {
  min-width: 1.15em;
  padding-bottom: 5px;
  border-bottom: 3px solid var(--fg-faint);
  text-align: center;
}
.hm-slot.solved { border-bottom-color: var(--good); }
.hm-slot.space  { border-bottom-color: transparent; }
.hangman-cat { color: var(--fg-dim); font-size: 0.86rem; }

/* ── Reduzierte Bewegung ──────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    transition-duration: .001ms !important;
  }
}
