/* ===== Leaderboard panel — slide-in drawer on the right, mirrors
   games-nav.css's left-side drawer (same fixed-overlay approach, same
   deliberate break from each game's own theme into Super Labs' own clean
   neutral look) so the two feel like one system on opposite edges. */

.lb-panel-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 1300;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease-out;
}

.lb-panel-backdrop.visible {
  opacity: 1;
  pointer-events: auto;
}

.lb-panel {
  --lb-bg: #f5f6f8;
  --lb-bg-alt: #eef0f4;
  --lb-fg: #1a1a1a;
  --lb-muted: #6b7280;
  --lb-border: #e2e5eb;
  --lb-accent: #3b82f6;

  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: min(380px, 90vw);
  background: var(--lb-bg);
  color: var(--lb-fg);
  border-left: 1px solid var(--lb-border);
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.18);
  z-index: 1400;
  transform: translateX(100%);
  transition: transform 220ms cubic-bezier(0.2, 0.85, 0.24, 1.04);
  display: flex;
  flex-direction: column;
  padding: 20px;
  gap: 14px;
  overflow-y: auto;
  font-family: "Inter", "SF Pro Display", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  .lb-panel {
    --lb-bg: #0f0f0f;
    --lb-bg-alt: #1a1a1a;
    --lb-fg: #f5f6f8;
    --lb-muted: #9ca3af;
    --lb-border: #2d2d2d;
    --lb-accent: #60a5fa;
  }
}

.lb-panel.open {
  transform: translateX(0);
}

.lb-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.lb-panel-header-title {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.lb-panel-title {
  font-size: 15px;
  font-weight: 700;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-panel-back {
  background: none;
  border: none;
  color: var(--lb-muted);
  cursor: pointer;
  padding: 4px;
  display: flex;
  flex-shrink: 0;
  border-radius: 8px;
}

/*
 * Every leaderboard entry point, forced to obey its own `hidden` attribute.
 *
 * This is the bug that leaked the feature. The buttons are `hidden` in the
 * markup and revealed by leaderboard-panel.js only once isEnabled() says so
 * — but each one also carries a game's own chrome class (.fullscreen-toggle,
 * .jd-header-menu-item, .jd-btn, .bx-btn, .btn) and every one of those
 * declares a `display`. An author rule beats the browser's built-in
 * `[hidden] { display: none }` no matter how specific either is, so the
 * attribute did nothing and a dark-launched feature drew a trophy on four
 * public games — an inert one, since the script had returned early and
 * never bound a click handler.
 *
 * Listed by id as well as class because the ids are the same in all four
 * games, and a blanket `[hidden]` rule in a file this widely included would
 * be reaching well past the leaderboard.
 */
.lb-panel-toggle[hidden],
#leaderboard-panel-toggle[hidden],
#header-menu-leaderboard[hidden],
#link-leaderboard[hidden],
#btn-save-progress[hidden] {
  display: none !important;
}

/* display:flex above beats the browser's default [hidden]{display:none} rule
   (same specificity, author origin wins) — restore it explicitly so the JS
   toggling the `hidden` attribute (list view vs. player-profile view) works. */
.lb-panel-back[hidden] {
  display: none;
}

.lb-panel-back:hover {
  background: var(--lb-bg-alt);
  color: var(--lb-fg);
}

.lb-panel-close {
  background: none;
  border: none;
  color: var(--lb-muted);
  cursor: pointer;
  padding: 4px;
  display: flex;
  border-radius: 8px;
}

.lb-panel-close:hover {
  background: var(--lb-bg-alt);
  color: var(--lb-fg);
}

.lb-panel-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.lb-panel-tab {
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--lb-border);
  background: transparent;
  color: var(--lb-muted);
  cursor: pointer;
}

.lb-panel-tab.is-active {
  background: var(--lb-fg);
  color: var(--lb-bg);
  border-color: transparent;
}

.lb-panel-list {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--lb-border);
  border-radius: 12px;
  overflow: hidden;
}

.lb-panel-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--lb-border);
  font-size: 13px;
  width: 100%;
  font-family: inherit;
  color: inherit;
  background: none;
  border-left: none;
  border-right: none;
  border-top: none;
  text-align: left;
  cursor: pointer;
}

.lb-panel-row:hover {
  background: var(--lb-bg-alt);
}

.lb-panel-row-static {
  cursor: default;
}

.lb-panel-row-static:hover {
  background: none;
}

.lb-panel-row:last-child {
  border-bottom: none;
}

.lb-panel-row.is-me {
  background: color-mix(in srgb, var(--lb-accent) 14%, transparent);
}

.lb-panel-row.is-me:hover {
  background: color-mix(in srgb, var(--lb-accent) 22%, transparent);
}

.lb-panel-rank {
  color: var(--lb-muted);
  width: 22px;
  flex-shrink: 0;
}

.lb-panel-row-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
}

.lb-panel-row-avatar-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
}

.lb-panel-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-panel-value {
  font-weight: 700;
  flex-shrink: 0;
}

.lb-panel-status {
  color: var(--lb-muted);
  font-size: 13px;
  padding: 16px 4px;
  text-align: center;
}

.lb-panel-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 28px 12px;
  text-align: center;
}

.lb-panel-empty p {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

.lb-panel-empty-sub {
  color: var(--lb-muted);
  font-size: 12px;
  font-weight: 500 !important;
  margin-bottom: 6px !important;
}

.lb-panel-play-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 8px;
  padding: 10px 22px;
  border: none;
  border-radius: 999px;
  background: var(--lb-accent);
  color: #fff;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.lb-panel-play-btn:hover {
  filter: brightness(1.08);
}

.lb-panel-play-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.lb-panel-add-friend-btn {
  margin: 12px auto 0;
}

/* Secondary action — same pill shape as .lb-panel-play-btn, muted instead
   of accent-filled so it doesn't compete with "Add Friend". */
.lb-panel-share-profile-btn {
  display: flex;
  margin: 10px auto 0;
  background: var(--lb-bg-alt);
  color: var(--lb-fg);
  border: 1px solid var(--lb-border);
}

.lb-panel-share-profile-btn:hover {
  filter: none;
  border-color: var(--lb-accent);
}

/* ===== Profile view header — avatar, name, rank, shown above the per-game
   list whether viewing your own profile (via the Me card) or another
   player's (via tapping their leaderboard row). */

.lb-panel-profile-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 4px;
  padding: 8px 4px 20px;
}

.lb-panel-profile-header .lb-panel-me-avatar {
  width: 88px;
  height: 88px;
  margin-bottom: 10px;
}

.lb-panel-profile-header .lb-panel-me-avatar-fallback {
  font-size: 34px;
}

.lb-panel-profile-header-info {
  min-width: 0;
  max-width: 100%;
}

.lb-panel-profile-header-name {
  font-size: 19px;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-panel-profile-header-rank {
  margin-top: 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--lb-accent);
}

/* ===== "Me" section — sign in / account summary, sits between the header
   and the game tabs. */

.lb-panel-me:empty {
  display: none;
}

.lb-panel-me-prompt {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--lb-muted);
}

.lb-panel-me-error {
  margin: 0 0 8px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  color: #b91c1c;
  background: color-mix(in srgb, #ef4444 14%, transparent);
}

@media (prefers-color-scheme: dark) {
  .lb-panel-me-error {
    color: #fca5a5;
  }
}

.lb-panel-me-providers {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lb-panel-provider-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 14px;
  border: 1px solid var(--lb-border);
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--lb-fg);
  text-decoration: none;
  background: var(--lb-bg-alt);
}

.lb-panel-provider-btn:hover {
  filter: brightness(1.05);
}

.lb-panel-me-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.lb-panel-me-row + .lb-panel-me-row {
  margin-top: 4px;
}

.lb-panel-me-code {
  font-family: inherit;
  border: none;
  background: none;
  color: var(--lb-fg);
  cursor: pointer;
  padding: 0;
  text-align: left;
}

/* ===== Larger tappable profile card — avatar, name, rank. Opens the same
   profile view used for any other player's row. */

.lb-panel-me-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 2px;
  width: 100%;
  padding: 14px 6px 10px;
  margin: -6px -6px 4px;
  border: none;
  border-radius: 12px;
  background: none;
  cursor: pointer;
  font-family: inherit;
  color: inherit;
}

.lb-panel-me-card:hover,
.lb-panel-me-card:focus-visible {
  background: var(--lb-bg-alt);
  outline: none;
}

.lb-panel-me-avatar {
  flex-shrink: 0;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  margin-bottom: 8px;
}

.lb-panel-me-avatar-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 25px;
  font-weight: 700;
}

.lb-panel-me-info {
  min-width: 0;
  max-width: 100%;
}

.lb-panel-me-name-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.lb-panel-me-name-text {
  font-size: 16px;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.lb-panel-me-edit {
  flex-shrink: 0;
  border: none;
  background: none;
  color: var(--lb-muted);
  cursor: pointer;
  padding: 3px;
  display: flex;
  border-radius: 6px;
}

.lb-panel-me-edit:hover {
  background: var(--lb-border);
  color: var(--lb-fg);
}

.lb-panel-me-rank {
  display: block;
  margin-top: 3px;
  font-size: 12px;
  font-weight: 600;
  color: var(--lb-accent);
}

.lb-panel-me-code {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--lb-muted);
  flex-shrink: 0;
}

.lb-panel-me-code svg {
  flex-shrink: 0;
  opacity: 0.7;
}

.lb-panel-me-code:hover {
  color: var(--lb-fg);
}

.lb-panel-me-code:hover svg {
  opacity: 1;
}

.lb-panel-me-actions {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 6px;
}

.lb-panel-me-friends,
.lb-panel-me-signout {
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  border: none;
  background: none;
  color: var(--lb-muted);
  padding: 0;
  cursor: pointer;
}

.lb-panel-me-friends:hover,
.lb-panel-me-signout:hover {
  color: var(--lb-fg);
}

/* ===== Global/Friends scope toggle */

.lb-panel-scope-toggle {
  display: flex;
  gap: 6px;
}

.lb-panel-scope-toggle[hidden] {
  display: none;
}

.lb-panel-scope-btn {
  flex: 1;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--lb-border);
  background: transparent;
  color: var(--lb-muted);
  cursor: pointer;
}

.lb-panel-scope-btn.is-active {
  background: var(--lb-bg-alt);
  color: var(--lb-fg);
  border-color: var(--lb-accent);
}

/* ===== Friends management view (add by code, list with remove) */

.lb-panel-friends-add {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.lb-panel-friends-input {
  flex: 1;
  min-width: 0;
  font-family: inherit;
  font-size: 13px;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--lb-border);
  background: var(--lb-bg-alt);
  color: var(--lb-fg);
}

.lb-panel-friends-add-btn {
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  padding: 0 16px;
  border: none;
  border-radius: 8px;
  background: var(--lb-accent);
  color: #fff;
  cursor: pointer;
}

.lb-panel-friends-add-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.lb-panel-friend-remove {
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  border: none;
  background: none;
  color: var(--lb-muted);
  cursor: pointer;
  padding: 4px 0;
  flex-shrink: 0;
}

.lb-panel-friend-remove:hover {
  color: var(--lb-accent);
}

/* Trigger button — reuses each game's own .fullscreen-toggle class for its
   visual chrome (size/color/border/shadow), so only the stacked position
   needs a per-game override (see each game's own css/main.css — button
   sizes and gutter spacing differ per game, so one shared top: value here
   wouldn't line up in all four). */

/* While the panel is open, fade out every floating corner button (fullscreen,
   leaderboard trigger, "more games") rather than relying on the panel's
   z-index to visually cover them — the panel is only min(380px, 90vw) wide,
   and during its slide-in transition a button underneath would otherwise be
   visible for a moment. body.lb-panel-open is toggled in leaderboard-panel.js. */
body.lb-panel-open .fullscreen-toggle,
body.lb-panel-open .games-nav-toggle {
  opacity: 0;
  pointer-events: none;
  transition: opacity 150ms ease;
}

/* ===== Sign-in overlay — centered modal from the game-over "Save
   progress" button. A separate, focused surface rather than opening the
   side panel: at that moment there's exactly one decision to make (sign
   in or not), so the panel's tabs/list would just compete for attention. */

.lb-signin-overlay {
  --lb-bg: #f5f6f8;
  --lb-bg-alt: #eef0f4;
  --lb-fg: #1a1a1a;
  --lb-muted: #6b7280;
  --lb-border: #e2e5eb;
  --lb-accent: #3b82f6;

  position: fixed;
  inset: 0;
  z-index: 1600;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease-out;
  font-family: "Inter", "SF Pro Display", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  .lb-signin-overlay {
    --lb-bg: #171717;
    --lb-bg-alt: #232323;
    --lb-fg: #f5f6f8;
    --lb-muted: #9ca3af;
    --lb-border: #2d2d2d;
    --lb-accent: #60a5fa;
  }
}

.lb-signin-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.lb-signin-card {
  position: relative;
  width: min(340px, 100%);
  background: var(--lb-bg);
  color: var(--lb-fg);
  border-radius: 22px;
  padding: 36px 26px 26px;
  text-align: center;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.35);
  transform: scale(0.94);
  transition: transform 220ms cubic-bezier(0.2, 0.85, 0.24, 1.04);
}

.lb-signin-overlay.open .lb-signin-card {
  transform: scale(1);
}

.lb-signin-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: none;
  border: none;
  color: var(--lb-muted);
  cursor: pointer;
  padding: 6px;
  display: flex;
  border-radius: 8px;
}

.lb-signin-close:hover {
  background: var(--lb-bg-alt);
  color: var(--lb-fg);
}

.lb-signin-logo {
  color: var(--lb-fg);
  margin-bottom: 14px;
}

.lb-signin-title {
  margin: 0 0 8px;
  font-size: 20px;
  font-weight: 800;
}

.lb-signin-copy {
  margin: 0 0 22px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--lb-muted);
}

.lb-signin-providers {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lb-signin-later {
  display: block;
  margin: 18px auto 0;
  background: none;
  border: none;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--lb-muted);
  cursor: pointer;
  padding: 4px;
}

.lb-signin-later:hover {
  color: var(--lb-fg);
}

/* ===== Profile — full-page overlay (not nested in the side panel). Bigger
   than the sign-in card, closer to a full-screen sheet on mobile via the
   96vw/92vh clamp, a large centered card on desktop. */

.lb-profile-overlay {
  --lb-bg: #f5f6f8;
  --lb-bg-alt: #eef0f4;
  --lb-fg: #1a1a1a;
  --lb-muted: #6b7280;
  --lb-border: #e2e5eb;
  --lb-accent: #3b82f6;

  position: fixed;
  inset: 0;
  z-index: 1700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease-out;
  font-family: "Inter", "SF Pro Display", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  .lb-profile-overlay {
    --lb-bg: #0f0f0f;
    --lb-bg-alt: #1a1a1a;
    --lb-fg: #f5f6f8;
    --lb-muted: #9ca3af;
    --lb-border: #2d2d2d;
    --lb-accent: #60a5fa;
  }
}

.lb-profile-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.lb-profile-card {
  position: relative;
  width: min(440px, 96vw);
  max-height: min(720px, 92vh);
  overflow-y: auto;
  background: var(--lb-bg);
  color: var(--lb-fg);
  border-radius: 22px;
  padding: 40px 24px 24px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.35);
  transform: scale(0.96);
  transition: transform 200ms cubic-bezier(0.2, 0.85, 0.24, 1.04);
}

.lb-profile-overlay.open .lb-profile-card {
  transform: scale(1);
}

.lb-profile-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: none;
  border: none;
  color: var(--lb-muted);
  cursor: pointer;
  padding: 6px;
  display: flex;
  border-radius: 8px;
}

.lb-profile-close:hover {
  background: var(--lb-bg-alt);
  color: var(--lb-fg);
}

.lb-profile-avatar-btn {
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
  border-radius: 50%;
  position: relative;
}

.lb-profile-avatar-btn::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.35);
  opacity: 0;
  transition: opacity 120ms ease;
}

.lb-profile-avatar-btn:hover::after {
  opacity: 1;
}

.lb-profile-avatar-static {
  display: contents;
}

/* Per-game rows are now links (tap the game to go play it) — reset the
   default <a> underline/color so they read as leaderboard rows, not text
   links, and add a small app icon before the name. */
.lb-panel-game-row {
  text-decoration: none;
}

.lb-panel-game-icon {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  flex-shrink: 0;
  margin-right: 2px;
}

.lb-profile-own-actions {
  margin-top: 14px;
}

/* ===== Avatar picker — reuses .lb-signin-overlay's centered-modal chrome,
   stacked above the profile overlay since it opens from within it. */

.lb-avatar-picker-overlay {
  z-index: 1800;
}

.lb-avatar-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.lb-avatar-option {
  border: 2px solid var(--lb-border);
  background: var(--lb-bg-alt);
  border-radius: 14px;
  padding: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lb-avatar-option:hover {
  border-color: var(--lb-accent);
}

.lb-avatar-option img {
  width: 100%;
  height: auto;
  border-radius: 50%;
}

.lb-avatar-shuffle-btn {
  width: 100%;
  background: var(--lb-bg-alt);
  color: var(--lb-fg);
  border: 1px solid var(--lb-border);
}

.lb-avatar-shuffle-btn:hover {
  filter: none;
  border-color: var(--lb-accent);
}
