:root {
  --bg: #1b1530;
  --panel: #271f45;
  --line: #3d3266;
  --text: #f3eefc;
  --muted: #a99fc7;
  --accent: #ffb347;
  --accent-text: #2a1a00;
  --ok: #4ade80;

  /* Largeur d'une carte : 5 cartes doivent tenir de front sur un téléphone. */
  --cw: min(16.5vw, 76px, 10.5dvh);
  --ch: calc(var(--cw) * 1.4);
  --gap: calc(var(--cw) * 0.1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}

.screen {
  max-width: 520px;
  min-height: 100dvh;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

h1 { margin: 0; font-size: 26px; line-height: 1.15; }
h2 { margin: 0 0 10px; font-size: 18px; }
p { margin: 0; }
.muted { color: var(--muted); font-size: 14px; }

/* ---------- Accueil et salle d'attente ---------- */

.hero { text-align: center; padding: 12px 0 4px; }
.logo { font-size: 56px; line-height: 1; margin-bottom: 6px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.panel h2 { margin: 0; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { color: var(--muted); font-size: 14px; }

input, select {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #150f27;
  color: var(--text);
  font: inherit;
  user-select: text;
  -webkit-user-select: text;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.join { display: flex; gap: 10px; }
.join input { flex: 1; min-width: 0; text-align: center; font-size: 22px; letter-spacing: 6px; }

.btn {
  padding: 13px 18px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #342a5c;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.small { padding: 6px 12px; font-size: 14px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font: inherit;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }

.install { text-align: center; padding: 8px; }

#lobby { align-items: stretch; text-align: center; justify-content: center; }
.code { font-size: 72px; font-weight: 800; letter-spacing: 10px; color: var(--accent); }
.players { list-style: none; margin: 8px 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.players li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-weight: 600;
}

.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: #6b6190; }
.dot.on { background: var(--ok); }

/* ---------- Table de jeu ---------- */

.screen.game { height: 100dvh; padding-left: 8px; padding-right: 8px; gap: 6px; }
.bar { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 14px; }
#table { flex: 1; min-height: 0; display: flex; flex-direction: column; justify-content: space-between; gap: 6px; position: relative; }

.row { display: flex; justify-content: center; align-items: flex-start; gap: var(--gap); }

.card {
  position: relative;
  flex: none;
  width: var(--cw);
  height: var(--ch);
  border-radius: calc(var(--cw) * 0.14);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cw) * 0.5);
  font-weight: 800;
  color: #fff;
  border: 2px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.45);
  transition: transform 0.12s;
}
.card.back { background: #12101f; border-color: #4a3a8a; font-size: calc(var(--cw) * 0.42); }

/* Carte face visible : bandeau avec le chiffre, puis la photo. */
.card.face {
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  overflow: hidden;
  background: #12101f;
  border-color: var(--tone);
  color: var(--tone);
}
.card.low { --tone: #ffd23f; --band: #3a2400; }
.card.mid { --tone: #3fd2ff; --band: #06303f; }
.card.high { --tone: #ff5fa2; --band: #3a0a27; }
.card.wild { --tone: #7dff6a; --band: #0b3a22; }
.num {
  flex: none;
  height: 30%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--band);
  font-family: 'Bungee', system-ui, sans-serif;
  font-size: calc(var(--cw) * 0.3);
  font-weight: 400;
  line-height: 1;
}
.pic { flex: 1; background-size: cover; background-position: center; }
.card.slot {
  background: transparent;
  border: 2px dashed var(--line);
  box-shadow: none;
  color: var(--line);
}

.card.sel { transform: translateY(calc(var(--cw) * -0.16)); outline: 3px solid #fff; outline-offset: 1px; }
.card.target, .fan.target > .card:last-child { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent); }
.card.pulse { animation: pulse 0.5s ease-out; }
@keyframes pulse {
  from { transform: scale(1.18); }
  to { transform: scale(1); }
}

.badge {
  position: absolute;
  right: 2px;
  bottom: 2px;
  min-width: 22px;
  padding: 1px 5px;
  border-radius: 999px;
  background: #0e0a1c;
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}
.mark { position: absolute; top: 2px; right: 4px; font-size: calc(var(--cw) * 0.2); color: #7dff6a; }

/* Défausse : les cartes du dessous dépassent en haut, la dernière est entière. */
.fan { display: flex; flex-direction: column; flex: none; }
.fan > .card + .card { margin-top: calc(var(--peek) - var(--ch)); }
.mine .fan { min-height: calc(var(--ch) + 88px); }

.opps { display: flex; flex-direction: column; gap: 6px; }
.opp { padding: 6px 8px 10px; border-radius: 14px; border: 1px solid transparent; }
.opp.active { border-color: var(--accent); background: rgba(255, 179, 71, 0.08); }
.opp-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.opp-name { font-weight: 700; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini { --cw: min(10.5vw, 48px, 6.5dvh); }
.mini .fan { min-height: calc(var(--ch) + 39px); }
.mini .badge { font-size: 11px; min-width: 20px; }
.opps.many .mini { --cw: min(8vw, 36px, 4.5dvh); }

.centre { padding: 10px 0; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; }

.status {
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}
.status.turn { color: var(--accent); font-weight: 700; }

.mine { display: flex; flex-direction: column; gap: 10px; }
.hand { padding-top: calc(var(--cw) * 0.16); }

/* ---------- Fenêtres et messages ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(10, 6, 22, 0.78);
}
.dialog {
  width: 100%;
  max-width: 340px;
  padding: 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
}
.dialog h2 { margin: 0; font-size: 22px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 20;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 12px;
  background: #0e0a1c;
  border: 1px solid var(--line);
  text-align: center;
}

.banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30;
  padding: calc(6px + env(safe-area-inset-top)) 12px 6px;
  background: #b3261e;
  color: #fff;
  font-size: 14px;
  text-align: center;
}
