:root {
  --bg-main: #f3f1ec;
  --card-bg: #ffffff;
  --border: #e0d9cc;
  --board-light: #f0d9b5;
  --board-dark: #b58863;
  --text-main: #222;
  --text-muted: #777;
  --accent: #b58863;
  --accent-dark: #9a6f4c;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden !important;
  overscroll-behavior-x: none;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  font-family: Arial, sans-serif;
  background: var(--bg-main);
  color: var(--text-main);
}

a {
  color: var(--accent-dark);
}

img {
  max-width: 100%;
  height: auto;
}

.page-wrap {
  width: 100%;
  max-width: 1220px;
  margin: 0 auto;
  padding: 16px;
  overflow-x: hidden;
}

.card {
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 2px 10px rgba(0,0,0,.05);
}

.btn,
button.btn {
  display: inline-block;
  max-width: 100%;
  padding: 10px 14px;
  border: 0;
  border-radius: 10px;
  font-weight: bold;
  cursor: pointer;
  text-decoration: none;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-dark);
}

.btn-light {
  background: #f0d9b5;
  color: #222;
}

.btn-danger {
  background: #7f1d1d;
  color: #fff;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: #222;
}

input,
select {
  width: 100%;
  max-width: 100%;
  padding: 11px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 16px;
  margin: 6px 0 12px;
}

label {
  font-weight: bold;
}

.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  max-width: 100%;
  border-collapse: collapse;
}

th {
  text-align: left;
  padding: 10px;
  background: var(--accent);
  color: #fff;
}

td {
  padding: 10px;
  border-bottom: 1px solid var(--border);
}

tr:hover {
  background: #f9f6f2;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  max-width: 100%;
}

.game-layout,
.lobby-grid {
  width: 100%;
  max-width: 100%;
}

#board {
  max-width: 100%;
}

#board .board-b72b1 {
  max-width: 100% !important;
  margin-left: auto !important;
  margin-right: auto !important;
}

/* Chess lobby table */
.chess-lobby-table {
  width: 100%;
  border-collapse: collapse;
}

.chess-lobby-table th,
.chess-lobby-table td {
  padding: 6px 8px;
  white-space: nowrap;
}

.chess-lobby-table th:nth-child(2),
.chess-lobby-table td:nth-child(2),
.chess-lobby-table th:nth-child(3),
.chess-lobby-table td:nth-child(3),
.chess-lobby-table th:nth-child(4),
.chess-lobby-table td:nth-child(4),
.chess-lobby-table th:nth-child(5),
.chess-lobby-table td:nth-child(5) {
  width: 1%;
  text-align: center;
}

.chess-lobby-table th:nth-child(1),
.chess-lobby-table td:nth-child(1) {
  white-space: normal;
}

@media (max-width: 700px) {
  .page-wrap {
    padding: 10px;
  }

  .topbar {
    display: block;
  }

  .topbar .btn {
    margin-top: 8px;
  }

  .card {
    padding: 10px;
  }

  .lobby-grid {
    grid-template-columns: 1fr !important;
  }

  input,
  select,
  button,
  .btn {
    max-width: 100%;
  }

  .chess-lobby-table {
    font-size: 13px;
  }

  .chess-lobby-table th,
  .chess-lobby-table td {
    padding: 6px 5px;
  }

  .chess-lobby-table .btn,
  .chess-lobby-table button.btn {
    padding: 8px 10px;
    font-size: 13px;
  }
}
/* =========================================
   CHESS LOBBY TABLE FIX (OVERRIDE MOBILE BREAK)
========================================= */
.chess-lobby-table,
.chess-lobby-table thead,
.chess-lobby-table tbody,
.chess-lobby-table tr,
.chess-lobby-table th,
.chess-lobby-table td {
  display: table !important;
  width: auto !important;
}

.chess-lobby-table tr {
  display: table-row !important;
}

.chess-lobby-table th,
.chess-lobby-table td {
  display: table-cell !important;
  padding: 6px 8px;
  white-space: nowrap;
}

/* Shrink small columns */
.chess-lobby-table th:nth-child(2),
.chess-lobby-table td:nth-child(2), /* Rating */
.chess-lobby-table th:nth-child(3),
.chess-lobby-table td:nth-child(3), /* Time */
.chess-lobby-table th:nth-child(4),
.chess-lobby-table td:nth-child(4), /* Type */
.chess-lobby-table th:nth-child(5),
.chess-lobby-table td:nth-child(5) { /* Side */
  width: 1%;
  text-align: center;
}

/* Let player column expand */
.chess-lobby-table th:nth-child(1),
.chess-lobby-table td:nth-child(1) {
  white-space: normal;
}p

/* Mobile Waiting Challenges card fix */
.waiting-challenges-card,
.waiting-card,
.lobby-card,
.challenges-card {
  max-width: 100%;
  overflow: hidden;
}

.table-scroll-x,
.waiting-table-wrap,
.challenge-table-wrap {
  width: 100%;
  max-width: 100%;
  overflow: visible !important;
}

.swipe-hint,
.mobile-swipe-hint {
  display: none !important;
}

@media (max-width: 760px) {
  table.challenge-table,
  .challenge-table,
  table.waiting-challenges-table,
  .waiting-challenges-table {
    display: block !important;
    width: 100% !important;
    min-width: 0 !important;
    border-collapse: separate !important;
    border-spacing: 0 10px !important;
  }

  .challenge-table thead,
  .waiting-challenges-table thead,
  .challenge-table tr:first-child th {
    display: none !important;
  }

  .challenge-table tbody,
  .waiting-challenges-table tbody {
    display: block !important;
    width: 100% !important;
  }

  .challenge-table tr,
  .waiting-challenges-table tr {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 8px 10px !important;
    width: 100% !important;
    margin: 0 0 12px !important;
    padding: 14px !important;
    border: 1px solid rgba(154,111,76,.16) !important;
    border-radius: 16px !important;
    background: #fff !important;
    box-shadow: 0 8px 24px rgba(40,31,20,.06) !important;
    box-sizing: border-box !important;
  }

  .challenge-table td,
  .waiting-challenges-table td {
    display: block !important;
    width: auto !important;
    min-width: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    font-size: 16px !important;
    line-height: 1.25 !important;
    white-space: normal !important;
    overflow: visible !important;
    text-align: left !important;
  }

  .challenge-table td::before,
  .waiting-challenges-table td::before {
    display: block;
    margin-bottom: 2px;
    color: #8a6a4a;
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .04em;
    font-family: Arial, Helvetica, sans-serif;
  }

  .challenge-table td:nth-child(1)::before,
  .waiting-challenges-table td:nth-child(1)::before { content: "Player"; }

  .challenge-table td:nth-child(2)::before,
  .waiting-challenges-table td:nth-child(2)::before { content: "Rating"; }

  .challenge-table td:nth-child(3)::before,
  .waiting-challenges-table td:nth-child(3)::before { content: "Time"; }

  .challenge-table td:nth-child(4)::before,
  .waiting-challenges-table td:nth-child(4)::before { content: "Side"; }

  .challenge-table td:nth-child(5),
  .waiting-challenges-table td:nth-child(5),
  .challenge-table td.actions,
  .waiting-challenges-table td.actions {
    grid-column: 1 / -1 !important;
    display: flex !important;
    gap: 8px !important;
    flex-wrap: wrap !important;
    align-items: center !important;
    padding-top: 4px !important;
  }

  .challenge-table td:nth-child(5)::before,
  .waiting-challenges-table td:nth-child(5)::before {
    display: none !important;
  }

  .challenge-table td:nth-child(5) a,
  .challenge-table td:nth-child(5) button,
  .waiting-challenges-table td:nth-child(5) a,
  .waiting-challenges-table td:nth-child(5) button,
  .challenge-table .btn,
  .waiting-challenges-table .btn {
    flex: 1 1 90px !important;
    min-width: 78px !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 12px 10px !important;
    border-radius: 14px !important;
    text-align: center !important;
    white-space: nowrap !important;
    box-sizing: border-box !important;
  }
}


/* Hide mobile swipe hint badge on challenge cards */
.swipe-hint, .mobile-swipe-hint { display: none !important; }
.challenge-card::after, .game-card::after, .lobby-game::after { content: none !important; display: none !important; }
