:root {
     --bg: #0b0f14;
     --card: #0f172a;
     --muted: #94a3b8;
     --fg: #e5e7eb;
     --brand: #22c55e;
     --brand-600: #16a34a;
     --ring: rgba(34,197,94,0.35);
     --border: #1f2937;
     --shadow: 0 10px 30px rgba(0,0,0,.35);
}
 html[data-theme="light"] {
     --bg: #f7f8fb;
     --card: #ffffff;
     --muted: #6b7280;
     --fg: #0f172a;
     --brand: #16a34a;
     --brand-600: #15803d;
     --ring: rgba(22,163,74,0.25);
     --border: #e5e7eb;
     --shadow: 0 10px 30px rgba(2,6,23,.08);
}
 * {
     box-sizing: border-box;
}
 html, body {
     height: 100%;
}
 body {
     margin: 0;
     font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
     color: var(--fg);
     background: radial-gradient(1200px 600px at 20% -10%, rgba(34,197,94,.08), transparent 60%), radial-gradient(1000px 500px at 100% 0%, rgba(34,197,94,.06), transparent 50%), var(--bg);
}
/* Layout */
 .app-shell {
     display: grid;
     grid-template-rows: auto 1fr auto;
     min-height: 100vh;
}
 .topbar {
     position: sticky;
     top: 0;
     z-index: 5;
     display: flex;
     align-items: center;
     justify-content: space-between;
     padding: 14px 20px;
     border-bottom: 1px solid var(--border);
     backdrop-filter: blur(8px);
     background: color-mix(in oklab, var(--bg) 80%, transparent);
}
 .brand {
     display:flex;
     gap:12px;
     align-items:center;
}
 .logo {
     width:36px;
     height:36px;
     display:grid;
     place-items:center;
     background: var(--card);
     border:1px solid var(--border);
     border-radius: 10px;
     box-shadow: var(--shadow);
}
 .title {
     font-weight:700;
     letter-spacing:.2px;
}
 .subtitle {
     font-size:12px;
     color: var(--muted);
     margin-top:2px;
}
 .actions {
     display:flex;
     align-items:center;
     gap:10px;
}
 .user-email {
     color: var(--muted);
     font-size: 14px;
}
 .hero {
     display:grid;
     place-items:center;
     padding: 48px 16px;
}
 .hero-card {
     max-width: 780px;
     width:100%;
     background: linear-gradient(180deg, color-mix(in oklab, var(--card) 86%, transparent), var(--card));
     border: 1px solid var(--border);
     border-radius: 18px;
     padding: 40px;
     box-shadow: var(--shadow);
}
 .hero-card h1 {
     margin: 0 0 10px;
     font-size: clamp(26px, 3vw, 34px);
}
 .hero-card p {
     color: var(--muted);
     margin: 0 0 20px;
}
 .hero-footnote {
     color: var(--muted);
     font-size: 13px;
     margin-top: 8px;
}
 .toolbar {
     display:flex;
     align-items:center;
     justify-content: space-between;
     gap: 12px;
     padding: 16px 20px 8px;
}
 .search {
     display:flex;
     align-items:center;
     gap:10px;
     background: var(--card);
     border: 1px solid var(--border);
     padding: 10px 14px;
     border-radius: 12px;
     min-width: 280px;
}
 .search input {
     background: transparent;
     border: none;
     outline: none;
     color: var(--fg);
     width: 280px;
}
 .search .icon {
     opacity: .7;
}
 .select {
     background: var(--card);
     color: var(--fg);
     border: 1px solid var(--border);
     border-radius: 10px;
     padding: 10px 12px;
}
 .labs {
     display:grid;
     gap: 14px;
     padding: 12px 20px 24px;
     grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}
 .lab-card, .skeleton-card {
     background: var(--card);
     border: 1px solid var(--border);
     border-radius: 14px;
     padding: 16px;
     cursor: pointer;
     transition: transform .08s ease, border-color .08s ease, box-shadow .2s ease;
}
 .lab-card:hover {
     transform: translateY(-2px);
     border-color: color-mix(in oklab, var(--brand) 60%, var(--border));
     box-shadow: 0 10px 24px rgba(34,197,94,.12);
}
 .lab-card h4 {
     margin: 0 0 6px;
     font-weight: 600;
     font-size: 15px;
     word-break: break-all;
}
 .lab-card small {
     color: var(--muted);
}
 .labs-skeleton .skeleton-card {
     animation: pulse 1.2s ease-in-out infinite;
}
 .skel-line {
     height: 12px;
     border-radius: 6px;
     background: color-mix(in oklab, var(--fg) 10%, transparent);
     margin-bottom: 10px;
}
 .skel-line.w40 {
     width: 40%;
}
 .skel-line.w70 {
     width: 70%;
}
 .skel-line.w90 {
     width: 90%;
}
 @keyframes pulse {
     0%{
        opacity:.8
    }
     50%{
        opacity:.45
    }
     100%{
        opacity:.8
    }
}
 .empty {
     display:grid;
     place-items:center;
     text-align:center;
     padding: 40px 20px;
}
 .empty-emoji {
     font-size: 42px;
     margin-bottom: 10px;
     color: var(--muted);
}
 .footer {
     display:flex;
     align-items:center;
     justify-content: space-between;
     gap: 8px;
     padding: 16px 20px;
     border-top: 1px solid var(--border);
     color: var(--muted);
}
 .footer .link {
     color: var(--muted);
     text-decoration: none;
     border-bottom: 1px dotted var(--muted);
}
 .footer .link:hover {
     color: var(--fg);
     border-color: var(--fg);
}
 .btn {
     border: 1px solid var(--border);
     background: var(--card);
     color: var(--fg);
     padding: 10px 14px;
     border-radius: 12px;
     cursor: pointer;
     transition: box-shadow .15s ease, transform .08s ease, border-color .1s ease;
}
 .btn:hover {
     transform: translateY(-1px);
     border-color: color-mix(in oklab, var(--brand) 55%, var(--border));
}
 .btn:focus {
     outline: none;
     box-shadow: 0 0 0 4px var(--ring);
}
 .btn:active {
     transform: translateY(0);
}
 .btn-primary {
     background: linear-gradient(180deg, var(--brand), var(--brand-600));
     border-color: transparent;
     color: white;
}
 .btn-primary:hover {
     filter: brightness(0.98);
}
 .btn-primary.btn-lg {
     padding: 12px 18px;
     border-radius: 14px;
     font-weight: 600;
}
 .btn-ghost {
     background: transparent;
}
 .icon-btn {
     background: var(--card);
     border: 1px solid var(--border);
     width: 38px;
     height: 38px;
     border-radius: 10px;
     cursor: pointer;
     display:grid;
     place-items:center;
}
 .hidden {
     display: none !important;
}
/* Markdown */
 .md {
     line-height: 1.72;
}
 .md h1,.md h2,.md h3 {
     margin-top: 1.1em;
}
 .md code {
     background: rgba(148,163,184,.15);
     padding: 2px 6px;
     border-radius: 6px;
}
 .md pre {
     background: #0b1020;
     color: #e2e8f0;
     padding: 14px;
     border-radius: 10px;
     overflow:auto;
     border: 1px solid #0f172a;
}
 .md a {
     color: var(--brand);
}
 .md table {
     border-collapse: collapse;
     width: 100%;
}
 .md th,.md td {
     border:1px solid var(--border);
     padding: 8px 10px;
}
/* Toast */
 .toast {
     position: fixed;
     left: 50%;
     bottom: 24px;
     transform: translateX(-50%) translateY(20px);
     background: var(--card);
     color: var(--fg);
     border: 1px solid var(--border);
     padding: 12px 16px;
     border-radius: 12px;
     box-shadow: var(--shadow);
     opacity: 0;
     pointer-events: none;
     transition: opacity .2s ease, transform .2s ease;
}
 .toast.show {
     opacity: 1;
     transform: translateX(-50%) translateY(0);
}
/* Small screens */
 @media (max-width: 640px) {
     .search {
         min-width: 0;
         width: 100%;
    }
     .toolbar {
         flex-direction: column;
         align-items: stretch;
    }
     .toolbar-right {
         width: 100%;
         display: flex;
         justify-content: flex-end;
    }
     .actions .user-email {
         display:none;
    }
}
 .badge {
     display:inline-flex;
     align-items:center;
     gap:6px;
     font-size: 12px;
     padding: 4px 8px;
     border-radius: 999px;
     border: 1px solid var(--border);
     background: var(--card);
     color: var(--muted);
}
 .badge.success {
     color: #16a34a;
     border-color: color-mix(in oklab, #22c55e 50%, var(--border));
     background: color-mix(in oklab, #22c55e 10%, var(--card));
}
 .lab-card.solved {
     border-color: color-mix(in oklab, #22c55e 70%, var(--border));
     box-shadow: 0 10px 24px rgba(34,197,94,.18);
}
 .flag-box {
     display:flex;
     gap:10px;
     margin-top: 12px;
}
 .flag-input {
     flex:1;
     padding: 10px 12px;
     border-radius: 10px;
     border:1px solid var(--border);
     background: var(--card);
     color: var(--fg);
}
/* ---------- Modal ---------- */
 .modal.hidden {
     display: none !important;
}
 .modal {
     position: fixed;
     inset: 0;
     z-index: 50;
}
 .modal-backdrop {
     position: absolute;
     inset: 0;
     background: rgba(2,6,23,0.62);
     backdrop-filter: blur(4px);
}
 .modal-panel {
     position: relative;
     z-index: 51;
     width: min(960px, calc(100% - 24px));
     max-height: calc(100% - 24px);
     margin: 12px auto;
     background: var(--card);
     color: var(--fg);
     border: 1px solid var(--border);
     border-radius: 16px;
     box-shadow: var(--shadow);
     display: flex;
     flex-direction: column;
}
 .modal-header {
     display:flex;
     align-items:center;
     justify-content: space-between;
     gap: 10px;
     padding: 14px 16px;
     border-bottom: 1px solid var(--border);
}
 .modal-title {
     margin: 0;
     font-size: 18px;
     word-break: break-all;
}
 .modal-body {
     padding: 16px;
     overflow: auto;
     max-height: calc(100vh - 24px - 56px);
}
 body.modal-open {
     overflow: hidden;
}
/* flag input inside modal */
 .flag-box {
     display:flex;
     gap:10px;
     margin-bottom: 12px;
}
 .flag-input {
     flex:1;
     padding: 10px 12px;
     border-radius: 10px;
     border:1px solid var(--border);
     background: var(--card);
     color: var(--fg);
}
/* optional: tighter table in leaderboard */
 #lbContainer table {
     width:100%;
     border-collapse: collapse;
}
 #lbContainer th, #lbContainer td {
     border:1px solid var(--border);
     padding: 8px 10px;
     text-align: left;
}
 #lbContainer th {
     background: color-mix(in oklab, var(--card) 80%, transparent);
}
 .toolbar-right {
     display: flex;
     align-items: center;
     gap: 10px;
}
/* Progress summary pill/box */
 .summary-box {
     display: inline-flex;
     align-items: center;
     gap: 8px;
     padding: 8px 12px;
     border: 1px solid var(--border);
     border-radius: 12px;
     background: var(--card);
     color: var(--fg);
     font-size: 14px;
     white-space: nowrap;
     box-shadow: var(--shadow);
}
/* On small screens, keep it readable */
 @media (max-width: 640px) {
     .summary-box {
         font-size: 13px;
         padding: 7px 10px;
    }
}
/* =========================== Mobile optimizations =========================== */
/* Bigger, more tappable cards */
 .lab-card {
     min-height: 90px;
     padding: 18px;
}
/* Keep code and tables usable on small screens */
 .md pre {
     overflow: auto;
     -webkit-overflow-scrolling: touch;
}
 .md code {
     word-break: break-word;
     white-space: pre-wrap;
}
 .md table {
     display: block;
     overflow-x: auto;
     -webkit-overflow-scrolling: touch;
}
/* Compact topbar on mobile */
 @media (max-width: 640px) {
     .topbar {
         padding: 12px 14px;
    }
     .logo {
         width: 32px;
         height: 32px;
         border-radius: 8px;
    }
     .title {
         font-size: 16px;
    }
     .subtitle {
         font-size: 11px;
    }
     .actions {
         gap: 8px;
    }
     .btn {
         padding: 9px 12px;
         border-radius: 10px;
    }
     .icon-btn {
         width: 34px;
         height: 34px;
         border-radius: 8px;
    }
}
/* Toolbar stacks nicely;
 search input full width */
 @media (max-width: 768px) {
     .toolbar {
         flex-direction: column;
         align-items: stretch;
         gap: 8px;
         padding: 14px 14px 8px;
    }
     .search {
         width: 100%;
         min-width: 0;
         padding: 10px 12px;
    }
     .search input {
         width: 100%;
         font-size: 16px;
    }
    /* prevents iOS zoom on focus */
     .toolbar-right {
         width: 100%;
         display: flex;
    }
     .select {
         width: 100%;
    }
}
/* Labs grid: 1 column on tiny screens, 2 on small, auto on larger */
 @media (max-width: 480px) {
     .labs {
         grid-template-columns: 1fr;
         padding: 10px 12px 20px;
         gap: 12px;
    }
}
 @media (min-width: 481px) and (max-width: 768px) {
     .labs {
         grid-template-columns: repeat(2, minmax(0, 1fr));
         padding: 12px 14px 22px;
         gap: 12px;
    }
}
/* Empty state spacing */
 @media (max-width: 640px) {
     .empty {
         padding: 28px 12px;
    }
     .empty-emoji {
         font-size: 36px;
    }
}
/* Modal: turn into full-screen sheet on mobile */
 @media (max-width: 768px) {
     .modal-panel {
         width: 100%;
         height: 100%;
         max-height: none;
         margin: 0;
         border-radius: 0;
         border-left: none;
         border-right: none;
    }
     .modal-header {
         position: sticky;
         top: 0;
         background: var(--card);
         z-index: 1;
         padding: 12px 14px;
    }
     .modal-title {
         font-size: 16px;
    }
     .modal-body {
         padding: 12px;
         max-height: calc(100vh - 56px);
    }
}
/* Flag input & button stack on small screens */
 @media (max-width: 640px) {
     .flag-box {
         flex-direction: column;
    }
     .flag-input {
         width: 100%;
         font-size: 16px;
    }
    /* avoid iOS zoom */
     .btn-primary {
         width: 100%;
    }
}
/* Footer spacing on phones */
 @media (max-width: 640px) {
     .footer {
         padding: 12px 14px;
         font-size: 13px;
    }
}
/* Reduce motion when user prefers */
 @media (prefers-reduced-motion: reduce) {
     * {
         animation-duration: 0.001ms !important;
         animation-iteration-count: 1 !important;
         transition-duration: 0.001ms !important;
         scroll-behavior: auto !important;
    }
}
/* ===== Leaderboard ===== */
 .lb-wrap {
     display: grid;
     gap: 12px;
}
 .lb-summary {
     display: grid;
     grid-template-columns: 1fr auto;
     align-items: center;
     gap: 10px;
     padding: 12px 14px;
     background: var(--card);
     border: 1px solid var(--border);
     border-radius: 12px;
}
 .lb-summary .me {
     font-weight: 600;
}
 .lb-summary .stats {
     color: var(--muted);
     font-size: 14px;
}
/* Grid table with fixed columns: rank | user | solved | points */
 .lb-table {
     border: 1px solid var(--border);
     border-radius: 12px;
     overflow: hidden;
}
 .lb-head, .lb-row {
     display: grid;
     grid-template-columns: 64px 1fr 110px 110px;
    /* rank | user | solved | points */
     gap: 0;
     align-items: center;
}
 .lb-head {
     background: color-mix(in oklab, var(--card) 80%, transparent);
     border-bottom: 1px solid var(--border);
     font-weight: 600;
}
 .lb-cell {
     padding: 12px 14px;
     white-space: nowrap;
     overflow: hidden;
     text-overflow: ellipsis;
}
 .lb-cell.rank {
     text-align: right;
     font-variant-numeric: tabular-nums;
     color: var(--muted);
}
 .lb-cell.user {
     display: flex;
     align-items: center;
     gap: 8px;
}
 .lb-cell.user .medal {
     width: 18px;
     text-align: center;
}
 .lb-cell.solved, .lb-cell.points {
     text-align: right;
     font-variant-numeric: tabular-nums;
}
/* Zebra rows */
 .lb-body .lb-row:nth-child(odd) {
     background: color-mix(in oklab, var(--fg) 4%, transparent);
}
/* Mobile: stack solved/points below user in two columns */
 @media (max-width: 640px) {
     .lb-head {
         display: none;
    }
    /* hide header on small screens */
     .lb-row {
         grid-template-columns: 50px 1fr;
        /* rank | user */
         padding: 8px 0;
         border-bottom: 1px solid var(--border);
    }
     .lb-cell.rank {
         grid-column: 1;
    }
     .lb-cell.user {
         grid-column: 2;
    }
     .lb-cell.meta {
         grid-column: 1 / -1;
         display: grid;
         grid-template-columns: 1fr 1fr;
         gap: 6px;
         padding: 0 14px 12px;
         color: var(--muted);
         font-size: 13px;
    }
     .lb-cell.meta .v {
         text-align: right;
         font-variant-numeric: tabular-nums;
         color: var(--fg);
    }
}


/* Highlight my row */
.lb-row.me {
  background: color-mix(in oklab, #22c55e 8%, transparent);
}
.lb-row.me .name {
  font-weight: 600;
}

/* "you" badge next to your name */
.you-badge {
  margin-left: 6px;
  font-size: 12px;
  line-height: 1;
  padding: 3px 6px;
  border-radius: 999px;
  border: 1px solid color-mix(in oklab, #22c55e 50%, var(--border));
  background: color-mix(in oklab, #22c55e 10%, var(--card));
  color: #16a34a;
}

/* small rank pill in summary */
.rank-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  margin-right: 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
  color: var(--fg);
  font-variant-numeric: tabular-nums;
}

/* Optional: constrain leaderboard height inside modal body */
.lb-body {
  max-height: 60vh;
  overflow: auto;
}

/* --- Leaderboard alignment fixes --- */

/* Hide the mobile meta strip on desktop */
.lb-cell.meta { display: none; }

/* Give the rank column a little more room so 'Rank' doesn't clip */
.lb-head, .lb-row {
  grid-template-columns: 80px 1fr 120px 120px; /* rank | user | solved | points */
}

/* Prevent header text from being ellipsized */
.lb-head .lb-cell {
  overflow: visible;
  text-overflow: clip;
  white-space: nowrap;
}

/* Keep numeric columns crisp and right-aligned */
.lb-cell.rank,
.lb-cell.solved,
.lb-cell.points {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Slightly dim the rank number for readability */
.lb-cell.rank { color: var(--muted); }

/* Tighter row height now that meta is hidden on desktop */
.lb-row { padding: 0; }

/* Mobile layout remains the same: show the meta strip only on small screens */
@media (max-width: 640px) {
  .lb-row {
    grid-template-columns: 50px 1fr; /* rank | user */
    padding: 8px 0;
  }
  .lb-cell.meta {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: 0 14px 12px;
    color: var(--muted);
    font-size: 13px;
  }
  .lb-cell.meta .v {
    text-align: right;
    font-variant-numeric: tabular-nums;
    color: var(--fg);
  }
}

/* =========================
   MOBILE POLISH (drop-in)
   ========================= */

/* Respect iOS safe areas */
body {
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* Topbar: tighter on phones */
@media (max-width: 640px) {
  .topbar { padding: 10px 12px; }
  .brand .title { font-size: 15px; }
  .brand .subtitle { font-size: 10px; }
  .actions { gap: 6px; }
  .btn { padding: 8px 10px; font-size: 14px; }
  .btn.btn-primary.btn-lg { padding: 12px 14px; }
  .icon-btn { width: 32px; height: 32px; }
}

/* Toolbar stacks gracefully; gives breathing room */
@media (max-width: 768px) {
  .toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px 12px 8px;
  }
  .search { width: 100%; min-width: 0; padding: 10px 12px; }
  .search input { width: 100%; font-size: 16px; } /* no iOS zoom */
  .toolbar-right {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr auto; /* summary left, controls right */
    gap: 8px;
    align-items: center;
  }
  /* When very tight, controls wrap underneath */
  @media (max-width: 480px) {
    .toolbar-right {
      grid-template-columns: 1fr;
    }
    #openLeaderboard, #sortSelect {
      width: 100%;
    }
  }
}

/* Summary pill readable on phones */
.summary-box {
  font-size: 13px;
  padding: 8px 10px;
}

/* Labs grid: full-width, tappable cards */
@media (max-width: 480px) {
  .labs { grid-template-columns: 1fr; padding: 10px 12px 20px; gap: 12px; }
  .lab-card { padding: 16px; border-radius: 12px; }
  .lab-card h4 { font-size: 14px; line-height: 1.35; word-break: break-word; }
  .badge { font-size: 11.5px; padding: 4px 7px; }
}

/* Medium phones: 2 columns when comfortable */
@media (min-width: 481px) and (max-width: 768px) {
  .labs { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 12px 14px 22px; gap: 12px; }
}

/* Empty state */
@media (max-width: 640px) {
  .empty { padding: 24px 12px; }
  .empty h3 { font-size: 16px; }
}

/* Modal: act like a full-screen sheet on mobile */
@media (max-width: 768px) {
  .modal { z-index: 1000; }               /* ensure above everything */
  .modal-panel {
    width: 100%;
    height: 100%;
    max-height: none;
    margin: 0;
    border-radius: 0;
    border-left: none; border-right: none;
  }
  .modal-header {
    position: sticky; top: env(safe-area-inset-top, 0);
    padding: 12px 14px;
    background: var(--card);
    z-index: 1;
  }
  .modal-title { font-size: 16px; }
  .modal-body { padding: 12px; max-height: calc(100vh - 56px); }
  .flag-box { flex-direction: column; }
  .flag-input, .btn-primary { width: 100%; font-size: 16px; }
}

/* Markdown readability on phones */
.md pre { overflow: auto; -webkit-overflow-scrolling: touch; }
.md code { white-space: pre-wrap; word-break: break-word; }
.md table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Footer spacing on phones */
@media (max-width: 640px) {
  .footer { padding: 12px 14px; font-size: 13px; }
}

/* ===== Leaderboard Mobile Refinements ===== */
.lb-wrap { gap: 12px; }
.lb-summary { padding: 12px 14px; }
.lb-summary .me { font-weight: 600; }
.lb-summary .stats { color: var(--muted); font-size: 14px; }

/* Desktop grid (unchanged) */
.lb-table { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.lb-head, .lb-row {
  display: grid;
  grid-template-columns: 64px 1fr 110px 110px; /* rank | user | solved | points */
  align-items: center;
}
.lb-head { background: color-mix(in oklab, var(--card) 80%, transparent); border-bottom: 1px solid var(--border); font-weight: 600; }
.lb-cell { padding: 12px 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-cell.rank, .lb-cell.solved, .lb-cell.points { text-align: right; font-variant-numeric: tabular-nums; }
.lb-cell.user { display:flex; align-items:center; gap:8px; }
.lb-cell.user .medal { width:18px; text-align:center; }

/* Zebra rows */
.lb-body .lb-row:nth-child(odd) { background: color-mix(in oklab, var(--fg) 4%, transparent); }

/* Phone layout: stack solved/points under user */
@media (max-width: 640px) {
  .lb-head { display: none; }
  .lb-row {
    grid-template-columns: 48px 1fr; /* rank | user */
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
  }
  .lb-cell.rank { grid-column: 1; color: var(--muted); }
  .lb-cell.user  { grid-column: 2; }
  .lb-cell.solved, .lb-cell.points { display: none; } /* hidden in stacked view */

  .lb-cell.meta {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: 0 14px 12px;
    color: var(--muted);
    font-size: 13px;
  }
  .lb-cell.meta .v { text-align: right; color: var(--fg); font-variant-numeric: tabular-nums; }
}

/* Highlight current user in leaderboard */
.lb-row.me {
  outline: 2px solid color-mix(in oklab, var(--brand) 35%, transparent);
  background: color-mix(in oklab, var(--brand) 7%, transparent);
}

.you-badge {
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  color: var(--brand);
  background: color-mix(in oklab, var(--brand) 15%, var(--card));
  border: 1px solid color-mix(in oklab, var(--brand) 45%, var(--border));
}

/* Loading state for leaderboard modal */
.lb-loading {
  display: grid;
  place-items: center;
  gap: 10px;
  padding: 24px;
  color: var(--muted);
}

.spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid color-mix(in oklab, var(--fg) 15%, transparent);
  border-top-color: var(--brand);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Confetti burst --- */
.confetti-piece {
  position: fixed;
  top: 0;
  pointer-events: none;
  width: 8px;
  height: 14px;
  opacity: 0;
  border-radius: 2px;
  transform: translate3d(0, -20px, 0) rotate(0deg);
  animation: confetti-fall 1200ms ease-out forwards, confetti-spin 1200ms linear forwards;
  z-index: 2000; /* above modals */
}

@keyframes confetti-fall {
  0%   { opacity: 0; transform: translate3d(var(--x, 0), -20px, 0) rotate(0deg); }
  10%  { opacity: 1; }
  100% { opacity: 0; transform: translate3d(var(--x, 0), 60vh, 0) rotate(360deg); }
}
@keyframes confetti-spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(720deg); }
}

/* Fullscreen confetti canvas */
#confettiCanvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 9999; /* above modals */
}

/* keep toast above any modal/backdrop */
.toast {
  z-index: 2147483646; /* higher than your modal/backdrop */
  pointer-events: none; /* clicks go through */
  position: fixed;      /* already in your CSS; rest unchanged */
}


/* raise modals above everything */
.modal { z-index: 1000; }

:root{
  --danger: #ef4444;     /* red-500 */
  --danger-600: #dc2626; /* red-600 */
  --danger-ring: rgba(239,68,68,.35);
}

/* Make ALL your close buttons red by ID */
#labModalClose, #appModalClose, #lbModalClose {
  background: linear-gradient(180deg, var(--danger), var(--danger-600));
  color: #fff;
  border-color: transparent;
}
#labModalClose:hover, #appModalClose:hover, #lbModalClose:hover {
  filter: brightness(.98);
}
#labModalClose:focus, #appModalClose:focus, #lbModalClose:focus {
  outline: none;
  box-shadow: 0 0 0 4px var(--danger-ring);
}

/* Access badge (days remaining) */
.access-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  color: var(--fg);
  font-size: 14px;
  box-shadow: var(--shadow);
  white-space: nowrap;
}

/* Green when active, red when expired */
.access-badge.ok    { border-color: color-mix(in oklab, #22c55e 50%, var(--border)); }
.access-badge.warn  { border-color: color-mix(in oklab, #eab308 50%, var(--border)); } /* < 5 days */
.access-badge.badge-expired,
.access-badge.expired {
  border-color: color-mix(in oklab, #ef4444 55%, var(--border));
  color: #ef9a9a;
}

@media (max-width: 640px) {
  .access-badge { font-size: 13px; padding: 7px 10px; }
}

.summary-box.ok { border-color: color-mix(in oklab, #22c55e 40%, var(--border)); }
.summary-box.warn { border-color: #eab308; color: #eab308; }
.summary-box.expired { border-color: #ef4444; color: #ef4444; }

.lab-card.locked {
  opacity: 0.5;
  filter: grayscale(100%);
  cursor: not-allowed;
  position: relative;
}
.lab-card.locked::after {
  content: "🔒";
  position: absolute;
  top: 8px;
  right: 10px;
  font-size: 1.2em;
}

html[data-theme="dark"] {
  /* same as your :root values (or leave empty if identical) */
  --bg: #0b0f14;
  --card: #0f172a;
  --muted: #94a3b8;
  --fg: #e5e7eb;
  --brand: #22c55e;
  --brand-600: #16a34a;
  --ring: rgba(34,197,94,0.35);
  --border: #1f2937;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
}

/* Simple horizontal progress */
.progress { position: relative; height: 22px; border:1px solid var(--border); border-radius:999px; background: var(--card); overflow:hidden; box-shadow: var(--shadow); }
.progress .label { position:absolute; inset:0; display:grid; place-items:center; font-size:12px; color:var(--fg); pointer-events:none; }
.progress-fill { height:100%; width:0%; transition: width .6s ease, background-color .25s linear; background-image: linear-gradient(transparent, rgba(0,0,0,.05)); }
.progress-fill.low  { background-color:#86efac; } /* <= 40% */
.progress-fill.mid  { background-color:#22c55e; } /* 41–70% */
.progress-fill.high { background-color:#166534; } /* > 70% */

.logo {
  width:36px; height:36px;
  display:grid; place-items:center;
  background: var(--card);
  border:1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  overflow: hidden;            /* clip image to the rounded box */
  text-decoration: none;       /* remove link underline */
}

.logo img {
  width: 70%; height: 70%;
  object-fit: contain;
  display: block;
}

/* Zebra rows: skip the current user row */
.lb-body .lb-row:not(.me):nth-child(odd) {
  background: color-mix(in oklab, var(--fg) 4%, transparent);
}

/* Strong, always-visible highlight for the current user */
.lb-row.me {
  position: relative;
  background: color-mix(in oklab, var(--brand) 16%, var(--card));
  box-shadow:
    inset 0 0 0 2px color-mix(in oklab, var(--brand) 60%, var(--border)),
    0 2px 0 rgba(0,0,0,.06);
}

/* Nudge per theme for best contrast */
html[data-theme="light"] .lb-row.me {
  background: color-mix(in oklab, var(--brand) 18%, #fff);
}
html[data-theme="dark"] .lb-row.me {
  background: color-mix(in oklab, var(--brand) 12%, var(--card));
}

/* Left accent bar for instant recognition */
.lb-row.me::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  border-radius: 0 4px 4px 0;
  background: linear-gradient(180deg, var(--brand), var(--brand-600));
}

/* Keep text readable on the highlight */
.lb-row.me .lb-cell { color: var(--fg); }
.lb-row.me .name { font-weight: 700; }

/* Add a column for "Last solve" */
.lb-head, .lb-row {
  grid-template-columns: 80px 1fr 110px 110px 160px; /* + last */
}

.lb-cell.last {
  text-align: right;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Optional: hide Last solve on small screens */
@media (max-width: 900px) {
  .lb-head, .lb-row { grid-template-columns: 80px 1fr 110px 110px; }
  .lb-cell.last { display: none; }
}

#rankBadge { font-weight: 600; }

.solved-ts {
  color: var(--muted);
  font-size: 12px;
  margin-top: 6px;
}
