/* Village de Noël — feuille de style unique.
 *
 * Mobile-first, CSS natif, aucune dépendance. Les variables sont en tête :
 * changer l'identité d'une app ne doit demander que de toucher ce bloc.
 */

@font-face {
  font-family: "Pixelify Sans";
  src: url("../fonts/pixelify-sans.woff2") format("woff2");
  font-weight: 500 700;
  font-display: swap;
}

/* Clair par défaut (neige), sombre si l'appareil le demande (forêt la nuit). */
:root {
  --bg: #f2f6f3; --surface: #ffffff; --surface-2: #dfe9e2; --text: #10261d; --text-dim: #4d6359;
  --accent: #c62f27; --danger: #c62f27; --line: #d3dfd7; --pine: #0f3a2b;
  --cell: #e6ede8; --ghost: #8fa89b; --grid: rgba(16, 38, 29, .28); --mut: #4d6359;
  --stage-a: #ffffff; --stage-b: #dbe8e1; --btn: #ffffff; --gold: #8a6100;
  --fg: var(--text); --fg-dim: var(--text-dim); --field: #eef4f0; --ok: #1f7a46; --warn: #8a5a00; --error: #b3261e;
  --radius: 16px; --gap: 14px; --safe-bottom: env(safe-area-inset-bottom, 0px);
  --display: "Pixelify Sans", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c2219; --surface: #123227; --surface-2: #1c4435; --text: #eef5ee; --text-dim: #a9c2b5;
    --accent: #e0483f; --danger: #ff8a80; --line: #24493b;
    --cell: #0e2a20; --ghost: #4d8069; --grid: rgba(238, 245, 238, .25); --mut: #a9c2b5;
    --stage-a: #1c4838; --stage-b: #0a1d16; --btn: #173b2e; --gold: #ffd34d;
    --field: #0e2a20; --ok: #7fd8a0; --warn: #f0b429; --error: #ff8a8a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; min-width: 0; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; min-height: 100vh; min-height: 100dvh; overscroll-behavior-y: none; -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%; }
body { padding-bottom: calc(var(--safe-bottom) + 24px); overflow-x: clip; }
:focus-visible { outline: 3px solid #e0a800; outline-offset: 2px; }
.spacer { flex: 1; }
.mut { color: var(--text-dim); }
.small { font-size: .88rem; margin: 0 0 8px; }
.mt { margin-top: 18px; }
.row { display: flex; align-items: center; gap: 10px; }

/* ---------------------------------------------------------------- en-tête */

#app-header { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 6px 18px; flex-wrap: wrap; background: #0f3a2b; color: #fff; padding: calc(10px + env(safe-area-inset-top, 0px)) max(4vw, 16px) 8px; }
#app-header .snow { position: absolute; inset: 0; pointer-events: none; opacity: .4; background-image: radial-gradient(#fff 1px, transparent 1.5px), radial-gradient(#fff 1.2px, transparent 1.7px); background-size: 46px 46px, 73px 73px; background-position: 0 0, 20px 30px; }
#app-header > * { position: relative; }
.brand { font: 700 1.7rem/1.1 var(--display); color: #fff; text-decoration: none; flex: 1; white-space: nowrap; }
#app-header nav { display: flex; gap: 4px; order: 3; }
#app-header nav a { color: #cfe5d7; text-decoration: none; font-weight: 600; padding: 10px 12px; border-radius: 10px; min-height: 44px; display: flex; align-items: center; }
#app-header nav a[aria-current] { background: rgba(255, 255, 255, .16); color: #fff; }
.icon-btn { width: 44px; height: 44px; border: 0; border-radius: 10px; background: rgba(255, 255, 255, .12); font-size: 20px; cursor: pointer; }
@media (max-width: 620px) { #app-header nav { width: 100%; } #app-header nav a { flex: 1; justify-content: center; padding: 8px 4px; font-size: .95rem; } .brand { font-size: 1.5rem; } }
@media (min-width: 621px) { #app-header nav { order: 0; } }

#app-main { max-width: 1280px; margin: 0 auto; padding: 16px max(3vw, 14px) 32px; }
h2 { font: 800 clamp(1.5rem, 4vw, 1.95rem)/1.15 system-ui, -apple-system, "Segoe UI", sans-serif; letter-spacing: -.015em; margin: 0 0 6px; text-wrap: balance; }
h3 { margin: 0 0 10px; font-size: 1.06rem; }
.lead { margin: 0 0 14px; color: var(--text-dim); max-width: 62ch; }

.screen { display: none; }
.screen.is-active { display: block; }

/* ----------------------------------------------------------- commandes */

.btn { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--btn); color: var(--text); font: 600 1rem/1.2 system-ui, sans-serif; cursor: pointer; text-decoration: none; }
.btn:disabled { opacity: .4; cursor: default; }
.btn.red { background: #c62f27; border-color: #c62f27; color: #fff; }
.btn.is-done { background: #1f7a46; border-color: #1f7a46; }
.btn[aria-pressed="true"]:not(.red) { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
#d-fav { font-size: 1.3rem; color: var(--gold); }
.filters { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; }
.filters input, .filters select { min-height: 46px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; padding: 0 12px; width: 100%; }
@media (max-width: 620px) { .filters { grid-template-columns: 1fr 1fr; } .filters input { grid-column: 1 / -1; } }
.cats { display: flex; gap: 8px; overflow-x: auto; padding: 12px 2px; scrollbar-width: thin; }
.chip { flex: none; min-height: 44px; padding: 0 14px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font: 600 .95rem system-ui, sans-serif; cursor: pointer; white-space: nowrap; }
.chip[aria-pressed="true"] { background: #0f3a2b; border-color: #0f3a2b; color: #fff; }
@media (prefers-color-scheme: dark) { .chip[aria-pressed="true"] { background: #eef5ee; border-color: #eef5ee; color: #0c2219; } }
.count { margin: 0 0 10px; color: var(--text-dim); font-size: .92rem; }

/* ----------------------------------------------------------- catalogue */

.cat { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.mcard { color: inherit; text-decoration: none; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.fig { position: relative; min-height: 340px; border-radius: 12px; }
.mcard .fig { min-height: 240px; border-radius: 0; }
.fig > canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.mcard .fig, .stage { background: radial-gradient(circle at 50% 35%, var(--stage-a), var(--stage-b)); }
.is-night .mcard .fig, .is-night .stage { background: radial-gradient(circle at 50% 30%, #23406e, #0a1128); }
.stage { min-height: clamp(320px, 52vw, 520px); }
.stage.tall { min-height: clamp(330px, 62vw, 760px); }
.mcard .meta { padding: 12px 16px 16px; flex: 1; display: flex; flex-direction: column; }
.mcard h2 { font-size: 1.2rem; margin: 0 0 4px; }
.mcard p { margin: 0 0 10px; color: var(--text-dim); font-size: .92rem; flex: 1; }
.fav-mark { position: absolute; top: 8px; right: 12px; color: #e0a800; font-size: 1.6rem; text-shadow: 0 1px 3px rgba(0, 0, 0, .4); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips span { font-size: .82rem; background: var(--bg); border: 1px solid var(--line); border-radius: 99px; padding: 2px 10px; white-space: nowrap; }
.chips .lv1 { background: #d8f0de; color: #135a30; border-color: transparent; }
.chips .lv2 { background: #fdeec4; color: #6a4a00; border-color: transparent; }
.chips .lv3 { background: #fbd9d5; color: #8a1c15; border-color: transparent; }
.bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin-top: 10px; }
.bar i { display: block; height: 100%; background: #1f7a46; }
.empty { grid-column: 1 / -1; color: var(--text-dim); }
@media (prefers-reduced-motion: no-preference) { .mcard { transition: transform .2s, box-shadow .2s; } .mcard:hover { transform: translateY(-3px); box-shadow: 0 10px 24px rgba(0, 0, 0, .15); } }

/* ---------------------------------------------------------------- fiche */

.dtop { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; }
#d-desc { margin: 0 0 10px; max-width: 70ch; }
.dprog { display: flex; align-items: center; gap: 12px; margin: 12px 0 16px; }
.dprog .bar { flex: 1; margin: 0; max-width: 420px; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; align-items: start; }
@media (max-width: 820px) { .grid2 { grid-template-columns: minmax(0, 1fr); } }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
@media (max-width: 480px) { .card { padding: 14px 12px; } }
.ctl { display: flex; align-items: center; gap: 10px; }
.ctl input { flex: 1; accent-color: var(--accent); height: 44px; }
.lvl { text-align: center; margin: 6px 0 10px; }
.lvl b { font-size: 1.2rem; font-variant-numeric: tabular-nums; }
.same { text-align: center; margin: -4px 0 8px; color: var(--ok); font-weight: 600; font-size: .92rem; }
.board-wrap { overflow: auto; max-height: 78vh; }
#board { display: block; margin: 0 auto; cursor: crosshair; }
.axis { display: flex; justify-content: space-between; gap: 8px; color: var(--text-dim); font-size: .82rem; margin-top: 6px; }
.info { min-height: 3em; margin: 10px 0; padding: 8px 12px; border-radius: 10px; background: var(--field); font-size: .95rem; }
.tip { color: var(--text-dim); font-size: .86rem; margin: 12px 0 0; }
.note { background: var(--field); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin: 16px 0 0; }
.tog { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.mats { display: grid; gap: 4px; }
.mats.wide { grid-template-columns: repeat(auto-fill, minmax(min(100%, 270px), 1fr)); gap: 4px 18px; }
.mat { all: unset; box-sizing: border-box; display: flex; gap: 10px; align-items: center; padding: 6px 8px; border-radius: 10px; min-height: 44px; }
button.mat { cursor: pointer; }
button.mat:focus-visible { outline: 3px solid #e0a800; }
.mat.on { background: var(--field); box-shadow: inset 0 0 0 2px var(--accent); }
.mat.got .nm, .mat.got .n { opacity: .5; text-decoration: line-through; }
.mat .sw { width: 28px; height: 28px; border-radius: 5px; flex: none; }
.mat .nm { flex: 1; line-height: 1.25; }
.mat small { display: block; color: var(--text-dim); font-size: .78rem; font-weight: 400; overflow-wrap: anywhere; }
.mat .n { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

/* -------------------------------------------------------------- village */

.myrow { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.myrow a { flex: 1; color: inherit; text-decoration: none; }
.myrow small { display: block; color: var(--text-dim); }
.myrow .q { min-width: 2ch; text-align: center; font-weight: 700; }
.vlist { list-style: none; margin: 0; padding: 0; max-height: 720px; overflow: auto; }
.vlist a { display: flex; gap: 12px; padding: 8px 4px; color: inherit; text-decoration: none; border-bottom: 1px solid var(--line); min-height: 44px; }
.vlist b { flex: none; width: 28px; height: 28px; border-radius: 50%; background: #b3261e; color: #fff; display: grid; place-items: center; font-size: .85rem; }
.vlist small { display: block; color: var(--text-dim); }
#v-map { display: block; border-radius: 10px; }
.know { margin: 0; padding-left: 1.2em; }
.know li { margin: 6px 0; }

/* Boutons du socle (bannière, toasts) */
.banner button, .toast button { font: inherit; border: 0; border-radius: 10px; min-height: 44px; padding: 10px 14px; cursor: pointer; color: inherit; background: var(--surface-2); }
.banner button.primary { background: var(--accent); color: #fff; font-weight: 600; }

/* --------------------------------------------------------------- toasts */

#toast-host {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(16px + var(--safe-bottom));
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  max-width: min(92vw, 440px);
  background: var(--surface-2);
  border-radius: 14px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  animation: rise 0.18s ease-out;
}
.toast button { padding: 6px 10px; min-height: 0; background: var(--accent); color: #fff; font-weight: 600; }

@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

/* ------------------------------------------------------------- bannières */

#banner-host { position: fixed; left: 0; right: 0; bottom: calc(16px + var(--safe-bottom)); z-index: 50; padding: 0 12px; }
.banner {
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.5);
  animation: rise 0.2s ease-out;
}
.banner .banner-body { flex: 1; }
.banner strong { display: block; margin-bottom: 2px; }
.banner p { margin: 0; color: var(--text-dim); font-size: 0.9rem; }
.banner .banner-close { background: transparent; color: var(--text-dim); padding: 4px 8px; min-height: 0; }

/* --------------------------------------------------------------- modales */

#modal-host {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(4, 8, 14, 0.72);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
#modal-host[hidden] { display: none; }
.sheet {
  width: 100%;
  max-width: 520px;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 18px 16px calc(18px + var(--safe-bottom));
  max-height: 85dvh;
  overflow-y: auto;
  animation: slide-up 0.2s ease-out;
}
@keyframes slide-up { from { transform: translateY(16px); opacity: 0; } }

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

/* ------------------------------------------------------- synchronisation */
/* Panneau posé par js/sync-ui.js dans #sync-panel. Les couleurs sortent des
   variables du thème définies en tête de fichier : ne rien coder en dur ici,
   sinon le panneau jure dans chaque app qui change de teinte. */

.sync-status {
  margin: 0 0 4px;
  font-weight: 600;
}

/* L'état est porté par un attribut plutôt que par une classe : sync-ui.js
   écrit un seul dataset.state, et le CSS décide seul de la couleur. */
.sync-status[data-state='ready'] { color: var(--ok, #7fd8a0); }
.sync-status[data-state='syncing'] { opacity: .7; }
.sync-status[data-state='unverified'] { color: var(--warn, #f0b429); }
.sync-status[data-state='error'] { color: var(--error, #ff8a8a); }
.sync-status[data-state='offline'],
.sync-status[data-state='anonymous'] { color: var(--fg-dim, #98a0ad); }

.sync-detail {
  margin: 0 0 14px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--fg-dim, #98a0ad);
}

.sync-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.sync-btn {
  flex: 1 1 auto;
  min-width: 160px;
  padding: 12px 16px;
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: var(--accent, #2f6fed);
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.sync-btn:disabled { opacity: .55; cursor: default; }
.sync-btn[hidden] { display: none; }

.sync-btn.ghost {
  color: var(--fg, #e8eaee);
  background: transparent;
  border: 1px solid var(--line, rgba(255, 255, 255, .16));
}

/* Bouton en attente de confirmation (déconnexion en deux temps). Sans repère
   visuel, le premier clic passe pour un clic qui n'a rien fait. */
.sync-btn.is-armed {
  color: var(--warn, #f0b429);
  border-color: var(--warn, #f0b429);
}

/* L'iframe de connexion. Elle annonce sa hauteur par postMessage ; la
   transition évite le à-coup quand on passe d'un panneau à l'autre. */
.sync-frame {
  margin-top: 16px;
  padding: 14px;
  background: var(--field, rgba(255, 255, 255, .05));
  border: 1px solid var(--line, rgba(255, 255, 255, .12));
  border-radius: 12px;
}

.sync-frame iframe {
  display: block;
  transition: height .15s ease-out;
}

.sync-frame[hidden] { display: none; }
