/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --felt: #1a6b2f;
  --felt-dark: #124d22;
  --felt-light: #228b40;
  --card-w: 62px;
  --card-h: 90px;
  --gold: #c9a227;
  --chat-bg: #1a1a2e;
  --chat-border: #2d2d4e;
  --red: #e74c3c;
  --blue: #2980b9;
  --green: #27ae60;
  --yellow: #f39c12;
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--felt-dark);
  color: #fff;
  min-height: 100vh;
}

.hidden { display: none !important; }

/* ── Buttons ── */
.btn-primary {
  background: var(--gold);
  color: #1a1a1a;
  border: none;
  padding: 10px 22px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  transition: opacity .15s;
}
.btn-primary:hover { opacity: .88; }

.btn-secondary {
  background: #444;
  color: #fff;
  border: 1px solid #666;
  padding: 8px 18px;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
}
.btn-secondary:hover { background: #555; }

.btn-small {
  background: transparent;
  border: 1px solid rgba(255,255,255,.3);
  color: #fff;
  padding: 5px 12px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
}
.btn-small:hover { background: rgba(255,255,255,.1); }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: #fff;
  padding: 10px 22px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0,0,0,.4);
}

/* ══════════════════════════════
   LOBBY
══════════════════════════════ */
.lobby-page {
  max-width: 700px;
  margin: 0 auto;
  padding: 40px 20px;
}

.lobby-header {
  text-align: center;
  margin-bottom: 36px;
  position: relative;
}
.lobby-header h1 { font-size: 42px; color: var(--gold); letter-spacing: 1px; }
.subtitle { color: rgba(255,255,255,.65); margin-top: 6px; }
.admin-link {
  position: absolute;
  top: 0; right: 0;
  color: rgba(255,255,255,.45);
  text-decoration: none;
  font-size: 13px;
}
.admin-link:hover { color: rgba(255,255,255,.8); }

.pseudo-section {
  display: flex;
  justify-content: center;
  margin-bottom: 36px;
}
.pseudo-section input {
  width: 280px;
  padding: 12px 16px;
  border-radius: 8px;
  border: 2px solid rgba(255,255,255,.2);
  background: rgba(0,0,0,.3);
  color: #fff;
  font-size: 16px;
  text-align: center;
  outline: none;
}
.pseudo-section input:focus { border-color: var(--gold); }

.rooms-section h2 { color: var(--gold); margin-bottom: 16px; font-size: 18px; }

.room-card {
  background: rgba(0,0,0,.35);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 10px;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  transition: border-color .15s;
}
.room-card:hover { border-color: rgba(201,162,39,.5); }
.room-info .room-title { font-size: 16px; font-weight: 600; }
.room-info .room-meta { font-size: 13px; color: rgba(255,255,255,.55); margin-top: 3px; }
.room-status { font-size: 12px; padding: 3px 10px; border-radius: 12px; font-weight: 600; }
.status-waiting { background: rgba(39,174,96,.25); color: #2ecc71; }
.status-playing { background: rgba(231,76,60,.25); color: #e74c3c; }

.empty-state { text-align: center; color: rgba(255,255,255,.4); padding: 40px; }
.loading { color: rgba(255,255,255,.4); text-align: center; padding: 20px; }

.game-badge-lobby {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .5px;
  text-transform: uppercase;
  margin-left: 8px;
}
.badge-poker { background: #2c2c3e; color: #a29bfe; }
.badge-rami  { background: #1e3a2f; color: #55efc4; }
.badge-belote{ background: #3a1e1e; color: #fab1a0; }
.badge-uno   { background: #3a2a1e; color: #fdcb6e; }

/* ══════════════════════════════
   GAME
══════════════════════════════ */
.game-body { overflow: hidden; height: 100vh; display: flex; flex-direction: column; }

.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.75);
  display: flex; align-items: center; justify-content: center;
  z-index: 500;
}
.modal-box {
  background: #1a2a1a;
  border: 2px solid var(--felt-light);
  border-radius: 14px;
  padding: 36px 40px;
  text-align: center;
  min-width: 300px;
}
.modal-box h2 { margin-bottom: 20px; color: var(--gold); }
.modal-box input {
  width: 100%; padding: 12px 16px;
  border-radius: 8px;
  border: 2px solid rgba(255,255,255,.2);
  background: rgba(0,0,0,.3);
  color: #fff; font-size: 16px;
  text-align: center;
  outline: none;
  margin-bottom: 14px;
}
.modal-box input:focus { border-color: var(--gold); }
.modal-hint { font-size: 11px; color: rgba(255,255,255,.35); margin: -8px 0 12px; text-align: center; }

.game-app { display: flex; flex-direction: column; height: 100vh; }

.game-header {
  background: rgba(0,0,0,.5);
  border-bottom: 1px solid rgba(255,255,255,.1);
  padding: 10px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.back-link { color: rgba(255,255,255,.55); text-decoration: none; margin-right: 14px; font-size: 14px; }
.back-link:hover { color: #fff; }
.room-name { font-weight: 700; font-size: 16px; }
.game-badge {
  margin-left: 10px;
  padding: 2px 10px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .5px;
  text-transform: uppercase;
}
.my-pseudo { font-size: 14px; color: var(--gold); margin-right: 12px; font-weight: 600; }

.game-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Game main ── */
.game-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 10px;
  gap: 8px;
}

/* Other players */
.other-players {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
  min-height: 80px;
}
.player-slot {
  background: rgba(0,0,0,.3);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 10px;
  padding: 8px 14px;
  text-align: center;
  min-width: 100px;
}
.player-slot.current-turn {
  border-color: var(--gold);
  box-shadow: 0 0 10px rgba(201,162,39,.4);
}
.player-slot .player-name { font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.player-slot .card-count { font-size: 11px; color: rgba(255,255,255,.55); }
.player-slot .host-tag { font-size: 10px; color: var(--gold); }

.face-down-cards {
  display: flex;
  gap: 4px;
  justify-content: center;
  margin-top: 4px;
}
.face-down-mini {
  width: 20px;
  height: 28px;
  background: #1a237e;
  border-radius: 3px;
  border: 1px solid rgba(255,255,255,.2);
}

/* Table center */
.table-center { flex: 1; display: flex; align-items: center; justify-content: center; }

.table-felt {
  background: var(--felt);
  border-radius: 16px;
  border: 6px solid #0d3d18;
  box-shadow: inset 0 2px 12px rgba(0,0,0,.4), 0 4px 20px rgba(0,0,0,.5);
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  min-width: 500px;
  max-width: 680px;
  width: 100%;
}

.piles-row {
  display: flex;
  gap: 28px;
  align-items: flex-end;
  justify-content: center;
}

.pile-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.pile-label { font-size: 11px; color: rgba(255,255,255,.5); letter-spacing: .5px; text-transform: uppercase; }
.pile-empty-text { color: rgba(255,255,255,.2); font-size: 11px; text-align: center; }

.pile-placeholder {
  width: var(--card-w);
  height: var(--card-h);
  border: 2px dashed rgba(255,255,255,.2);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.table-pile-zone .table-placeholder {
  width: 160px;
  height: var(--card-h);
}

.events-log {
  max-height: 54px;
  overflow-y: auto;
  width: 100%;
  font-size: 12px;
  color: rgba(255,255,255,.6);
  text-align: center;
}
.event-line { padding: 2px 0; }
.event-win { color: var(--gold); font-weight: 700; }
.event-turn { color: #55efc4; }

.game-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.turn-indicator {
  font-size: 13px;
  font-weight: 600;
  color: var(--gold);
  background: rgba(201,162,39,.15);
  padding: 5px 16px;
  border-radius: 20px;
  border: 1px solid rgba(201,162,39,.3);
}

.action-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.btn-action {
  background: rgba(0,0,0,.4);
  border: 1px solid rgba(255,255,255,.25);
  color: #fff;
  padding: 7px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  transition: background .15s, border-color .15s;
}
.btn-action:hover:not(:disabled) { background: rgba(255,255,255,.15); }
.btn-action:disabled { opacity: .35; cursor: not-allowed; }
.btn-action.btn-draw { border-color: rgba(39,174,96,.5); color: #2ecc71; }
.btn-action.btn-pass { border-color: rgba(255,255,255,.2); color: rgba(255,255,255,.6); }

.host-controls {
  display: flex;
  gap: 10px;
  justify-content: center;
}

/* ── My hand ── */
.my-hand-section {
  flex-shrink: 0;
  min-height: 120px;
}
.hand-label {
  font-size: 12px;
  color: rgba(255,255,255,.5);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 6px;
}
.hand-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: flex-end;
  min-height: 94px;
}

/* ══════════════════════════════
   CARDS
══════════════════════════════ */
.card {
  width: var(--card-w);
  height: var(--card-h);
  background: #fff;
  border-radius: 8px;
  border: 1px solid #ddd;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 5px;
  cursor: pointer;
  user-select: none;
  box-shadow: 2px 3px 6px rgba(0,0,0,.35);
  transition: transform .12s, box-shadow .12s;
  flex-shrink: 0;
  position: relative;
}
.card:hover { transform: translateY(-6px); box-shadow: 2px 8px 14px rgba(0,0,0,.45); }
.card.selected {
  transform: translateY(-18px);
  box-shadow: 0 12px 24px rgba(0,0,0,.5);
  border-color: var(--gold);
  outline: 2px solid var(--gold);
}
.card.red { color: #cc1111; }
.card.black { color: #111; }

.card-top { font-size: 13px; font-weight: 700; line-height: 1; }
.card-center { font-size: 22px; text-align: center; line-height: 1; }
.card-bottom { font-size: 13px; font-weight: 700; line-height: 1; transform: rotate(180deg); align-self: flex-end; }

/* UNO cards */
.card.uno {
  border: 3px solid rgba(255,255,255,.7);
  color: #fff;
  text-shadow: 1px 1px 2px rgba(0,0,0,.5);
}
.card.uno.uno-red    { background: var(--red); }
.card.uno.uno-blue   { background: var(--blue); }
.card.uno.uno-green  { background: var(--green); }
.card.uno.uno-yellow { background: var(--yellow); color: #111; text-shadow: none; }
.card.uno.uno-wild   {
  background: linear-gradient(135deg, var(--red) 25%, var(--blue) 25% 50%, var(--green) 50% 75%, var(--yellow) 75%);
}

/* Card back */
.card-back {
  width: var(--card-w);
  height: var(--card-h);
  background: #1a237e;
  background-image:
    repeating-linear-gradient(45deg, rgba(255,255,255,.06) 0, rgba(255,255,255,.06) 1px, transparent 0, transparent 50%),
    repeating-linear-gradient(-45deg, rgba(255,255,255,.06) 0, rgba(255,255,255,.06) 1px, transparent 0, transparent 50%);
  background-size: 8px 8px;
  border-radius: 8px;
  border: 2px solid rgba(255,255,255,.2);
  box-shadow: 2px 3px 6px rgba(0,0,0,.4);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.card-back.clickable { cursor: pointer; transition: transform .12s; }
.card-back.clickable:hover { transform: translateY(-4px); }

.deck-count {
  position: absolute;
  bottom: 5px; right: 7px;
  font-size: 12px;
  color: rgba(255,255,255,.7);
  font-weight: 700;
}

/* ── Table scattered cards ── */
.table-pile-zone .table-placeholder {
  position: relative;
  width: 160px;
}
.table-card-item {
  position: absolute;
  transform-origin: center center;
}

/* ══════════════════════════════
   CHAT
══════════════════════════════ */
.chat-panel {
  width: 280px;
  min-width: 220px;
  background: var(--chat-bg);
  border-left: 1px solid var(--chat-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.chat-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--chat-border);
  font-weight: 600;
  font-size: 14px;
  color: rgba(255,255,255,.75);
}

.players-mini {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.player-mini-item {
  font-size: 12px;
  color: rgba(255,255,255,.55);
  display: flex;
  align-items: center;
  gap: 6px;
}
.player-mini-item .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #2ecc71;
  flex-shrink: 0;
}
.player-mini-item.current-turn-mini { color: var(--gold); }
.player-mini-item.current-turn-mini .dot { background: var(--gold); }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chat-msg {
  font-size: 13px;
  line-height: 1.4;
}
.chat-msg .msg-author { font-weight: 700; color: var(--gold); margin-right: 4px; }
.chat-msg .msg-time { font-size: 10px; color: rgba(255,255,255,.3); margin-left: 4px; }
.chat-msg .msg-text { color: rgba(255,255,255,.85); }

.chat-input-row {
  display: flex;
  border-top: 1px solid var(--chat-border);
  padding: 8px 10px;
  gap: 8px;
}
.chat-input-row input {
  flex: 1;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 6px;
  color: #fff;
  padding: 7px 10px;
  font-size: 13px;
  outline: none;
}
.chat-input-row input:focus { border-color: rgba(255,255,255,.3); }
.btn-send {
  background: var(--felt);
  border: none;
  color: #fff;
  border-radius: 6px;
  padding: 7px 14px;
  cursor: pointer;
  font-size: 15px;
}
.btn-send:hover { background: var(--felt-light); }

/* ══════════════════════════════
   ADMIN
══════════════════════════════ */
.admin-body { background: #0d0d1a; }

.admin-login {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login-box {
  background: #1a1a2e;
  border: 1px solid #2d2d4e;
  border-radius: 14px;
  padding: 40px 48px;
  text-align: center;
  min-width: 320px;
}
.login-box h1 { color: var(--gold); margin-bottom: 24px; font-size: 28px; }
.login-box input {
  width: 100%;
  padding: 12px 16px;
  border-radius: 8px;
  border: 2px solid rgba(255,255,255,.15);
  background: rgba(0,0,0,.3);
  color: #fff;
  font-size: 15px;
  text-align: center;
  outline: none;
  margin-bottom: 14px;
}
.login-box input:focus { border-color: var(--gold); }
.error-msg { color: var(--red); font-size: 13px; margin-top: 8px; }

.admin-dashboard { max-width: 860px; margin: 0 auto; padding: 0 20px 40px; }
.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 0 16px;
  border-bottom: 1px solid rgba(255,255,255,.1);
  margin-bottom: 28px;
}
.admin-header h1 { display: inline; font-size: 22px; color: var(--gold); margin-left: 14px; }
.admin-section { margin-bottom: 32px; }
.admin-section h2 { color: rgba(255,255,255,.75); font-size: 16px; margin-bottom: 14px; display: flex; align-items: center; gap: 12px; }

.create-form {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.create-form input, .create-form select {
  padding: 10px 14px;
  border-radius: 7px;
  border: 1px solid rgba(255,255,255,.15);
  background: rgba(255,255,255,.07);
  color: #fff;
  font-size: 14px;
  outline: none;
}
.create-form input { flex: 1; min-width: 220px; }
.create-form input:focus, .create-form select:focus { border-color: var(--gold); }
.create-form select option { background: #1a1a2e; }

.admin-room-card {
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 10px;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.admin-room-info .admin-room-title { font-weight: 600; font-size: 15px; }
.admin-room-info .admin-room-meta { font-size: 12px; color: rgba(255,255,255,.45); margin-top: 4px; }
.admin-room-actions { display: flex; gap: 10px; align-items: center; }

.btn-copy-link {
  background: rgba(39,174,96,.2);
  border: 1px solid rgba(39,174,96,.4);
  color: #2ecc71;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.btn-copy-link:hover { background: rgba(39,174,96,.35); }

.btn-delete {
  background: rgba(231,76,60,.15);
  border: 1px solid rgba(231,76,60,.4);
  color: #e74c3c;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.btn-delete:hover { background: rgba(231,76,60,.3); }

/* Scrollbar */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 3px; }

/* ══════════════════════════════
   RESPONSIVE MOBILE
══════════════════════════════ */
@media (max-width: 768px) {
  /* ── Game body: scroll instead of fixed height ── */
  .game-body { overflow: auto; height: auto; }
  .game-app  { height: auto; min-height: 100vh; }

  /* ── Header compact ── */
  .game-header { padding: 8px 12px; flex-wrap: wrap; gap: 6px; }
  .header-left { gap: 8px; flex-wrap: wrap; }
  .room-name   { font-size: 14px; }
  .my-pseudo   { font-size: 13px; margin-right: 6px; }
  #copy-link-btn { font-size: 12px; padding: 4px 10px; }

  /* ── Layout: stack vertically ── */
  .game-layout { flex-direction: column; overflow: visible; }

  /* ── Main area ── */
  .game-main { padding: 8px; gap: 6px; overflow: visible; }

  /* ── Other players: horizontal scroll ── */
  .other-players {
    flex-wrap: nowrap;
    overflow-x: auto;
    justify-content: flex-start;
    min-height: 70px;
    padding-bottom: 4px;
  }
  .player-slot { min-width: 80px; padding: 6px 10px; }
  .player-slot .player-name { font-size: 12px; }
  .face-down-mini { width: 14px; height: 20px; }

  /* ── Table felt: full width, no min-width ── */
  .table-center { width: 100%; }
  .table-felt {
    min-width: unset;
    width: 100%;
    padding: 10px 12px;
    gap: 8px;
    border-width: 4px;
    border-radius: 12px;
  }

  /* ── Piles: smaller spacing ── */
  .piles-row { gap: 14px; }
  .table-pile-zone .table-placeholder { width: 120px; }

  /* ── Cards: smaller on mobile ── */
  :root {
    --card-w: 48px;
    --card-h: 70px;
  }
  .card-top    { font-size: 11px; }
  .card-center { font-size: 17px; }
  .card-bottom { font-size: 11px; }
  .card.uno .card-center { font-size: 20px; }
  .deck-count  { font-size: 10px; }

  /* ── Events log ── */
  .events-log { font-size: 11px; max-height: 44px; }

  /* ── Action buttons: wrap & full-width ── */
  .action-buttons {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
  }
  .btn-action {
    font-size: 12px;
    padding: 7px 12px;
    flex: 1 1 auto;
    min-width: 90px;
    text-align: center;
  }
  .host-controls { flex-direction: column; gap: 8px; width: 100%; }
  .host-controls .btn-primary,
  .host-controls .btn-secondary { width: 100%; }

  /* ── Turn indicator ── */
  .turn-indicator { font-size: 12px; padding: 4px 12px; }

  /* ── My hand: horizontal scroll ── */
  .my-hand-section { flex-shrink: 0; padding: 0 0 8px; }
  .hand-label { font-size: 11px; margin-bottom: 4px; }
  .hand-cards {
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 5px;
    padding-bottom: 4px;
    align-items: flex-end;
  }
  .card { flex-shrink: 0; }
  .card.selected { transform: translateY(-12px); }
  .card:hover    { transform: translateY(-4px); }

  /* ── Chat: below game, fixed height ── */
  .chat-panel {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--chat-border);
    height: 260px;
    flex-shrink: 0;
  }
  .chat-messages { padding: 8px 12px; }
  .chat-msg      { font-size: 12px; }

  /* ── Players mini: horizontal ── */
  .players-mini { flex-direction: row; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
  .player-mini-item { font-size: 11px; }

  /* ── Lobby ── */
  .lobby-page  { padding: 24px 16px; }
  .lobby-header h1 { font-size: 32px; }
  .admin-link  { position: static; display: block; margin-top: 8px; text-align: center; }
  .pseudo-section input { width: 100%; }
  .room-card   { flex-direction: column; align-items: flex-start; gap: 10px; }

  /* ── Modal ── */
  .modal-box { padding: 28px 24px; min-width: unset; width: 90vw; }

  /* ── Admin ── */
  .create-form { flex-direction: column; }
  .create-form input, .create-form select { width: 100%; }
  .admin-room-card { flex-direction: column; gap: 10px; }
  .admin-room-actions { flex-wrap: wrap; }
}
