/*
 * Deux palettes, une seule variable a lire partout ailleurs.
 *
 * Le CSS ne connait que `dark` et `light` : c'est le JavaScript qui traduit
 * le choix « systeme » en l'un des deux et pose l'attribut. Sans cela il
 * faudrait ecrire la palette claire deux fois — une fois pour le choix
 * explicite, une fois dans une media query — et la seconde finirait par
 * diverger de la premiere.
 */

/* Nuit de poste radio : la palette d'origine, et celle par defaut. */
:root,
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #081423;
  --bg-soft: #0d1f33;
  --card: #112840;
  --card-hi: #17344f;
  --line: #24446a;
  --ink: #e9f1fa;
  --ink-dim: #9ab2cc;
  --ink-faint: #6a869f;
  --accent: #2f90ff;
  --accent-soft: rgba(47, 144, 255, 0.16);
  --signal: #29b6f6;
  --ok: #34d399;
  --ko: #f87171;
  --bar-from: #123a63;
  --shadow: rgba(0, 0, 0, 0.45);
  --on-accent: #fff;
}

/*
 * Plein jour. L'accent et le signal y sont assombris : le bleu clair du theme
 * sombre passe a 2,4 contre 1 sur du blanc, sous le seuil lisible.
 */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #eef3f9;
  --bg-soft: #ffffff;
  --card: #ffffff;
  --card-hi: #e7eef7;
  --line: #cfdced;
  --ink: #0b1b2d;
  --ink-dim: #45607c;
  --ink-faint: #63788f;
  --accent: #1667cf;
  --accent-soft: rgba(22, 103, 207, 0.12);
  --signal: #0e6f9e;
  --ok: #0a7f57;
  --ko: #c33a3a;
  --bar-from: #9dc4ee;
  --shadow: rgba(13, 31, 51, 0.18);
  --on-accent: #fff;
}

:root {
  --radius: 16px;
  /* Capacitor injecte --safe-area-inset-* dans la WebView ; env() prend le
     relais dans un navigateur ordinaire. */
  --safe-top: var(--safe-area-inset-top, env(safe-area-inset-top, 0px));
  --safe-bottom: var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  user-select: none;
}

button, input, textarea, select { font: inherit; color: inherit; }

/* --- Ossature --------------------------------------------------------- */

header.top {
  position: relative;
  padding: calc(var(--safe-top) + 9px) 16px 9px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
}

header.top .mark { flex: none; display: block; }

header.top h1 {
  margin: 0;
  flex: 1;
  min-width: 0;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: 0.2px;
  /* Un titre long se coupe plutot que de passer sur deux lignes : c'est ce
     debordement qui deformait la barre sur les ecrans au nom un peu long. */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Sur l'accueil, le titre est le logotype lui-meme. */
header.top h1.brand { font-weight: 700; letter-spacing: -0.2px; }
header.top h1.brand em { font-style: normal; color: var(--accent); }

/* La separation n'est pas un trait neutre : elle epelle BEEPCODE en morse,
   ecrit par la table de codage de l'application (voir app.js). */
.hdr-rule {
  position: absolute;
  left: 16px;
  bottom: -1px;
  display: flex;
  align-items: center;
  gap: 3px;
  pointer-events: none;
}
.hdr-rule i {
  display: block;
  height: 3px;
  border-radius: 999px;
  background: var(--signal);
  opacity: 0.75;
}
.hdr-rule i.dot { width: 3px; }
.hdr-rule i.dash { width: 9px; }
.hdr-rule i.gap { width: 3px; background: none; }

.icon-btn {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  color: var(--ink-dim);
  cursor: pointer;
  flex: none;
  padding: 0;
}
/* Le bouton mesure 38 px a l'oeil, 44 px sous le doigt. */
.icon-btn::after { content: ''; position: absolute; inset: -3px; }
.icon-btn:active { background: var(--card-hi); border-color: var(--accent); color: var(--ink); }
.icon-btn svg { display: block; }
/* Chaque bouton porte ses deux icones ; la classe « back » choisit laquelle
   s'affiche. On ne s'appuie pas sur l'attribut hidden : la regle du
   navigateur qui le masque perd contre le display du selecteur ci-dessus. */
.icon-btn .ic-back { display: none; }
.icon-btn.back .ic-main { display: none; }
.icon-btn.back .ic-back { display: block; }

main {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 16px 24px;
}

nav.tabs {
  flex: none;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: var(--bg-soft);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
}

nav.tabs button {
  background: none;
  border: 0;
  padding: 9px 2px 10px;
  display: grid;
  gap: 3px;
  justify-items: center;
  color: var(--ink-faint);
  font-size: 10.5px;
  font-weight: 600;
  cursor: pointer;
}

nav.tabs button .ic { font-size: 19px; line-height: 1; }
nav.tabs button[aria-selected="true"] { color: var(--accent); }

/* --- Briques ---------------------------------------------------------- */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

.card h2 {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 650;
}

.card p.hint {
  margin: 0 0 14px;
  color: var(--ink-dim);
  font-size: 13px;
}

.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.spacer { height: 10px; }

.btn {
  background: var(--card-hi);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 16px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: 0.45; pointer-events: none; }

textarea, input[type="text"], input[type="email"] {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  resize: none;
  user-select: text;
}
textarea:focus, input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  height: 28px;
}

.field { margin-bottom: 14px; }
.field label {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--ink-dim);
  margin-bottom: 2px;
}
.field label b { color: var(--accent); font-variant-numeric: tabular-nums; }

.switch {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}
.switch:last-child { border-bottom: 0; }
.switch small { display: block; color: var(--ink-faint); font-size: 12px; }
.switch input { width: 46px; height: 27px; accent-color: var(--accent); flex: none; }

.morse {
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  letter-spacing: 2px;
  color: var(--signal);
  user-select: text;
  word-break: break-word;
}

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.6px;
}
.badge.ok { background: rgba(52, 211, 153, 0.15); color: var(--ok); }
.badge.ko { background: rgba(248, 113, 113, 0.15); color: var(--ko); }
.badge.mute { background: var(--card-hi); color: var(--ink-faint); }

.empty { text-align: center; color: var(--ink-faint); padding: 28px 12px; font-size: 13px; }

/* --- Alphabet --------------------------------------------------------- */

.alpha-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(82px, 1fr));
  gap: 8px;
}
.alpha {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 6px;
  text-align: center;
  cursor: pointer;
}
.alpha.playing { border-color: var(--accent); background: var(--accent-soft); }
.alpha b { display: block; font-size: 19px; font-weight: 650; }
.alpha span {
  display: block;
  font-family: ui-monospace, Consolas, monospace;
  color: var(--accent);
  font-size: 12px;
  letter-spacing: 1.5px;
  margin-top: 2px;
}
.alpha em { display: block; font-style: normal; font-size: 10px; color: var(--ink-faint); margin-top: 3px; }

.seg {
  display: flex;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 3px;
  margin-bottom: 14px;
}
.seg button {
  flex: 1;
  background: none;
  border: 0;
  border-radius: 9px;
  padding: 9px 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-dim);
  cursor: pointer;
}
.seg button[aria-selected="true"] { background: var(--card-hi); color: var(--ink); }

/* --- Emission --------------------------------------------------------- */

.tx-out {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  min-height: 74px;
  font-family: ui-monospace, Consolas, monospace;
  letter-spacing: 2px;
  line-height: 1.9;
  word-break: break-word;
  user-select: text;
}
.tx-out .sym { color: var(--ink-dim); }
.tx-out .sym.live { color: var(--accent); text-shadow: 0 0 12px rgba(47, 144, 255, 0.55); }
.tx-out .sep { color: var(--ink-faint); margin: 0 3px; }

.lamp {
  height: 8px;
  border-radius: 999px;
  background: var(--line);
  margin: 14px 0 4px;
  transition: background 60ms linear, box-shadow 60ms linear;
}
.lamp.on { background: var(--accent); box-shadow: 0 0 18px rgba(47, 144, 255, 0.7); }

.progress { height: 4px; border-radius: 999px; background: var(--line); overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--accent); width: 0; }

/* --- Manipulateur ----------------------------------------------------- */

.key-pad {
  height: 190px;
  border-radius: 22px;
  background: radial-gradient(120% 120% at 50% 0%, var(--card-hi), var(--card));
  border: 2px solid var(--line);
  display: grid;
  place-items: center;
  font-size: 15px;
  font-weight: 650;
  color: var(--ink-faint);
  touch-action: none;
  margin-bottom: 12px;
  transition: transform 60ms, border-color 60ms, box-shadow 60ms;
}
.key-pad.down {
  border-color: var(--accent);
  background: radial-gradient(120% 120% at 50% 0%, rgba(47, 144, 255, 0.32), var(--card-hi));
  color: var(--accent);
  box-shadow: 0 0 30px rgba(47, 144, 255, 0.3) inset;
  transform: scale(0.99);
}

.live-code {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 30px;
  letter-spacing: 6px;
  color: var(--accent);
  min-height: 40px;
  text-align: center;
}
.live-code .ghost { color: var(--ink-faint); }

.readout {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  min-height: 88px;
  font-size: 19px;
  letter-spacing: 1.5px;
  word-break: break-word;
  user-select: text;
}
.readout .cursor { color: var(--accent); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* --- Ecoute micro ----------------------------------------------------- */

.meter {
  height: 54px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  position: relative;
  overflow: hidden;
  margin-bottom: 12px;
}
.meter i {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  background: linear-gradient(90deg, var(--bar-from), var(--accent));
  width: 0;
  transition: width 60ms linear;
}
.meter u {
  position: absolute;
  top: 0; bottom: 0;
  width: 2px;
  background: var(--ko);
  opacity: 0.8;
}
/*
 * Le « > » compte : sans lui la regle frappait aussi les deux libelles a
 * l'interieur, qui se retrouvaient tous deux colles sur toute la surface et
 * imprimes l'un sur l'autre — « En attente » et « — Hz » donnaient
 * « Enattente Hz » melange.
 */
.meter > span {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  /* Le texte passe sur la barre coloree comme sur le fond : une ombre portee
     sombre le detacherait mal en theme clair, un contour discret tient mieux. */
  text-shadow: 0 1px 3px var(--shadow);
}

/* --- Exercices -------------------------------------------------------- */

.quiz-prompt { text-align: center; padding: 22px 10px 8px; }
.quiz-prompt .big { font-size: 62px; font-weight: 650; line-height: 1; }
.quiz-prompt .code {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 34px;
  letter-spacing: 7px;
  color: var(--accent);
}
.quiz-prompt .word { font-size: 30px; letter-spacing: 4px; }

.choices { display: grid; grid-template-columns: repeat(auto-fill, minmax(66px, 1fr)); gap: 8px; }
.choices button {
  background: var(--card-hi);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 15px 4px;
  font-size: 20px;
  font-weight: 650;
  cursor: pointer;
}
.choices button.ok { background: rgba(52, 211, 153, 0.2); border-color: var(--ok); color: var(--ok); }
.choices button.ko { background: rgba(248, 113, 113, 0.2); border-color: var(--ko); color: var(--ko); }

.scorebar {
  display: flex;
  gap: 8px;
  justify-content: space-between;
  font-size: 12px;
  color: var(--ink-dim);
  margin-bottom: 10px;
}
.scorebar b { color: var(--ink); font-variant-numeric: tabular-nums; }

.paddle { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.paddle button {
  background: var(--card-hi);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 22px 0;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 26px;
  color: var(--accent);
  cursor: pointer;
  touch-action: manipulation;
}
.paddle button:active { background: var(--accent-soft); border-color: var(--accent); }

/* --- Lecons ----------------------------------------------------------- */

.lesson {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  margin-bottom: 8px;
  cursor: pointer;
}
.lesson .no {
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--card-hi);
  font-weight: 700;
  font-size: 13px;
}
.lesson.done .no { background: rgba(52, 211, 153, 0.18); color: var(--ok); }
.lesson.current { border-color: var(--accent); }
.lesson.current .no { background: var(--accent); color: var(--on-accent); }
.lesson.locked { opacity: 0.45; }
.lesson b { display: block; font-size: 14px; }
.lesson small { color: var(--ink-faint); font-size: 12px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  background: var(--card-hi);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 5px 9px;
  font-size: 13px;
  font-weight: 600;
}
.chip span {
  font-family: ui-monospace, Consolas, monospace;
  color: var(--accent);
  font-size: 11px;
  margin-left: 5px;
  letter-spacing: 1px;
}

.bar { height: 6px; border-radius: 999px; background: var(--line); overflow: hidden; margin-top: 8px; }
.bar i { display: block; height: 100%; background: var(--ok); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 78px);
  transform: translateX(-50%);
  background: var(--card-hi);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 16px;
  font-size: 13px;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms;
}
.toast.show { opacity: 1; }

/* --- Accueil ---------------------------------------------------------- */

/*
 * Le bloc d'ecoute ouvre l'accueil : il doit se voir, pas occuper l'ecran.
 * L'espacement est donc serre partout sauf sur le bouton, qui reste a sa
 * taille — en dessous de 44 px il cesse d'etre confortable au doigt.
 */
.hero {
  background: linear-gradient(160deg, var(--card-hi), var(--card));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 14px;
  text-align: center;
}
.hero-code {
  font-size: 13px;
  opacity: 0.85;
  margin-bottom: 8px;
  word-break: break-word;
}
.hero h2 { margin: 0 0 8px; font-size: 20px; font-weight: 650; line-height: 1.25; }
.hero p {
  margin: 0 0 12px;
  color: var(--ink-dim);
  font-size: 13px;
  line-height: 1.35;
}

.progress-card { cursor: pointer; }
.progress-card b { display: block; font-size: 14px; }
.progress-card small { color: var(--ink-faint); font-size: 12px; }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 12px 13px;
  text-align: left;
  cursor: pointer;
  display: grid;
  gap: 3px;
  align-content: start;
}
.tile:active { border-color: var(--accent); }
.tile-ic { font-size: 24px; line-height: 1.1; margin-bottom: 3px; }
.tile b { font-size: 14.5px; font-weight: 650; }
.tile small { color: var(--ink-faint); font-size: 11.5px; line-height: 1.35; }

/* --- Histoire --------------------------------------------------------- */

.prose {
  margin: 6px 0 10px;
  color: var(--ink-dim);
  font-size: 13.5px;
  line-height: 1.62;
  user-select: text;
}

.timeline { position: relative; margin: 0 0 14px 7px; padding-left: 19px; }
.timeline::before {
  content: '';
  position: absolute;
  left: 0;
  top: 6px;
  bottom: 6px;
  width: 2px;
  background: linear-gradient(var(--accent), var(--line));
  opacity: 0.55;
}

.era { position: relative; padding-bottom: 20px; }
.era::before {
  content: '';
  position: absolute;
  left: -23px;
  top: 6px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--bg);
}
.era-year {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12px;
  letter-spacing: 1px;
  color: var(--accent);
  font-weight: 700;
}
.era-body b { display: block; font-size: 15px; margin-top: 1px; }

/* --- Affiche ---------------------------------------------------------- */

.poster {
  margin: 0 0 14px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--card);
  line-height: 0;
}
.poster img { width: 100%; height: auto; display: block; }

/* --- Information au premier lancement --------------------------------- */

.notice {
  position: fixed;
  left: 10px;
  right: 10px;
  bottom: calc(var(--safe-bottom) + 68px);
  background: var(--card-hi);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px 12px;
  z-index: 60;
  box-shadow: 0 10px 30px var(--shadow);
}
.notice p {
  margin: 0 0 12px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink-dim);
}
.notice .row { justify-content: flex-end; }
.notice .btn { padding: 9px 14px; font-size: 13px; }

/* Un avertissement se distingue du reste de la prose. */
.prose.warn {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  color: var(--ink);
}

/* --- Defi de la semaine ------------------------------------------------ */

/* La tuile du defi occupe toute la largeur : son contenu change chaque
   semaine, contrairement aux modules qui sont toujours les memes. */
.tile.featured {
  grid-column: 1 / -1;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  border-color: var(--accent);
  background: linear-gradient(150deg, var(--card-hi), var(--card));
}
.tile.featured .tile-ic { margin: 0; font-size: 26px; }
/* Hors de la grille de la tuile, ces deux-la retombent en flux inline et se
   collent l'un a l'autre : il faut les remettre en blocs. */
.tile.featured b { display: block; font-size: 15px; }
/*
 * Le sous-titre est tenu a deux lignes exactement : reserve quand il est
 * court, coupe quand il deborde. C'est ce qui donne aux entrees de
 * progression — lecon, defi, parcours — la meme hauteur au pixel, quelle que
 * soit la langue ou la longueur des nombres affiches.
 */
.tile.featured small {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  line-height: 1.35;
  margin-top: 1px;
  min-height: 2.7em;
}
/*
 * La barre ferme la tuile sur toute sa largeur, sous les trois colonnes. Sa
 * marge propre s'ajouterait a la gouttiere de la grille et la detacherait du
 * texte : c'est la gouttiere qui l'espace, pas elle.
 */
.tile.featured .bar { grid-column: 1 / -1; margin-top: 0; }

/* Le pseudonyme sera publie : on le montre tel qu'il sortira. */
.field input[type="text"], .field input[type="email"] {
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  letter-spacing: 1px;
}

/* Le badge : un palier, pas une simple etiquette — il monte en presence. */
.rank {
  display: inline-block;
  padding: 7px 16px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.3px;
  border: 1px solid var(--line);
  background: var(--card-hi);
  color: var(--ink-dim);
}
.rank-1 { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.rank-2 {
  border-color: var(--signal);
  color: #07202e;
  background: linear-gradient(135deg, var(--signal), var(--accent));
}

/* --- Parcours ---------------------------------------------------------- */

/* Un parcours entierement termine se distingue sans crier. */
.tile.featured.complete { border-color: var(--ok); }
.tile.featured.complete .tile-ic { filter: none; }

/* Une mission verrouillee reste lisible mais ne se laisse pas ouvrir. */
.lesson.locked { cursor: default; }
.lesson.done .no { background: rgba(52, 211, 153, 0.18); color: var(--ok); }

.paths-target {
  font-weight: 650;
  letter-spacing: 3px;
}

/* Un lien discret en pied de page, pour ce qui n'est pas un module. */
.linkish {
  background: none;
  border: 0;
  padding: 0 0 6px;
  color: var(--ink-dim);
  font-size: 13px;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.linkish:active { color: var(--accent); }

/* --- Classement des defis ---------------------------------------------- */

/* Une ligne de classement se lit comme une mission, mais ne s'ouvre pas. */
.score-row { cursor: default; }
.score-row.mine { border-color: var(--accent); }
.score-row.mine .no { background: var(--accent); color: var(--on-accent); }

/* Les temps se comparent d'un coup d'oeil : chiffres de meme chasse. */
.score-row .time {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 15px;
}

/* Le message d'un defi est du trafic, pas de la prose. */
.board-msg {
  display: block;
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  letter-spacing: 1px;
  word-break: break-word;
}

/* --- Suivez-nous -------------------------------------------------------- */

/*
 * Les logos sont de vrais dessins, pas des emoji : ils s'alignent sur la
 * hauteur qu'occupait l'emoji pour que la grille ne bouge pas.
 */
.net-ic {
  display: block;
  height: 26px;
  margin-bottom: 5px;
}
.net-logo {
  width: 26px;
  height: 26px;
  display: block;
}

/* Le site et le contact sont traces au filet : ils prennent l'accent. */
.net-tile .net-logo { color: var(--accent); }

/*
 * Une tuile qui garde sa place sans etre encore active : un reseau dont on
 * n'a pas l'adresse, un module annonce mais pas ecrit. Elle s'eteint
 * franchement et ne se clique pas — on la voit venir sans croire qu'elle
 * repond deja.
 */
.tile.off {
  opacity: 0.38;
  cursor: default;
}
.tile.off .net-logo { filter: grayscale(1); }

/* --- Se faire comprendre ------------------------------------------------ */

/*
 * Tout y est plus grand qu'ailleurs, et c'est le point : le texte est lu par
 * quelqu'un d'autre, souvent a distance, et le manipulateur est actionne par
 * quelqu'un qui ne vise pas forcement bien.
 */
.talk-readout {
  min-height: 92px;
  padding: 14px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-soft);
  font-size: 30px;
  font-weight: 650;
  line-height: 1.25;
  letter-spacing: 2px;
  word-break: break-word;
  margin-bottom: 12px;
}

/* Les phrases courantes : pour qui ne peut pas tout epeler. */
.talk-phrases {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}
.talk-phrase {
  font-size: 16px;
  font-weight: 650;
  padding: 14px 10px;
}

/* Le manipulateur prend la moitie de l'ecran : on ne le rate pas. */
.talk-pad {
  min-height: 190px;
  font-size: 17px;
}

/* --- Rubik's Cube ------------------------------------------------------- */

/* Une etape acquise se distingue sans crier : la bordure prend le vert. */
.cube-step.done { border-color: var(--ok); }
.cube-step .no {
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--card-hi);
  font-weight: 700;
  font-size: 13px;
}
.cube-step.done .no { background: rgba(52, 211, 153, 0.18); color: var(--ok); }
.cube-step h2 { margin: 0; }

/* Une formule se lit en chasse fixe, bien espacee : chaque lettre compte. */
.cube-alg {
  margin: 8px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  font-size: 17px;
  letter-spacing: 3px;
  text-align: center;
}

/*
 * Le chrono : une grande zone qu'on ne peut pas rater, dont la couleur dit
 * l'etat. Rouge quand on tient, vert quand on peut lacher, accent en course.
 */
.cube-pad {
  min-height: 200px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg-soft);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  touch-action: none;
  transition: background 120ms, border-color 120ms;
}
.cube-pad.holding { border-color: var(--ko); background: rgba(248, 113, 113, 0.12); }
.cube-pad.armed { border-color: var(--ok); background: rgba(52, 211, 153, 0.16); }
.cube-pad.running { border-color: var(--accent); background: var(--accent-soft); }
.cube-clock {
  font-size: 56px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 1px;
  line-height: 1;
}

/* Les statistiques en une ligne : meilleur, ao5, ao12, total. */
.cube-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.cube-stat {
  text-align: center;
  padding: 10px 4px;
  border-radius: 12px;
  background: var(--card-hi);
}
.cube-stat small { display: block; color: var(--ink-faint); font-size: 11px; }
.cube-stat b { display: block; font-size: 15px; font-variant-numeric: tabular-nums; margin-top: 2px; }

/* --- Rubik's Cube en trois dimensions ------------------------------------ */

/*
 * Vingt-six cubies poses dans l'espace. Le cube lui-meme est un point
 * (0 x 0) au centre de la scene ; chaque cubie s'en ecarte par sa transform.
 */
.c3d-stage {
  width: 100%;
  display: grid;
  place-items: center;
  perspective: 820px;
  touch-action: none;
  user-select: none;
}
.c3d-cube {
  position: relative;
  width: 0;
  height: 0;
  transform-style: preserve-3d;
  transition: transform 220ms ease;
}
.c3d-cubie {
  position: absolute;
  transform-style: preserve-3d;
}
.c3d-face {
  position: absolute;
  inset: 0;
  box-sizing: border-box;
  background: #151515;
  border: 2px solid #101010;
  border-radius: 4px;
  backface-visibility: hidden;
}
.c3d-face.lit { border-color: #0c0c0c; }

/* En mode apprendre, la scene reste en haut : une formule jouee depuis le
 * bas de la page se voit quand meme. */
.cube-stage-wrap { padding: 4px 0 6px; }
.cube-stage-wrap.sticky {
  position: sticky;
  top: 0;
  z-index: 5;
  margin: 0 -16px;
  padding: 6px 16px 8px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.cube-stage-hint { text-align: center; margin: 6px 0 12px; }
.cube-view-bar {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-top: 4px;
}
.cube-view-btn { padding: 4px 14px; min-height: 0; font-size: 14px; }

/* Une formule en jetons : le mouvement en cours s'allume, les passes s'eteignent. */
.cube-moves {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin: 8px 0 0;
}
.mv {
  min-width: 36px;
  padding: 7px 8px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 16px;
  text-align: center;
  transition: transform 120ms, background 120ms, border-color 120ms, opacity 120ms;
}
.mv.now {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  transform: scale(1.1);
}
.mv.done { opacity: 0.4; }
button.mv { cursor: pointer; }
button.mv:disabled { opacity: 0.25; cursor: default; }
.cube-algbtns { margin-top: 8px; gap: 8px; }
.cube-algbtns .btn { padding-left: 8px; padding-right: 8px; }
.cube-algblock + .cube-algblock { margin-top: 12px; }
.cube-play { padding: 6px 10px; min-height: 0; font-size: 13px; white-space: nowrap; }

/* Les lecons du parcours : une bordure verte quand l'exercice est reussi. */
.cube-lesson.done { border-color: var(--ok); }
.cube-exercise {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--card-hi);
}
.cube-exercise .cube-moves.built {
  min-height: 44px;
  padding: 4px;
  border-radius: 10px;
  border: 1px dashed var(--line);
}
.cube-built-line { height: 8px; }
.cube-options { display: grid; gap: 6px; margin-top: 8px; }
.cube-options.grid { grid-template-columns: repeat(4, 1fr); }
.cube-options.grid .btn { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
details.cube-more { margin-top: 10px; }
details.cube-more > summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--accent);
  padding: 6px 0;
  list-style: none;
}
details.cube-more > summary::-webkit-details-marker { display: none; }
details.cube-more > summary::before { content: '▸ '; }
details.cube-more[open] > summary::before { content: '▾ '; }
details.cube-more.case {
  margin-top: 6px;
  padding: 4px 12px 10px;
  border-radius: 10px;
  background: var(--card-hi);
}
details.cube-more.case > summary { color: var(--ink); }

/* Les six faces et leurs couleurs, a toucher pour les voir sur le cube. */
.cube-faces {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}
.cube-face-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  text-align: left;
  font: inherit;
  cursor: pointer;
}
.cube-face-chip small { color: var(--ink-dim); }
.cube-swatch {
  width: 18px;
  height: 18px;
  flex: none;
  border-radius: 5px;
  border: 1px solid rgba(0, 0, 0, 0.35);
}
.cube-select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  margin-bottom: 8px;
}

/* Le decompte du chrono : READY puis 3, 2, 1 en tres grand, GO au depart. */
.cube-pad.ready { border-color: var(--accent); background: var(--accent-soft); }
.cube-pad.count { border-color: var(--ok); background: rgba(52, 211, 153, 0.16); }
.cube-clock.count { font-size: 84px; letter-spacing: 2px; }

/* Le cube interactif : les dix-huit mouvements en trois rangees de six. */
.cube-options.grid.six { grid-template-columns: repeat(6, 1fr); }
.cube-options.grid.six .btn { padding-left: 4px; padding-right: 4px; }

/* Les badges du cube : six paliers, ceux qui restent a gagner en grise. */
.cube-badges {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.cube-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 12px;
  background: var(--card-hi);
  border: 1px solid transparent;
}
.cube-badge .ico { font-size: 26px; line-height: 1; flex: none; }
.cube-badge b { display: block; font-size: 13px; }
.cube-badge small { display: block; color: var(--ink-dim); font-size: 11px; margin-top: 2px; }
.cube-badge.won { border-color: var(--ok); background: rgba(52, 211, 153, 0.12); }
.cube-badge.todo { opacity: 0.55; }
.cube-badge.todo .ico { filter: grayscale(1); }

/* Sur la tuile d'accueil du cube, la rangee des six badges. */
.tile-badges { display: flex; gap: 4px; margin-top: 6px; font-size: 15px; line-height: 1; }
.tile-badges i { font-style: normal; }
.tile-badges i.todo { opacity: 0.3; filter: grayscale(1); }

/* --- Morpion ------------------------------------------------------------- */

.ttt-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  margin: 10px auto 0;
}
.ttt-grid.mini { width: 150px; }
.ttt-grid.big { width: min(100%, 300px); gap: 8px; }
.ttt-cell {
  aspect-ratio: 1;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  font-size: 22px;
  display: grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
  transition: background 120ms, border-color 120ms, transform 120ms;
}
.ttt-grid.big .ttt-cell { font-size: 40px; }
.ttt-cell:disabled { cursor: default; }
.ttt-cell.x { color: var(--accent); }
.ttt-cell.o { color: var(--ok); }
.ttt-cell.blocked { color: var(--ink-faint); background: var(--card-hi); border-style: dashed; }
.ttt-cell.lit { background: var(--accent-soft); border-color: var(--accent); }
.ttt-cell.win { background: rgba(52, 211, 153, 0.22); border-color: var(--ok); }
.ttt-status {
  margin: 0 0 4px;
  text-align: center;
  font-weight: 700;
  min-height: 22px;
}
.ttt-status.ok { color: var(--ok); }
.ttt-status.warn { color: var(--ko); }
.ttt-setting { margin-bottom: 10px; }
.ttt-setting small { display: block; color: var(--ink-faint); font-size: 11.5px; margin-bottom: 4px; }
.ttt-order { margin: 0; padding-left: 22px; }
.ttt-order li { margin: 6px 0; line-height: 1.4; }
.ttt-puzzle {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--card-hi);
  border: 1px solid transparent;
}
.ttt-puzzle.done { border-color: var(--ok); }
.cube-stats.three { grid-template-columns: repeat(3, 1fr); }

/* Le cube du morpion : trois etages en CSS, qu'on fait tourner. */
.t3d-stage {
  height: 300px;
  display: grid;
  place-items: center;
  perspective: 900px;
  touch-action: none;
  user-select: none;
}
.t3d-scene {
  position: relative;
  width: 0;
  height: 0;
  transform-style: preserve-3d;
  transition: transform 160ms ease-out;
}
.t3d-layer {
  position: absolute;
  left: -78px;
  top: -78px;
  width: 156px;
  height: 156px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  box-sizing: border-box;
  border-radius: 10px;
  background: rgba(47, 144, 255, 0.10);
  border: 1px solid var(--line);
  transform-style: preserve-3d;
  backface-visibility: visible;
}
.t3d-layer .ttt-cell {
  font-size: 22px;
  border-radius: 8px;
  background: var(--bg-soft);
  /* Un pion se lit des deux cotes : le cube se retourne. */
  transform: translateZ(1px);
}
.ttt-layers {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.ttt-layer-flat small { display: block; text-align: center; color: var(--ink-faint); font-size: 11px; }
.ttt-layer-flat .ttt-grid.mini { width: 100%; margin-top: 4px; gap: 3px; }
.ttt-layer-flat .ttt-cell { font-size: 15px; border-radius: 6px; }

/* Le morpion par correspondance : une partie par carte, l'etat en tete. */
.ttt-game { position: relative; }
.ttt-game .ttt-meta { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.ttt-game .ttt-meta small { color: var(--ink-faint); }
.ttt-game .ttt-grid.mini { width: 180px; }
.ttt-game .ttt-grid.mini .ttt-cell { font-size: 24px; }
.ttt-game .ttt-layers .ttt-grid.mini { width: 100%; }
.ttt-game .ttt-layers .ttt-cell { font-size: 15px; }
.ttt-game textarea { width: 100%; box-sizing: border-box; }

.ttt-h { margin: 4px 0 10px; font-size: 15px; }
