/* ===== Friends and profiles (js/friends.js) =====
   The profile card (tap a name on the leaderboard), and the Friends and Move to another device
   sections on My passport. Loaded by index.html and passport.html. */

/* ---- The card ---- */
.fr-overlay {
  z-index: 350;                       /* above the end-game modal and the leaderboard */
}

.fr-modal {
  position: relative;
  max-width: 400px;
  padding: 24px;
  text-align: left;
}

.fr-close {
  position: absolute;
  top: 12px;
  right: 12px;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  color: var(--text-secondary);
  background: none;
  border-radius: 50%;
}

.fr-title {
  margin: 0 0 16px;
  font-size: 20px;
  font-weight: 700;
}

.fr-status {
  margin: 24px 0;
  text-align: center;
  color: var(--text-secondary);
}

/* Avatars (the same look as My passport) */
.fr-modal .pp-avatar,
.fr-list .pp-avatar {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  font-weight: 700;
  color: #fff;
  background: var(--surface-2);
  border-radius: 50%;
}

.fr-modal .pp-avatar img,
.fr-list .pp-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.fr-modal .pp-avatar-none,
.fr-list .pp-avatar-none {
  background: var(--accent);
}

/* Head: avatar, name, country, playing since */
.fr-head {
  display: flex;
  align-items: center;
  gap: 16px;
  padding-right: 32px;               /* clear of the close button */
}

.fr-avatar {
  width: 80px;
  height: 80px;
  font-size: 34px;
}

.fr-who {
  min-width: 0;
}

.fr-name {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.fr-country,
.fr-since {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 4px 0 0;
  font-size: 14px;
  color: var(--text-secondary);
}

.fr-flag {
  flex: none;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.fr-heading {
  margin: 22px 0 8px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
}

.fr-note {
  margin: 16px 0 0;
  font-size: 14px;
  line-height: 1.45;
  color: var(--text-secondary);
}

.fr-heading + .fr-note {
  margin-top: 0;
}

.fr-center {
  text-align: center;
}

.fr-btn {
  display: inline-block;
  margin-top: 16px;
  text-decoration: none;
}

/* Today: your result and theirs side by side */
.fr-today {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.fr-today-col {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px;
  background: var(--surface-1);
  border-radius: var(--radius);
}

.fr-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fr-today-col strong {
  font-size: 22px;
  line-height: 1.2;
}

.fr-today-col span:last-child {
  font-size: 13px;
  color: var(--text-secondary);
}

.fr-result-none {
  padding: 6px 0;
}

/* Head to head: 3 - 2 */
.fr-h2h {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 12px;
  background: var(--surface-1);
  border-radius: var(--radius);
}

.fr-h2h > div:not(.fr-h2h-dash) {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  max-width: 40%;
}

.fr-h2h strong {
  font-size: 34px;
  line-height: 1.1;
}

.fr-h2h span {
  max-width: 100%;
  font-size: 13px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fr-h2h-dash {
  font-size: 28px;
  color: var(--text-muted);
}

.fr-foot {
  margin: 20px 0 0;
  padding-top: 14px;
  font-size: 13px;
  color: var(--text-secondary);
  border-top: 1px solid var(--surface-3);
}

.fr-link {
  padding: 0;
  font: inherit;
  font-weight: 600;
  color: var(--accent);
  background: none;
  border: none;
  cursor: pointer;
}

.fr-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

/* ---- Leaderboard: names open the card ---- */
.lb-name-btn {
  display: inline-flex;
  align-items: center;
  gap: 0;
  max-width: 100%;
  padding: 0;
  font: inherit;
  color: inherit;
  text-align: left;
  background: none;
  border: none;
  border-radius: 0;
  cursor: pointer;
}

@media (hover: hover) {
  .lb-name-btn:hover {
    text-decoration: underline;
    opacity: 1;
  }
}

.lb-friend-mark {
  flex: none;
  margin-left: 5px;
  vertical-align: -2px;
  fill: var(--accent);
}

/* ---- My passport: friends list ---- */
.fr-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px;
}

.fr-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px 8px 8px;
  font-size: 15px;
  font-weight: 600;
  text-align: left;
  background: var(--surface-1);
  border-radius: 999px;
}

.fr-row-avatar {
  width: 36px;
  height: 36px;
  font-size: 16px;
}

.fr-row-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Friend code, invite, add by code, and the move codes */
.fr-tools {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 16px;
}

.fr-tool {
  min-width: 0;                        /* lets the grid column shrink on small phones */
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  margin: 0;
  padding: 16px;
  background: var(--surface-1);
  border-radius: 12px;
}

.fr-tool-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.fr-code {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.08em;
  font-variant-numeric: tabular-nums;
}

.fr-tool-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  width: 100%;
}

.fr-tool input {
  flex: 1;
  min-width: 0;
  width: 100%;
  padding: 9px 12px;
  font: inherit;
  font-size: 14px;
  text-transform: uppercase;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-0);
}

.fr-tool input::placeholder {
  text-transform: none;
}

.fr-tool .pp-note,
.fr-tool .pp-error {
  margin: 0;
}

.fr-small {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  text-align: left;
}

/* "You're now friends with..." */
.pp-flash {
  margin: 0 0 12px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--good);
  background: var(--good-bg);
  border-radius: var(--radius);
  transition: opacity 0.4s ease;
}

.pp-flash.is-out {
  opacity: 0;
}

/* ---- Phones ---- */
@media (max-width: 900px) {
  .fr-tools {
    grid-template-columns: 1fr;
  }

  .fr-avatar {
    width: 64px;
    height: 64px;
    font-size: 28px;
  }

  .fr-name {
    font-size: 19px;
  }
}

/* ---- Leaderboard: All / Friends, ranks, and narrow screens ---- */
.lb-head {
  align-items: center;
  gap: 12px;
}

.lb-filter {
  display: inline-flex;
  flex: none;
  padding: 2px;
  background: var(--surface-2);
  border-radius: 999px;
}

.lb-filter-btn {
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  background: none;
  border-radius: 999px;
}

.lb-filter-btn[aria-pressed="true"] {
  color: var(--text-primary);
  background: var(--surface-0);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.lb-filter-btn:active {
  transform: none;
}

/* If a long name and a big rank don't fit, the table scrolls sideways rather than squashing */
.lb-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 12px 0 20px;
}

.lb-scroll .lb-table {
  margin: 0;
  min-width: 320px;
}

.lb-table td,
.lb-table th {
  white-space: nowrap;
}

.lb-rank {
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
}

/* Names take the room that's left, and are cut short with … rather than pushing the numbers off */
.lb-table .lb-player {
  width: 100%;
  max-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lb-player .lb-name-btn {
  display: inline;
}

.lb-table td:not(.lb-player) {
  font-variant-numeric: tabular-nums;
}

/* The gap between the leader and the players around you */
.lb-table tr.lb-gap td {
  padding: 2px 4px;
  font-size: 16px;
  line-height: 1;
  letter-spacing: 0.2em;
  text-align: center;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

/* Friends view: who's still to play */
.lb-waiting {
  margin: -8px 0 16px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-secondary);
}

.lb-waiting > span:first-child {
  font-weight: 600;
}
