:root {
  --felt: #0b6e3b;
  --felt-dark: #095a30;
  --gold: #f4c95d;
  --card-bg: #fdfdf7;
  --red: #c0392b;
  --black: #1c1c1c;
  --ink: #f5f5f0;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: radial-gradient(circle at 50% 20%, var(--felt) 0%, var(--felt-dark) 70%, #053d20 100%);
  color: var(--ink);
  min-height: 100vh;
}

#app {
  max-width: 1000px;
  margin: 0 auto;
  padding: 24px 16px 60px;
}

h1 { text-align: center; font-size: 2rem; letter-spacing: 1px; }
h1 .sub { display: block; font-size: 0.9rem; opacity: 0.75; font-weight: 400; letter-spacing: 3px; }

.panel {
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  padding: 24px;
  margin: 16px auto;
  max-width: 460px;
  backdrop-filter: blur(2px);
}

label { display: block; margin: 12px 0 4px; font-size: 0.85rem; opacity: 0.85; }

input {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.95);
  color: #111;
  font-size: 1rem;
  text-transform: none;
}
input.code { text-transform: uppercase; letter-spacing: 6px; text-align: center; font-weight: 700; }

button {
  cursor: pointer;
  border: none;
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 1rem;
  font-weight: 600;
  transition: transform 0.08s ease, filter 0.15s ease;
}
button:hover:not(:disabled) { filter: brightness(1.08); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary { background: var(--gold); color: #3a2c00; width: 100%; margin-top: 16px; }
.btn-secondary { background: rgba(255, 255, 255, 0.15); color: var(--ink); }
.btn-ghost { background: transparent; border: 1px solid rgba(255,255,255,0.3); color: var(--ink); }

.divider { text-align: center; margin: 20px 0; opacity: 0.6; }

/* Lobby */
.room-code {
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: 10px;
  text-align: center;
  color: var(--gold);
  margin: 8px 0 4px;
}
.copy-hint { text-align: center; font-size: 0.8rem; opacity: 0.7; margin-bottom: 16px; }

.player-list { list-style: none; padding: 0; margin: 16px 0; }
.player-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; margin: 6px 0;
  background: rgba(255,255,255,0.08); border-radius: 10px;
}
.badge { font-size: 0.7rem; padding: 2px 8px; border-radius: 20px; background: var(--gold); color:#3a2c00; font-weight:700; }
.badge.off { background:#777; color:#eee; }
.dot { width:10px;height:10px;border-radius:50%;background:#4caf50; }
.dot.off { background:#999; }

/* Table */
.table-wrap { display: flex; flex-direction: column; gap: 16px; }
.opponents { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.opponent {
  background: rgba(0,0,0,0.25); border-radius: 12px; padding: 10px 14px; text-align: center; min-width: 110px;
  border: 2px solid transparent;
}
.opponent.turn { border-color: var(--gold); box-shadow: 0 0 14px rgba(244,201,93,0.5); }
.opponent.finished { opacity: 0.55; }
.opponent .nm { font-weight: 700; }
.opponent .cnt { font-size: 0.8rem; opacity: 0.85; }
.opponent .role { font-size: 0.7rem; color: var(--gold); margin-top:2px; }
.opponent .off { font-size:0.65rem; color:#ffb3b3; }

.center-area {
  min-height: 150px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; background: rgba(0,0,0,0.18); border-radius: 16px; padding: 18px;
}
.status-line { text-align: center; font-size: 0.95rem; }
.status-line strong { color: var(--gold); }

.pile { display: flex; gap: -20px; min-height: 96px; align-items: center; }
.pile.empty { opacity: 0.5; font-style: italic; }

.card {
  width: 64px; height: 92px; border-radius: 8px; background: var(--card-bg);
  color: var(--black); position: relative; box-shadow: 0 3px 8px rgba(0,0,0,0.35);
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 1.4rem;
  user-select: none;
}
.card.red { color: var(--red); }
.card .corner { position: absolute; top: 4px; left: 6px; font-size: 0.8rem; line-height: 1; text-align:center; }
.card .corner.br { top: auto; left: auto; bottom: 4px; right: 6px; transform: rotate(180deg); }
.pile .card { margin-left: -22px; }
.pile .card:first-child { margin-left: 0; }

/* Hand */
.hand-area { background: rgba(0,0,0,0.25); border-radius: 16px; padding: 16px; }
.hand-area h3 { margin: 0 0 10px; font-size: 0.9rem; opacity: 0.85; }
.hand { display: flex; flex-wrap: wrap; gap: 6px; }
.hand .card { cursor: pointer; transition: transform 0.1s ease, box-shadow 0.1s ease; }
.hand .card:hover { transform: translateY(-6px); }
.hand .card.selected { transform: translateY(-14px); box-shadow: 0 0 0 3px var(--gold), 0 6px 12px rgba(0,0,0,0.4); }
.hand .card.dim { opacity: 0.45; }

.actions { display: flex; gap: 10px; margin-top: 14px; justify-content: center; flex-wrap: wrap; }

.log {
  margin-top: 16px; background: rgba(0,0,0,0.3); border-radius: 12px; padding: 10px 14px;
  font-size: 0.8rem; max-height: 140px; overflow-y: auto; line-height: 1.6;
}
.log div { opacity: 0.9; }

/* Results */
.results { list-style: none; padding: 0; }
.results li { display:flex; align-items:center; gap:12px; padding:12px 16px; margin:8px 0; border-radius:12px; background: rgba(255,255,255,0.08); }
.results .pos { font-size:1.6rem; width:40px; text-align:center; }
.results .role { margin-left:auto; font-weight:700; color: var(--gold); }
.results li.pres { background: linear-gradient(90deg, rgba(244,201,93,0.25), transparent); }
.results li.tdc { background: linear-gradient(90deg, rgba(192,57,43,0.25), transparent); }

.toast {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
  background: #c0392b; color: #fff; padding: 12px 20px; border-radius: 10px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.4); z-index: 100; font-weight: 600;
}
.hidden { display: none; }
.muted { opacity: 0.7; font-size: 0.85rem; }
.center { text-align: center; }

/* ---------- Couche d'effets (FX) ---------- */
#fx {
  position: fixed; inset: 0; pointer-events: none; overflow: hidden;
  z-index: 200;
}

.fx-banner {
  position: absolute; left: 50%; top: 38%;
  transform: translate(-50%, -50%);
  font-weight: 900; letter-spacing: 2px; text-align: center;
  padding: 14px 30px; border-radius: 16px; white-space: nowrap;
  text-shadow: 0 3px 10px rgba(0,0,0,0.5);
  will-change: transform, opacity;
}
.fx-banner.gold   { color: #3a2c00; background: linear-gradient(135deg, #ffe7a0, var(--gold)); box-shadow: 0 10px 40px rgba(244,201,93,0.6); }
.fx-banner.red    { color: #fff; background: linear-gradient(135deg, #e05a4d, #c0392b); box-shadow: 0 10px 40px rgba(192,57,43,0.6); }
.fx-banner.green  { color: #073d20; background: linear-gradient(135deg, #8af0b0, #2ecc71); box-shadow: 0 10px 40px rgba(46,204,113,0.55); }
.fx-banner.blue   { color: #fff; background: linear-gradient(135deg, #5bc0eb, #2d7dd2); box-shadow: 0 10px 40px rgba(45,125,210,0.55); }
.fx-banner .big { font-size: 2.6rem; display: block; line-height: 1.1; }
.fx-banner .small { font-size: 0.95rem; opacity: 0.85; font-weight: 700; }

.fx-confetti {
  position: absolute; top: -20px; width: 11px; height: 14px; border-radius: 2px;
  will-change: transform, opacity;
}

.fx-ring {
  position: absolute; left: 50%; top: 38%; width: 60px; height: 60px;
  margin: -30px 0 0 -30px; border-radius: 50%;
  border: 4px solid var(--gold); will-change: transform, opacity; opacity: 0;
}

/* Pulse sur le joueur dont c'est le tour */
@keyframes turnPulse {
  0%, 100% { box-shadow: 0 0 10px rgba(244,201,93,0.35); }
  50%      { box-shadow: 0 0 22px rgba(244,201,93,0.85); }
}
.opponent.turn { animation: turnPulse 1.4s ease-in-out infinite; }

/* La carte du dessus de la pile (dernière jouée) brille un instant */
.pile .card.just-played { box-shadow: 0 0 0 3px var(--gold), 0 8px 22px rgba(0,0,0,0.5); }

@media (prefers-reduced-motion: reduce) {
  .opponent.turn { animation: none; }
}

/* ---------- Éléments réservés au mobile (cachés sur desktop) ---------- */
.log-collapsed { display: none; }
#clearBtn .ico { display: none; }

/* ---------- Mobile (≤ 640px) ---------- */
@media (max-width: 640px) {
  /* Écran de jeu : layout en colonne pleine hauteur, sans scroll de page.
     dvh suit la barre d'URL mobile qui apparaît/disparaît. */
  body[data-screen="game"] { overflow: hidden; }
  body[data-screen="game"] #app {
    max-width: none;
    height: 100dvh;
    padding: 8px 8px 0;
    display: flex;
    flex-direction: column;
  }
  body[data-screen="game"] #app > h1 { font-size: 1.1rem; margin: 2px 0 6px; flex: 0 0 auto; }

  .table-wrap { flex: 1 1 auto; min-height: 0; gap: 8px; }

  /* Adversaires : défilement horizontal au lieu de wrapper et pousser la pile. */
  .opponents {
    flex: 0 0 auto; flex-wrap: nowrap; justify-content: flex-start;
    overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 2px;
  }
  .opponent { min-width: 92px; padding: 6px 10px; }

  /* Centre : absorbe l'espace restant, la pile reste centrée et visible. */
  .center-area { flex: 1 1 auto; min-height: 0; overflow: hidden; }

  /* Zone basse fixe : jamais poussée hors écran. */
  .bottom-zone {
    flex: 0 0 auto; display: flex; flex-direction: column; gap: 8px;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  /* Journal replié sur la dernière ligne, dépliable au tap. */
  .log-collapsed {
    display: flex; align-items: center; gap: 8px;
    background: rgba(0,0,0,0.3); border-radius: 10px; padding: 8px 12px;
    font-size: 0.8rem; cursor: pointer; user-select: none;
  }
  .log-collapsed .log-last { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .log-collapsed .log-toggle { opacity: 0.7; transition: transform 0.2s ease; }
  .bottom-zone .log { display: none; margin: 0; max-height: 38vh; }
  .bottom-zone .log.open { display: block; }

  .hand-area { padding: 8px; background: transparent; }
  .hand-area h3 { display: none; }

  /* Éventail : chevauchement FIXE, lisible quel que soit le nombre de cartes,
     et défilement horizontal quand la main dépasse la largeur. */
  .hand {
    flex-wrap: nowrap; justify-content: safe center; gap: 0; padding-top: 32px;
    overflow-x: auto; -webkit-overflow-scrolling: touch; touch-action: pan-x;
  }
  .hand .card {
    flex: 0 0 auto; width: 60px; height: 86px;
    margin-left: -28px;   /* ~32px de chaque carte reste visible */
    transition: transform 0.12s ease, box-shadow 0.12s ease, margin 0.12s ease;
  }
  .hand .card:first-child { margin-left: 0; }
  .hand .card:hover { transform: none; }   /* supprime le hover collant tactile */
  /* Carte sélectionnée : soulevée ET écartée de ses voisines (gauche + droite)
     et au-dessus, donc nette au lieu d'être noyée dans la liste. */
  .hand .card.selected {
    transform: translateY(-22px); z-index: 10;
    margin-left: 10px;
    box-shadow: 0 0 0 3px var(--gold), 0 8px 16px rgba(0,0,0,0.5);
  }
  .hand .card.selected + .card { margin-left: 10px; }
  /* En mode serré, seul le coin haut-gauche reste lisible. */
  .hand .card .corner { font-size: 1.05rem; top: 5px; left: 6px; }
  .hand .card > span:not(.corner) { display: none; }  /* pip centrale */
  .hand .card .corner.br { display: none; }

  /* Barre d'action ancrée : Jouer domine, cible ≥ 52px. */
  .actions { margin-top: 6px; gap: 8px; flex-wrap: nowrap; }
  .actions button { min-height: 52px; }
  #playBtn { flex: 1 1 auto; margin-top: 0; }
  #passBtn { flex: 0 0 auto; }
  #clearBtn { flex: 0 0 auto; padding: 12px 14px; }
  #clearBtn .lbl { display: none; }
  #clearBtn .ico { display: inline; font-size: 1.2rem; }

  /* Confort tactile : pas de délai 300ms ni de flash gris natif. */
  .card, button, .log-collapsed { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
}
