/* ═══════════════════════════════════════════════════════════════════════════
   La dernière valse — design system
   Tokens + composants. Rien ici ne dépend de la maquette : cette feuille est
   faite pour être reprise telle quelle dans l'appli (gabarits Twig, et tokens
   recopiés dans le @theme de Tailwind v4 si on part sur Tailwind).
   Thème sombre unique : l'appli ne vit que dans la pénombre du Pic.
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
  color-scheme: dark;

  /* Couleurs — chacune a un seul rôle */
  --nuit:          #0e1118;  /* fond de page */
  --nuit-2:        #161a24;  /* surfaces : lignes, cartes, champs */
  --nuit-3:        #252b3a;  /* filets, bords */
  --os:            #e8e3d6;  /* texte principal */
  --os-2:          #9b9ca8;  /* texte secondaire, « à faire » */
  --laiton:        #c9a45c;  /* Vernier : tout ce qu'on actionne */
  --laiton-clair:  #e6cb8f;  /* sélection, focus, case en cours */
  --spectre:       #9fd6cc;  /* les fantômes : résolu, révélé */
  --rose:          #b77a80;  /* Fontenelle : fleurs, refus doux */
  --cire:          #9b2433;  /* sceaux, cachets, alertes */
  --cire-clair:    #e0707c;  /* texte d'alerte sur fond sombre */

  /* Polices — à auto-héberger en sous-ensemble latin dans l'appli */
  --f-titre: "Grenze Gotisch", Georgia, serif;
  --f-texte: "Spectral", Georgia, "Times New Roman", serif;
  --f-cap:   "Spectral SC", "Spectral", Georgia, serif;
  --f-outil: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; /* admin seulement */

  /* Échelle typographique */
  --t-xs:  12px;
  --t-s:   14px;
  --t-m:   17px;  /* corps */
  --t-l:   20px;
  --t-xl:  26px;
  --t-2xl: 34px;

  /* Espacements */
  --e-1: 4px;
  --e-2: 8px;
  --e-3: 12px;
  --e-4: 16px;
  --e-5: 24px;
  --e-6: 32px;

  --rayon: 4px;
  --cible: 48px;  /* hauteur minimale de tout ce qu'on touche */

  /* Grain de papier : SVG tuilé, aucun appel réseau */
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.06'/%3E%3C/svg%3E");
}

/* ── Base ─────────────────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background-color: var(--nuit);
  background-image: radial-gradient(90% 40% at 50% 0%, rgba(159, 214, 204, .06), transparent 70%), var(--grain);
  background-size: auto, 220px 220px;
  color: var(--os);
  font: var(--t-m)/1.6 var(--f-texte);
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, .titre {
  font-family: var(--f-titre);
  font-weight: 500;
  line-height: 1.05;
  letter-spacing: .01em;
  text-wrap: balance;
  margin: 0;
}
.titre--2xl { font-size: var(--t-2xl); }
.titre--xl  { font-size: var(--t-xl); }

p { margin: 0; }
strong, b { font-weight: 600; }

:focus-visible { outline: 2px solid var(--laiton-clair); outline-offset: 2px; }

.etiquette {
  font-family: var(--f-cap);
  font-size: var(--t-xs);
  letter-spacing: .14em;
  text-transform: lowercase;
  color: var(--laiton);
}
.discret { color: var(--os-2); }

/* ── Écran (une page de l'appli) ──────────────────────────────────────── */

.ecran {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--e-4);
  padding: var(--e-5) var(--e-4) 0;
}
.ecran__barre {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--e-3);
  min-height: 32px;
  font-family: var(--f-cap);
  font-size: var(--t-s);
  letter-spacing: .06em;
  color: var(--os-2);
}
.ecran__retour {
  background: none;
  border: 0;
  padding: var(--e-2) var(--e-2) var(--e-2) 0;
  margin-left: calc(-1 * var(--e-1));
  color: var(--laiton);
  font: inherit;
  letter-spacing: inherit;
  cursor: pointer;
}
.ecran__corps { display: flex; flex-direction: column; gap: var(--e-4); }
.ecran__pied {
  margin-top: auto;
  position: sticky;
  bottom: 0;
  display: flex;
  flex-direction: column;
  gap: var(--e-2);
  padding: var(--e-5) 0 var(--e-4);
  background: linear-gradient(to bottom, transparent, var(--nuit) 35%);
}

/* ── Boutons ──────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--e-2);
  min-height: var(--cible);
  padding: 0 var(--e-5);
  border: 1px solid var(--laiton);
  border-radius: var(--rayon);
  background: var(--laiton);
  color: var(--nuit);
  font: 600 16px/1 var(--f-cap);
  letter-spacing: .06em;
  text-decoration: none;
  cursor: pointer;
  transition: background-color .15s, border-color .15s, color .15s;
}
.btn:hover, .btn:active { background: var(--laiton-clair); border-color: var(--laiton-clair); }
.btn:disabled, .btn[aria-disabled="true"] {
  background: transparent;
  border-color: var(--nuit-3);
  color: var(--os-2);
  cursor: not-allowed;
}
.btn--plein { width: 100%; }

.btn--second { background: transparent; color: var(--laiton); }
.btn--second:hover, .btn--second:active {
  background: color-mix(in srgb, var(--laiton) 14%, transparent);
  color: var(--laiton-clair);
}

.btn--petit { min-height: 40px; padding: 0 var(--e-4); font-size: var(--t-s); }

/* ── Champs ───────────────────────────────────────────────────────────── */

.champ { display: flex; flex-direction: column; gap: var(--e-1); }
.champ__label { font-size: var(--t-s); color: var(--os-2); }
.champ__saisie {
  min-height: var(--cible);
  width: 100%;
  padding: var(--e-2) 0;
  border: 0;
  border-bottom: 2px solid color-mix(in srgb, var(--laiton) 45%, transparent);
  border-radius: 0;
  background: transparent;
  color: var(--os);
  font: var(--t-l) var(--f-texte);
  caret-color: var(--laiton-clair);
}
.champ__saisie:focus { outline: none; border-bottom-color: var(--laiton-clair); }
.champ__saisie::placeholder { color: color-mix(in srgb, var(--os-2) 60%, transparent); }
.champ__saisie--code { font-family: var(--f-cap); font-size: var(--t-xl); letter-spacing: .18em; text-transform: uppercase; }

/* ── Gabarit de réponse ───────────────────────────────────────────────── */
/* Une case par lettre ; espaces et ponctuation déjà posés. Un <input> transparent
   recouvre le tout : un tap ouvre le clavier du téléphone. */

.gabarit { position: relative; padding: var(--e-3) 0; }
.gabarit__cases {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--e-3) 14px;  /* 14px = l'espace entre deux mots */
}
.gabarit__mot { display: inline-flex; gap: 4px; }
.gabarit__saisie {
  position: absolute;
  inset: 0;
  width: 100%;
  opacity: 0;
  border: 0;
  font-size: 16px; /* évite le zoom automatique d'iOS */
  cursor: text;
}
.case {
  width: 22px;
  height: 36px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 3px;
  border-bottom: 2px solid color-mix(in srgb, var(--laiton) 45%, transparent);
  font: 600 22px/1 var(--f-cap);
  color: var(--os);
}
.case--pleine { border-bottom-color: var(--laiton); }
.case--active {
  border-bottom: 3px solid var(--laiton-clair);
  background: color-mix(in srgb, var(--laiton) 14%, transparent);
}
.case--fixe { width: 10px; border-color: transparent; color: var(--os-2); }

.gabarit--refus .gabarit__cases { animation: tremble .45s ease; }
.gabarit--refus .case { border-bottom-color: var(--rose); }
.gabarit--juste .case { border-bottom-color: var(--spectre); color: var(--spectre); }

@keyframes tremble {
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

/* ── Messages ─────────────────────────────────────────────────────────── */

.message { font-size: var(--t-s); text-align: center; min-height: 1.6em; }
.message--refus { color: var(--rose); font-style: italic; }
.message--juste { color: var(--spectre); }

/* ── Carton d'invitation ──────────────────────────────────────────────── */

.carton {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--e-2);
  padding: var(--e-5) var(--e-4);
  border: 1px solid var(--nuit-3);
  border-radius: var(--rayon);
  background: var(--nuit-2);
  text-align: center;
}
.carton__orn { color: var(--laiton); letter-spacing: .4em; font-size: var(--t-xs); }
.carton__titre { font-family: var(--f-titre); font-size: var(--t-2xl); line-height: 1; }

/* ── Sceau (cachet de cire, plat) ─────────────────────────────────────── */

.sceau {
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 50%;
  background: var(--cire);
  display: grid;
  place-items: center;
  color: #f2dcdc;
  font-family: var(--f-titre);
  font-size: var(--t-l);
}

/* ── Ligne d'énigme (liste du carnet) ─────────────────────────────────── */

.liste { display: flex; flex-direction: column; gap: var(--e-2); margin: 0; padding: 0; list-style: none; }
.enigme {
  width: 100%;
  min-height: 56px;
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) auto;
  gap: var(--e-3);
  align-items: center;
  padding: var(--e-2) var(--e-3);
  border: 1px solid var(--nuit-3);
  border-radius: var(--rayon);
  background: var(--nuit-2);
  color: var(--os);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color .15s, background-color .15s;
}
.enigme:hover { border-color: color-mix(in srgb, var(--laiton) 60%, transparent); }
.enigme__num { font-family: var(--f-titre); font-size: var(--t-xl); line-height: 1; color: var(--os-2); text-align: center; }
.enigme__nom { font-size: 16px; line-height: 1.25; }
.enigme__etat { font-family: var(--f-cap); font-size: var(--t-xs); letter-spacing: .08em; color: var(--os-2); white-space: nowrap; }

.enigme--suggeree { border-color: var(--laiton); background: color-mix(in srgb, var(--laiton) 10%, var(--nuit-2)); }
.enigme--suggeree .enigme__num, .enigme--suggeree .enigme__etat { color: var(--laiton); }

.enigme--resolue {
  border-color: color-mix(in srgb, var(--spectre) 45%, transparent);
  background: color-mix(in srgb, var(--spectre) 7%, var(--nuit-2));
}
.enigme--resolue .enigme__num, .enigme--resolue .enigme__etat { color: var(--spectre); }

.enigme--scellee { border-style: dashed; background: transparent; cursor: not-allowed; }
.enigme--scellee:hover { border-color: var(--nuit-3); }

.enigme--ouverte { border-color: var(--laiton); }
.enigme--ouverte .enigme__num, .enigme--ouverte .enigme__etat { color: var(--laiton); }

/* ── Fragment du journal ──────────────────────────────────────────────── */

.fragment {
  display: flex;
  flex-direction: column;
  gap: var(--e-3);
  padding: var(--e-5) var(--e-4);
  border: 1px solid color-mix(in srgb, var(--spectre) 30%, transparent);
  border-radius: 3px;
  background: color-mix(in srgb, var(--spectre) 6%, var(--nuit-2));
  box-shadow: 0 0 40px -12px color-mix(in srgb, var(--spectre) 45%, transparent);
}
.fragment__heure { font-family: var(--f-cap); font-size: var(--t-s); letter-spacing: .06em; color: var(--spectre); }
.fragment__heure b { font-family: var(--f-titre); font-weight: 700; font-size: var(--t-l); letter-spacing: 0; }
.fragment__texte { font-style: italic; font-size: var(--t-m); line-height: 1.7; }
.fragment__symbole { display: flex; align-items: center; gap: var(--e-3); font-size: var(--t-s); color: var(--os-2); }
.fragment__symbole svg { width: 36px; height: 36px; flex: none; }

/* L'encre qui remonte : chaque mot du texte est un <span> */
.fragment--revele .fragment__texte span { animation: encre 1.2s ease both; }
@keyframes encre { from { opacity: 0; filter: blur(6px); } to { opacity: 1; filter: blur(0); } }

/* ── Symboles (traits, sans remplissage) ──────────────────────────────── */

.symbole { fill: none; stroke: var(--laiton); stroke-width: 1.4; stroke-linejoin: round; stroke-linecap: round; }
.symbole--spectre { stroke: var(--spectre); }

/* ── Cadran ───────────────────────────────────────────────────────────── */

.cadran { width: 100%; max-width: 340px; aspect-ratio: 1; display: block; margin: 0 auto; }
.cadran__fond { fill: var(--nuit-2); stroke: var(--laiton); stroke-width: 1.5; }
.cadran__anneau { fill: none; stroke: var(--nuit-3); }
.cadran__heure { cursor: pointer; }
.cadran__heure:focus { outline: none; }
.cadran__zone { fill: transparent; stroke: transparent; }
.cadran__heure:focus-visible .cadran__zone { stroke: var(--laiton-clair); stroke-width: 2; }
.cadran__chiffre { font-family: var(--f-titre); font-size: 19px; fill: var(--os); }
.cadran__point { fill: var(--os-2); }
.cadran__heure--allumee .cadran__chiffre { fill: var(--spectre); }
.cadran__heure--allumee .symbole { stroke: var(--spectre); }
.cadran__heure--allumee .cadran__zone { fill: color-mix(in srgb, var(--spectre) 14%, transparent); }
.cadran__aiguille { transform-origin: 120px 120px; transition: transform .9s cubic-bezier(.5, 1.6, .4, 1); }
.cadran__aiguille--h { fill: var(--laiton); }
.cadran__aiguille--m { stroke: var(--os); stroke-width: 1.6; stroke-linecap: round; }
.cadran__axe { fill: var(--laiton); }
.cadran--refus { animation: tremble .45s ease; }

.suite {
  font-family: var(--f-titre);
  font-size: var(--t-xl);
  color: var(--spectre);
  text-align: center;
  min-height: 1.4em;
  font-variant-numeric: tabular-nums;
}

/* ── Statuts (documents de travail) ───────────────────────────────────── */

.statut {
  font-family: var(--f-cap);
  font-size: var(--t-xs);
  letter-spacing: .08em;
  border: 1px solid currentColor;
  border-radius: 3px;
  padding: 1px 6px;
  white-space: nowrap;
}
.statut--propose { color: var(--laiton); }
.statut--ouvert { color: var(--rose); }

/* ── Tableau de bord (admin) : outil, pas d'habillage ─────────────────── */

.tableau-cadre { border: 1px solid var(--nuit-3); border-radius: 6px; background: var(--nuit-2); overflow-x: auto; }
.tableau { width: 100%; min-width: 620px; border-collapse: collapse; font: 14px/1.4 var(--f-outil); }
.tableau th, .tableau td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--nuit-3); }
.tableau th { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--os-2); }
.tableau .nombre { font-variant-numeric: tabular-nums; }
.tableau .btn { font-family: var(--f-outil); letter-spacing: 0; font-weight: 600; }
.ligne--bloquee td:first-child { box-shadow: inset 3px 0 0 var(--cire); }
.alerte { color: var(--cire-clair); font-weight: 600; }
.pastilles { display: inline-flex; gap: 3px; }
.pastilles i { width: 10px; height: 10px; border-radius: 50%; border: 1px solid var(--os-2); }
.pastilles i.ok { background: var(--spectre); border-color: var(--spectre); }

/* ── Mouvement réduit ─────────────────────────────────────────────────── */

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