/* Salon de Jeux : styles communs à toute l'appli.
   Toutes les couleurs sont des variables ; thème sombre automatique (prefers-color-scheme).
   Chaque jeu ajoute ses propres styles dans src/games/<jeu>/<jeu>.css. */

@font-face {
  font-family: 'Atkinson Hyperlegible';
  src: url('../../assets/fonts/atkinson-hyperlegible-400.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Atkinson Hyperlegible';
  src: url('../../assets/fonts/atkinson-hyperlegible-700.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Young Serif';
  src: url('../../assets/fonts/young-serif-400.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;
  --bg: #EBF0ED; --surface: #FFFFFF; --surface-2: #F2F6F3; --ink: #15221D; --muted: #4D5D56; --line: #C5D1CA;
  --brand: #1D5C48; --on-brand: #FFFFFF; --soft: #D6E8DE; --focus: #2457C5; --bad: #B3261E; --good: #1B7A4A;
  --felt: #1E5A47; --felt-deep: #154233; --felt-line: rgba(255, 255, 255, .4); --on-felt: #F2FAF6;
  --card-bg: #FFFFFF; --card-ink: #1B1F24; --card-red: #C0262D; --back-a: #2E4C8C; --back-b: #3A60AE;
  --sq-light: #E8E2D0; --sq-dark: #2F5D4B;
  --pc-w-hi: #FFFFFF; --pc-w: #F4EEDD; --pc-w-edge: #B7AB8C; --pc-r-hi: #E9776A; --pc-r: #C23A2E; --pc-r-edge: #7A1E17; --gold: #F2B705;
  --sdk-hi: #E3EEE8; --sdk-same: #CCE0F5; --sdk-sel: #B9DFC9; --sdk-user: #1F56C4; --sdk-bad: #B3261E; --sdk-wrong: #F9D4D0;
  --scrim: rgba(0, 0, 0, .55);
  --font-display: 'Young Serif', Georgia, 'Times New Roman', serif;
  --font-body: 'Atkinson Hyperlegible', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0F1613; --surface: #18221E; --surface-2: #202C27; --ink: #E8F0EC; --muted: #9DB1A8; --line: #30433A;
    --brand: #6FC8A4; --on-brand: #06231A; --soft: #25423A; --focus: #8DB6FF; --bad: #FF8F85; --good: #7FDCA8;
    --felt: #17493A; --felt-deep: #0E3126; --sq-light: #D6D0BC; --sq-dark: #25493C;
    --sdk-hi: #1F2D27; --sdk-same: #27415E; --sdk-sel: #2C5444; --sdk-user: #8DB6FF; --sdk-bad: #FF8F85; --sdk-wrong: #4A2623;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0F1613; --surface: #18221E; --surface-2: #202C27; --ink: #E8F0EC; --muted: #9DB1A8; --line: #30433A;
  --brand: #6FC8A4; --on-brand: #06231A; --soft: #25423A; --focus: #8DB6FF; --bad: #FF8F85; --good: #7FDCA8;
  --felt: #17493A; --felt-deep: #0E3126; --sq-light: #D6D0BC; --sq-dark: #25493C;
  --sdk-hi: #1F2D27; --sdk-same: #27415E; --sdk-sel: #2C5444; --sdk-user: #8DB6FF; --sdk-bad: #FF8F85; --sdk-wrong: #4A2623;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 18px;
  line-height: 1.4;
  padding: max(14px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(36px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation; /* pas de zoom au double toucher */
}
h1, h2, h3 { font-family: var(--font-display); font-weight: 400; margin: 0; text-wrap: balance; line-height: 1.15; }
h1 { font-size: 2.3rem; }
h2 { font-size: 1.7rem; }
h3 { font-size: 1.45rem; }
p { margin: 0; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.screen { max-width: 560px; margin-inline: auto; display: flex; flex-direction: column; gap: 14px; }
.screen.game { -webkit-user-select: none; user-select: none; }
.game-body { display: flex; flex-direction: column; gap: 14px; }
.bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* ---------- Boutons ---------- */
.btn {
  min-height: 56px; min-width: 0; padding: 0 18px; border-radius: 14px;
  border: 2px solid var(--line); background: var(--surface); color: var(--ink);
  font-weight: 700; display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer;
}
.btn:active { background: var(--soft); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn:disabled { opacity: .4; cursor: default; }
.btn[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
button:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.tools { display: flex; gap: 8px; }
.tools .btn { flex: 1; padding: 0 6px; font-size: 1rem; }
.status { min-height: 1.5em; text-align: center; color: var(--muted); }
.status strong { color: var(--ink); }
.tip { color: var(--muted); font-size: .95rem; text-align: center; }

/* Choix segmenté (niveaux, taille du plateau) */
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border: 2px solid var(--line); border-radius: 14px; overflow: hidden; background: var(--surface); }
.seg button { min-height: 56px; border: 0; background: transparent; font-weight: 700; cursor: pointer; padding: 0 6px; }
.seg button + button { border-inline-start: 2px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--brand); color: var(--on-brand); }

/* ---------- Accueil ---------- */
#home { gap: 18px; }
.lede { color: var(--muted); font-size: 1.15rem; }
.tiles { display: grid; gap: 14px; }
.tile {
  display: grid; grid-template-columns: 76px minmax(0, 1fr); gap: 16px; align-items: center; text-align: left;
  width: 100%; min-height: 108px; padding: 16px; border-radius: 20px;
  background: var(--surface); border: 2px solid var(--line); cursor: pointer;
}
.tile:active { background: var(--soft); }
.tile svg { width: 76px; height: 76px; }
.t-name { font-family: var(--font-display); font-size: 1.55rem; display: block; line-height: 1.15; }
.t-desc { color: var(--muted); font-size: 1rem; display: block; margin-top: 2px; }
.tile.soon { border-style: dashed; background: transparent; cursor: default; opacity: .8; }
.tile.soon:active { background: transparent; }
.install { font-size: 1.15rem; min-height: 64px; }
.foot { color: var(--muted); font-size: .95rem; }

/* Icônes des tuiles (SVG en ligne) */
.ic-bg { fill: var(--soft); stroke: var(--brand); stroke-width: 3; }
.ic-line { stroke: var(--brand); stroke-width: 2; fill: none; }
.ic-t { fill: var(--ink); font: 700 17px var(--font-body); text-anchor: middle; }
.ic-card { fill: var(--card-bg); stroke: var(--line); stroke-width: 2; }
.ic-back { fill: var(--back-a); stroke: var(--card-bg); stroke-width: 3; }
.ic-red { fill: var(--card-red); font: 700 22px var(--font-body); text-anchor: middle; }
.ic-lt { fill: var(--sq-light); }
.ic-dk { fill: var(--sq-dark); }
.ic-pw { fill: var(--pc-w); stroke: var(--pc-w-edge); stroke-width: 2; }
.ic-pr { fill: var(--pc-r); stroke: var(--pc-r-edge); stroke-width: 2; }
.ic-tri { fill: var(--muted); }

/* ---------- Fenêtre de dialogue ---------- */
.sheet { position: fixed; inset: 0; z-index: 50; background: var(--scrim); display: flex; align-items: flex-end; justify-content: center; padding: 16px; }
.sheet-box {
  width: 100%; max-width: 480px; background: var(--surface); color: var(--ink); border-radius: 22px; padding: 22px;
  display: flex; flex-direction: column; gap: 14px; margin-bottom: env(safe-area-inset-bottom, 0px);
}
.sheet-actions { display: flex; flex-direction: column-reverse; gap: 10px; } /* bouton principal en haut, pleine largeur */
.sheet-actions .btn { flex: 1; }

@media (prefers-reduced-motion: no-preference) {
  .btn, .tile, .seg button { transition: background-color .12s; }
}

/* ---------- Écran de fin de partie ---------- */
.result-sheet { align-items: center; }
.result-box { text-align: center; align-items: stretch; }
.res-stars { display: flex; justify-content: center; gap: 6px; margin-top: -4px; }
.res-star { width: 64px; height: 64px; color: var(--line); display: inline-block; }
.res-star svg { width: 100%; height: 100%; fill: currentColor; }
.res-star.on { color: var(--gold); filter: drop-shadow(0 2px 0 rgba(0, 0, 0, .18)); }
.res-text { color: var(--muted); }
.res-gain { font-size: 1.5rem; font-weight: 700; color: var(--ink); min-height: 0; }
.res-gain:empty, .res-bonus:empty { display: none; }
.res-bonus { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.res-bonus li { background: var(--soft); border-radius: 12px; padding: 10px 12px; font-weight: 700; }
.res-total { color: var(--muted); font-size: 1rem; }

/* ---------- Téléphone à l'horizontale ----------
   Les jeux qui le gèrent (paysage: true) mettent leurs commandes dans une colonne à droite ;
   le bouton « ← Accueil » vient se placer en haut de cette colonne. */
:root { --cote: 190px; }
@media (orientation: landscape) and (max-height: 560px) {
  body { padding-top: max(8px, env(safe-area-inset-top)); padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .screen.game[data-paysage] { max-width: none; position: relative; }
  .screen.game[data-paysage] > .bar { position: absolute; top: 0; right: 0; width: var(--cote); z-index: 2; }
  .screen.game[data-paysage] > .bar .btn { width: 100%; }
  .screen.game[data-paysage] > .bar h2 { display: none; }
}

/* ---------- Mouvement : boutons, accueil, transitions d'écran ---------- */
.home-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.star-chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 999px;
  background: var(--surface); border: 2px solid var(--gold); font-weight: 700; font-size: 1.2rem; color: var(--ink);
}
.star-chip::first-letter { color: var(--gold); }
.defi-banner {
  background: var(--soft); border: 2px solid var(--brand); border-radius: 14px; padding: 10px 14px; font-weight: 700; text-align: center;
}

@media (prefers-reduced-motion: no-preference) {
  .btn, .tile { transition: background-color .12s, transform .12s cubic-bezier(.2, .8, .2, 1), box-shadow .12s; }
  .btn:active:not(:disabled), .tile:active:not(.soon) { transform: scale(.97); }
  .seg button { transition: background-color .2s, color .2s; }

  /* Changement d'écran : glissement léger (API View Transitions) */
  ::view-transition-old(root), ::view-transition-new(root) { animation-duration: .28s; animation-timing-function: cubic-bezier(.2, .8, .2, 1); }
  html[data-sens="avant"]::view-transition-old(root) { animation-name: vt-sortie-gauche; }
  html[data-sens="avant"]::view-transition-new(root) { animation-name: vt-entree-droite; }
  html[data-sens="arriere"]::view-transition-old(root) { animation-name: vt-sortie-droite; }
  html[data-sens="arriere"]::view-transition-new(root) { animation-name: vt-entree-gauche; }
  @keyframes vt-sortie-gauche { to { opacity: 0; transform: translateX(-30px); } }
  @keyframes vt-entree-droite { from { opacity: 0; transform: translateX(30px); } }
  @keyframes vt-sortie-droite { to { opacity: 0; transform: translateX(30px); } }
  @keyframes vt-entree-gauche { from { opacity: 0; transform: translateX(-30px); } }
}
@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root), ::view-transition-new(root) { animation: none; }
}
#sheet-text { white-space: pre-line; }

/* ---------- Tuiles pixel art « Tiny Islands » (Majadroid, CC0) ---------- */
:root { --mer: #639BFF; --mer-fonce: #4F86EA; --herbe: #328C19; }
.tuile {
  display: block; width: var(--ts); height: var(--ts); flex: none;
  background-image: url('../../assets/ile/tuiles.png'); background-repeat: no-repeat;
  background-size: calc(var(--ts) * 14) calc(var(--ts) * 10);
  background-position: calc(var(--tc) * var(--ts) * -1) calc(var(--tr) * var(--ts) * -1);
  image-rendering: pixelated; image-rendering: crisp-edges;
}
.ilot { display: grid; width: max-content; }

/* ---------- Accueil : modes de jeu, missions ---------- */
.tiles.grandes .tile { min-height: 116px; border-width: 3px; border-color: var(--brand); }
.ic-mer { fill: var(--mer); }
.titre-section { font-family: var(--font-display); font-size: 1.3rem; margin-top: 4px; }
.titre-section b { font-family: var(--font-body); font-size: 1rem; background: var(--soft); border-radius: 999px; padding: 2px 10px; vertical-align: middle; }
.missions-accueil { background: var(--surface); border: 2px solid var(--line); border-radius: 20px; padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.missions-accueil ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.missions-accueil li { display: flex; align-items: center; gap: 10px; }
.missions-accueil li small { color: #9A6C00; font-weight: 700; margin-left: auto; white-space: nowrap; }
.missions-accueil li.ok { color: var(--muted); }
.missions-accueil .coche { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; flex: none; font-weight: 700; color: var(--on-brand); }
.missions-accueil li.ok .coche { background: var(--brand); border-color: var(--brand); }

/* Zone d'installation, en haut de l'accueil */
.install-zone { display: flex; flex-direction: column; gap: 8px; }
.install-zone:not(:has(> :not([hidden]))) { display: none; }
.install-aide { border-style: dashed; font-weight: 700; }

/* Bandeau du mode développeur */
.dev-bandeau {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: space-between;
  background: repeating-linear-gradient(45deg, #FFF2B8 0 12px, #FFE68A 12px 24px); color: #3A2A00;
  border: 2px solid #E0B400; border-radius: 14px; padding: 8px 12px; font-size: .95rem;
}
.dev-bandeau .btn { min-height: 44px; background: #fff; }

/* Logo de l'accueil */
.home-top { align-items: center; }
.home-top .logo { width: 64px; height: 64px; border-radius: 16px; flex: none; box-shadow: 0 3px 8px rgba(0, 0, 0, .15); }
.home-top .titre { flex: 1; min-width: 0; }
.home-top h1 { font-size: 1.9rem; white-space: nowrap; }
.sprite {
  display: block; width: var(--ts); height: var(--ts); flex: none;
  background-image: url('../../assets/ile/sprites.png'); background-repeat: no-repeat;
  background-size: calc(var(--ts) * 16) calc(var(--ts) * 8);
  background-position: calc(var(--tc) * var(--ts) * -1) calc(var(--tr) * var(--ts) * -1);
  image-rendering: pixelated;
}
