/* Mobile/Tablet Player Entry Modal */
/* Ensure [hidden] attribute works even though we set explicit display values on these elements */
.player-entry-modal[hidden],
.player-entry-modal-backdrop[hidden] {
  display: none;
}

.player-entry-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.002);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  z-index: 10040;
}

.player-entry-modal {
  position: fixed;
  left: 50%;
  top: var(--player-entry-modal-top, 80px);
  transform: translateX(-50%);
  width: min(760px, calc(100vw - 20px));
  max-height: min(
    calc(100dvh - var(--player-entry-modal-top, 80px) - 12px),
    calc(100svh - var(--player-entry-modal-top, 80px) - 12px)
  );
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.35);
  padding: 0;
  z-index: 10041;
  animation: playerEntryModalIn 0.16s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.player-entry-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 12px 16px;
  margin: 0;
  background: inherit;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 72%, transparent);
}

.player-entry-modal-header h3 {
  margin: 0;
  font-size: var(--text-lg);
  letter-spacing: 0.01em;
}

.player-entry-modal-titles {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 2px;
}

.player-entry-modal-subtitle {
  color: var(--muted);
  font-size: var(--text-sm, 13px);
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-entry-close-btn {
  min-height: 38px;
  padding: 8px 16px;
  border-radius: 12px;
}

.player-entry-modal-note {
  flex-shrink: 0;
  margin: 0;
  padding: 10px 16px 12px;
  color: var(--muted);
  font-size: calc(13px + var(--font-size-step));
}

.player-entry-modal-list {
  flex: 1 1 auto;
  overflow-y: auto;
  display: grid;
  gap: 10px;
  padding: 0 16px;
}

.player-entry-row {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  display: grid;
  gap: 8px;
}

.player-entry-row-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.player-entry-row-title {
  font-size: calc(13px + var(--font-size-step));
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.player-entry-row-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  margin-left: auto;
}

.player-entry-row-actions.is-status-only {
  gap: 0;
}

.player-entry-register-status {
  font-size: calc(12px + var(--font-size-step));
  color: var(--muted);
  text-align: right;
}

.player-entry-register-btn {
  min-height: 42px;
  min-width: 140px;
  /* Inline label + spinner. flex keeps them on the same baseline + lets
     the spinner sit immediately to the right of the label text. */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

/* While the cloud-function round-trip is in flight, dim the button and
   spin a small ring next to the label so the user sees their tap landed. */
.player-entry-register-btn.is-loading {
  opacity: 0.85;
  cursor: progress;
}
.player-entry-register-btn-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: currentColor;
  border-radius: 50%;
  flex-shrink: 0;
  animation: registerBtnSpin 0.7s linear infinite;
}
@keyframes registerBtnSpin {
  to { transform: rotate(360deg); }
}

.player-entry-remove-btn {
  background: rgba(220, 53, 69, 0.12);
  border-color: rgba(220, 53, 69, 0.35);
  color: #ff8f99;
  min-height: 42px;
  min-width: 86px;
  margin-left: auto;
  padding: 8px 10px;
  font-size: calc(13px + var(--font-size-step));
  white-space: nowrap;
}

.player-entry-remove-btn:hover:not(:disabled) {
  background: rgba(220, 53, 69, 0.2);
  border-color: rgba(220, 53, 69, 0.55);
}

.player-entry-remove-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.player-entry-field {
  display: grid;
  gap: 6px;
  font-size: calc(13px + var(--font-size-step));
  color: var(--muted);
}

.player-entry-name-input,
.player-entry-handicap-input {
  min-height: 42px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-alt);
  color: var(--ink);
  padding: 8px 10px;
  font-size: calc(16px + var(--font-size-step));
}

.player-entry-handicap-input {
  text-align: center;
  width: 88px;
}

.player-entry-handicap-input::placeholder {
  color: var(--muted);
  opacity: 0.9;
}

.player-entry-handicap-control {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.player-entry-step-btn {
  min-width: 42px;
  min-height: 42px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-alt);
  color: var(--ink);
  font-size: calc(20px + var(--font-size-step));
  font-weight: 700;
  cursor: pointer;
}

.player-entry-step-btn:hover {
  border-color: rgba(74, 158, 255, 0.6);
}

.player-entry-modal-footer {
  flex-shrink: 0;
  margin-top: 0;
  padding: 14px 16px 16px;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
@media (max-width: 1024px) {
  .player-entry-modal {
    width: calc(100vw - 12px);
    max-height: min(
      calc(100dvh - var(--player-entry-modal-top, 80px) - 12px),
      calc(100svh - var(--player-entry-modal-top, 80px) - 12px)
    );
    border-radius: 14px;
  }
  .player-entry-modal-header {
    padding: 10px 12px;
  }
  .player-entry-modal-note {
    padding: 8px 12px 10px;
  }
  .player-entry-modal-list {
    padding: 0 12px;
  }
  .player-entry-modal-footer {
    padding: 12px 12px 12px;
  }
}

@media (max-width: 768px) {
  .player-entry-modal {
    width: calc(100vw - 8px);
    max-height: min(
      calc(100dvh - var(--player-entry-modal-top, 80px) - var(--safe-bottom-inset, env(safe-area-inset-bottom, 0px)) - 8px),
      calc(100svh - var(--player-entry-modal-top, 80px) - var(--safe-bottom-inset, env(safe-area-inset-bottom, 0px)) - 8px)
    );
    border-radius: 12px;
  }
  .player-entry-modal-header {
    padding: 10px;
  }
  .player-entry-close-btn {
    min-height: 34px;
    padding: 6px 12px;
    border-radius: 10px;
  }
  .player-entry-modal-note {
    padding: 6px 10px 8px;
  }
  .player-entry-modal-list {
    padding: 0 10px;
  }
  .player-entry-modal-footer {
    /* Use --safe-bottom-inset so Android nav-bar clearance works. */
    padding: 10px 10px max(10px, var(--safe-bottom-inset, env(safe-area-inset-bottom, 10px)));
    justify-content: stretch;
  }

  .player-entry-modal-footer .btn {
    flex: 1 1 auto;
  }

  .player-entry-row-title-row {
    align-items: flex-start;
  }

  .player-entry-row-actions {
    width: 100%;
  }

  .player-entry-row-actions.is-status-only {
    justify-content: flex-end;
  }
}

/* =========================================================================
   Light theme overrides — moved from light-theme-overrides.css
   ========================================================================= */

:root[data-theme="light"] .player-entry-modal-backdrop {
  background: rgba(255, 255, 255, 0.006);
}

:root[data-theme="light"] .player-entry-row {
  background: #f7f9fc;
}

:root[data-theme="light"] .player-entry-remove-btn {
  background: rgba(220, 53, 69, 0.08);
  border-color: rgba(220, 53, 69, 0.28);
  color: #b42232;
}

:root[data-theme="light"] .player-entry-name-input,
:root[data-theme="light"] .player-entry-handicap-input,
:root[data-theme="light"] .player-entry-step-btn,
:root[data-theme="light"] .player-entry-close-btn {
  background: #ffffff;
}

/* Animations — referenced by .player-entry-modal and triggered by index.js
   (playerEntryModalOut on close). Moved from light-theme-overrides.css. */
@keyframes playerEntryModalIn {
  from {
    transform: translateX(-50%) translateY(100dvh);
    opacity: 0.92;
  }
  to {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
  }
}

@keyframes playerEntryModalOut {
  from {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
  }
  to {
    transform: translateX(-50%) translateY(100dvh);
    opacity: 0.85;
  }
}

/* ── Per-round games picker modal ──────────────────────────────────────
   Opens the first time the user lands on the Games tab for a round, and
   via the '+' tile to add more games later. Mirrors the player-entry
   modal pattern so dark/light themes stay consistent. */
.games-picker-modal[hidden],
.games-picker-modal-backdrop[hidden] {
  display: none;
}
.games-picker-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 10080;
}
.games-picker-modal {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(520px, calc(100vw - 24px));
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  padding: 18px 18px 16px;
  z-index: 10081;
}
.games-picker-modal-header h3 {
  margin: 0 0 4px;
  font-size: var(--text-lg);
}
.games-picker-modal-subtitle {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: calc(12px + var(--font-size-step));
  line-height: 1.35;
}
.games-picker-modal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.games-picker-tile {
  padding: 14px 12px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--panel-alt, transparent);
  color: var(--ink);
  font-size: calc(13px + var(--font-size-step));
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 56px;
  position: relative;
  transition: transform 0.08s ease, box-shadow 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}
.games-picker-tile:hover {
  transform: translateY(-1px);
  border-color: rgba(74, 158, 255, 0.55);
}
/* Selected tile — solid blue with white text. Specificity 0,3,1 wins over
   the generic .btn / light-theme cascade without needing !important. */
.games-picker-modal .games-picker-tile[data-selected="true"],
.games-picker-modal button.games-picker-tile[data-selected="true"] {
  background: linear-gradient(180deg, #2384dc, #176dc6);
  border-color: #4a9eff;
  color: #ffffff;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.22),
    0 8px 18px -10px rgba(35, 132, 220, 0.55);
}
:root[data-theme="light"] .games-picker-modal .games-picker-tile[data-selected="true"] {
  background: linear-gradient(180deg, #2384dc, #176dc6);
  color: #ffffff;
}
.games-picker-tile:active { transform: scale(0.97); }

/* Locked tile — game not in the current SKU. Dimmed with a lock badge;
   the tap still lands (routes to the paywall) so no pointer-events: none. */
.games-picker-modal .games-picker-tile[data-locked="true"] {
  opacity: 0.55;
  border-style: dashed;
}
.games-picker-modal .games-picker-tile[data-locked="true"]:hover {
  transform: none;
  border-color: var(--line);
}
.games-picker-tile-lock {
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 12px;
  line-height: 1;
}
.games-picker-tile-lock[hidden] { display: none; }

/* Library-backed "Your Custom Games" section — a generic boolean tile
   doesn't fit Custom Game's shape (N named instances), so it gets its own
   list + Add-to-round/Remove actions instead of a spot in the grid above. */
.games-picker-custom-section {
  margin-bottom: 16px;
}
.games-picker-custom-section[hidden] { display: none; }
.games-picker-custom-heading {
  margin: 0 0 8px;
  font-size: calc(12px + var(--font-size-step));
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.games-picker-custom-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}
.games-picker-custom-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line-soft, var(--line));
  border-radius: var(--radius-md, 12px);
  background: var(--panel-alt, transparent);
}
.games-picker-custom-row-label {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  font-size: calc(13px + var(--font-size-step));
}
.games-picker-custom-row-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.games-picker-custom-row-action {
  flex: 0 0 auto;
  white-space: nowrap;
}
.games-picker-custom-row-error {
  flex: 1 1 100%;
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--danger);
}
.games-picker-custom-loading,
.games-picker-custom-empty {
  margin: 0 0 10px;
  font-size: calc(12px + var(--font-size-step));
  color: var(--muted);
}
.games-picker-custom-error {
  color: var(--danger);
}
.games-picker-custom-retry-btn {
  align-self: flex-start;
  margin-bottom: 10px;
}
.games-picker-custom-create-btn {
  align-self: flex-start;
}

/* The paywall overlay normally sits at z-index 9000, below this modal
   (10081). When a locked tile routes to the paywall the picker stays open
   underneath, so lift the paywall above it for just that case. */
body.games-picker-modal-open .paywall-overlay {
  z-index: 10085;
}

.games-picker-modal-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  position: sticky;
  bottom: 0;
  z-index: 1;
  margin-top: auto;
  padding-top: 10px;
  background: var(--panel);
}
.games-picker-modal-footer .btn { min-width: 96px; }
.games-picker-modal-footer .games-picker-confirm-btn {
  background: linear-gradient(180deg, #2384dc, #176dc6);
  border-color: #4a9eff;
  color: #ffffff;
}

body.games-picker-modal-open { overflow: hidden; }

/* ── '+' add-more tile in the games launcher row ──────────────────────
   Same shape/size as a normal game-toggle-item so the row reads as a
   cohesive tab strip. */
.game-toggle-item-add[hidden] { display: none; }
.game-toggle-add {
  border-style: dashed;
  opacity: 0.85;
}
.game-toggle-add:hover { opacity: 1; }
.games-add-plus {
  font-weight: 700;
  font-size: 18px;
  display: inline-block;
  width: 17px;
  height: 17px;
  line-height: 17px;
  text-align: center;
}
