.player-dialog {
  max-width: 500px;
}
.player-dialog form {
  text-align: left;
}
.player-dialog label {
  display: block;
  font-weight: 900;
  margin-bottom: 8px;
  color: #084d98;
}
.player-dialog input {
  box-sizing: border-box;
  width: 100%;
  padding: 15px 16px;
  border: 2px solid #87c9e4;
  border-radius: 14px;
  background: #fff;
  color: #073e85;
  font:
    700 20px "Trebuchet MS",
    Arial,
    sans-serif;
}
.player-dialog input:focus {
  outline: 3px solid #ffd834;
  outline-offset: 3px;
}
.player-dialog .gold-button {
  width: 100%;
}
.form-error {
  min-height: 22px;
  color: #a12926;
  font-size: 15px;
}

/* Full-bleed Leaderboard screen with clean backdrop art and real HTML/CSS table & buttons. */
.leaderboard-dialog {
  max-width: none;
  max-height: none;
  width: 100vw;
  height: 100dvh;
  padding: 0;
  border: 0;
  margin: 0;
  overflow: hidden;
  background: #087f9d;
  font-family: "Trebuchet MS", Arial, sans-serif;
  color: #063a80;
}
.leaderboard-dialog::backdrop {
  background: #003a68cc;
}
.leaderboard-dialog[open] {
  display: block;
}
.leaderboard-frame {
  position: relative;
  width: 100vw;
  height: 100dvh;
  box-sizing: border-box;
  padding: max(22px, calc(14px + env(safe-area-inset-top)))
    max(28px, calc(16px + env(safe-area-inset-right)))
    max(24px, calc(16px + env(safe-area-inset-bottom)))
    max(28px, calc(16px + env(safe-area-inset-left)));
  background: url("assets/leaderboard/desktop.webp") left center / cover
    no-repeat;
  display: grid;
  grid-template-columns: minmax(260px, 36%) minmax(0, 1fr);
  grid-template-rows: 1fr;
  align-items: center;
  gap: clamp(18px, 3vw, 40px);
}

.leaderboard-tools {
  position: absolute;
  top: max(16px, calc(12px + env(safe-area-inset-top)));
  left: max(18px, calc(12px + env(safe-area-inset-left)));
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 10px;
}
.leaderboard-tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
  border: 2px solid #8df1ff;
  border-radius: 13px;
  background: linear-gradient(180deg, #1ea7ff 0%, #056fe0 55%, #004bb8 100%);
  color: #fff;
  box-shadow:
    0 3px 0 #003a95,
    0 5px 14px rgba(0, 30, 80, 0.35);
  font:
    900 14px/1 "Trebuchet MS",
    Arial,
    sans-serif;
  transition:
    filter 0.14s ease,
    transform 0.14s ease;
}
.leaderboard-tool-btn:hover {
  filter: brightness(1.08);
}
.leaderboard-tool-btn:active {
  transform: translateY(2px);
}
.leaderboard-tool-btn:disabled {
  opacity: 0.6;
}
.leaderboard-close-btn {
  width: 40px;
  padding: 0;
  font-size: 26px;
}

.leaderboard-card {
  grid-column: 2;
  grid-row: 1;
  justify-self: center;
  width: min(100%, 700px);
  max-height: calc(
    100dvh -
      max(
        48px,
        calc(32px + env(safe-area-inset-top) + env(safe-area-inset-bottom))
      )
  );
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #fffdf4 0%, #fff8e2 100%);
  border: 4px solid #ffd428;
  border-radius: 28px;
  padding: clamp(14px, 2vh, 22px) clamp(14px, 2vw, 24px)
    clamp(12px, 1.6vh, 18px);
  box-shadow:
    0 0 0 4px #0657c7,
    0 20px 52px rgba(0, 28, 76, 0.44);
  overflow: hidden;
}

.leaderboard-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-bottom: clamp(10px, 1.4vh, 16px);
  flex-shrink: 0;
}
.leaderboard-title-row {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.leaderboard-trophy {
  width: clamp(28px, 3.6vw, 40px);
  height: clamp(28px, 3.6vw, 40px);
  color: #c87900;
  flex-shrink: 0;
}
.leaderboard-title {
  margin: 0;
  font-family: "Arial Black", "Trebuchet MS", Arial, sans-serif;
  font-size: clamp(24px, 3.1vw, 38px);
  line-height: 1;
  letter-spacing: 0.5px;
  color: #06327c;
}
.leaderboard-badge {
  display: inline-block;
  padding: 4px 18px;
  border-radius: 999px;
  background: linear-gradient(180deg, #fff169 0%, #ffcb00 100%);
  border: 2px solid #f2a200;
  color: #06327c;
  font-size: clamp(12px, 1.25vw, 15px);
  font-weight: 900;
  letter-spacing: 1px;
}

.leaderboard-table {
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  border-collapse: separate;
  border-spacing: 0 4px;
  table-layout: fixed;
  font-weight: 900;
  font-size: clamp(14px, 1.65vw, 21px);
}
.leaderboard-table th,
.leaderboard-table td {
  padding: clamp(3px, 0.55vh, 7px) 12px;
  vertical-align: middle;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  box-sizing: border-box;
}
.leaderboard-table thead th {
  background: linear-gradient(#1282f0, #0046b6);
  color: #fff;
  text-transform: uppercase;
  font-size: 0.8em;
  letter-spacing: 0.6px;
  padding-block: clamp(6px, 0.9vh, 10px);
}
.leaderboard-table th:first-child,
.leaderboard-table td:first-child {
  width: 19%;
  text-align: center;
  border-radius: 14px 0 0 14px;
}
.leaderboard-table th:nth-child(2),
.leaderboard-table tbody th {
  text-align: left;
}
.leaderboard-table th:last-child,
.leaderboard-table td:last-child {
  width: 30%;
  text-align: right;
  border-radius: 0 14px 14px 0;
  font-variant-numeric: tabular-nums;
}
.leaderboard-table tbody tr > * {
  background: #dff5ff;
}
.leaderboard-table tbody tr:nth-child(even) > * {
  background: #f0faff;
}
.leaderboard-table tbody tr:nth-child(1) > * {
  background: linear-gradient(#fff6aa, #ffe36c);
}
.leaderboard-table tbody tr:nth-child(2) > * {
  background: linear-gradient(#edf5ff, #c9dbf5);
}
.leaderboard-table tbody tr:nth-child(3) > * {
  background: linear-gradient(#ffebd1, #f9c8a7);
}
.rank-badge {
  display: inline-grid;
  place-items: center;
  min-width: 1.75em;
  height: 1.38em;
  border-radius: 0.45em;
  background: linear-gradient(#129aff, #0054bf);
  box-shadow: 0 2px 0 #003a86;
  color: #fff;
  font-size: 0.88em;
}
.leaderboard-table tr:nth-child(-n + 3) .rank-badge {
  border-radius: 50%;
  height: 1.65em;
  min-width: 1.65em;
  color: #513002;
  background: linear-gradient(#fffec4, #eab42e);
  box-shadow: 0 1px 0 2px #c69015;
}
.leaderboard-table tr:nth-child(2) .rank-badge {
  background: linear-gradient(#fff, #b0c4df);
  box-shadow: 0 1px 0 2px #87a0be;
}
.leaderboard-table tr:nth-child(3) .rank-badge {
  background: linear-gradient(#ffdeb9, #d79a56);
  box-shadow: 0 1px 0 2px #ac7038;
}
.leaderboard-table tbody .is-you > * {
  background: #ffec63 !important;
  box-shadow:
    inset 0 2px #007cd2,
    inset 0 -2px #007cd2;
}
.leaderboard-table small {
  font-size: 11px;
  background: #005cab;
  color: #fff;
  padding: 2px 5px;
  border-radius: 5px;
  margin-left: 6px;
  vertical-align: middle;
}

.leaderboard-your-rank {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-top: 8px;
  padding: 7px 14px;
  border: 2px solid #0079c5;
  border-radius: 12px;
  background: #fff5a5;
  font-size: clamp(14px, 1.3vw, 18px);
  font-weight: 900;
  flex-shrink: 0;
}
.leaderboard-your-rank[hidden] {
  display: none;
}
.leaderboard-your-rank span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-state {
  margin: 8px 0 0;
  color: #2c628c;
  text-align: center;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.3;
  flex-shrink: 0;
}

.leaderboard-navigation {
  grid-column: 1;
  grid-row: 1;
  align-self: end;
  justify-self: center;
  width: min(100%, 360px);
  margin-bottom: clamp(16px, 5vh, 52px);
  display: grid;
  gap: 10px;
}
.leaderboard-navigation .gold-button,
.leaderboard-navigation .blue-button {
  width: 100%;
  margin: 0;
  min-height: 50px;
  padding: 11px 16px;
  font-size: clamp(15px, 1.45vw, 18px);
}
.leaderboard-loss-actions {
  display: grid;
  gap: 10px;
}
.leaderboard-loss-actions[hidden],
.leaderboard-navigation button[hidden] {
  display: none;
}
.leaderboard-navigation button:focus-visible,
.leaderboard-tools button:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
}

@media (max-aspect-ratio: 1/1) {
  .leaderboard-frame {
    background-image: url("assets/leaderboard/mobile.webp");
    background-position: center top;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    padding: max(16px, calc(10px + env(safe-area-inset-top)))
      max(14px, calc(10px + env(safe-area-inset-right)))
      max(16px, calc(12px + env(safe-area-inset-bottom)))
      max(14px, calc(10px + env(safe-area-inset-left)));
  }
  .leaderboard-tools {
    top: max(12px, calc(8px + env(safe-area-inset-top)));
    left: max(12px, calc(8px + env(safe-area-inset-left)));
    gap: 8px;
  }
  .leaderboard-tool-btn {
    min-height: 36px;
    padding: 0 11px;
    font-size: 13px;
  }
  .leaderboard-close-btn {
    width: 36px;
    padding: 0;
    font-size: 24px;
  }
  .leaderboard-card {
    width: min(100%, 440px);
    max-height: 62dvh;
    margin-top: auto;
    padding: 12px 12px 10px;
    border-radius: 22px;
    border-width: 3px;
    box-shadow:
      0 0 0 3px #0657c7,
      0 14px 36px rgba(0, 28, 76, 0.42);
  }
  .leaderboard-header {
    gap: 4px;
    margin-bottom: 8px;
  }
  .leaderboard-trophy {
    width: 26px;
    height: 26px;
  }
  .leaderboard-title {
    font-size: 22px;
  }
  .leaderboard-badge {
    font-size: 11px;
    padding: 2px 14px;
  }
  .leaderboard-table {
    font-size: clamp(13px, 3.6vw, 16px);
    border-spacing: 0 3px;
  }
  .leaderboard-table th,
  .leaderboard-table td {
    padding: 3px 8px;
  }
  .leaderboard-table thead th {
    padding-block: 6px;
  }
  .leaderboard-table th:first-child,
  .leaderboard-table td:first-child {
    width: 18%;
  }
  .leaderboard-table th:last-child,
  .leaderboard-table td:last-child {
    width: 32%;
  }
  .leaderboard-table small {
    font-size: 9px;
    padding: 1px 4px;
    margin-left: 4px;
  }
  .leaderboard-your-rank {
    margin-top: 6px;
    padding: 5px 10px;
    font-size: 13px;
  }
  .leaderboard-state {
    margin-top: 6px;
    font-size: 12px;
  }
  .leaderboard-navigation {
    align-self: center;
    width: min(100%, 440px);
    margin-bottom: 0;
    flex-shrink: 0;
  }
  .leaderboard-navigation .gold-button,
  .leaderboard-navigation .blue-button {
    min-height: 46px;
    padding: 9px 14px;
    font-size: 15px;
  }
  .leaderboard-loss-actions {
    gap: 8px;
  }
  .leaderboard-dialog[data-context="loss"] .leaderboard-card {
    max-height: 52dvh;
  }
  .leaderboard-dialog[data-context="loss"] .leaderboard-navigation .gold-button,
  .leaderboard-dialog[data-context="loss"]
    .leaderboard-navigation
    .blue-button {
    min-height: 42px;
    padding: 7px 12px;
    font-size: 14px;
  }
}

/* Prevent focus restoration after a dialog from scrolling the fixed ending. */
.vacation-scene {
  overflow: clip;
}
