/* ============================================================
   UNO PWA — Mobile-First CSS
   Palette : fond sombre, cartes vives, style arcade premium
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@700;800;900&family=Nunito+Sans:wght@400;600&display=swap');

/* ---- Variables ---- */
:root {
  --bg:       #0d0f1a;
  --surface:  #181b2e;
  --surface2: #212540;
  --border:   rgba(255,255,255,0.08);
  --text:     #f0f0f8;
  --muted:    #8888aa;

  --red:    #e8253b;
  --yellow: #f5c518;
  --green:  #29c75f;
  --blue:   #2196f3;
  --wild:   #c44dff;

  --card-w: 68px;
  --card-h: 108px;
  --card-r: 12px;
  --shadow: 0 8px 32px rgba(0,0,0,0.5);

  --anim-fast: 180ms;
  --anim-mid:  350ms;
  --anim-slow: 600ms;
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Nunito Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* ---- Screens ---- */
.screen {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: env(safe-area-inset-top, 20px) 20px env(safe-area-inset-bottom, 20px);
  opacity: 0; pointer-events: none;
  transform: translateY(20px);
  transition: opacity var(--anim-mid) ease, transform var(--anim-mid) ease;
}
.screen.active { opacity: 1; pointer-events: all; transform: translateY(0); }

/* ---- Logo ---- */
.logo {
  font-family: 'Nunito', sans-serif;
  font-weight: 900;
  font-size: clamp(72px, 22vw, 140px);
  line-height: 1;
  letter-spacing: -2px;
  background: linear-gradient(135deg, #e8253b 0%, #f5c518 35%, #29c75f 65%, #2196f3 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 0 40px rgba(232,37,59,0.4));
  animation: logoPulse 3s ease-in-out infinite;
}
@keyframes logoPulse {
  0%,100% { filter: drop-shadow(0 0 40px rgba(232,37,59,0.4)); }
  50%      { filter: drop-shadow(0 0 80px rgba(245,197,24,0.5)); }
}

.tagline {
  font-size: 14px; letter-spacing: 3px; text-transform: uppercase;
  color: var(--muted); margin-top: -8px; margin-bottom: 48px;
}

/* ---- Buttons ---- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; max-width: 320px;
  padding: 16px 24px;
  border: none; border-radius: 16px;
  font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 18px;
  cursor: pointer; transition: transform 120ms, box-shadow 120ms;
  text-decoration: none;
}
.btn:active { transform: scale(0.96); }

.btn-primary {
  background: var(--red);
  color: #fff;
  box-shadow: 0 4px 20px rgba(232,37,59,0.5);
}
.btn-primary:active { box-shadow: 0 2px 10px rgba(232,37,59,0.4); }

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-wild {
  background: linear-gradient(135deg, var(--red), var(--wild));
  color: #fff;
  box-shadow: 0 4px 20px rgba(196,77,255,0.4);
}

.btn-sm {
  width: auto; padding: 10px 20px;
  font-size: 15px; border-radius: 12px;
}

.btn-row { display: flex; gap: 12px; width: 100%; max-width: 320px; }
.btn-row .btn { max-width: none; flex: 1; }

/* ---- Inputs ---- */
.input-group { width: 100%; max-width: 320px; margin-bottom: 12px; }
.input-label { font-size: 12px; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; display: block; }
.input {
  width: 100%; padding: 14px 16px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 12px; color: var(--text);
  font-family: 'Nunito', sans-serif; font-weight: 700; font-size: 20px;
  text-align: center; letter-spacing: 4px; text-transform: uppercase;
  outline: none; transition: border-color 200ms;
}
.input:focus { border-color: var(--blue); }
.input::placeholder { color: var(--muted); font-size: 14px; letter-spacing: 2px; }

/* ---- Card gap / spacing ---- */
.gap-8  { gap: 8px; }
.gap-16 { gap: 16px; }
.mt-8   { margin-top: 8px; }
.mt-16  { margin-top: 16px; }
.mt-24  { margin-top: 24px; }
.w-full { width: 100%; }

/* ---- Toast ---- */
.toast-area { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); z-index: 999; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  background: var(--surface2); border: 1px solid var(--border);
  padding: 10px 20px; border-radius: 99px;
  font-family: 'Nunito', sans-serif; font-weight: 700; font-size: 14px;
  animation: toastIn var(--anim-fast) ease, toastOut 300ms ease 2.5s forwards;
  white-space: nowrap;
}
@keyframes toastIn  { from { opacity: 0; transform: translateY(-12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { to   { opacity: 0; transform: translateY(-12px); } }

/* ============================================================
   LOBBY SCREEN
   ============================================================ */
.lobby-room-code {
  font-family: 'Nunito', sans-serif; font-weight: 900;
  font-size: clamp(40px, 14vw, 72px);
  letter-spacing: 10px;
  background: linear-gradient(90deg, var(--blue), var(--wild));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.lobby-title { font-size: 12px; letter-spacing: 2px; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }

.players-list {
  width: 100%; max-width: 360px;
  display: flex; flex-direction: column; gap: 8px;
  margin: 20px 0;
}
.player-chip {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 14px; padding: 12px 16px;
  animation: slideIn var(--anim-mid) ease;
}
@keyframes slideIn { from { opacity: 0; transform: translateX(-16px); } }
.player-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Nunito', sans-serif; font-weight: 900; font-size: 16px;
  flex-shrink: 0;
}
.player-name { font-weight: 700; flex: 1; }
.player-host  { font-size: 11px; color: var(--yellow); text-transform: uppercase; letter-spacing: 1px; }

/* ============================================================
   GAME SCREEN
   ============================================================ */
#screen-game {
  padding: 0;
  background: radial-gradient(ellipse at 50% 30%, #1a2540 0%, #0d0f1a 70%);
}

.game-wrapper {
  position: relative; width: 100%; height: 100dvh;
  display: flex; flex-direction: column;
}

/* ---- Opponents (top) ---- */
.opponents-row {
  display: flex; align-items: flex-start; justify-content: center;
  gap: 12px; padding: 12px 12px 0;
  flex-wrap: nowrap; overflow-x: auto;
  scrollbar-width: none;
}
.opponent-card {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  min-width: 60px; flex-shrink: 0;
}
.opponent-name {
  font-size: 11px; font-weight: 700; color: var(--muted);
  text-align: center; max-width: 64px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.opponent-hand {
  display: flex; position: relative; height: 42px;
}
.opponent-hand .mini-card {
  position: absolute; width: 28px; height: 42px;
  border-radius: 5px; border: 1.5px solid rgba(255,255,255,0.2);
  background: linear-gradient(135deg, #1e2244, #2a2f55);
  transition: transform var(--anim-fast);
}
.opponent-card.active-player .opponent-name { color: var(--yellow); }
.opponent-card.active-player .mini-card { border-color: var(--yellow); }
.turn-indicator {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--yellow);
  animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.6); opacity: 0.6; } }

/* ---- Board (center) ---- */
.board-center {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px;
  position: relative;
}

.board-cards {
  display: flex; align-items: center; gap: 20px;
}

/* ---- UNO Card ---- */
.uno-card {
  width: var(--card-w); height: var(--card-h);
  border-radius: var(--card-r);
  display: flex; align-items: center; justify-content: center;
  position: relative; cursor: pointer;
  transform-style: preserve-3d;
  transition: transform var(--anim-fast) ease, box-shadow var(--anim-fast) ease;
  will-change: transform;
  flex-shrink: 0;
}
.uno-card:active { transform: scale(0.94); }

/* Card face structure */
.card-face {
  position: absolute; inset: 0;
  border-radius: var(--card-r);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.card-inner {
  position: absolute; inset: 6px;
  border-radius: 8px;
  border: 2px solid rgba(255,255,255,0.6);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.card-value {
  font-family: 'Nunito', sans-serif;
  font-weight: 900;
  font-size: 28px;
  color: #fff;
  text-shadow: 0 2px 6px rgba(0,0,0,0.4);
  transform: rotate(-15deg);
  line-height: 1;
}
.card-corner {
  position: absolute;
  font-family: 'Nunito', sans-serif; font-weight: 900;
  font-size: 13px; color: #fff; line-height: 1;
}
.card-corner.tl { top: 5px; left: 7px; text-align: left; }
.card-corner.br { bottom: 5px; right: 7px; transform: rotate(180deg); }

/* Colors */
.card-red    { background: var(--red);    box-shadow: 0 6px 24px rgba(232,37,59,0.5); }
.card-yellow { background: var(--yellow); box-shadow: 0 6px 24px rgba(245,197,24,0.5); }
.card-green  { background: var(--green);  box-shadow: 0 6px 24px rgba(41,199,95,0.5); }
.card-blue   { background: var(--blue);   box-shadow: 0 6px 24px rgba(33,150,243,0.5); }
.card-wild   {
  background: conic-gradient(var(--red) 0deg 90deg, var(--yellow) 90deg 180deg, var(--green) 180deg 270deg, var(--blue) 270deg 360deg);
  box-shadow: 0 6px 24px rgba(196,77,255,0.5);
}
.card-red    .card-inner { background: rgba(0,0,0,0.15); }
.card-yellow .card-inner { background: rgba(0,0,0,0.12); }
.card-yellow .card-value,
.card-yellow .card-corner { color: rgba(0,0,0,0.8); }
.card-green  .card-inner { background: rgba(0,0,0,0.15); }
.card-blue   .card-inner { background: rgba(0,0,0,0.15); }
.card-wild   .card-inner { background: rgba(0,0,0,0.2); }

/* Draw pile (card back) */
.card-back {
  background: #1a1f3d;
  border: 3px solid rgba(255,255,255,0.15);
  box-shadow: 0 6px 24px rgba(0,0,0,0.5);
  cursor: pointer;
}
.card-back .card-inner { background: rgba(255,255,255,0.04); border-color: rgba(255,255,255,0.2); }
.card-back .card-value { font-size: 22px; background: linear-gradient(135deg, var(--red), var(--yellow), var(--green), var(--blue)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.card-back:hover { transform: scale(1.05) rotate(-2deg); }
.card-back:active { transform: scale(0.96); }

/* Discard pile */
.discard-pile { position: relative; }
.discard-pile .card-played {
  position: absolute;
  animation: cardLand var(--anim-mid) cubic-bezier(0.22, 1, 0.36, 1) both;
}
@keyframes cardLand {
  from { transform: translateY(-40px) scale(1.1) rotate(var(--fly-rot, -8deg)); opacity: 0; }
  to   { transform: translateY(0) scale(1) rotate(var(--rest-rot, 4deg)); opacity: 1; }
}

/* Playable highlight */
.uno-card.playable { cursor: pointer; }
.uno-card.playable:hover {
  transform: translateY(-12px) scale(1.05);
  z-index: 10;
}
.uno-card.playable::after {
  content: '';
  position: absolute; inset: -3px;
  border-radius: calc(var(--card-r) + 3px);
  border: 3px solid rgba(255,255,255,0.7);
  animation: glowBorder 1.2s ease-in-out infinite;
  pointer-events: none;
}
@keyframes glowBorder {
  0%,100% { border-color: rgba(255,255,255,0.5); box-shadow: 0 0 0 rgba(255,255,255,0); }
  50%     { border-color: rgba(255,255,255,0.9); box-shadow: 0 0 12px rgba(255,255,255,0.3); }
}

/* ---- Player hand (bottom) ---- */
.player-area {
  flex-shrink: 0;
  display: flex; flex-direction: column; align-items: center;
  padding: 8px 0 max(16px, env(safe-area-inset-bottom));
}

.hand-scroll {
  display: flex; align-items: flex-end;
  gap: 0;
  overflow-x: auto; overflow-y: visible;
  padding: 16px 24px 8px;
  scrollbar-width: none;
  max-width: 100vw;
}
.hand-scroll::-webkit-scrollbar { display: none; }

/* Fan layout */
.hand-card {
  transition: transform var(--anim-fast) ease, z-index 0ms;
  margin-left: -18px;
  flex-shrink: 0;
}
.hand-card:first-child { margin-left: 0; }
.hand-card:hover { z-index: 10; }

/* unoPulse keyframe (partagé) */
@keyframes unoPulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.08); } }

/* ---- Game status bar ---- */
.status-bar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  z-index: 10;
}
.direction-badge {
  font-size: 22px;
  transition: transform var(--anim-mid) ease;
}
.direction-badge.reversed { transform: scaleX(-1); }
.color-indicator {
  width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.5);
  transition: background var(--anim-fast);
}

/* ---- Color picker modal ---- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.75); backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity var(--anim-fast);
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.color-picker {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 28px;
  text-align: center;
  animation: popIn var(--anim-mid) cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes popIn { from { transform: scale(0.7); opacity: 0; } }
.color-picker h3 {
  font-family: 'Nunito', sans-serif; font-weight: 800;
  font-size: 18px; margin-bottom: 20px;
}
.color-options { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.color-btn {
  width: 72px; height: 72px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.3);
  cursor: pointer; transition: transform 120ms, border-color 120ms;
}
.color-btn:hover  { transform: scale(1.12); border-color: #fff; }
.color-btn:active { transform: scale(0.95); }
.color-btn.red    { background: var(--red); }
.color-btn.yellow { background: var(--yellow); }
.color-btn.green  { background: var(--green); }
.color-btn.blue   { background: var(--blue); }

/* ---- Draw penalty message ---- */
.draw-penalty {
  font-family: 'Nunito', sans-serif; font-weight: 800;
  font-size: 14px; color: var(--yellow);
  background: rgba(245,197,24,0.15); border: 1px solid rgba(245,197,24,0.3);
  padding: 6px 16px; border-radius: 99px;
  animation: fadeInPop var(--anim-mid) ease;
}
@keyframes fadeInPop { from { opacity: 0; transform: scale(0.8); } }

/* ---- Results screen ---- */
.result-emoji { font-size: 80px; animation: bounceIn var(--anim-slow) cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes bounceIn { from { transform: scale(0); opacity: 0; } }
.result-title {
  font-family: 'Nunito', sans-serif; font-weight: 900;
  font-size: 36px; margin: 16px 0 4px;
}
.result-subtitle { color: var(--muted); font-size: 16px; margin-bottom: 32px; }

/* ---- Menu btn (top-right) ---- */
.menu-btn {
  background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: 22px; padding: 4px;
  transition: color 150ms;
}
.menu-btn:hover { color: var(--text); }

/* ---- Turn banner (remplace l'overlay sombre) ---- */
.turn-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(30, 35, 70, 0.7);
  border: 1px solid rgba(255,255,255,0.1);
  backdrop-filter: blur(4px);
  padding: 6px 16px;
  border-radius: 99px;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 13px;
  color: var(--muted);
  pointer-events: none;
  transition: opacity var(--anim-mid);
}
.turn-banner.hidden { opacity: 0; }
.turn-banner-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--yellow);
  animation: pulse 1s ease-in-out infinite;
}

/* ---- Boutons UNO + Contre-UNO sur le tapis ---- */
.board-action-btns {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  min-height: 44px;
}

.board-uno-btn {
  font-family: 'Nunito', sans-serif; font-weight: 900;
  font-size: 17px; letter-spacing: 1px;
  background: var(--red);
  color: #fff; border: none;
  padding: 10px 26px; border-radius: 99px;
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(232,37,59,0.55);
  transition: transform 100ms, box-shadow 100ms, opacity 200ms;
}
.board-uno-btn:active { transform: scale(0.93); }
.board-uno-btn.hidden { display: none; }
.board-uno-btn.pulse { animation: unoPulse 0.7s ease-in-out infinite; }

.board-counter-btn {
  font-family: 'Nunito', sans-serif; font-weight: 900;
  font-size: 15px; letter-spacing: 1px;
  background: linear-gradient(135deg, var(--wild), #5b30cc);
  color: #fff; border: none;
  padding: 10px 22px; border-radius: 99px;
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(196,77,255,0.45);
  transition: transform 100ms, box-shadow 100ms;
}
.board-counter-btn:active { transform: scale(0.93); }
.board-counter-btn.hidden { display: none; }

/* ---- Card fly animation ---- */
@keyframes flyToCenter {
  0%   { transform: translateY(0) scale(1) rotate(0deg); opacity: 1; }
  100% { transform: translateY(-40vh) scale(0.6) rotate(10deg); opacity: 0; }
}
.card-flying { animation: flyToCenter var(--anim-mid) ease forwards; }

/* ---- Responsive ---- */
@media (min-width: 420px) {
  :root { --card-w: 76px; --card-h: 120px; }
  .card-value { font-size: 32px; }
}
@media (min-width: 600px) {
  :root { --card-w: 84px; --card-h: 132px; }
  .hand-card { margin-left: -14px; }
}
