/* =========================================================
   CACTUS — Feuille de style
   Identité : soirée de cartes dans le désert. Table en feutre
   vert profond, lueur de couche de soleil en accent, cartes
   crème chaud. Typo "Baloo 2" (titres, rond & costaud comme
   un panneau de saloon) + "Inter" (texte, très lisible).
   ========================================================= */

@import url('https://fonts.googleapis.com/css2?family=Baloo+2:wght@500;700;800&family=Inter:wght@400;500;600;700&display=swap');

:root {
  /* Palette */
  --felt-950: #0c231c;
  --felt-900: #123a2c;
  --felt-800: #17513a;
  --felt-700: #1f6b49;
  --sand-100: #f7efd9;
  --sand-200: #efe2bd;
  --sand-300: #e3cf92;
  --sun-400: #f0b429;
  --sun-500: #d99a1d;
  --dusk-500: #ff7a52;
  --ink-900: #14201b;
  --ink-600: #3d4d44;
  --ruby-500: #d1473f;
  --white: #fffdf8;

  --radius-card: 10px;
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;

  --shadow-soft: 0 6px 18px rgba(0,0,0,0.28);
  --shadow-card: 0 2px 0 rgba(0,0,0,0.25), 0 6px 14px rgba(0,0,0,0.35);

  --font-display: 'Baloo 2', 'Trebuchet MS', sans-serif;
  --font-body: 'Inter', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  overflow-x: hidden;
  background: radial-gradient(ellipse at top, var(--felt-800) 0%, var(--felt-950) 65%);
  color: var(--sand-100);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  background-image:
    radial-gradient(ellipse at top, var(--felt-800) 0%, var(--felt-950) 65%),
    repeating-linear-gradient(135deg, rgba(255,255,255,0.015) 0 2px, transparent 2px 40px);
}

h1, h2, h3 { font-family: var(--font-display); margin: 0; letter-spacing: 0.2px; }

a { color: inherit; }

button {
  font-family: var(--font-body);
  cursor: pointer;
  border: none;
}

input {
  font-family: var(--font-body);
}

/* ---------- Motif de fond façon épines de cactus ---------- */
.cactus-mark {
  display: inline-block;
  transform: translateY(1px);
}

/* ---------- Lobby ---------- */
.lobby-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px 40px;
}

.brand {
  text-align: center;
  margin-bottom: 28px;
}

.brand .logo {
  font-size: 52px;
  line-height: 1;
  margin-bottom: 6px;
  filter: drop-shadow(0 4px 10px rgba(0,0,0,0.4));
}

.brand h1 {
  font-size: 40px;
  font-weight: 800;
  color: var(--sand-100);
  text-shadow: 0 3px 0 rgba(0,0,0,0.3);
}

.brand p {
  margin-top: 6px;
  color: var(--sand-300);
  font-size: 15px;
}

.panel {
  background: linear-gradient(180deg, var(--felt-700), var(--felt-800));
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  padding: 22px;
  width: 100%;
  max-width: 380px;
}

.tabs {
  display: flex;
  background: rgba(0,0,0,0.25);
  border-radius: 999px;
  padding: 4px;
  margin-bottom: 18px;
}

.tab-btn {
  flex: 1;
  background: transparent;
  color: var(--sand-300);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  padding: 10px 0;
  border-radius: 999px;
  transition: background .15s ease, color .15s ease;
}

.tab-btn.active {
  background: var(--sun-400);
  color: var(--ink-900);
}

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--sand-300);
  margin-bottom: 6px;
  font-weight: 600;
}

.field input {
  width: 100%;
  padding: 13px 14px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(0,0,0,0.22);
  color: var(--white);
  font-size: 16px;
  outline: none;
}

.field input:focus {
  border-color: var(--sun-400);
  box-shadow: 0 0 0 3px rgba(240,180,41,0.25);
}

.field input.code-input {
  text-transform: uppercase;
  letter-spacing: 0.28em;
  text-align: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 20px;
}

.btn-primary {
  width: 100%;
  padding: 14px;
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, var(--sun-400), var(--sun-500));
  color: var(--ink-900);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  box-shadow: 0 3px 0 #a9770f, 0 8px 16px rgba(0,0,0,0.3);
  transition: transform .08s ease;
}
.btn-primary:active { transform: translateY(2px); box-shadow: 0 1px 0 #a9770f; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  width: 100%;
  padding: 12px;
  border-radius: var(--radius-md);
  background: rgba(255,255,255,0.08);
  color: var(--sand-100);
  font-weight: 600;
  border: 1px solid rgba(255,255,255,0.14);
}

.error-msg {
  background: rgba(209,71,63,0.18);
  border: 1px solid rgba(209,71,63,0.5);
  color: #ffb4af;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 14px;
}

.hint {
  text-align: center;
  color: var(--sand-300);
  font-size: 12.5px;
  margin-top: 16px;
  line-height: 1.5;
}

/* ---------- Salle d'attente ---------- */
.waiting-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 16px;
}

.game-code-display {
  text-align: center;
  margin: 18px 0 26px;
}
.game-code-display .label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--sand-300);
}
.game-code-display .code {
  font-family: var(--font-display);
  font-size: 42px;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--sun-400);
  text-shadow: 0 3px 0 rgba(0,0,0,0.35);
}
.share-hint {
  font-size: 13px;
  color: var(--sand-300);
  text-align: center;
  margin-top: 4px;
}

.player-chip-list {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 24px;
}

.player-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(0,0,0,0.2);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-weight: 600;
}
.player-chip .seat-num {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--felt-700);
  color: var(--sand-100);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-family: var(--font-display); font-weight: 700;
}
.player-chip.host-chip .seat-num { background: var(--sun-400); color: var(--ink-900); }
.player-chip .host-tag {
  margin-left: auto;
  font-size: 11px;
  background: var(--sun-400);
  color: var(--ink-900);
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 700;
}
.player-chip-empty {
  border-style: dashed;
  justify-content: center;
  color: var(--sand-300);
  opacity: 0.6;
}

/* ---------- Plateau de jeu ---------- */
.board-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.top-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px 10px;
  padding: 8px 12px;
  background: rgba(0,0,0,0.22);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  font-size: 13px;
}
.top-bar .round-pill {
  color: var(--sand-300);
  order: 3;
  flex: 1 0 100%;
  text-align: center;
  font-size: 12px;
}
.top-bar .code-pill {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.08em;
  background: rgba(255,255,255,0.08);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 13px;
}
.top-bar button.log-toggle {
  background: rgba(255,255,255,0.08);
  color: var(--sand-100);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
}

.table-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 10px;
  gap: 8px;
  position: relative;
  overflow-y: auto;
  overflow-x: hidden;
}

.opponents-row {
  display: flex;
  justify-content: space-around;
  align-items: flex-start;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 4px;
}

.opp {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: rgba(0,0,0,0.18);
  border-radius: var(--radius-md);
  padding: 8px 10px 10px;
  border: 1px solid rgba(255,255,255,0.06);
  min-width: 108px;
  position: relative;
  transition: box-shadow .2s ease, border-color .2s ease;
}
.opp.is-turn {
  border-color: var(--sun-400);
  box-shadow: 0 0 0 2px rgba(240,180,41,0.35), 0 0 18px rgba(240,180,41,0.25);
}
.opp .opp-name {
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
}
.opp .opp-score {
  font-size: 11px;
  color: var(--sand-300);
}
.opp .cactus-tag {
  font-size: 10px;
  background: var(--dusk-500);
  color: var(--ink-900);
  padding: 1px 7px;
  border-radius: 999px;
  font-weight: 700;
}
.opp-hand {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
}

.center-pile {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 6px 0;
}

.pile-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.pile-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--sand-300);
  font-weight: 600;
}
.draw-pile-stack {
  position: relative;
  width: 58px;
  height: 82px;
}
.draw-pile-count {
  position: absolute;
  bottom: -18px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--sand-300);
  white-space: nowrap;
}

.my-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding-bottom: 6px;
}

.my-hand {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.my-name-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
}
.my-name-row .opp-score { font-size: 11px; }

/* ---------- Cartes ---------- */
.card {
  width: 52px;
  height: 74px;
  border-radius: var(--radius-card);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-card);
  user-select: none;
  transition: transform .12s ease, box-shadow .12s ease;
}
.opp-hand .card, .my-hand .card { width: 56px; height: 80px; }

.card-back {
  background:
    radial-gradient(circle at 30% 30%, var(--felt-700), var(--felt-900) 70%);
  border: 2px solid var(--sand-300);
}
.card-back::after {
  content: '🌵';
  font-size: 22px;
  opacity: 0.85;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.4));
}

.card-face {
  background: var(--sand-100);
  border: 2px solid var(--white);
  flex-direction: column;
  color: var(--ink-900);
  font-family: var(--font-display);
}
.card-face .rank { font-size: 18px; font-weight: 800; line-height: 1; }
.card-face .suit { font-size: 18px; line-height: 1; margin-top: 2px; }
.card-face.red { color: var(--ruby-500); }
.card-face.black { color: var(--ink-900); }

.card-empty {
  background: transparent;
  border: 2px dashed rgba(255,255,255,0.18);
  box-shadow: none;
}

.card-slot {
  background: transparent;
  border: none;
  padding: 0;
}
.card-slot.selectable .card { cursor: pointer; }
.card-slot.selectable .card:hover { transform: translateY(-4px); }
.card-slot.selected .card {
  transform: translateY(-8px);
  box-shadow: 0 0 0 3px var(--sun-400), var(--shadow-card);
}

.card-mini {
  width: 30px;
  height: 42px;
  border-radius: 6px;
}
.card-mini.card-back::after { font-size: 13px; }

.card.pulse {
  animation: pulseGlow 1.4s ease-in-out infinite;
}
@keyframes pulseGlow {
  0%, 100% { box-shadow: var(--shadow-card); }
  50% { box-shadow: 0 0 0 4px rgba(240,180,41,0.45), var(--shadow-card); }
}

/* ---------- Barre d'actions ---------- */
.action-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  align-items: stretch;
  padding: 10px 12px calc(14px + env(safe-area-inset-bottom));
  background: rgba(0,0,0,0.28);
  border-top: 1px solid rgba(255,255,255,0.07);
}

.action-btn {
  flex: 1 1 calc(50% - 8px);
  min-width: 128px;
  min-height: 48px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  line-height: 1.2;
  white-space: normal;
  word-break: keep-all;
  transition: transform .08s ease, opacity .15s ease;
}
.action-btn:active { transform: translateY(2px); }
.action-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.action-btn.primary { background: linear-gradient(180deg, var(--sun-400), var(--sun-500)); color: var(--ink-900); box-shadow: 0 3px 0 #a9770f; }
.action-btn.danger { background: linear-gradient(180deg, #e0655a, var(--ruby-500)); color: var(--white); box-shadow: 0 3px 0 #8f2f28; }
.action-btn.ghost { background: rgba(255,255,255,0.08); color: var(--sand-100); border: 1px solid rgba(255,255,255,0.14); box-shadow: none; }
.action-btn.cactus-btn { background: linear-gradient(180deg, #4fae72, var(--felt-700)); color: var(--white); box-shadow: 0 3px 0 #0e3524; }

.turn-banner {
  text-align: center;
  font-size: 13px;
  padding: 6px;
  color: var(--sand-300);
  min-height: 18px;
}
.turn-banner.my-turn { color: var(--sun-400); font-weight: 700; }

/* ---------- Journal d'événements (tiroir) ---------- */
.log-drawer {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: flex-end;
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease;
}
.log-drawer.open { opacity: 1; pointer-events: auto; }
.log-drawer-panel {
  background: var(--felt-900);
  width: 100%;
  max-height: 60vh;
  border-radius: 18px 18px 0 0;
  padding: 16px;
  overflow-y: auto;
  border-top: 1px solid rgba(255,255,255,0.1);
  transform: translateY(100%);
  transition: transform .2s ease;
}
.log-drawer.open .log-drawer-panel { transform: translateY(0); }
.log-drawer h3 { margin-bottom: 10px; font-size: 16px; }
.log-entry {
  font-size: 13px;
  color: var(--sand-200);
  padding: 6px 0;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.log-entry .log-time {
  color: var(--sand-300);
  font-size: 11px;
  margin-right: 6px;
}

/* ---------- Modales ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}
.modal-box {
  background: linear-gradient(180deg, var(--felt-700), var(--felt-800));
  border-radius: var(--radius-lg);
  padding: 22px;
  max-width: 360px;
  width: 100%;
  text-align: center;
  border: 1px solid rgba(255,255,255,0.1);
  box-shadow: var(--shadow-soft);
}
.modal-box h3 { font-size: 19px; margin-bottom: 10px; }
.modal-box p { font-size: 14px; color: var(--sand-200); line-height: 1.5; margin-bottom: 16px; }
.modal-box .modal-card {
  margin: 0 auto 16px;
}
.modal-actions {
  display: flex;
  gap: 8px;
}
.modal-actions .action-btn { flex: 1; }

/* ---------- Fin de manche ---------- */
.results-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 14px 0;
  text-align: left;
}
.result-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(0,0,0,0.2);
  border-radius: var(--radius-md);
  padding: 8px 10px;
}
.result-row.winner-row {
  border: 1px solid var(--sun-400);
  background: rgba(240,180,41,0.12);
}
.result-row .rr-name { font-weight: 700; font-size: 14px; flex: 1; }
.result-row .rr-score { font-family: var(--font-display); font-weight: 800; font-size: 16px; color: var(--sun-400); }
.result-row .rr-cards { display: flex; gap: 3px; }
.result-row .rr-tag {
  font-size: 10px;
  background: var(--dusk-500);
  color: var(--ink-900);
  padding: 1px 6px;
  border-radius: 999px;
  font-weight: 700;
}

.toast {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink-900);
  color: var(--sand-100);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-soft);
  z-index: 60;
  opacity: 0;
  transition: opacity .2s ease, transform .2s ease;
  pointer-events: none;
  white-space: nowrap;
  max-width: 90vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(6px); }

.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: var(--sand-100);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Responsive : écrans larges ---------- */
@media (min-width: 720px) {
  .card { width: 60px; height: 86px; }
  .opp-hand .card, .my-hand .card { width: 64px; height: 90px; }
  .card-face .rank, .card-face .suit { font-size: 20px; }
  .table-area { padding: 20px 30px; }
  .opponents-row { gap: 20px; }
}

/* ---------- Responsive : petits téléphones (≤380px) ---------- */
@media (max-width: 380px) {
  .table-area { padding: 8px 6px; gap: 6px; }

  .opponents-row { gap: 6px; }
  .opp { min-width: 92px; padding: 6px 7px 8px; gap: 4px; }
  .opp .opp-name { font-size: 12px; max-width: 96px; }
  .opp .opp-score { font-size: 10px; }
  .opp-hand { gap: 3px; }

  .card { width: 44px; height: 62px; border-radius: 8px; }
  .opp-hand .card, .my-hand .card { width: 46px; height: 65px; }
  .card-back::after { font-size: 18px; }
  .card-face .rank, .card-face .suit { font-size: 15px; }

  .center-pile { gap: 14px; }
  .draw-pile-stack { width: 48px; height: 68px; }

  .my-hand { gap: 6px; }

  .action-btn { font-size: 13px; min-width: 110px; min-height: 44px; padding: 10px 10px; }

  .top-bar { padding: 7px 10px; font-size: 12px; }

  .brand .logo { font-size: 42px; }
  .brand h1 { font-size: 32px; }
  .panel { padding: 18px; }
  .game-code-display .code { font-size: 34px; }
}

/* ---------- Responsive : très petits téléphones (≤340px) ---------- */
@media (max-width: 340px) {
  .opp { min-width: 84px; }
  .card { width: 40px; height: 57px; }
  .opp-hand .card, .my-hand .card { width: 42px; height: 60px; }
  .card-face .rank, .card-face .suit { font-size: 13px; }
  .action-btn { min-width: 100%; flex-basis: 100%; }
}

.hidden { display: none !important; }

/* ---------- Confettis & bandeau de victoire ---------- */
.confetti-canvas {
  position: fixed;
  inset: 0;
  z-index: 70;
  pointer-events: none;
}

.win-banner {
  background: linear-gradient(135deg, var(--sun-400), var(--dusk-500));
  color: var(--ink-900);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 14px;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 17px;
  line-height: 1.3;
  text-align: center;
  box-shadow: 0 6px 20px rgba(240,180,41,0.4);
  animation: winPop .5s cubic-bezier(.34,1.56,.64,1);
}

@keyframes winPop {
  0% { transform: scale(0.55); opacity: 0; }
  60% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
