/* Polices auto-hébergées (pas de dépendance réseau externe) */
@font-face {
  font-family: 'Caveat';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('fonts/caveat-700.ttf') format('truetype');
}
@font-face {
  font-family: 'Special Elite';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/special-elite.ttf') format('truetype');
}

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #060708;
  --paper: #efeee6;
  --accent: #57b791;
  --danger: #c8493f;
  --ui: 'Special Elite', 'Courier New', monospace;
  --hand: 'Caveat', cursive;
}

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--paper);
  font-family: var(--ui);
  overflow: hidden;
  user-select: none;
}

/* ---------- Scène 3D ---------- */
#scene3d {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
}
.vignette {
  position: fixed;
  inset: 0;
  z-index: 1;
  background: radial-gradient(95% 85% at 50% 45%, transparent 45%, rgba(0, 0, 0, 0.7) 100%);
  pointer-events: none;
}

/* grain de film animé + fines lignes de balayage, pour le côté pellicule */
.grain {
  position: fixed;
  inset: -60%;
  z-index: 2;
  pointer-events: none;
  opacity: 0.055;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grainShift 0.9s steps(6) infinite;
}
@keyframes grainShift {
  0% { transform: translate(0, 0); }
  20% { transform: translate(-4%, 3%); }
  40% { transform: translate(3%, -5%); }
  60% { transform: translate(-5%, -2%); }
  80% { transform: translate(4%, 4%); }
  100% { transform: translate(0, 0); }
}
.scanlines {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  opacity: 0.05;
  background: repeating-linear-gradient(to bottom, transparent 0 2px, rgba(0, 0, 0, 0.9) 2px 3px);
}
body.reduced-motion .grain { animation: none; }
body.reduced-motion .scanlines { display: none; }

/* ---------- Panneaux (lobby / attente) ---------- */
.panel {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  text-align: center;
  padding: 20px;
  background: rgba(3, 4, 5, 0.55);
  backdrop-filter: blur(2px);
}
.logo {
  font-size: clamp(64px, 12vw, 130px);
  letter-spacing: 8px;
  text-shadow: 0 0 30px rgba(87, 183, 145, 0.35), 0 4px 0 #000;
}
.logo span { color: var(--accent); }
.tagline { opacity: 0.75; margin-bottom: 10px; }

input {
  font-family: var(--ui);
  font-size: 20px;
  padding: 12px 16px;
  background: #141518;
  border: 2px solid #34373d;
  border-radius: 8px;
  color: var(--paper);
  text-align: center;
  outline: none;
  width: min(300px, 80vw);
}
input:focus { border-color: var(--accent); }
#codeInput { width: 130px; text-transform: uppercase; letter-spacing: 6px; }

.lobby-actions { display: flex; flex-direction: column; gap: 14px; align-items: center; }
.join-row { display: flex; gap: 10px; }

.btn {
  font-family: var(--ui);
  font-size: 18px;
  padding: 12px 26px;
  background: #1d1f23;
  color: var(--paper);
  border: 2px solid #3a3d44;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.08s, background 0.15s, border-color 0.15s;
}
.btn:hover { background: #26292f; border-color: var(--accent); }
.btn:active { transform: scale(0.96); }
.btn.primary { background: var(--accent); color: #0c1310; border-color: var(--accent); }
.btn.primary:hover { background: #6ccaa4; }
.btn:disabled { opacity: 0.35; cursor: not-allowed; border-color: #3a3d44; }
.error { color: var(--danger); min-height: 24px; }

.waiting-label { opacity: 0.6; letter-spacing: 3px; }
.room-code {
  font-size: clamp(60px, 12vw, 120px);
  letter-spacing: 20px;
  padding-left: 20px;
  color: var(--accent);
  text-shadow: 0 0 24px rgba(87, 183, 145, 0.4);
}
.waiting-sub { opacity: 0.8; font-size: 20px; }
.dots::after { content: ''; animation: dots 1.5s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }

/* ---------- Compte Discord ---------- */
.btn.discord {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: #5865f2;
  border-color: #4752c4;
  color: #fff;
  font-size: 1.05rem;
  padding: 12px 22px;
  text-decoration: none;
}
.btn.discord:hover { background: #4752c4; }
.auth-note {
  margin-top: 14px;
  color: #8b877a;
  font-size: 0.85rem;
  text-align: center;
  line-height: 1.5;
}
.pfp {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid #4a4e57;
  object-fit: cover;
  background: #17181c;
}
.pfp.small { width: 22px; height: 22px; border-width: 1px; vertical-align: middle; margin-right: 6px; }
.profile-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  justify-content: center;
}
.me-username { font-size: 1.1rem; color: #e8e4d6; }
.btn.tiny { padding: 5px 10px; font-size: 0.75rem; opacity: 0.8; }
.home-cols {
  display: flex;
  gap: 14px;
  margin-top: 18px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 640px;
}
.home-box {
  background: rgba(10, 11, 13, 0.72);
  border: 1px solid #2c2e33;
  border-radius: 10px;
  padding: 12px 16px;
  min-width: 230px;
  flex: 1;
}
.home-box h3 { margin: 0 0 8px; font-size: 0.9rem; color: #b8b4a6; }
.stats-list { list-style: none; margin: 0; padding: 0; font-size: 0.85rem; }
.stats-list li { display: flex; justify-content: space-between; gap: 12px; padding: 2px 0; color: #8b877a; }
.stats-list li b { color: #e8e4d6; }
.stats-list li.hot b { color: #7fd6a8; }
.board-list { list-style: none; margin: 0; padding: 0; font-size: 0.85rem; counter-reset: rank; }
.board-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
  color: #b8b4a6;
  counter-increment: rank;
}
.board-list li::before { content: counter(rank) '.'; color: #6b675c; min-width: 18px; }
.board-list li:first-child::before { content: '👑'; }
.board-list .board-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-list .board-wins { color: #7fd6a8; }
.board-list li.empty { color: #6b675c; font-style: italic; }
.board-list li.empty::before { content: ''; }

/* ---------- HUD ---------- */
.hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
.hud button { pointer-events: auto; }

.hud-top {
  position: absolute;
  top: 2.5vh;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.opp-list {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 92vw;
}
.opp-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(8, 9, 11, 0.65);
  padding: 5px 16px;
  border-radius: 22px;
  border: 1px solid #2c2e33;
  font-size: 15px;
}
.opp-chip.turn { border-color: var(--accent); box-shadow: 0 0 14px rgba(87, 183, 145, 0.3); }
.opp-chip .sum { opacity: 0.85; letter-spacing: 1px; }
.opp-chip .status { font-size: 12px; padding: 1px 8px; border-radius: 14px; background: #26292f; }
.opp-chip .status:empty { display: none; }
.opp-chip .status.passed { background: #45231f; color: #f0a49d; }
.opp-chip .status.ready { background: var(--accent); color: #0c1310; }
.opp-chip .status.away { background: #2a2f3a; color: #9db4d4; }

.lobby-players {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 20px;
}
.lobby-players li::before { content: '👤 '; }
.lobby-players li.host::before { content: '👑 '; }
.waiting-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.pname { font-size: 20px; text-shadow: 0 2px 4px #000; }
.wins { color: var(--accent); font-size: 16px; }
.badge {
  font-size: 14px;
  padding: 2px 10px;
  border-radius: 20px;
  background: #26292f;
  border: 1px solid #3a3d44;
}
.badge:empty { display: none; }
.badge.turn { background: var(--accent); color: #0c1310; border-color: var(--accent); }
.badge.stood { background: #45231f; color: #f0a49d; border-color: #6e3129; }
.opp-score { font-size: 18px; opacity: 0.85; text-shadow: 0 2px 5px #000; letter-spacing: 2px; }

.turn-banner {
  position: absolute;
  top: 12vh;
  left: 50%;
  transform: translateX(-50%);
  font-size: clamp(17px, 2.2vw, 24px);
  padding: 8px 24px;
  background: rgba(8, 9, 11, 0.7);
  border-radius: 10px;
  border: 1px solid #3a3d44;
  text-shadow: 0 2px 4px #000;
  white-space: nowrap;
}
.turn-banner.me {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 18px rgba(87, 183, 145, 0.3);
}

.turn-timer {
  position: absolute;
  top: 18vh;
  left: 50%;
  transform: translateX(-50%);
  font-size: 18px;
  padding: 4px 16px;
  background: rgba(8, 9, 11, 0.75);
  border: 1px solid #3a3d44;
  border-radius: 18px;
  letter-spacing: 1px;
}
.turn-timer.urgent {
  color: #ff4437;
  border-color: var(--danger);
  animation: dangerPulse 0.6s infinite;
}

/* Stats de fin de partie */
.stats-box {
  position: absolute;
  left: 50%;
  bottom: 16vh;
  transform: translateX(-50%);
  background: rgba(10, 11, 14, 0.92);
  border: 1px solid #33363c;
  border-radius: 14px;
  padding: 16px 26px;
  animation: nextIn 0.4s ease-out;
}
.stats-box .stats-title { text-align: center; margin-bottom: 10px; color: #d8c98a; }
.stats-box table { border-collapse: collapse; font-size: 15px; }
.stats-box th, .stats-box td { padding: 4px 14px; text-align: center; }
.stats-box th { color: var(--accent); }
.stats-box td:first-child { text-align: left; opacity: 0.8; }
.stats-box tr + tr td { border-top: 1px solid #22242a; }

/* Boutons système */
.sys-buttons {
  position: fixed;
  top: 2.5vh;
  right: 2vw;
  z-index: 40;
  display: flex;
  gap: 8px;
}
.sys-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid #3a3d44;
  background: rgba(14, 16, 19, 0.85);
  color: var(--paper);
  font-family: var(--ui);
  font-size: 17px;
  cursor: pointer;
}
.sys-btn:hover { border-color: var(--accent); }
.sys-btn.off { opacity: 0.4; }

/* Panneau d'aide */
.help-panel {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(4, 5, 6, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
}
.help-box {
  position: relative;
  background: #121316;
  border: 2px solid #33363c;
  border-radius: 16px;
  padding: 30px 36px;
  max-width: min(720px, 92vw);
  max-height: 84vh;
  overflow-y: auto;
}
.help-box h2 { margin: 12px 0 10px; font-size: 24px; color: var(--accent); }
.help-box h2:first-of-type { margin-top: 0; }
.help-rules { list-style: none; display: flex; flex-direction: column; gap: 8px; font-size: 15px; opacity: 0.95; }
.help-badges { list-style: none; display: flex; flex-direction: column; gap: 7px; font-size: 14px; }
.help-badges li { padding-left: 8px; border-left: 3px solid #3a3d44; }
.help-badges li.sacre { border-color: #c9a338; }
.help-badges li.jugement { border-color: #7d2f8f; }
.help-close { position: sticky; top: 0; float: right; font-size: 14px; padding: 6px 14px; }

.shock-level {
  font-size: 14px;
  color: #ff9e93;
  letter-spacing: 1px;
}
.badge-count { font-size: 14px; color: #d8c98a; letter-spacing: 1px; }
.shock-level.danger {
  color: #ff4437;
  animation: dangerPulse 0.8s infinite;
}
@keyframes dangerPulse {
  50% { text-shadow: 0 0 12px #ff4437; }
}

/* Flash d'électrocution plein écran */
.shock-flash {
  position: fixed;
  inset: 0;
  z-index: 90;
  pointer-events: none;
  opacity: 0;
  background:
    radial-gradient(100% 100% at 50% 50%, rgba(190, 230, 255, 0.35) 0%, rgba(255, 40, 20, 0.45) 100%);
}
.shock-flash.zap {
  animation: zapFlash 1.1s steps(2, jump-none);
}
@keyframes zapFlash {
  0% { opacity: 1; }
  20% { opacity: 0.2; }
  35% { opacity: 0.9; }
  55% { opacity: 0.15; }
  70% { opacity: 0.6; }
  100% { opacity: 0; }
}

.hud-bottom {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 0 3vw 3vh;
  gap: 16px;
}
.score-big {
  font-size: clamp(44px, 7vw, 84px);
  line-height: 1;
  text-shadow: 0 4px 0 #000, 0 0 30px rgba(0, 0, 0, 0.9);
  letter-spacing: 2px;
}
.score-big.busted {
  color: #ff4437;
  text-shadow: 0 4px 0 #000, 0 0 24px rgba(255, 68, 55, 0.6);
}
.score-big.pulse { animation: scorePulse 0.35s ease-out; }
@keyframes scorePulse {
  30% { transform: scale(1.14); }
}
.score-big.target-change { animation: targetFlash 0.9s ease-out; }
@keyframes targetFlash {
  25% { color: #f0cd6a; text-shadow: 0 4px 0 #000, 0 0 34px rgba(240, 205, 106, 0.9); transform: scale(1.18); }
}
.me-tag {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 8px;
}
.actions { display: flex; gap: 14px; }
.btn.action {
  font-size: clamp(18px, 2vw, 24px);
  padding: 16px 36px;
  background: rgba(14, 16, 19, 0.85);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
}
.btn.action:hover:not(:disabled) { border-color: var(--accent); background: #1b1e23; }
.btn.action.ghost { background: rgba(10, 11, 13, 0.6); border-color: #2e3136; }
.btn.action.next {
  background: var(--accent);
  color: #0c1310;
  border-color: var(--accent);
  animation: nextIn 0.35s ease-out;
}
.btn.action.next:hover:not(:disabled) { background: #6ccaa4; }
@keyframes nextIn {
  from { transform: translateY(16px); opacity: 0; }
}

/* verdict de manche dans le bandeau */
.turn-banner.win {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 22px rgba(87, 183, 145, 0.35);
}
.turn-banner.lose {
  border-color: var(--danger);
  color: #ff9e93;
  box-shadow: 0 0 22px rgba(200, 73, 63, 0.35);
}
.turn-banner.gold {
  border-color: #c9a338;
  color: #f0cd6a;
  box-shadow: 0 0 22px rgba(201, 163, 56, 0.4);
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  background: #1d1f23;
  border: 1px solid var(--danger);
  color: #f0b3ad;
  padding: 12px 26px;
  border-radius: 10px;
  font-size: 17px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
}
.toast.ok { border-color: var(--accent); color: #a9e6cd; }
.toast.gold { border-color: #c9a338; color: #f0cd6a; box-shadow: 0 0 24px rgba(201, 163, 56, 0.35); }
.toast.info { border-color: #2f6b7d; color: #8fd8ea; }

[hidden] { display: none !important; }

/* ---------- Mobile ---------- */
@media (max-width: 640px) {
  .hud-bottom { flex-direction: column; align-items: center; gap: 8px; }
  .score-big { font-size: 40px; }
  .btn.action { font-size: 17px; padding: 12px 24px; }
  .turn-banner { top: 9vh; }
}
