:root {
  --bg: #14121f;
  --panel: #1f1b33;
  --panel2: #2a2545;
  --text: #f2f0ff;
  --muted: #a49fc4;
  --accent: #8b7bff;
  --on-accent: #120d33;
  --gold: #ffcf4d;
  --ink: #0b0a14;
  --ok: #5fd39a;
  --warn: #ffb454;
  --overlay: rgba(20, 18, 31, .82);
  --bar: #14121f;   /* bande sous la barre d'état : voir la règle prefers-color-scheme ci-dessous */
  color-scheme: dark;
}
/* iOS colore l'heure et la batterie selon le réglage clair/sombre du TÉLÉPHONE (pas selon le thème de l'app). La bande qui
 * s'étend sous la barre d'état suit donc le réglage du téléphone : elle se confond avec le fond quand le thème de l'app
 * est le même (cas courant, invisible), et reste lisible si l'on force un thème différent de celui du téléphone. */
@media (prefers-color-scheme: light) { :root { --bar: #f3f1fa; } }
/* Thème clair : choisi explicitement (data-theme="light", posé par theme.js) ou, en mode automatique, suivant le système. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f3f1fa; --panel: #ffffff; --panel2: #e6e2f5; --text: #1c1833; --muted: #5d577c;
    --accent: #6b5bff; --on-accent: #ffffff; --gold: #b98600; --ok: #1c9a62; --warn: #c76a00;
    --overlay: rgba(243, 241, 250, .9);
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #f3f1fa; --panel: #ffffff; --panel2: #e6e2f5; --text: #1c1833; --muted: #5d577c;
  --accent: #6b5bff; --on-accent: #ffffff; --gold: #b98600; --ok: #1c9a62; --warn: #c76a00;
  --overlay: rgba(243, 241, 250, .9);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; background: var(--bg); }
/* Pas de zoom au double-tap (le pincement reste possible) ; pas de sélection de texte sur les boutons. */
html, body, button, select, summary { touch-action: manipulation; }
.btn, .sel, summary { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
/* Mise en page : c'est la PAGE qui défile (et non un conteneur de hauteur fixée), l'en-tête reste collé en haut.
 * Sur iPhone, le contenu va ainsi jusqu'au bord réel de l'écran, sans dépendre de la hauteur de fenêtre annoncée par iOS.
 * Les marges de sécurité (barre d'état, indicateur d'accueil, bords en paysage) ne servent qu'à ne pas masquer le contenu. */
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 6px;
  padding: calc(env(safe-area-inset-top) + 24px) max(14px, env(safe-area-inset-right)) 8px max(14px, env(safe-area-inset-left));
  background: var(--bg);
  /* bande sous la barre d'état : couleur du réglage du téléphone (cf. --bar), pour que l'heure reste lisible */
  background: linear-gradient(var(--bar), var(--bar)) 0 0 / 100% env(safe-area-inset-top) no-repeat, var(--bg);
}
.top h1 { margin: 0; font-size: 1.25rem; font-weight: 700; }
.back {
  font-size: 2rem; line-height: 1; color: var(--text); text-decoration: none;
  padding: 0 10px 4px 2px; margin-left: -4px;
}

main {
  /* contenu centré sur 640 px max ; le bas laisse la place de l'indicateur d'accueil */
  padding: 4px max(14px, calc((100% - 640px) / 2), env(safe-area-inset-right)) calc(env(safe-area-inset-bottom) + 16px)
           max(14px, calc((100% - 640px) / 2), env(safe-area-inset-left));
}
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.lead { margin: 4px 0 12px; color: var(--muted); }

/* ---------- boutons & champs ---------- */
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 10px 0; }
.row.center { justify-content: center; }
.btn, .sel, .input {
  appearance: none; -webkit-appearance: none;
  border: 0; border-radius: 12px;
  background: var(--panel2); color: var(--text);
  font: inherit; font-weight: 600;
  min-height: 44px; padding: 10px 14px;
}
.btn { cursor: pointer; }
.btn:active { transform: scale(.97); }
.btn:focus-visible, .sel:focus-visible, .input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn[disabled] { opacity: .4; cursor: default; }
.sel { padding-right: 10px; }
.input { width: 100%; font-weight: 500; user-select: text; -webkit-user-select: text; }
.actions .btn { flex: 1 1 0; padding-inline: 8px; }

.info {
  display: flex; justify-content: space-between;
  color: var(--muted); font-variant-numeric: tabular-nums;
}
.info .time { color: var(--text); font-weight: 700; font-size: 1.1rem; }

/* ---------- accueil : lanceur ---------- */
.sortbar { justify-content: flex-end; margin: 4px 0 2px; gap: 10px; }
.sortbar .sel { min-height: 38px; padding: 6px 10px; font-size: .9rem; }
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-top: 8px; }
.tile {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 20px 10px 16px; min-height: 164px;
  background: var(--panel); border-radius: 20px;
  color: inherit; text-decoration: none; text-align: center;
  -webkit-tap-highlight-color: transparent;
}
a.tile:active { transform: scale(.97); background: var(--panel2); }
a.tile:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.tile.soon { opacity: .55; }
.tile .ico {
  width: 68px; height: 68px; margin-bottom: 8px; border-radius: 20px;
  display: grid; place-items: center; color: #fff;
  box-shadow: 0 6px 16px rgba(0, 0, 0, .28);
}
.tile .ico svg { width: 40px; height: 40px; }
.tile strong { font-size: 1.05rem; }
.tile .desc { color: var(--muted); font-size: .8rem; line-height: 1.3; }
.badge {
  position: absolute; top: 10px; right: 10px;
  padding: 2px 9px; border-radius: 999px;
  background: var(--panel2); color: var(--muted); font-size: .7rem; font-weight: 600;
}
.center-text { text-align: center; }

/* ---------- paramètres (engrenage en haut à droite) ---------- */
.gear {
  position: relative; margin-left: auto; width: 40px; height: 40px; padding: 0;
  display: grid; place-items: center; border: 0; border-radius: 12px;
  background: transparent; color: var(--muted); cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.gear:active { background: var(--panel2); }
.gear:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
.gear svg { width: 24px; height: 24px; display: block; }
.gear .dot {   /* visible seulement hors ligne */
  position: absolute; top: 6px; right: 6px; width: 11px; height: 11px; border-radius: 50%;
  background: var(--warn); border: 2px solid var(--bg);
}

/* ---------- badge de série de jours (façon notification iOS) ---------- */
.tile .ico { position: relative; }
.streak {
  position: absolute; top: -8px; right: -8px;
  min-width: 26px; height: 26px; padding: 0 7px; border-radius: 13px;
  display: grid; place-items: center;
  background: #ff3b30; color: #fff; font-size: .9rem; font-weight: 700; line-height: 1;
  border: 2px solid var(--panel); box-shadow: 0 2px 6px rgba(0, 0, 0, .3);
  font-variant-numeric: tabular-nums;
}

/* ---------- panneau des paramètres ---------- */
.set-section { margin: 14px 0 0; }
.set-section h3 { margin: 0 0 6px; font-size: .8rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.set-net { display: flex; align-items: center; gap: 10px; margin: 0; }
.set-net svg { width: 24px; height: 24px; flex: none; }
.set-net[data-state="online"] { color: var(--ok); }
.set-net[data-state="offline"] { color: var(--warn); }
.set-net strong { color: var(--text); }
.seg { display: flex; gap: 6px; }
.seg .btn { flex: 1 1 0; padding-inline: 6px; }
.seg .btn[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.btn.danger { background: transparent; color: #ff5a4f; box-shadow: inset 0 0 0 2px currentColor; }
:root[data-theme="light"] .btn.danger { color: #d3281d; }
@media (prefers-color-scheme: light) { :root:not([data-theme="dark"]) .btn.danger { color: #d3281d; } }
.sheet .set-close { width: 100%; margin-top: 16px; }

/* couleurs des tuiles (même palette que les icônes de l'app, cf. tools/make_icons.py) */
.g-queens .ico { background: #6b5bff; color: #ffcf4d; }
.g-nonogram .ico { background: #1fb5a3; }
.g-sudoku .ico { background: #f0634f; }
.g-watersort .ico { background: #3d8bff; }
.g-flow .ico { background: #e8a317; }
.g-other .ico { background: #8b7bff; }
.g-2048 .ico { background: #e0922f; }
.g-rushhour .ico { background: #d9453b; }
.g-arrow .ico { background: #2f9e6e; }
.g-mines .ico { background: #5b6b86; }
.g-solitaire .ico { background: #2f8f52; }
.g-connect4 .ico { background: #2f6fe0; }
.g-mastermind .ico { background: #8a4fd6; }
.g-snake .ico { background: #4aa83b; }
.g-seat .ico { background: #c4527a; }
.g-tetris .ico { background: #1f9fc4; }
.g-tangram .ico { background: #d0742f; }
.g-zip .ico { background: #0f8fa8; }
.g-patches .ico { background: #b8567a; }
.g-tango .ico { background: #d6a21c; }
.g-sokoban .ico { background: #8c6a3f; }

/* ---------- superpositions ---------- */
.overlay {
  position: absolute; inset: 0; z-index: 3;
  display: grid; place-items: center; text-align: center; padding: 14px;
  background: var(--overlay);
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
  border-radius: 12px;
}
.overlay h2, .overlay p { margin: 4px 0; }
.win-crown { color: var(--gold); }
.win-crown svg { width: 56px; height: 56px; }
.spinner {
  width: 38px; height: 38px; margin: 0 auto 8px; border-radius: 50%;
  border: 4px solid var(--panel2); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.modal {
  position: fixed; inset: 0; z-index: 20;
  display: grid; align-items: end; justify-items: center;
  background: rgba(0, 0, 0, .6);
}
.sheet {
  width: min(100%, 520px);
  background: var(--panel); border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
}
.sheet h2 { margin: 0 0 4px; font-size: 1.15rem; }

.rules { margin-top: 12px; color: var(--muted); }
.rules summary { cursor: pointer; font-weight: 600; padding: 6px 0; }
.rules ul { margin: 6px 0 0; padding-left: 20px; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 30;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: #000c; color: #fff; padding: 10px 16px; border-radius: 999px;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.4s; }
  .toast { transition: none; }
}

/* ---------- portrait uniquement ----------
 * iOS ignore le verrouillage d'orientation des PWA : sur un téléphone tenu à l'horizontale, on masque l'app derrière
 * un message demandant de la remettre à la verticale. (Android applique en plus `orientation: portrait` du manifeste.) */
.rotate { display: none; }
@media (orientation: landscape) and (max-height: 500px) and (pointer: coarse) {
  .rotate {
    position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 100;
    display: grid; place-content: center; justify-items: center; gap: 14px;
    background: var(--bg); color: var(--text); text-align: center; padding: 20px;
  }
  .rotate svg { width: 56px; height: 56px; color: var(--accent); animation: tilt 2.4s ease-in-out infinite; }
  .rotate p { margin: 0; font-weight: 600; }
}
@keyframes tilt { 0%, 30% { transform: rotate(-90deg); } 60%, 100% { transform: rotate(0); } }
@media (prefers-reduced-motion: reduce) { .rotate svg { animation: none; } }
