/* ---------- 🏆 Leaderboard: the Writing Desk look (docs/DESIGN.md, css/desk.css) ----------
   Header: a soft Home button, the 排 brush title and the 🏠 / 🌍 switch. One row of board chips.
   Then 我 Your place (your buddy, rank, who to pass, Brain level bar, Practice ▶) on the left, and the
   podium plus the kids near you on the right. Upright iPads and phones stack them, Your place first.
   The rows shown are js/progress.js's (bots and the 🌍 "around you" rules included); this file is only the look.
   Some css/glow.css rules still name #leaderboard (the shared Ink Pop header, chips and buttons), so a few
   rules here start with #leaderboard to win over them. */
#leaderboard.desk-screen {
  background-color: var(--a-bg);
  background-image: linear-gradient(var(--a-grid) 1.5px, transparent 1.5px), linear-gradient(90deg, var(--a-grid) 1.5px, transparent 1.5px);
  background-size: 84px 84px; background-position: 0 0; color: var(--a-fg);
  --lb-gut: max(26px, env(safe-area-inset-left), env(safe-area-inset-right));
}

/* ---- header ---- */
#leaderboard .game-head {
  flex-wrap: wrap; gap: 12px 16px; width: 100%; max-width: 1360px; margin: 0 auto; box-sizing: border-box;
  padding: max(16px, env(safe-area-inset-top)) var(--lb-gut) 8px;
}
#leaderboard .game-head .icon-btn {
  width: 52px; height: 52px; border: 0; background: var(--a-card); color: var(--a-fg); box-shadow: var(--a-sh);
}
#leaderboard .game-head .icon-btn:active { transform: translateY(2px); box-shadow: var(--a-sh-sm); }
#leaderboard .game-head .icon-btn svg.ic { width: 26px; height: 26px; }
#leaderboard .screen-title { font-size: 40px; gap: 12px; color: var(--a-fg); }
#leaderboard .screen-title .dk-hz { font-size: 44px; }
#leaderboard .lb-scope { margin: 0 0 0 auto; width: auto; border: 0; }
#leaderboard .lb-scope button { flex: none; font-size: 16px; padding: 0 18px; min-height: 44px; }
#leaderboard .lb-scope button.on { box-shadow: none; }

/* ---- body ---- */
#leaderboard .lb-body {
  gap: 14px; padding: 4px var(--lb-gut) max(26px, env(safe-area-inset-bottom));
  width: 100%; max-width: 1360px; margin: 0 auto; box-sizing: border-box;
}

/* the seven boards: one row that fits an iPad held sideways; narrower screens slide it sideways */
#leaderboard #lb-tabs {
  display: flex; flex-wrap: nowrap; justify-content: space-between; gap: 8px; align-self: stretch;
  margin: 0 calc(-1 * var(--lb-gut)); padding: 4px var(--lb-gut) 10px;
  background: none; border: 0; border-radius: 0; box-shadow: none;
  overflow-x: auto; scrollbar-width: none; overscroll-behavior-x: contain;
}
#leaderboard #lb-tabs::-webkit-scrollbar { display: none; }
#leaderboard #lb-tabs .dk-chip { padding: 0 14px; }

.lb-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; }
@media (min-width: 900px), (orientation: landscape) and (min-width: 700px) {
  .lb-grid { grid-template-columns: minmax(300px, 440px) minmax(0, 1fr); gap: 24px; }
}
.lb-side { display: grid; gap: 16px; min-width: 0; }

/* ---- 我 Your place ---- */
.lb-me { padding: 26px 28px; display: grid; gap: 16px; align-content: start; min-width: 0; }
.lb-me-top { display: flex; align-items: center; gap: 20px; min-width: 0; }
.lb-me-face {
  width: 120px; height: 120px; flex: none; border-radius: 30px; background: var(--a-test-bg);
  display: grid; place-items: center;
}
.lb-me-face svg.buddy { width: 88px; height: 88px; }
.lb-me-rank { display: grid; gap: 4px; min-width: 0; }
.lb-me-rank strong { font: 400 66px/1 var(--f-display); color: var(--a-fg); }
.lb-me-rank span { font-weight: 900; font-size: 18px; color: var(--a-mute); }
#leaderboard .lb-race {
  margin: 0; padding: 0; width: auto; text-align: left; background: none; border: 0; box-shadow: none;
  font-weight: 900; font-size: 22px; line-height: 1.3; color: var(--a-fg); text-wrap: balance;
}
#leaderboard .lb-race b { color: var(--a-fg); }
.lb-race .lb-place { display: none; }   /* the big #13 above already says it */
#leaderboard .lb-race .lb-up { display: block; color: var(--a-ok); font-size: 17px; margin-bottom: 4px; }
.lb-me-xp { display: grid; gap: 8px; }
.lb-me-xp[hidden] { display: none; }
.lb-me-xp-t { display: flex; justify-content: space-between; gap: 12px; font-weight: 800; font-size: 16px; color: var(--a-mute); }
.lb-go { justify-self: start; }
.lb-champ-card {
  margin-top: 4px; padding: 14px 16px; border-radius: 16px; background: var(--a-env-bg);
  font-weight: 800; font-size: 15px; line-height: 1.45; color: var(--a-fg);
}
.lb-champ-card[hidden] { display: none; }
.lb-champ-card .lb-champ, .lb-champ-card .lb-hall { display: block; margin: 0; font-size: 15px; }
.lb-champ-card .lb-hall { margin-top: 6px; color: #8a5a00; }

/* ---- 🟢 Online now (🌍 Everyone) ---- */
#leaderboard .lb-online { width: auto; margin: 0; padding: 18px 20px 12px; background: var(--a-card); border-radius: 20px; box-shadow: var(--a-sh); min-width: 0; }
#leaderboard .lb-online[hidden] { display: none; }
#leaderboard .lb-online h3 { font-size: 22px; flex-wrap: wrap; }
#leaderboard .lb-online h3 small { color: var(--a-mute); font-size: 15px; }
#leaderboard .lb-online-kid { border: 0; box-shadow: none; background: var(--a-word-bg); border-radius: 16px; }
#leaderboard .lb-online-kid b { font-size: 20px; }
#leaderboard .lb-duel-btn { border: 0; min-height: 44px; padding: 0 16px; background: var(--a-fg); box-shadow: none; }
#leaderboard .lb-duel-btn:active { transform: translateY(2px); box-shadow: none; }
#leaderboard .lb-online-none { color: var(--a-mute); font-size: 16px; padding-bottom: 6px; }

/* ---- the board: podium, then the kids near you ---- */
.lb-board { padding: 22px 26px 24px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
#leaderboard .lb-note { text-align: center; margin: 24px auto; width: min(460px, 100%); }
#leaderboard .lb-note[hidden] { display: none; }
#leaderboard .lb-note p { font-weight: 800; color: var(--a-mute); font-size: 18px; margin: 0 0 14px; }
#leaderboard .lb-note .big-btn {
  display: inline-flex; align-items: center; justify-content: center; width: auto; min-height: 52px; padding: 0 28px;
  border: 0; border-radius: 16px; background: var(--a-fg); color: #fff; box-shadow: none; font: 900 18px/1 var(--f-body);
}
#leaderboard .lb-note .big-btn:active { transform: translateY(2px); box-shadow: none; }
#leaderboard .lb-empty { text-align: center; font-weight: 800; color: var(--a-mute); font-size: 18px; margin: 24px 0; }
#leaderboard .lb-empty[hidden] { display: none; }

#leaderboard .lb-podium { display: flex; align-items: flex-end; justify-content: center; gap: 14px; width: 100%; margin: 22px 0 8px; }
#leaderboard .lb-podium[hidden] { display: none; }
#leaderboard .lb-step { flex: 1 1 0; max-width: 180px; min-width: 0; display: flex; flex-direction: column; align-items: center; }
#leaderboard .lb-who { display: flex; flex-direction: column; align-items: center; gap: 2px; margin-bottom: 8px; min-width: 0; max-width: 100%; }
#leaderboard .lb-who .lb-face {
  position: relative; width: 66px; height: 66px; border: 0; border-radius: 50%; background: none; box-shadow: none;
  display: grid; place-items: center;
}
#leaderboard .lb-who .lb-face svg.buddy { width: 60px; height: 60px; }
#leaderboard .lb-step.p1 .lb-face { width: 80px; height: 80px; }
#leaderboard .lb-step.p1 .lb-face svg.buddy { width: 74px; height: 74px; }
#leaderboard .lb-step.me .lb-face { background: var(--a-test-bg); box-shadow: 0 0 0 3px var(--a-go); }
/* the winner's crown sits on the corner like a badge, so it never covers the hat a buddy is wearing */
#leaderboard .lb-crown { position: absolute; top: -6px; left: -16px; translate: none; rotate: -24deg; width: 36px; height: 25px; z-index: 1; }
#leaderboard .lb-who b { font: 900 19px/1.2 var(--f-body); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#leaderboard .lb-who .lb-val { font-weight: 800; font-size: 15px; color: var(--a-mute); white-space: nowrap; }
#leaderboard .lb-who .lb-val strong { font: inherit; color: inherit; margin: 0; }
#leaderboard .lb-block {
  width: 100%; border: 0; border-radius: 18px 18px 8px 8px; padding: 0; box-shadow: inset 0 2px 0 rgba(255, 255, 255, .55);
  display: grid; place-items: center; font: 400 44px/1 var(--f-display); text-shadow: none; -webkit-text-stroke: 0;
}
#leaderboard .lb-step.p1 .lb-block { height: 150px; background: linear-gradient(#ffe066, #f5a623); color: #8a5a00; font-size: 52px; }
#leaderboard .lb-step.p2 .lb-block { height: 110px; background: linear-gradient(#f1f4f8, #b3bdcb); color: #5a6577; }
#leaderboard .lb-step.p3 .lb-block { height: 84px; background: linear-gradient(#f3b27a, #c06a32); color: #6b3a10; font-size: 40px; }
#leaderboard .lb-podium-base { display: none; }

#leaderboard .lb-near { margin: 8px 0 2px; }
#leaderboard .lb-near[hidden] { display: none; }
#leaderboard .lb-rows { display: flex; flex-direction: column; gap: 8px; width: auto; margin: 0; }
#leaderboard .lb-row {
  display: grid; grid-template-columns: 40px 46px minmax(0, 1fr) auto; align-items: center; gap: 12px;
  min-height: 60px; padding: 6px 16px; border: 0; border-radius: 16px; background: var(--a-word-bg); box-shadow: none;
}
#leaderboard .lb-row.me { background: var(--a-test-bg); box-shadow: 0 0 0 3px var(--a-go); }
#leaderboard .lb-rank { font: 400 24px/1 var(--f-display); color: var(--a-mute); text-align: center; }
#leaderboard .lb-avatar { display: grid; place-items: center; font-size: 34px; }
#leaderboard .lb-avatar svg.buddy { width: 44px; height: 44px; }
#leaderboard .lb-name { font: 900 19px/1.2 var(--f-body); color: var(--a-fg); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#leaderboard .lb-name small { font: 800 15px/1 var(--f-body); }
#leaderboard .lb-value { font: 900 16px/1.2 var(--f-body); color: var(--c-write); white-space: nowrap; }
#leaderboard .lb-value strong { font-weight: 900; }
#leaderboard .lb-gap { text-align: center; font-weight: 900; font-size: 16px; color: var(--a-mute); letter-spacing: 1px; padding: 2px 0; }
/* 🤖 practice players, grayed out for developer accounts only (js/board.js) */
#leaderboard .lb-row.bot, #leaderboard .lb-step.bot .lb-who { opacity: .45; filter: grayscale(1); }

/* ---- phones and other narrow screens: the switch goes under the title ---- */
@media (max-width: 699px) {
  #leaderboard.desk-screen { --lb-gut: max(16px, env(safe-area-inset-left), env(safe-area-inset-right)); }
  #leaderboard .screen-title { font-size: 32px; }
  #leaderboard .screen-title .dk-hz { font-size: 36px; }
  #leaderboard .lb-scope { flex: 1 0 100%; margin: 0; display: flex; }
  #leaderboard .lb-scope button { flex: 1 1 0; padding: 0 10px; }
  .lb-me { padding: 20px; gap: 14px; }
  .lb-me-face { width: 88px; height: 88px; border-radius: 24px; }
  .lb-me-face svg.buddy { width: 66px; height: 66px; }
  .lb-me-rank strong { font-size: 52px; }
  #leaderboard .lb-race { font-size: 19px; }
  .lb-board { padding: 18px 16px 20px; }
  #leaderboard .lb-podium { gap: 8px; }
  #leaderboard .lb-step.p1 .lb-block { height: 112px; font-size: 44px; }
  #leaderboard .lb-step.p2 .lb-block { height: 82px; font-size: 38px; }
  #leaderboard .lb-step.p3 .lb-block { height: 62px; font-size: 34px; }
  #leaderboard .lb-who b { font-size: 17px; }
  #leaderboard .lb-row { grid-template-columns: 32px 40px minmax(0, 1fr) auto; gap: 10px; padding: 6px 12px; }
  #leaderboard .lb-avatar svg.buddy { width: 38px; height: 38px; }
  #leaderboard .lb-name { font-size: 17px; }
}
/* short screens (a phone held sideways): smaller pieces so Practice ▶ stays in view */
@media (max-height: 500px) {
  #leaderboard .game-head { padding-top: max(8px, env(safe-area-inset-top)); padding-bottom: 4px; }
  #leaderboard .screen-title { font-size: 30px; }
  #leaderboard .screen-title .dk-hz { font-size: 34px; }
  #leaderboard .game-head .icon-btn { width: 46px; height: 46px; }
  #leaderboard .lb-body { gap: 8px; }
  #leaderboard #lb-tabs { padding-bottom: 6px; }
  .lb-me { padding: 16px 20px; gap: 10px; }
  .lb-me > .dk-label { display: none; }   /* the big rank says it; keeps Practice ▶ above the fold */
  .lb-me-face { width: 64px; height: 64px; border-radius: 18px; }
  .lb-me-face svg.buddy { width: 48px; height: 48px; }
  .lb-me-rank strong { font-size: 44px; }
  .lb-me-rank span { font-size: 15px; }
  #leaderboard .lb-race { font-size: 17px; }
  .lb-me-xp-t { font-size: 14px; }
  .lb-board { padding: 14px 18px 18px; }
  #leaderboard .lb-podium { margin-top: 18px; }
  #leaderboard .lb-who .lb-face, #leaderboard .lb-step.p1 .lb-face { width: 54px; height: 54px; }
  #leaderboard .lb-who .lb-face svg.buddy, #leaderboard .lb-step.p1 .lb-face svg.buddy { width: 50px; height: 50px; }
  #leaderboard .lb-step.p1 .lb-block { height: 86px; font-size: 40px; }
  #leaderboard .lb-step.p2 .lb-block { height: 64px; font-size: 34px; }
  #leaderboard .lb-step.p3 .lb-block { height: 50px; font-size: 30px; }
  #leaderboard .lb-who b { font-size: 16px; }
  #leaderboard .lb-row { min-height: 52px; }
}
