/* Ensure PinModal is always on top */
#pin-modal {
  z-index: 10001 !important;
}
#pin-modal-content {
  z-index: 10002 !important;
}
/* Modal styles for PIN entry */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0,0,0,0.35);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal.show {
  display: flex !important;
}
.modal-content {
  background: #fff;
  padding: 24px 20px 18px 20px;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  min-width: 220px;
  max-width: 340px;
  text-align: center;
}
.modal-title {
  font-size: 1.2em;
  font-weight: bold;
  margin-bottom: 8px;
}
.modal-btn {
  background: var(--primary);
  color: white;
  border: none;
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 1em;
  font-weight: bold;
  cursor: pointer;
  margin-top: 8px;
}
.modal-btn:hover {
  background: #0177b6;
}
/* Fix QR and heading overlap in freeplay.html for mobile */
.facility-qr-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 24px;
  margin-bottom: 12px;
}

@media (max-width: 600px) {
  .facility-qr-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  .facility-qr-row img {
    margin-bottom: 4px;
  }
  .facility-qr-row h2 {
    margin-top: 0;
    margin-bottom: 0;
    font-size: 1.1em;
  }
}
/* Queue group header layout and styling */
.queue-group-header-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 2px;
}
.queue-group-position {
  margin: 0;
  padding: 6px 12px;
  display: inline-block;
  font-size: 1.08em;
}
.queue-group-lock {
  margin-right: 0;
  margin-left: 0;
  display: flex;
  align-items: center;
}
.queue-group-meta-row {
  margin-top: 4px;
  color: #444;
  display: flex;
  gap: 18px;
  align-items: center;
  font-size: 0.98em;
}
.btn-lock, .btn-unlock {
  border: none;
  background: transparent;
  padding: 4px 6px;
  font-size: 1.5em;
  outline: none;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 0.2s, transform 0.1s;
}
.btn-lock:hover, .btn-unlock:hover {
  opacity: 1;
  transform: scale(1.15);
}
/* Delta bar edge lines */
.delta-edge {
  display: inline-block;
  width: 2px;
  height: 14px;
  background: #bbb;
  vertical-align: middle;
  margin: 0 2px;
}
/* Delta bar visual styles */
.delta-bar {
  display: inline-block;
  height: 12px;
  border-radius: 6px;
  vertical-align: middle;
}
.delta-above {
  background: #2e7d32;
}
.delta-below {
  background: #d32f2f;
}
.delta-neutral {
  background: #757575;
}
/* Delta visual indicator styles */
.queue-player-delta.delta-above {
  color: #2e7d32; /* green for above average */
  font-weight: bold;
}
.queue-player-delta.delta-below {
  color: #d32f2f; /* red for below average */
  font-weight: bold;
}
.queue-player-delta.delta-neutral {
  color: #757575; /* gray for neutral */
}
/* Balance Queue button style */
.btn-balance {
  background: var(--info);
  color: white;
  border: none;
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 1em;
  font-weight: bold;
  cursor: pointer;
  margin-top: 8px;
}
.btn-balance:hover {
  background: #0177b6;
}
/* Prevent long player names from causing button overlap in queue rows */
.queue-player-name {
  max-width: 100px; /* Prevent name overflow */
  white-space: normal;
  word-break: break-word;
  overflow-wrap: break-word;
  font-weight: 700;
  color: #000;
  font-size: 1.5em;
  text-align: left !important;
}
/* Make queue groups stack left-to-right and wrap like courts */
.queue-groups {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); /* Adjust minimum width for better resizing */
  gap: 16px; /* Reduce gap for smaller screens */
  margin-bottom: 32px; /* Adjust spacing for consistency */
}
.queue-group {
  background: #ffffff;
  border-radius: 12px;
  padding: 12px; /* Reduce padding for smaller screens */
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  border: 3px solid var(--primary);
  margin: 0;
  box-sizing: border-box;
}
/* Highlight new queue players (joined from form, not end-game) */
.queue-player-new {
  background: linear-gradient(135deg, #fff9c4 0%, #ffeb3b 100%);
  animation: pulse-player-new 1.5s ease-in-out infinite;
}
.queue-player-new td {
  font-weight: 600;
}
@keyframes pulse-player-new {
  0%, 100% { 
    background: linear-gradient(135deg, #fff9c4 0%, #ffeb3b 100%);
  }
  50% { 
    background: linear-gradient(135deg, #fffde7 0%, #fdd835 100%);
  }
}
/* Match queue group table to court size and style */
.queue-group-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: #f9f9f9;
  border-radius: 8px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.05);
  margin-top: 8px;
  margin-bottom: 8px;
  overflow: hidden;
  table-layout: auto; /* Allow table to adjust dynamically */
  word-wrap: break-word; /* Prevent overflow issues */
}
.queue-group-table th, .queue-group-table td {
  padding: 8px; /* Adjust padding for better fit */
  text-align: center;
  border-bottom: 1px solid #e0e0e0;
  font-size: 0.9em; /* Ensure text remains readable */
  word-break: break-word;
  overflow-wrap: anywhere;
}
.queue-group-table th {
  background: #e1f5fe;
  color: var(--primary);
  font-weight: 600;
  font-size: 1em;
}
.queue-group-table tr:last-child td {
  border-bottom: none;
}
.queue-player-actions button {
  margin: 0 4px;
}
:root {
      --primary: #4a7c59;
      --light: #f0f8f4;
      --dark: #1a3c34;
      --accent: #a8d5ba;
      --danger: #d32f2f;
      --warning: #f57c00;
      --trade: #FF9800;
      --info: #0288d1;
      --success: #2e7d32;
    }
    body {
      font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
      background: #f0f4f8;
      color: var(--dark);
      margin: 0;
      padding: 20px;
    }
    .container {
      max-width: 1400px;
      margin: 0 auto;
    }
    h1 {
      text-align: center;
      color: var(--dark);
      margin-bottom: 10px;
    }
    .status-bar {
      text-align: center;
      margin: 15px 0;
      padding: 12px;
      background: #e8f5e9;
      border-radius: 8px;
      font-weight: 500;
      color: var(--dark);
      font-size: 1.1em;
    }

    .join-form {
      background: white;
      padding: 20px;
      border-radius: 12px;
      box-shadow: 0 4px 12px rgba(0,0,0,0.1);
      margin-bottom: 20px;
      display: flex;
      gap: 12px;
      flex-wrap: wrap;
      align-items: center;
      justify-content: center;
    }
    .join-form input, .join-form select, .join-form button {
      padding: 10px 14px;
      font-size: 1em;
      border: 1px solid #ccc;
      border-radius: 8px;
    }
    .join-form input { width: 180px; }
    .join-form select { width: 100px; }
    .join-form button {
      background: var(--primary);
      color: white;
      border: none;
      cursor: pointer;
      font-weight: bold;
    }
    .join-form button:hover { background: #3a5f47; }

    .add-courts {
      background: #e8f5e9;
      padding: 16px;
      border-radius: 12px;
      margin-bottom: 20px;
      text-align: center;
    }
    .add-courts input {
      width: 260px;
      padding: 10px;
      font-size: 1em;
      border: 1px solid #ccc;
      border-radius: 8px;
    }
    .add-courts button {
      background: var(--success);
      color: white;
      border: none;
      padding: 10px 16px;
      border-radius: 8px;
      font-weight: bold;
      cursor: pointer;
      margin-left: 8px;
    }
    .add-courts button:hover { background: #1b5e20; }

    .courts-container {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
      gap: 20px;
      margin-bottom: 40px;
    }
    .court {
      background: #ffffff;
      border-radius: 12px;
      padding: 16px;
      box-shadow: 0 4px 12px rgba(0,0,0,0.1);
      border: 3px solid var(--primary);
    }
    .court-new {
      background: linear-gradient(135deg, #fff9c4 0%, #ffeb3b 100%);
      border: 4px solid #fbc02d;
      box-shadow: 0 6px 20px rgba(251, 192, 45, 0.6);
      animation: pulse-new 1.5s ease-in-out infinite;
    }
    .court-new .court-header {
      color: #f57f17;
      font-weight: 900;
      text-shadow: 0 1px 2px rgba(0,0,0,0.1);
    }
    @keyframes pulse-new {
      0%, 100% { 
        transform: scale(1);
        box-shadow: 0 6px 20px rgba(251, 192, 45, 0.6);
      }
      50% { 
        transform: scale(1.02);
        box-shadow: 0 8px 30px rgba(251, 192, 45, 0.9);
      }
    }
    .court-header {
      font-weight: bold;
      font-size: 1.2em;
      margin-bottom: 8px;
      color: var(--primary);
      text-align: center;
      display: flex;
      justify-content: space-between;
      align-items: center;
    }
    /* Court timer and avg wait styling - visually consistent */
    .timer {
      text-align: left;
      color: var(--primary); /* Use primary color for timer */
      font-weight: 600;
      font-size: 1em;
      margin-bottom: 6px;
      margin-top: 4px;
      background: #e1f5fe;
      padding: 4px 8px;
      border-radius: 6px;
      display: inline-block;
      margin-right: 60px; /* Add space to prevent collision with QR code */
    }
    .court-avg-wait {
      text-align: left;
      color: var(--primary); /* Match timer color */
      font-weight: 600;
      font-size: 1em;
      margin-bottom: 10px;
      margin-top: 4px;
      background: #e1f5fe;
      padding: 4px 8px;
      border-radius: 6px;
      display: inline-block;
      margin-right: 60px; /* Add space to prevent collision with QR code */
    }

    .court-actions {
      display: flex;
      gap: 6px;
      justify-content: center;
      margin-top: 10px;
    }
    .btn-end, .btn-close, .btn-open {
      background: var(--danger);
      color: white;
      border: none;
      padding: 6px 10px;
      border-radius: 6px;
      font-size: 0.8em;
      cursor: pointer;
    }
    .btn-end:hover { background: #b71c1c; }
    .btn-close { background: var(--warning); }
    .btn-close:hover { background: #e65100; }
    .btn-open { background: var(--success); }
    .btn-open:hover { background: #1b5e20; }

    .close-btn {
      background: var(--warning);
      color: white;
      border: none;
      padding: 6px 10px;
      border-radius: 6px;
      font-size: 0.8em;
      cursor: pointer;
    }
    .close-btn:hover { background: #e65100; }

    .players-grid {
      display: flex;
      flex-direction: column;
      gap: 0;
    }
    .player {
      background: #f9f9f9;
      padding: 12px;
      border-bottom: 1px solid #e0e0e0;
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
    }
    .player:first-child {
      border-radius: 8px 8px 0 0;
    }
    .player:last-child {
      border-radius: 0 0 8px 8px;
      border-bottom: none;
    }
    .player-name {
      font-weight: 500;
      font-size: 0.95em;
      white-space: nowrap;
    }
    .player-rating {
      flex-shrink: 0;
    }

    /* DUPR Rating Colors */
    .rating-2-0 { background: #FFD700; color: #333; }
    .rating-2-5 { background: #CCAC00; color: white; }
    .rating-3-0 { background: #00CED1; color: #333; }
    .rating-3-5 { background: #008B8B; color: white; }
    .rating-4-0 { background: #32CD32; color: #333; }
    .rating-4-5 { background: #228B22; color: white; }
    .rating-5-0 { background: #FF4500; color: white; }
    .rating-5-5 { background: #CC3700; color: white; }

    .rating-badge {
      display: inline-block;
      font-weight: bold;
      padding: 4px 10px;
      border-radius: 12px;
      font-size: 0.85em;
      margin-left: 6px;
      box-shadow: 0 1px 0 rgba(0,0,0,0.05) inset;
      -webkit-font-smoothing: antialiased;
      background-clip: padding-box;
    }

/* Ensure rating badges inside tables keep rounded corners and spacing */
.queue-group-table td .rating-badge,
.trade-candidate-table td .rating-badge,
.player .rating-badge {
  display: inline-block;
  border-radius: 10px;
  padding: 4px 10px;
}

/* Style for trade modal candidate table (match queue group table) */
.trade-candidate-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: #f9f9f9;
  border-radius: 8px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.05);
  margin-top: 8px;
  margin-bottom: 8px;
  overflow: hidden;
}
.trade-candidate-table th, .trade-candidate-table td {
  padding: 10px 8px;
  text-align: center;
  border-bottom: 1px solid #e0e0e0;
}

    .queue-section {
      width: 100%;
      box-sizing: border-box;
    }
    .queue-header {
      font-size: 1.3em;
      font-weight: bold;
      color: var(--dark);
      margin-bottom: 16px;
      text-align: center;
    }
    .queue-groups {
      display: grid;
      /* ensure groups are at least as wide as courts */
      grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
      gap: 20px;
      margin-bottom: 40px;
      margin-top: 16px;
      width: 100%;
      box-sizing: border-box;
    }
    /* horizontal wrapper for tables inside queue groups */
    .table-scroll {
      width: 100%;
      overflow-x: auto;
      -webkit-overflow-scrolling: touch;
    }

    /* Prevent wrapping for rating, delta, wait, and actions columns; give them fixed widths */
    .queue-group-table th:nth-child(2), .queue-group-table td.queue-player-rating,
    .queue-group-table th:nth-child(3), .queue-group-table td.queue-player-wait,
    .queue-group-table th:nth-child(4), .queue-group-table td.queue-player-actions {
      white-space: nowrap;
      word-break: normal;
      overflow-wrap: normal;
    }

    .queue-group-table th:nth-child(2), .queue-group-table td.queue-player-rating { width: 64px; }
    .queue-group-table th:nth-child(3), .queue-group-table td.queue-player-wait { width: 64px; }
    .queue-group-table th:nth-child(4), .queue-group-table td.queue-player-actions { width: 130px; }

    /* Ensure action buttons have fixed sizes and don't cause wrapping */
    .queue-player-actions { white-space: nowrap; }
    .queue-player-actions .btn-trade, .queue-player-actions .btn-leave {
      min-width: auto;
      padding: 2px;
      box-sizing: border-box;
      font-size: 1.5em;
      line-height: 1;
    }
    .queue-group {
      background: #ffffff;
      border-radius: 12px;
      padding: 12px; /* Reduce padding for smaller screens */
      box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
      border: 3px solid var(--primary);
      margin-bottom: 20px;
    }
    .group-title {
      font-weight: 600;
      color: var(--dark);
      margin-bottom: 10px;
      font-size: 1.1em;
    }
    .group-players {
      display: grid;
      grid-template-columns: repeat(2, 1fr);
      gap: 10px;
    }
    .queue-player {
      background: #ffffff;
      padding: 10px;
      border-radius: 8px;
      text-align: center;
      box-shadow: 0 2px 6px rgba(0,0,0,0.05);
      font-size: 0.9em;
    }
    .wait-time {
      font-size: 0.8em;
      color: #d32f2f;
      font-weight: 500;
      margin-top: 4px;
    }
    .stuck-warning {
      color: var(--warning);
      font-weight: bold;
      font-size: 0.75em;
    }
    .player-actions {
      margin-top: 6px;
      display: flex;
      gap: 4px;
      justify-content: center;
    }
    .btn-trade, .btn-leave {
      font-size: 1.5em;
      padding: 4px;
      border: none;
      background: transparent;
      cursor: pointer;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      line-height: 1;
      min-height: auto;
      min-width: auto;
      opacity: 0.6;
      transition: opacity 0.2s, transform 0.1s;
    }
    .btn-trade:hover, .btn-leave:hover {
      opacity: 1;
      transform: scale(1.15);
    }

    /* Trade Modal */
    .trade-modal {
      position: fixed;
      top: 0; left: 0; right: 0; bottom: 0;
      background: rgba(0,0,0,0.7);
      display: flex;
      align-items: center;
      justify-content: center;
      z-index: 10000;
      visibility: hidden;
      opacity: 0;
      transition: all 0.3s;
      overflow: hidden;
    }
    .trade-modal.show { visibility: visible; opacity: 1; }
    .trade-content {
      background: white;
      padding: 24px;
      border-radius: 16px;
      width: 90%;
      max-width: 500px;
      max-height: 80vh;
      overflow-y: auto;
      box-shadow: 0 10px 30px rgba(0,0,0,0.3);
      z-index: 10001;
      position: relative;
    }
    .trade-title {
      font-size: 1.3em;
      font-weight: bold;
      color: var(--primary);
      margin-bottom: 16px;
      text-align: center;
    }
    .trade-group {
      margin-bottom: 16px;
      padding-bottom: 12px;
      border-bottom: 1px solid #eee;
    }
    .trade-group-title {
      font-weight: bold;
      color: var(--info);
      margin-bottom: 8px;
      font-size: 0.95em;
    }
    .trade-candidate {
      background: #f0f8f4;
      padding: 10px;
      border-radius: 8px;
      cursor: pointer;
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 6px;
    }
    .trade-candidate:hover {
      background: #d0e8d4;
    }
    .trade-btn-close {
      background: var(--danger);
      color: white;
      border: none;
      padding: 10px 20px;
      border-radius: 8px;
      font-size: 1em;
      cursor: pointer;
      width: 100%;
      margin-top: 12px;
    }

    /* Trade modal column layout */
    .trade-candidate-list { display: block; margin-top: 8px; }
    .trade-player-info {
      background: linear-gradient(135deg, #f0f8f4 0%, #e3f2e8 100%);
      padding: 16px;
      border-radius: 12px;
      margin: 16px 0;
      border: 2px solid #4a7c59;
    }
    .trade-player-name {
      font-size: 1.2em;
      font-weight: bold;
      color: #2d5a3d;
      margin-bottom: 10px;
    }
    .trade-player-rating {
      display: flex;
      align-items: center;
      gap: 8px;
    }
    .trade-header, .trade-row {
      display: grid;
      grid-template-columns: 1fr 72px 110px 86px;
      gap: 12px;
      padding: 6px 8px;
      align-items: center;
    }
    .trade-header { font-weight: bold; border-bottom: 1px solid #ddd; }
    .trade-row { cursor: pointer; border-bottom: 1px solid #f3f3f3; }
    .trade-row:hover { background: #fafafa; }
    .trade-col { padding: 2px 4px; }
    .trade-col-name { text-align: left; }
    .trade-col-rating { text-align: right; }
    .trade-col-competitiveness { text-align: right; }
    .trade-col-group { text-align: center; }

    .modal {
      position: fixed;
      top: 0; left: 0; right: 0; bottom: 0;
      background: rgba(0,0,0,0.7);
      display: flex;
      align-items: center;
      justify-content: center;
      z-index: 1000;
      visibility: hidden;
      opacity: 0;
      transition: all 0.3s;
    }
    .modal.show { visibility: visible; opacity: 1; }
    .modal-content {
      background: white;
      padding: 24px;
      border-radius: 16px;
      width: 90%;
      max-width: 400px;
      text-align: center;
      box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    }
    .modal-title {
      font-size: 1.4em;
      font-weight: bold;
      color: var(--primary);
      margin-bottom: 16px;
    }
    .modal-players {
      display: grid;
      grid-template-columns: 1fr;
      gap: 10px;
      margin-bottom: 20px;
    }
    .modal-player {
      background: #f0f8f4;
      padding: 10px;
      border-radius: 10px;
      font-weight: 500;
    }
    .modal-btn {
      background: var(--primary);
      color: white;
      border: none;
      padding: 12px 24px;
      border-radius: 8px;
      font-size: 1em;
      font-weight: bold;
      cursor: pointer;
    }
    .modal-btn:hover { background: #3a5f47; }

    @media (max-width: 768px) {
      .join-form, .add-courts { flex-direction: column; }
      .join-form input, .join-form select, .add-courts input { width: 100%; }
      .group-players, .players-grid { grid-template-columns: 1fr; }
    }

/* Your existing block — keep it */
button, [onclick] {
  touch-action: manipulation !important;
  cursor: pointer !important;
  pointer-events: auto !important;
  -webkit-appearance: none;
  appearance: none;
  min-height: 44px;
  min-width: 44px;
}

/* THIS IS THE REAL FIX */
.court-actions,
.court-actions button,
.btn-end,
.btn-close {
  position: relative !important;
  z-index: 9999 !important;
  pointer-events: auto !important;
}

.court::before,
.court::after,
.court-actions::before,
.court-actions::after {
  content: none !important;
  display: none !important;
}

/* Style queue groups like courts */
/* Match .queue-group to .court exactly */
.queue-group {
  background: #ffffff;
  border-radius: 12px;
  padding: 12px; /* Reduce padding for smaller screens */
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  border: 3px solid var(--primary);
  margin-bottom: 40px;
  display: flex;
  flex-direction: column;
}
.queue-group .court-header {
  font-weight: bold;
  font-size: 1.2em;
  margin-bottom: 8px;
  color: var(--primary);
  text-align: center;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.queue-group .players-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
}
.queue-group .player {
  background: #f9f9f9;
  padding: 10px;
  border-radius: 8px;
  text-align: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
}
.queue-group .player-name {
  font-weight: 500;
  font-size: 0.95em;
}
.queue-group .player-rating,
.queue-group .player-delta {
  font-size: 0.85em;
  color: #555;
}

/* DUPr Color Scheme for Player Ratings */
.rating-low {
  color: #ff0000; /* Red for low ratings */
}
.rating-mid {
  color: #ffa500; /* Orange for mid ratings */
}
.rating-high {
  color: #008000; /* Green for high ratings */
}
.rating-elite {
  color: #0000ff; /* Blue for elite ratings */
}

/* Ensure Trade and Leave buttons are subtle icon-only buttons */
.btn-trade, .btn-leave {
  height: auto;
  padding: 4px;
  font-size: 1.5em;
  border: none;
  background: transparent;
  display: inline-flex;
  align-items: center;
  opacity: 0.6;
  transition: opacity 0.2s, transform 0.1s;
}
.btn-trade:hover, .btn-leave:hover {
  opacity: 1;
  transform: scale(1.15);
}