/* ============================================================================
   LINKZ — style kawaii cartoon B (standard FACETA, cf BACKLOG.md
   §PIVOT DESIGN / §PROGRAMME AUTONOME, suite alphabétique après `lexo`,
   31/66 flotte). RESTYLAGE EN PLACE : mêmes sélecteurs, mêmes ids/classes
   d'état que src/game.js et src/render.js (aucun renommage, aucun élément
   retiré) — seule l'apparence change : contour épais net (--toon-outline/--toon-outline-w),
   aplats + UNE seule ombre plate "sticker" (jamais de flou), reflet kawaii
   posé en 2ᵉ COUCHE de `background` (jamais en ::after après le contenu,
   pour ne jamais recouvrir un glyphe — leçon C6§2/mahzo), formes rondes.
   Identité jade & ivoire (table de mahjong) conservée dans les DEUX thèmes ;
   les tuiles restent ivoire quel que soit le thème (objet physique).
   ============================================================================ */

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --text: #16261f;
  --text-soft: #3d5a4d;
  --muted: #6c8577;
  --bg: #eef7ee;
  --bg-grad: radial-gradient(1200px 800px at 50% -10%, #f8fbec 0%, #eef7ee 55%, #e2edd8 100%);

  /* (C8) panneaux en dégradé 2 tons (matière), pas un aplat plat. */
  --panel: linear-gradient(160deg, #ffffff 0%, #eaf3e6 100%);
  --panel-2: linear-gradient(155deg, #f4f9ee 0%, #e2eeda 100%);
  --field: linear-gradient(165deg, #0f6b45 0%, #0a4a2f 100%);

  --jade: #0d5a3e;
  --jade-dark: #073d29;
  --jade-light: #1f9463;
  --gold: #c98a12;
  --gold-light: #e8b83f;
  --danger: #c23b3b;

  --tile-face: linear-gradient(160deg, #ffffff 0%, #fbf7ea 55%);
  --tile-edge: #cdb87f;

  /* Contour : --toon-outline ADAPTATIF (foncé sur fond clair) pour panneaux/chips ;
     --toon-outline-ink TOUJOURS foncé, pour les éléments posés sur un aplat vif
     (boutons pleins) — lisible dans les deux thèmes (même leçon FACETA C7). */
  --toon-outline: var(--jade-dark);
  --toon-outline-ink: #06301f;
  --toon-outline-w: 2.5px;
  --kawaii-sheen: radial-gradient(circle at 30% 24%, rgba(255, 255, 255, .55), rgba(255, 255, 255, 0) 50%);

  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow: 0 4px 0 var(--toon-outline-ink);
  --shadow-lg: 0 7px 0 var(--toon-outline-ink);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

  --tile: 52px;
  color-scheme: light;
}

/* Thème piloté par le hub (_kit/theme.js pose data-theme AVANT le premier
   rendu, toujours 'dark' ou 'light', jamais absent) — un seul contrat CSS,
   plus de @media (prefers-color-scheme) qui ignorerait un choix explicite
   du joueur divergent de l'OS (retour porteur 2026-09-10, même patron que
   FACETA/triplo/mergy/kakz). */
html[data-theme="dark"] {
  --text: #eef4ef;
  --text-soft: #b9c9c0;
  --muted: #8aa89a;
  --bg: #0c1712;
  --bg-grad: radial-gradient(1200px 800px at 50% -10%, #17281f 0%, #0e1a14 55%, #08120d 100%);

  --panel: linear-gradient(160deg, #1c3327 0%, #122019 100%);
  --panel-2: linear-gradient(155deg, #223b2d 0%, #172a20 100%);
  --field: linear-gradient(165deg, #0a4a2f 0%, #052a1a 100%);

  --jade-light: #2bb883;
  --gold: #e0b34a;
  --gold-light: #f2cc74;

  --tile-face: linear-gradient(160deg, #fbf4dd 0%, #f0e6c8 55%);
  --tile-edge: #a68f5c;

  /* Ink adaptatif clair (visible sur les panneaux sombres) ; ink-dark reste
     un vrai foncé (boutons/tuiles vifs restent lisibles dans les 2 thèmes). */
  --toon-outline: #5fe0a8;
  --toon-outline-ink: #04140d;
  color-scheme: dark;
}

html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg-grad) fixed, var(--bg);
  color: var(--text);
  overflow: hidden;
}
html[dir="rtl"] body { direction: rtl; }

button { font-family: inherit; }

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-height: 100dvh;
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  gap: 10px;
}

/* ---------------------------------------------------------------- HUD --- */
.hud {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--kawaii-sheen), var(--panel-2);
  border: var(--toon-outline-w) solid var(--toon-outline);
  font-size: 13px;
  font-weight: 800;
  color: var(--toon-outline);
  white-space: nowrap;
  box-shadow: var(--shadow);
  transition: transform .12s ease, box-shadow .12s ease;
}
.pill.icon {
  width: 38px; height: 38px; padding: 0;
  justify-content: center;
  font-size: 17px;
  text-decoration: none;
  cursor: pointer;
}
.pill.icon:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--toon-outline-ink); }
.pill.lives { color: var(--danger); border-color: var(--danger); }
.wallet-hud { display: flex; gap: 6px; margin-inline-start: auto; }
.wchip {
  display: flex; align-items: center; gap: 5px;
  padding: 7px 11px; border-radius: 999px;
  background: var(--kawaii-sheen), var(--panel-2); border: var(--toon-outline-w) solid var(--toon-outline);
  font-weight: 800; font-size: 13px; box-shadow: var(--shadow);
  color: var(--toon-outline);
}
.wchip.earn { color: var(--gold); border-color: var(--gold); box-shadow: 0 4px 0 var(--jade-dark); }
/* Icônes SVG trait fin (règle design galaxie SANTVIA, zéro emoji) : les
   wrappers .ic/.ico dimensionnaient déjà leur glyphe via font-size — le svg
   hérite la même taille en `1em` pour rester au même gabarit sans dupliquer
   de valeurs px par contexte (HUD, playbar, outils, dialogs). */
.ic, .ico { display: inline-flex; align-items: center; justify-content: center; line-height: 1; }
.ic svg, .ico svg, .big-emoji svg { width: 1em; height: 1em; display: block; }
.ic { font-size: 14px; }

/* --------------------------------------------------------------- ÉCRANS --- */
.screen { display: none; flex: 1; min-height: 0; flex-direction: column; overflow: hidden; }
.screen.show { display: flex; }

/* ---- Accueil --- */
#scr-home { overflow-y: auto; gap: 14px; padding-bottom: 6px; }
.hero { text-align: center; padding: 6px 0 2px; }
.logo { font-size: 40px; font-weight: 900; letter-spacing: 1px; color: var(--toon-outline); }
.logo b { color: var(--gold); }
.sub { font-size: 13px; color: var(--text-soft); margin-top: 4px; }
.sub.small { font-size: 12px; }

.panel {
  background: var(--kawaii-sheen), var(--panel);
  border: var(--toon-outline-w) solid var(--toon-outline);
  border-radius: var(--radius-lg);
  padding: 12px 14px 14px;
  box-shadow: var(--shadow);
}
.panel-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.panel-head h2 { font-size: 14px; margin: 0; text-transform: uppercase; letter-spacing: .04em; color: var(--text-soft); }

.diff-row { display: flex; gap: 8px; }
.diff-btn {
  flex: 1; padding: 10px 6px; border-radius: var(--radius-md);
  border: var(--toon-outline-w) solid var(--toon-outline); background: var(--kawaii-sheen), var(--panel-2);
  color: var(--toon-outline); font-weight: 800; font-size: 13px; cursor: pointer;
  box-shadow: 0 3px 0 var(--toon-outline-ink);
  transition: transform .12s ease, box-shadow .12s ease;
}
.diff-btn.active {
  background: var(--kawaii-sheen), linear-gradient(160deg, var(--jade-light), var(--jade));
  color: #fff; border-color: var(--toon-outline-ink);
  box-shadow: 0 3px 0 var(--toon-outline-ink);
}
.diff-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--toon-outline-ink); }

.boards-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.board-card {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 10px 6px 8px;
  border-radius: var(--radius-md);
  border: var(--toon-outline-w) solid var(--toon-outline);
  background: var(--kawaii-sheen), var(--panel-2);
  cursor: pointer;
  box-shadow: 0 3px 0 var(--toon-outline-ink);
  transition: transform .12s ease, box-shadow .12s ease;
}
.board-card:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--toon-outline-ink); }
.board-card.selected { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold), 0 3px 0 var(--toon-outline-ink); }
.board-card.locked { opacity: .55; cursor: not-allowed; }
.board-thumb { width: 46px; height: 46px; display: flex; align-items: center; justify-content: center; }
.thumb-grid { display: grid; grid-template-columns: repeat(var(--tcols), 1fr); grid-template-rows: repeat(var(--trows), 1fr); width: 100%; height: 100%; gap: 1px; }
.thumb-grid i { background: var(--jade-light); border-radius: 1px; }
.board-card.locked .thumb-grid i { background: var(--muted); }
.board-label { font-size: 10.5px; font-weight: 700; text-align: center; color: var(--text-soft); line-height: 1.15; }
.board-stars { font-size: 10px; color: var(--gold); letter-spacing: 1px; }

.home-actions { display: flex; flex-direction: column; gap: 8px; padding: 2px 2px 4px; }
.home-actions .row { display: flex; gap: 8px; }

.btn {
  border: var(--toon-outline-w) solid var(--toon-outline-ink); border-radius: var(--radius-md);
  padding: 13px 16px; font-weight: 800; font-size: 14px;
  cursor: pointer; touch-action: manipulation;
  transition: transform .12s ease, box-shadow .12s ease;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--toon-outline-ink) !important; }
.btn.primary {
  background: var(--kawaii-sheen), linear-gradient(160deg, var(--gold-light), var(--gold));
  color: #241a04;
  box-shadow: var(--shadow-lg);
}
.btn.ghost {
  background: var(--kawaii-sheen), var(--panel-2); color: var(--toon-outline); border: var(--toon-outline-w) solid var(--toon-outline);
  box-shadow: var(--shadow);
}
.btn.ghost.slim { flex: 1; padding: 10px 12px; font-size: 13px; }
.btn.ad { background: var(--kawaii-sheen), linear-gradient(160deg, #6fd39a, #2f9e63); color: #06180e; width: 100%; box-shadow: var(--shadow-lg); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---- Jeu --- */
#scr-play { gap: 8px; }
.playbar { display: flex; align-items: center; gap: 6px; flex-shrink: 0; flex-wrap: wrap; }
.playbar .pill { font-size: 12.5px; }

.board-wrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
.board-frame {
  position: relative;
  display: inline-block;
  border-radius: var(--radius-lg);
  background: var(--kawaii-sheen), linear-gradient(160deg, var(--jade-light), var(--jade) 55%, var(--jade-dark));
  border: var(--toon-outline-w) solid var(--toon-outline-ink);
  box-shadow: var(--shadow-lg);
  padding: var(--tile);
}
#board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--tile));
  grid-template-rows: repeat(var(--rows), var(--tile));
  z-index: 1;
}
.path-layer {
  /* Recouvre EXACTEMENT le padding-box de .board-frame (le padding = 1 tuile
     est l'anneau vide où un chemin peut contourner le plateau) — voir la
     note de coordonnées en tête de src/render.js. */
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}
.path-layer polyline {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.path-layer .hint-line {
  stroke: var(--gold-light);
  stroke-width: 6;
  stroke-dasharray: 2 14;
  opacity: .9;
  animation: dash-flow 1s linear infinite;
}
.path-layer .match-line {
  stroke: #fff;
  stroke-width: 7;
  opacity: .95;
  stroke-dasharray: 320;
  stroke-dashoffset: 320;
  animation: draw-path .32s ease forwards;
  filter: drop-shadow(0 0 6px rgba(255,255,255,.6));
}
@keyframes draw-path { to { stroke-dashoffset: 0; } }
@keyframes dash-flow { to { stroke-dashoffset: -32; } }

.tile {
  width: var(--tile); height: var(--tile);
  padding: 5px;
  background: var(--kawaii-sheen), var(--tile-face);
  border: 2.5px solid var(--toon-outline-ink);
  border-radius: 10px;
  box-shadow: 0 4px 0 var(--tile-edge);
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
  touch-action: manipulation;
}
.tile svg { width: 100%; height: 100%; display: block; }
.tile:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--tile-edge); }
.tile.selected {
  transform: translateY(-3px);
  box-shadow: 0 0 0 3px var(--gold), 0 7px 0 var(--tile-edge);
}
.tile.hint { animation: hint-pulse 1s ease-in-out infinite; }
@keyframes hint-pulse {
  0%, 100% { box-shadow: 0 4px 0 var(--tile-edge); }
  50% { box-shadow: 0 0 0 3px var(--gold-light), 0 4px 0 var(--tile-edge); }
}
.tile.matched { animation: match-pop .36s ease forwards; pointer-events: none; }
@keyframes match-pop {
  0% { transform: scale(1); opacity: 1; }
  40% { transform: scale(1.12); opacity: 1; }
  100% { transform: scale(.2); opacity: 0; }
}
.tile.shake { animation: shake-tile .32s ease; }
@keyframes shake-tile {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}
.tile.appear { animation: appear-tile .28s ease; }
@keyframes appear-tile {
  0% { transform: scale(.2); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
.tile.shuffle-pop { animation: shuffle-pop .32s ease; }
@keyframes shuffle-pop {
  0% { transform: scale(.85) rotate(-3deg); }
  60% { transform: scale(1.08) rotate(2deg); }
  100% { transform: scale(1) rotate(0); }
}

.spark {
  position: absolute; left: 0; top: 0; width: 6px; height: 6px; margin: -3px;
  border-radius: 50%; background: var(--gold-light);
  pointer-events: none; z-index: 3;
  animation: spark-fly .55s ease-out forwards;
}
@keyframes spark-fly {
  0% { transform: translate(0, 0) scale(1); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(.2); opacity: 0; }
}

.tools { display: flex; gap: 8px; flex-shrink: 0; padding-bottom: 2px; }
.tool-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 9px 4px; border-radius: var(--radius-md);
  background: var(--kawaii-sheen), var(--panel-2); border: var(--toon-outline-w) solid var(--toon-outline);
  color: var(--toon-outline); cursor: pointer;
  box-shadow: 0 3px 0 var(--toon-outline-ink);
  transition: transform .12s ease, box-shadow .12s ease;
}
.tool-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--toon-outline-ink); }
.tool-btn .ic { font-size: 18px; color: var(--toon-outline); }
.tool-btn .lbl { font-size: 10.5px; font-weight: 700; color: var(--text-soft); }
.tool-btn .badge { font-size: 10px; font-weight: 800; color: var(--gold); }

/* -------------------------------------------------------------- OVERLAYS --- */
.ov {
  display: none; position: fixed; inset: 0; z-index: 1000;
  align-items: center; justify-content: center;
  background: rgba(6, 12, 9, .6);
  padding: 20px;
}
.ov.show { display: flex; }
.dialog {
  width: 100%; max-width: 340px;
  background: var(--kawaii-sheen), var(--panel);
  border: var(--toon-outline-w) solid var(--toon-outline);
  border-radius: var(--radius-lg);
  padding: 22px 20px;
  text-align: center;
  color: var(--text);
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; gap: 10px;
  animation: dialog-in .2s ease;
}
@keyframes dialog-in { from { transform: translateY(10px) scale(.97); opacity: 0; } to { transform: none; opacity: 1; } }
.big-emoji { font-size: 40px; color: var(--toon-outline); }
.dialog h2 { margin: 0; font-size: 20px; }
.dialog p { margin: 0; font-size: 13.5px; color: var(--text-soft); line-height: 1.5; }
.stars { font-size: 28px; color: var(--gold); letter-spacing: 3px; }
.done-stats { display: flex; gap: 10px; justify-content: center; margin: 4px 0; }
.done-stats .s { background: var(--kawaii-sheen), var(--panel-2); border: var(--toon-outline-w) solid var(--toon-outline); border-radius: var(--radius-sm); padding: 8px 14px; }
.done-stats .k { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.done-stats .v { font-size: 18px; font-weight: 800; color: var(--toon-outline); }

#toast {
  display: none; position: fixed; left: 16px; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom));
  background: var(--kawaii-sheen), var(--field);
  color: #fff; padding: 12px 16px;
  border: var(--toon-outline-w) solid var(--toon-outline-ink);
  border-radius: var(--radius-md); font-size: 13.5px; text-align: center;
  z-index: 2000; box-shadow: var(--shadow-lg);
}
#toast.show { display: block; animation: toast-in .25s ease; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

@media (max-width: 420px) {
  :root { --tile: 42px; }
  .boards-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .logo { font-size: 32px; }
}
@media (min-width: 720px) {
  :root { --tile: 60px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
