/* ======================================================================
   style.css — Thème néon sombre, responsive, pour « Connect the Dots ».
   ====================================================================== */

:root {
  --bg: #0a0e1a;
  --bg2: #111726;
  --panel: #141b2e;
  --panel-border: #243049;
  --text: #e7ecf6;
  --muted: #8a98b8;
  --accent: #26d6ff;
  --accent2: #ff3b6b;
  --good: #39ff88;
  --warn: #ffd23f;
  --shadow: 0 0 24px rgba(38, 214, 255, 0.18);
  --radius: 14px;
  /* Largeur de référence de la grille (partagée par le plateau ET les rangées de
     boutons sous la grille, pour qu'ils soient toujours alignés). */
  --board-w: min(76vh, 100%);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(1200px 800px at 50% -10%, #16203a 0%, var(--bg) 60%);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}

a { color: var(--accent); }

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: rgba(10, 14, 26, 0.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--panel-border);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
}

.brand {
  font-weight: 800;
  font-size: 20px;
  letter-spacing: 0.5px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 20px rgba(38, 214, 255, 0.25);
}

.topbar .spacer { flex: 1; }

.pseudo-box { display: flex; align-items: center; gap: 6px; }

input, select, button {
  font: inherit;
  color: var(--text);
}

input[type="text"], select {
  background: var(--bg2);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 7px 10px;
  outline: none;
}
input[type="text"]:focus, select:focus { border-color: var(--accent); }

button {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
  transition: transform .08s ease, border-color .15s ease, background .15s ease;
  /* Tactile : cible >= 40px, pas de délai de 300ms, pas de surbrillance de tap. */
  min-height: 40px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
button:hover { border-color: var(--accent); }
button:active { transform: translateY(1px); }
button.primary {
  background: linear-gradient(90deg, rgba(38,214,255,.2), rgba(255,59,107,.2));
  border-color: var(--accent);
}
button:disabled { opacity: .45; cursor: not-allowed; }

.layout {
  display: grid;
  grid-template-columns: 280px 1fr 300px;
  gap: 18px;
  padding: 18px;
  max-width: 1500px;
  margin: 0 auto;
}
@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  /* Sur une seule colonne, le PLATEAU passe en premier (le plus important). */
  .game-wrap { order: -1; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.panel h2 { margin: 0 0 12px; font-size: 15px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }

/* ----- Sélecteur de tailles & niveaux ----- */
.sizes { display: flex; flex-wrap: wrap; gap: 6px; }
.size-btn {
  width: 42px; height: 42px; padding: 0;
  display: grid; place-items: center;
  font-weight: 700;
}
.size-btn.locked { opacity: .4; }
.size-btn.current { border-color: var(--accent); background: rgba(38,214,255,.12); }

.levels { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; max-height: 260px; overflow:auto; }
.level-btn {
  width: 36px; height: 36px; padding: 0; font-size: 13px;
  display:grid; place-items:center;
}
.level-btn.done { border-color: var(--good); color: var(--good); }
.level-btn.current { border-color: var(--accent); background: rgba(38,214,255,.14); }

.progress-line { margin-top: 10px; font-size: 13px; color: var(--muted); }

/* ----- Zone de jeu ----- */
.game-wrap { display: flex; flex-direction: column; align-items: center; }
.hud {
  display: flex; gap: 16px; align-items: center; flex-wrap: wrap;
  margin-bottom: 12px; width: 100%; justify-content: center;
}
.hud .stat {
  background: var(--bg2); border: 1px solid var(--panel-border);
  border-radius: 10px; padding: 6px 12px; font-variant-numeric: tabular-nums;
}
.hud .stat b { color: var(--accent); }

.board-frame {
  position: relative;
  width: var(--board-w);
  max-width: 680px;
  aspect-ratio: 1 / 1;
  background: var(--bg2);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  overflow: hidden;
  touch-action: none;
}
.board-frame:focus { outline: 2px solid var(--accent); outline-offset: 2px; }
/* Tactile : pas de sélection de texte ni de menu contextuel sur appui long. */
.board-frame { -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; }
.ctd-board { -webkit-touch-callout: none; }

.ctd-board { width: 100%; height: 100%; display: block; }

.ctd-cell { fill: transparent; stroke: none; }
.ctd-cell.is-filled { fill-opacity: 0.20; }
.ctd-grid line { stroke: rgba(255,255,255,0.06); stroke-width: 0.02; }
.ctd-path { opacity: 0.92; filter: drop-shadow(0 0 .12px currentColor); }
.ctd-path.is-complete { opacity: 1; }
.ctd-dot { stroke: rgba(0,0,0,0.35); stroke-width: 0.04; }
.ctd-dot.is-twin { animation: twinblink .6s ease-in-out infinite; }
@keyframes twinblink {
  0%, 100% { r: 0.32; opacity: 1; }
  50% { r: 0.20; opacity: 0.45; }
}

/* Rangée de contrôles sous la grille du jeu : largeur = largeur de la grille.
   Les boutons de zoom restent compacts ; « Recommencer » / « Nouvelle grille »
   s'étirent pour que la somme des largeurs égale celle de la grille. */
.zoom-controls {
  display: flex; gap: 8px; margin-top: 12px;
  width: var(--board-w); max-width: 680px;
}
.zoom-controls button { min-width: 0; }
#zoomOut, #zoomReset, #zoomIn { flex: 0 0 auto; width: 46px; }
#btnRestart, #btnNew, #btnAuto { flex: 1 1 0; }

/* Boutons d'action de l'éditeur : la rangée fait la LARGEUR de la grille, et les
   4 boutons se partagent cette largeur à parts égales (somme = largeur grille). */
.editor-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  width: var(--board-w);
  max-width: 680px;
}
.editor-actions button {
  flex: 1 1 0;          /* parts égales */
  min-width: 0;         /* autorise le rétrécissement/retour à la ligne du texte */
  padding-left: 6px;
  padding-right: 6px;
}

/* ----- Hall of Fame & créateurs ----- */
.hof-list, .creators-list { list-style: none; margin: 0; padding: 0; }
.hof-list li, .creators-list li {
  display: flex; justify-content: space-between; gap: 8px;
  padding: 7px 4px; border-bottom: 1px dashed var(--panel-border);
  font-size: 14px;
}
.hof-list .rank { color: var(--muted); min-width: 22px; }
.hof-list .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hof-list .time { color: var(--accent); font-variant-numeric: tabular-nums; }

/* ----- Toasts ----- */
.toasts {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; z-index: 100; align-items:center;
}
.toast {
  background: var(--panel); border: 1px solid var(--accent);
  color: var(--text); padding: 10px 16px; border-radius: 12px;
  box-shadow: var(--shadow); animation: toastin .25s ease;
  max-width: 90vw;
}
.toast.bad { border-color: var(--accent2); }
.toast.good { border-color: var(--good); }
@keyframes toastin { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; } }

/* ----- Flash de victoire ----- */
.win-flash {
  position: fixed; inset: 0; pointer-events: none; z-index: 90;
  background: radial-gradient(circle at 50% 50%, rgba(57,255,136,.35), transparent 60%);
  opacity: 0;
}
.win-flash.show { animation: winflash 1s ease; }
@keyframes winflash {
  0% { opacity: 0; } 30% { opacity: 1; } 100% { opacity: 0; }
}

/* ----- Atelier ----- */
.atelier-controls { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 16px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; color: var(--muted); }

.bar { height: 10px; background: var(--bg2); border-radius: 6px; overflow: hidden; border:1px solid var(--panel-border); margin: 8px 0; }
.bar > span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--good)); transition: width .2s ease; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; }
.card {
  background: var(--bg2); border: 1px solid var(--panel-border); border-radius: 12px;
  padding: 10px; display: flex; flex-direction: column; gap: 8px;
}
.card .mini { width: 100%; aspect-ratio: 1/1; background: #0c1322; border-radius: 8px; }
.card .info { font-size: 12px; color: var(--muted); }
.card .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.card .actions button { padding: 5px 8px; font-size: 12px; }

.json-pop {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 200;
  display: none; place-items: center; padding: 20px;
}
.json-pop.show { display: grid; }
.json-pop .box { background: var(--panel); border: 1px solid var(--accent); border-radius: 12px; padding: 16px; max-width: 700px; width: 100%; max-height: 88vh; overflow: auto; display:flex; flex-direction:column; gap:10px; }
.json-pop textarea { width: 100%; height: min(320px, 42vh); background: var(--bg); color: var(--text); border: 1px solid var(--panel-border); border-radius: 8px; padding: 10px; font-family: ui-monospace, monospace; font-size: 12px; }

.muted { color: var(--muted); }
.center { text-align: center; }
.hidden { display: none !important; }

/* ----- Tablettes / grands téléphones ----- */
@media (max-width: 760px) {
  .topbar { padding: 10px 14px; gap: 10px; }
  .layout { padding: 12px; gap: 14px; }
  /* Le plateau occupe la largeur, borné en hauteur pour laisser voir la barre
     d'état et les boutons sans trop défiler. */
  :root { --board-w: min(100%, 72vh); }
  .board-frame { max-width: 100%; }
}

/* ----- Petits écrans (cellulaires) ----- */
@media (max-width: 560px) {
  .topbar { gap: 8px; padding: 9px 12px; }
  .brand { font-size: 16px; }
  /* Pseudo : compact mais utilisable, s'étire dans l'espace restant. */
  .pseudo-box { gap: 4px; flex: 1 1 120px; min-width: 0; }
  .pseudo-box .muted { display: none; }            /* on masque le libellé « Pseudo » */
  .pseudo-box input { width: 100%; min-width: 0; padding: 7px 9px; }
  .topbar button { padding: 7px 10px; }
  .layout { padding: 8px; gap: 10px; }
  .panel { padding: 12px; }
  .panel h2 { font-size: 13px; margin-bottom: 8px; }
  .hud { gap: 6px; margin-bottom: 8px; }
  .hud .stat { padding: 5px 8px; font-size: 12px; }
  :root { --board-w: min(100%, 70vh); }
  .board-frame { max-width: 100%; }
  .zoom-controls { gap: 6px; }
  #btnRestart, #btnNew { font-size: 13px; }
  .atelier-controls { gap: 8px; }
  .gallery { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
  /* cibles tactiles confortables */
  .level-btn { width: 40px; height: 40px; }
  .size-btn { width: 44px; height: 44px; }
  /* Modales : pleine largeur, hauteur maîtrisée. */
  .json-pop { padding: 10px; }
  .json-pop .box { max-height: 92vh; }
}

/* ----- Très petits écrans (≤ 380px) ----- */
@media (max-width: 380px) {
  .brand { font-size: 14px; }
  .hud .stat { font-size: 11px; padding: 4px 7px; }
  .topbar { gap: 6px; }
}

/* ======================================================================
   Anti-débordement : aucune grille / aperçu ne dépasse de l'écran (mobile).
   ====================================================================== */
html, body { overflow-x: hidden; }
/* Les enfants de grilles/flex peuvent rétrécir (sinon largeur mini = contenu). */
.layout > *, .game-wrap, .panel { min-width: 0; max-width: 100%; }
/* Tout plateau / aperçu SVG reste dans son conteneur. */
.board-frame, .mini, #zoomPreview, #liveMini { max-width: 100%; }
.ctd-board, .mini, #zoomPreview svg, #liveMini svg { max-width: 100%; height: auto; display: block; }
/* Le plateau ne dépasse jamais la largeur disponible NI une hauteur raisonnable. */
.board-frame { width: var(--board-w); max-width: 100%; }
@media (max-width: 760px) {
  /* Galerie : des cartes qui tiennent toujours (jamais de piste plus large que l'écran). */
  .gallery { grid-template-columns: repeat(auto-fill, minmax(min(140px, 100%), 1fr)); }
  /* Modales : largeur bornée à l'écran. */
  .json-pop .box { max-width: 100%; }
  #zoomPreview { max-width: 100%; }
}
/* Respecte les encoches (iPhone) : marge de sécurité. */
.topbar { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
