:root {
    --bg: #eef1f5; --surface: #ffffff; --ink: #1b2838; --muted: #5d6b7c;
    --line: #dde3ea; --accent: #1766a8; --accent-soft: #e4effa; --err: #b42318;
    --grid: rgba(27,40,56,.09);
  }
  @media (prefers-color-scheme: dark) {
    :root {
      --bg: #101822; --surface: #1b2838; --ink: #e3ebf3; --muted: #8fa3b8;
      --line: #2a475e; --accent: #66c0f4; --accent-soft: #1f3a52; --err: #ff8b80;
      --grid: rgba(199,213,224,.1);
    }
  }
  *, *::before, *::after { box-sizing: border-box; }
  html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
  body { min-width: 320px; overflow-wrap: anywhere; }
  img, canvas { max-width: 100%; }
  button, a { -webkit-tap-highlight-color: transparent; }
  button { touch-action: manipulation; }
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  }
  body {
    margin: 0; background: var(--bg); color: var(--ink);
    font: 400 15px/1.5 "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  }
  .skip { position: absolute; left: -9999px; }
  .skip:focus { left: 1rem; top: .6rem; z-index: 10; background: #fff; color: #000; padding: .4rem .8rem; border-radius: 4px; }
  .top {
    background: #171a21; color: #fff; height: 56px; padding: 0 max(1.5rem, calc((100% - 1440px) / 2));
    display: flex; align-items: center; gap: 1.2rem; border-bottom: 1px solid #000;
  }
  .brand { display: flex; align-items: center; gap: .7rem; color: inherit; text-decoration: none; }
  .brand img { width: 32px; height: 32px; border-radius: 6px; display: block; }
  .brand b { display: block; font-weight: 600; font-size: 1.05rem; line-height: 1.15; }
  .brand small { display: block; color: #8fa3b8; font-size: .8rem; line-height: 1.15; }
  .links { display: flex; gap: 1.1rem; margin-left: 1rem; }
  .links a { color: #c6d4df; text-decoration: none; font-size: .92rem; }
  .links a:hover { color: #fff; }
  .top .seg { margin-left: auto; border-color: rgba(255,255,255,.25); }
  .top .seg button { color: #c6d4df; }
  .top .seg button[aria-pressed="true"] { background: rgba(102,192,244,.2); color: #66c0f4; }
  .top a:focus-visible, .top button:focus-visible { outline-color: #66c0f4; }

  .gamecard { display: block; margin: 1rem .4rem 0; text-decoration: none; color: var(--ink);
    border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--bg); }
  .gamecard img { display: block; width: 100%; height: auto; aspect-ratio: 460 / 215; object-fit: cover; }
  .gamecard span { display: block; padding: .6rem .8rem; font-size: .85rem; color: var(--muted); }
  .gamecard:hover { border-color: var(--accent); }

  .foot { border-top: 1px solid var(--line); background: var(--surface); color: var(--muted);
    padding: 1rem max(1.8rem, calc((100% - 1440px) / 2)); font-size: .85rem; display: flex; flex-wrap: wrap; gap: .4rem 1.5rem; }
  .foot a { color: var(--muted); }
  .foot .r { margin-left: auto; }

  .layout { display: grid; grid-template-columns: 230px minmax(0, 1fr); min-height: calc(100vh - 56px - 52px); width: 100%; max-width: none; margin: 0; }
  aside { background: var(--surface); border-right: 1px solid var(--line); padding: 1rem .6rem; display: flex; flex-direction: column; justify-content: space-between; }
  aside h3 { margin: 0 .7rem .5rem; font-size: .85rem; font-weight: 500; color: var(--muted); }
  aside button {
    display: block; width: 100%; text-align: left; border: 0; background: none; color: var(--ink);
    font: inherit; padding: .5rem .7rem; border-radius: 6px; cursor: pointer;
  }
  aside button:hover { background: var(--bg); }
  aside button[aria-current="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
  button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

  /* Center only the main page content; leave the sidebar/menu in its own column. */
  main#content { padding: 1.6rem 1.8rem 3rem; width: min(100%, 1100px); justify-self: center; min-width: 0; }
  h1 { margin: 0; font-size: 1.45rem; font-weight: 600; letter-spacing: -.01em; }
  .desc { margin: .3rem 0 1.4rem; color: var(--muted); max-width: 62ch; }

  .kpis { display: flex; flex-wrap: wrap; align-content: center; min-height: 92px; margin-bottom: 1.4rem; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
  /* Reserve KPI space before API data arrives to prevent cumulative layout shift. */
  .ranked-view .kpis { display: none; }
  .kpi { padding: .9rem 1.6rem .9rem 0; margin-right: 1.6rem; border-right: 1px solid var(--line); }
  .kpi:last-child { border-right: 0; }
  .kpi .v { font-size: 1.7rem; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
  .kpi .l { color: var(--muted); font-size: .88rem; }
  .kpi .trend { display: block; margin-top: .12rem; font-size: .8rem; font-weight: 500; }
  .kpi .trend.up { color: #16845b; }
  .kpi .trend.down { color: #c2413b; }
  .kpi .trend.flat { color: var(--muted); }
  .kpi .peak { display: block; margin-top: .12rem; color: var(--muted); font-size: .76rem; }

  .chart-box { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 1rem 1.2rem; }
  .chart-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .6rem; flex-wrap: wrap; gap: .5rem; }
  .chart-head .upd { color: var(--muted); font-size: .85rem; }
  .seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
  .seg button { border: 0; background: none; color: var(--muted); font: inherit; font-size: .88rem; padding: .3rem .8rem; cursor: pointer; }
  .seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
  .canvas-wrap { position: relative; height: clamp(220px, 52vh, 400px); min-width: 0; }
  .msg { position: absolute; inset: 0; display: none; place-items: center; text-align: center; color: var(--err); padding: 1rem; }
  .msg.on { display: grid; }

  .table-box { margin-top: 1.4rem; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; overflow-x: auto; }
  .ranked-view .chart-box { display: none; }
  .ranked-tools { display: flex; flex-wrap: wrap; gap: .65rem; align-items: center; margin: 0 0 1rem; }
  .chart-actions { display: flex; align-items: center; gap: .55rem; flex-wrap: wrap; justify-content: flex-end; }
  .refresh-btn { min-height: 34px; border: 1px solid var(--line); border-radius: 7px; padding: .35rem .65rem; background: var(--surface); color: var(--ink); font: inherit; font-size: .82rem; cursor: pointer; }
  .refresh-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
  .refresh-btn:disabled { opacity: .65; cursor: wait; }
  .data-note { color: var(--muted); font-size: .82rem; margin: .35rem 0 .8rem; }
  .ranked-stat .sub { color: var(--muted); font-size: .76rem; margin-top: .15rem; }
  .ranked-insights { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: .8rem; margin: 0 0 1rem; }
  .insight-box { background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: .85rem 1rem; min-width: 0; }
  .insight-box h3 { margin: 0 0 .55rem; font-size: .92rem; }
  .insight-box ul { margin: 0; padding-left: 1.1rem; color: var(--muted); font-size: .84rem; }
  .insight-box li + li { margin-top: .3rem; }
  .ranked-tools input, .ranked-tools select { min-height: 40px; border: 1px solid var(--line); border-radius: 7px; padding: .55rem .7rem; background: var(--surface); color: var(--ink); font: inherit; }
  .ranked-tools input { flex: 1 1 230px; min-width: 160px; }
  .ranked-tools select { flex: 0 1 auto; max-width: 100%; }
  .ranked-tools button { min-height: 40px; border: 1px solid var(--line); border-radius: 7px; padding: .5rem .8rem; background: var(--surface); color: var(--ink); font: inherit; cursor: pointer; }
  .ranked-tools button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
  .ranked-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(155px, 1fr)); gap: .8rem; margin-bottom: 1rem; }
  .ranked-stat { border: 1px solid var(--line); background: var(--surface); border-radius: 9px; padding: .85rem 1rem; min-width: 0; }
  .ranked-stat .v { font-size: 1.35rem; font-weight: 600; overflow-wrap: anywhere; }
  .ranked-stat .l { color: var(--muted); font-size: .82rem; }
  .podium { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: .8rem; margin-bottom: 1rem; align-items: stretch; }
  .podium-card { min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 1rem .8rem; text-align: center; }
  .podium-card.first { border-color: #d8ad39; box-shadow: inset 0 3px #d8ad39; }
  .podium-card .medal { font-size: 1.45rem; }
  .podium-card .podium-avatar { display: block; width: 58px; height: 58px; border-radius: 50%; object-fit: cover; background: var(--bg); margin: .35rem auto .55rem; opacity: 0; }
  .podium-card .podium-name { display: block; font-weight: 600; overflow-wrap: anywhere; }
  .podium-card a { color: inherit; text-decoration: none; }
  .podium-card a:hover { color: var(--accent); }
  .podium-card .podium-points { color: var(--accent); font-weight: 600; margin-top: .25rem; }
  .podium-card .podium-meta { color: var(--muted); font-size: .82rem; }
  .rank-change { font-size: .78rem; color: var(--muted); margin-left: .35rem; font-weight: 500; }
  .rank-change.up { color: #16845b; } .rank-change.down { color: #c2413b; }
  .ranked-view .table-box { margin-top: 0; }
  .ranked-table th, .ranked-table td { text-align: left; }
  .ranked-table td:first-child { font-weight: 600; }
  .ranked-table .rank { width: 4.5rem; font-size: 1.05rem; }
  .ranked-table .player { min-width: 220px; }
  .ranked-table .player-main { display: flex; align-items: center; gap: .65rem; }
  .ranked-table .steam-avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; flex: 0 0 36px; background: var(--bg); opacity: 0; }
  .ranked-table .player-name { font-weight: 600; }
  .ranked-table .points { color: var(--accent); font-weight: 600; }
  .skin-cell { display: flex; align-items: center; gap: .5rem; }
  .skin-icon { width: 36px; height: 36px; flex: 0 0 36px; object-fit: contain; border-radius: 7px; background: var(--bg); border: 1px solid var(--line); padding: 2px; }
  .skin-icon.missing { visibility: hidden; }
  .skin-gallery { margin: 0 0 1rem; }
  .skin-gallery-head { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: .3rem .8rem; margin: 0 0 .65rem; }
  .skin-gallery-head h2 { font-size: 1rem; margin: 0; font-weight: 600; }
  .skin-gallery-head a { font-size: .82rem; color: var(--muted); }
  .skin-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(112px, 1fr)); gap: .65rem; }
  .skin-card { min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: .7rem .5rem; text-align: center; }
  .skin-card img { display: block; width: 76px; height: 76px; object-fit: contain; margin: 0 auto .45rem; border-radius: 8px; background: var(--bg); }
  .skin-card .skin-name { font-size: .82rem; font-weight: 500; overflow-wrap: anywhere; }
  .skin-card .skin-count { color: var(--muted); font-size: .78rem; }
  .podium-card .podium-skin { display: block; width: 44px; height: 44px; object-fit: contain; margin: .45rem auto 0; }
  .ranked-table .steam-link { display: block; color: var(--muted); font-size: .78rem; font-weight: 400; text-decoration: none; }
  .ranked-table .steam-link:hover { color: var(--accent); text-decoration: underline; }
  .ranked-table tr:nth-child(-n+3) .rank { font-size: 1.25rem; }
  table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
  caption { text-align: left; padding: .8rem 1rem; font-weight: 500; }
  th, td { padding: .5rem 1rem; text-align: right; border-top: 1px solid var(--line); white-space: nowrap; }
  th:first-child, td:first-child { text-align: left; }
  th { color: var(--muted); font-weight: 500; font-size: .88rem; }

  /* ===== Player profiles view ===== */
  .profiles-view #rankedPodium, .profiles-view .skin-gallery, .profiles-view #rankedInsights { display: none; }
  /* Wider layout for the profiles view (the table has many columns). */
  .profiles-view main#content { width: min(100%, 1800px); }
  .profiles-view .layout { grid-template-columns: 210px minmax(0, 1fr); }
  .profiles-view .ranked-summary { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
  .profile-table th, .profile-table td { padding-left: 1.1rem; padding-right: 1.1rem; }
  .profile-table .player { min-width: 260px; }
  .pd-grid { grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }
  .profile-table td { vertical-align: top; }
  .profile-table .pf-main { font-weight: 600; }
  .profile-table .pf-sub { display: block; color: var(--muted); font-size: .78rem; font-weight: 400; }
  .profile-table .badges { display: flex; gap: .3rem; flex-wrap: wrap; white-space: normal; min-width: 130px; }
  .pf-badge { display: inline-block; font-size: .72rem; font-weight: 500; padding: .1rem .5rem; border-radius: 999px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
  .pf-badge.dxp { background: rgba(216,173,57,.2); color: #8a5a00; }
  @media (prefers-color-scheme: dark) { .pf-badge.dxp { color: #f2c14e; } }
  .detail-btn { border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; font-size: .8rem; padding: .3rem .6rem; border-radius: 6px; cursor: pointer; white-space: nowrap; }
  .detail-btn:hover { border-color: var(--accent); color: var(--accent); }
  .profile-table tr.detail-row td { padding: 0; background: var(--bg); font-weight: 400; white-space: normal; }
  .pd-wrap { padding: 1rem; }
  .pd-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .8rem; }
  .pd-card { background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: .8rem .9rem; min-width: 0; }
  .pd-card.pd-wide { grid-column: 1 / -1; }
  .pd-card h4 { margin: 0 0 .5rem; font-size: .9rem; }
  .pd-card dl { margin: 0; }
  .pd-row { display: flex; justify-content: space-between; gap: .8rem; padding: .18rem 0; font-size: .84rem; }
  .pd-row dt { color: var(--muted); }
  .pd-row dd { margin: 0; font-weight: 500; text-align: right; font-variant-numeric: tabular-nums; }
  .pd-bar { height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; margin: .25rem 0 .45rem; }
  .pd-bar span { display: block; height: 100%; background: #1d9a8a; }
  .pd-stack { display: flex; height: 10px; border-radius: 99px; overflow: hidden; background: var(--line); margin: .4rem 0; }
  .pd-stack span { display: block; height: 100%; }
  .pd-legend { display: flex; flex-wrap: wrap; gap: .3rem .9rem; font-size: .78rem; color: var(--muted); }
  .pd-legend i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: .3rem; }
  .profile-table td.c-detail::before { display: none; }

  /* ===== RESPONSIVE ===== */

  @supports (height: 100dvh) {
    .layout { min-height: calc(100dvh - 56px - 52px); }
  }
  .top { padding-left: max(1.5rem, env(safe-area-inset-left), calc((100% - 1440px) / 2)); padding-right: max(1.5rem, env(safe-area-inset-right), calc((100% - 1440px) / 2)); }
  .foot { padding-bottom: max(1rem, env(safe-area-inset-bottom)); }

  @media (min-width: 1500px) {
    main#content { width: min(100%, 1240px); }
  }

  /* Small laptops / landscape tablets */
  @media (max-width: 1100px) {
    .layout { grid-template-columns: 200px minmax(0, 1fr); }
    main#content { padding: 1.4rem 1.2rem 2.5rem; }
  }

  /* Tablets / phones: the menu becomes a sticky tab bar */
  @media (max-width: 800px) {
    .layout { display: block; min-height: 0; }
    aside {
      position: sticky; top: 0; z-index: 5; display: block; padding: .45rem .6rem;
      border-right: 0; border-bottom: 1px solid var(--line);
    }
    #menu {
      display: flex; gap: .3rem; overflow-x: auto; scroll-snap-type: x proximity;
      scrollbar-width: none; -webkit-overflow-scrolling: touch;
    }
    #menu::-webkit-scrollbar { display: none; }
    aside h3, .gamecard { display: none; }
    aside button {
      width: auto; flex: 0 0 auto; white-space: nowrap; min-height: 42px;
      scroll-snap-align: start; border: 1px solid transparent;
    }
    aside button[aria-current="true"] { border-color: var(--accent); }

    main#content {
      width: 100%;
      padding: 1.2rem max(1rem, env(safe-area-inset-right)) 2.5rem max(1rem, env(safe-area-inset-left));
    }
    .top { gap: .8rem; padding-left: max(1rem, env(safe-area-inset-left)); padding-right: max(1rem, env(safe-area-inset-right)); }
    .links { margin-left: 0; }
    .brand small { display: none; }
    .foot { padding-left: max(1rem, env(safe-area-inset-left)); padding-right: max(1rem, env(safe-area-inset-right)); }
    .foot .r { margin-left: 0; }
    .kpi { margin-right: 1rem; padding-right: 1rem; }
    .chart-box { padding: .85rem; }
    th, td { padding: .55rem .75rem; }
    /* keep the first column visible when the table scrolls horizontally */
    .table-box table:not(.ranked-table) th:first-child,
    .table-box table:not(.ranked-table) td:first-child { position: sticky; left: 0; background: var(--surface); z-index: 1; }
  }
  /* Keep data tables as tables on phones; the table container handles horizontal scrolling. */

  @media (max-width: 560px) {
    .podium { grid-template-columns: minmax(0, 1fr); gap: .6rem; }
    .podium-card { padding: .8rem; }
    .podium-card .podium-avatar { width: 48px; height: 48px; }
    .ranked-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; }
    .ranked-stat { padding: .7rem .8rem; }
    .ranked-stat .v { font-size: 1.15rem; }
    .ranked-insights { grid-template-columns: minmax(0, 1fr); }
    .skin-grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: .5rem; }
    .skin-card img { width: 64px; height: 64px; }
    .ranked-tools { gap: .5rem; }
    .ranked-tools input { flex: 1 1 100%; min-width: 0; font-size: 16px; } /* 16px = no auto-zoom on iOS */
    .ranked-tools select { flex: 1 1 0; min-width: 0; font-size: 16px; }
    .ranked-tools button { flex: 0 0 auto; }
  }

  @media (max-width: 520px) {
    .top { min-height: 56px; height: auto; padding-top: .6rem; padding-bottom: .6rem; flex-wrap: wrap; }
    .brand { flex: 1 1 auto; min-width: 0; }
    .links { order: 3; flex: 1 1 100%; overflow-x: auto; padding: .2rem 0; gap: 1.1rem; scrollbar-width: none; white-space: nowrap; }
    .links::-webkit-scrollbar { display: none; }
    .top .seg { margin-left: auto; flex-shrink: 0; }
    main#content { padding-top: 1rem; padding-bottom: 2rem; }
    h1 { font-size: 1.3rem; }
    .desc { margin-bottom: 1rem; }
    .kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0; min-height: 146px; }
    .kpi { min-width: 0; margin: 0; padding: .75rem .5rem .75rem 0; border-right: 0; }
    .kpi .v { font-size: clamp(1.25rem, 6vw, 1.6rem); overflow-wrap: anywhere; }
    .chart-head { align-items: flex-start; }
    .chart-head .upd { flex: 1 1 100%; }
    .chart-actions { width: 100%; justify-content: space-between; }
    .seg button { min-height: 38px; padding: .35rem .65rem; }
    .refresh-btn { min-height: 38px; }
    .canvas-wrap { height: 260px; }
    .foot { gap: .5rem; flex-direction: column; }
  }

  @media (max-width: 360px) {
    h1 { font-size: 1.15rem; }
    .ranked-summary { grid-template-columns: minmax(0, 1fr); }
    .kpi .l, .kpi .trend, .kpi .peak { font-size: .74rem; }
    .chart-actions .refresh-btn { padding: .35rem .5rem; font-size: .78rem; }
  }

  /* Phone in landscape: give the chart more height */
  @media (max-height: 480px) and (orientation: landscape) {
    .canvas-wrap { height: 72vh; min-height: 200px; }
    aside { position: static; }
  }

  @media (hover: none) {
    .links a, aside button { padding-top: .55rem; padding-bottom: .55rem; }
  }


  /* ===== Table layout: stable columns, readable density, responsive horizontal scroll ===== */
  .layout { grid-template-columns: 230px minmax(0, 1fr); }
  main#content { width: 100%; max-width: none; min-width: 0; justify-self: stretch; }
  .profiles-view main#content { width: 100%; max-width: none; }
  .table-box {
    display: block; position: relative; width: 100%; max-width: 100%; min-width: 0;
    margin-top: 1.1rem; overflow: auto; max-height: calc(100vh - 190px); overscroll-behavior: contain;
    border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
    scrollbar-width: thin; scrollbar-color: var(--muted) transparent;
    -webkit-overflow-scrolling: touch; cursor: grab;
  }
  .table-box:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  .table-box.is-dragging { cursor: grabbing; user-select: none; }
  .table-box.is-dragging img, .table-box.is-dragging a { -webkit-user-drag: none; }
  .table-box::-webkit-scrollbar { height: 10px; width: 10px; }
  .table-box::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--muted) 55%, transparent); border: 3px solid transparent; border-radius: 99px; background-clip: padding-box; }
  .table-box::-webkit-scrollbar-thumb:hover { background: var(--muted); border: 2px solid transparent; background-clip: padding-box; }
  .table-box table { margin: 0; }
  .table-box caption { position: sticky; left: 0; padding: .85rem 1rem; background: var(--surface); }
  .table-box thead th { position: sticky; top: 0; z-index: 4; background: var(--surface); box-shadow: 0 1px 0 var(--line); }

  /* Profile table: predictable column proportions and enough width for meaningful labels. */
  .profile-table { width: 100%; min-width: 1280px; table-layout: fixed; }
  .profile-table th, .profile-table td {
    padding: .68rem .72rem; white-space: normal; vertical-align: top;
    overflow-wrap: break-word; line-height: 1.4;
  }
  .profile-table th { font-size: .8rem; line-height: 1.25; text-align: left; }
  .profile-table td { font-size: .88rem; }
  .profile-table th:first-child, .profile-table td:first-child { text-align: center; }
  .profile-table th:nth-child(1), .profile-table td.rank { width: 58px; }
  .profile-table th:nth-child(2), .profile-table td.player { width: 205px; }
  .profile-table th:nth-child(3) { width: 76px; }
  .profile-table th:nth-child(4) { width: 100px; }
  .profile-table th:nth-child(5) { width: 142px; }
  .profile-table th:nth-child(6) { width: 142px; }
  .profile-table th:nth-child(7) { width: 160px; }
  .profile-table th:nth-child(8) { width: 160px; }
  .profile-table th:nth-child(9) { width: 165px; }
  .profile-table th:nth-child(10) { width: 90px; }
  .profile-table.weekly-profile-table th:nth-child(5) { width: 110px; }
  .profile-table.weekly-profile-table th:nth-child(6) { width: 140px; }
  .profile-table.weekly-profile-table th:nth-child(7) { width: 140px; }
  .profile-table.weekly-profile-table th:nth-child(8) { width: 155px; }
  .profile-table.weekly-profile-table th:nth-child(9) { width: 155px; }
  .profile-table.weekly-profile-table th:nth-child(10) { width: 165px; }
  .profile-table.weekly-profile-table th:nth-child(11) { width: 90px; }
  .profile-table tbody tr:not(.detail-row):nth-child(even) { background: color-mix(in srgb, var(--bg) 42%, var(--surface)); }
  .profile-table tbody tr:not(.detail-row):hover { background: var(--accent-soft); }
  .profile-table .rank { font-size: .98rem; font-weight: 600; }
  .profile-table .player { min-width: 0; }
  .profile-table .player-main { display: flex; align-items: center; gap: .55rem; min-width: 0; }
  .profile-table .player-main > div { min-width: 0; }
  .profile-table .player-name { display: block; font-weight: 600; overflow-wrap: anywhere; }
  .profile-table .steam-avatar { width: 32px; height: 32px; flex: 0 0 32px; border-radius: 50%; object-fit: cover; }
  .profile-table .steam-link { display: inline-block; max-width: 100%; overflow-wrap: anywhere; }
  .profile-table .pf-main { font-weight: 600; font-variant-numeric: tabular-nums; }
  .profile-table .pf-sub { display: block; margin-top: .15rem; color: var(--muted); font-size: .76rem; font-weight: 400; white-space: normal; overflow-wrap: anywhere; }
  .profile-table .badges { display: flex; flex-direction: column; align-items: flex-start; gap: .4rem; min-width: 0; white-space: normal; }
  .profile-table .pf-badge { display: inline-flex; align-items: center; gap: .25rem; max-width: 100%; font-size: .74rem; line-height: 1.25; font-weight: 600; padding: .28rem .6rem; border: 1px solid color-mix(in srgb, var(--accent) 18%, transparent); border-radius: 7px; background: var(--accent-soft); color: var(--accent); white-space: normal; overflow-wrap: anywhere; }
  .profile-table .pf-badge.dxp { background: rgba(216,173,57,.18); border-color: rgba(216,173,57,.42); color: #8a5a00; }
  @media (prefers-color-scheme: dark) { .profile-table .pf-badge.dxp { color: #f2c14e; border-color: rgba(242,193,78,.4); } }
  .profile-table td.c-detail { text-align: center; vertical-align: middle; }
  .profile-table .detail-btn { white-space: nowrap; }
  .profile-table tr.detail-row td { padding: 0; background: var(--bg); font-weight: 400; white-space: normal; }
  .profile-table .pd-wrap { padding: clamp(.75rem, 1.5vw, 1.25rem); }
  .profile-table .pd-grid { grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr)); }

  /* Keep player identity visible while the wide table is moved sideways. */
  .profile-table thead th:nth-child(1) { left: 0; z-index: 7; }
  .profile-table tbody tr:not(.detail-row) td.rank { position: sticky; left: 0; z-index: 3; background: var(--surface); }
  .profile-table thead th:nth-child(2) { position: sticky; left: 58px; z-index: 6; background: var(--surface); }
  .profile-table tbody tr:not(.detail-row) td.player { position: sticky; left: 58px; z-index: 2; background: var(--surface); box-shadow: 5px 0 7px -7px var(--ink); }
  .profile-table tbody tr:not(.detail-row):nth-child(even) td.rank,
  .profile-table tbody tr:not(.detail-row):nth-child(even) td.player { background: color-mix(in srgb, var(--bg) 42%, var(--surface)); }
  .profile-table tbody tr:not(.detail-row):hover td.rank,
  .profile-table tbody tr:not(.detail-row):hover td.player { background: var(--accent-soft); }

  @media (min-width: 1500px) {
    main#content { width: 100%; max-width: none; }
  }
  @media (max-width: 1100px) {
    .layout { grid-template-columns: 200px minmax(0, 1fr); }
    main#content { padding-left: 1rem; padding-right: 1rem; }
  }
  @media (max-width: 800px) {
    .layout { display: block; min-height: 0; }
    .profile-table { min-width: 1220px; }
    .table-box { margin-top: .8rem; border-radius: 8px; }
  }
  @media (max-width: 520px) {
    .profile-table th, .profile-table td { padding: .62rem .6rem; }
    .profile-table th:nth-child(2), .profile-table td.player { width: 190px; }
  }


  /* Per-player online indicator based on the player's Last Update timestamp. */
  .player-status { display:inline-block; width:8px; height:8px; flex:0 0 8px; border-radius:50%; margin-right:.4rem; vertical-align:middle; background:#dc3545; box-shadow:0 0 0 0 rgba(220,53,69,.45); }
  .player-status.is-online { background:#22c55e; box-shadow:0 0 0 0 rgba(34,197,94,.55); animation: player-status-pulse 1.8s infinite; }
  .player-status.is-offline { background:#ef4444; animation:none; }
  @keyframes player-status-pulse { 0% { box-shadow:0 0 0 0 rgba(34,197,94,.55); } 70% { box-shadow:0 0 0 6px rgba(34,197,94,0); } 100% { box-shadow:0 0 0 0 rgba(34,197,94,0); } }
  @media (prefers-reduced-motion: reduce) { .player-status.is-online { animation:none; } }



  /* ===== Consistent profile table, badge and Progress-detail alignment ===== */
  .profiles-view main#content { min-width: 0; width: 100%; max-width: none; }
  .profiles-view .layout { grid-template-columns: 210px minmax(0, 1fr); }
  .profiles-view .table-box { width: 100%; min-width: 0; overflow: auto; }
  .profile-table {
    width: max(100%, 1394px);
    min-width: 1394px;
    table-layout: fixed;
    border-collapse: separate;
    border-spacing: 0;
  }
  .profile-table.weekly-profile-table { width: max(100%, 1504px); min-width: 1504px; }
  .profile-table th,
  .profile-table td {
    box-sizing: border-box;
    padding: .68rem .72rem;
    line-height: 1.4;
    vertical-align: middle;
    white-space: normal;
    overflow-wrap: break-word;
  }
  .profile-table th { text-align: left; vertical-align: middle; }
  .profile-table th:nth-child(1), .profile-table td.rank { width: 58px; text-align: center; }
  .profile-table th:nth-child(2), .profile-table td.player { width: 220px; text-align: left; }
  .profile-table th:nth-child(3), .profile-table td:nth-child(3) { width: 76px; text-align: center; }
  .profile-table th:nth-child(4), .profile-table td:nth-child(4) { width: 100px; text-align: right; }
  .profile-table:not(.weekly-profile-table) th:nth-child(5), .profile-table:not(.weekly-profile-table) td:nth-child(5) { width: 145px; }
  .profile-table:not(.weekly-profile-table) th:nth-child(6), .profile-table:not(.weekly-profile-table) td:nth-child(6) { width: 145px; }
  .profile-table:not(.weekly-profile-table) th:nth-child(7), .profile-table:not(.weekly-profile-table) td:nth-child(7) { width: 155px; }
  .profile-table:not(.weekly-profile-table) th:nth-child(8), .profile-table:not(.weekly-profile-table) td:nth-child(8) { width: 155px; }
  .profile-table:not(.weekly-profile-table) th:nth-child(9), .profile-table:not(.weekly-profile-table) td:nth-child(9) { width: 250px; }
  .profile-table:not(.weekly-profile-table) th:nth-child(10), .profile-table:not(.weekly-profile-table) td:nth-child(10) { width: 90px; }
  .profile-table.weekly-profile-table th:nth-child(5), .profile-table.weekly-profile-table td:nth-child(5) { width: 110px; text-align: right; }
  .profile-table.weekly-profile-table th:nth-child(6), .profile-table.weekly-profile-table td:nth-child(6) { width: 145px; }
  .profile-table.weekly-profile-table th:nth-child(7), .profile-table.weekly-profile-table td:nth-child(7) { width: 145px; }
  .profile-table.weekly-profile-table th:nth-child(8), .profile-table.weekly-profile-table td:nth-child(8) { width: 155px; }
  .profile-table.weekly-profile-table th:nth-child(9), .profile-table.weekly-profile-table td:nth-child(9) { width: 155px; }
  .profile-table.weekly-profile-table th:nth-child(10), .profile-table.weekly-profile-table td:nth-child(10) { width: 250px; }
  .profile-table.weekly-profile-table th:nth-child(11), .profile-table.weekly-profile-table td:nth-child(11) { width: 90px; }
  .profile-table td.rank,
  .profile-table td:nth-child(3),
  .profile-table td:nth-child(4),
  .profile-table.weekly-profile-table td:nth-child(5) { font-variant-numeric: tabular-nums; white-space: nowrap; }
  .profile-table .player-main { display: flex; align-items: center; gap: .55rem; min-width: 0; }
  .profile-table .player-main > div { min-width: 0; }
  .profile-table .player-name, .profile-table .steam-link { overflow-wrap: anywhere; }
  .profile-table .badges {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: .4rem;
    width: 100%; min-width: 0; white-space: normal;
  }
  .profile-table .pf-badge {
    display: inline-flex; align-items: center; gap: .35rem;
    box-sizing: border-box; max-width: 100%; min-width: 0;
    padding: .32rem .55rem; min-height: 27px;
    font-size: .74rem; line-height: 1.3; font-weight: 600;
    white-space: normal; overflow-wrap: anywhere; word-break: normal;
    border-radius: 7px;
  }
  .profile-table .pf-badge.dxp { text-align: left; }
  .profile-table td.c-detail, .profile-table th:last-child { text-align: center; }
  .profile-table td.c-detail { width: 90px; }
  .profile-table .detail-btn { display: inline-flex; align-items: center; justify-content: center; min-height: 32px; white-space: nowrap; }
  .profile-table tr.detail-row td { padding: 0; vertical-align: top; white-space: normal; }
  .profile-table .pd-wrap { box-sizing: border-box; width: 100%; padding: clamp(.75rem, 1.5vw, 1.25rem); }
  .profile-table .pd-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(250px, 100%), 1fr)); align-items: stretch; gap: .8rem; }
  .profile-table .pd-card { box-sizing: border-box; min-width: 0; }
  .profile-table .pd-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, auto); align-items: baseline; gap: .65rem; padding: .22rem 0; }
  .profile-table .pd-row dt { min-width: 0; overflow-wrap: anywhere; }
  .profile-table .pd-row dd { min-width: 0; max-width: 100%; text-align: right; overflow-wrap: anywhere; }
  .profile-table .pd-row dd .pf-badge { max-width: 100%; }
  .profile-table .pd-card h4 { line-height: 1.35; }
  .profile-table .pd-legend { align-items: flex-start; }
  .profile-table .pd-legend > span { min-width: 0; overflow-wrap: anywhere; }
  @media (max-width: 800px) {
    .profiles-view .layout { display: block; }
    .profiles-view main#content { padding-left: .75rem; padding-right: .75rem; }
    .profile-table { width: max(100%, 1394px); min-width: 1394px; }
    .profile-table.weekly-profile-table { width: max(100%, 1504px); min-width: 1504px; }
  }


  /* Hard reset for the expanded Progress panel: keep labels and values on a shared grid. */
  .profile-table tr.detail-row > td { width: auto !important; max-width: none; }
  .profile-table .pd-wrap { display: block; width: 100%; max-width: 100%; box-sizing: border-box; overflow: hidden; }
  .profile-table .pd-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; width: 100%; align-items: start; }
  .profile-table .pd-card { width: 100%; min-width: 0; max-width: 100%; overflow: hidden; }
  /* Progress: align values in a shared column directly beside their labels. */
  .profile-table .pd-card dl { display: grid; grid-template-columns: fit-content(48%) minmax(0, 1fr); column-gap: 10px; row-gap: 0; width: 100%; margin: 0; }
  .profile-table .pd-row { display: contents !important; }
  .profile-table .pd-row dt { display: block; min-width: 0; margin: 0; padding: .22rem 0; text-align: left; white-space: normal; overflow-wrap: anywhere; }
  .profile-table .pd-row dd { display: block; min-width: 0; width: auto; margin: 0; padding: .22rem 0; text-align: left !important; white-space: normal; overflow-wrap: anywhere; word-break: normal; }
  .profile-table .pd-row dd .pf-badge { display: inline-flex; max-width: 100%; }
  .profile-table .pd-card.pd-wide { grid-column: 1 / -1; }
  .profile-table .pd-stack { width: 100%; box-sizing: border-box; }
  .profile-table .pd-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; }
  .profile-table .pd-legend > span { max-width: 100%; min-width: 0; }
  @media (max-width: 1100px) { .profile-table .pd-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
  @media (max-width: 620px) { .profile-table .pd-grid { grid-template-columns: minmax(0, 1fr); } .profile-table .pd-card.pd-wide { grid-column: auto; } }

  /* Progression: keep each label immediately next to its own value. */
  .profile-table .pd-card dl { display: block !important; }
  .profile-table .pd-row { display: flex !important; flex-wrap: wrap; justify-content: flex-start !important; align-items: baseline; gap: .3rem .45rem !important; padding: .22rem 0; }
  .profile-table .pd-row dt { display: inline !important; flex: 0 1 auto; width: auto; max-width: 100%; padding: 0; margin: 0; white-space: normal; overflow-wrap: anywhere; }
  .profile-table .pd-row dd { display: inline !important; flex: 0 1 auto; width: auto; max-width: 100%; padding: 0; margin: 0; text-align: left !important; white-space: normal; overflow-wrap: anywhere; word-break: normal; }
  .profile-table .pd-row dd .pf-badge { display: inline-flex; vertical-align: baseline; max-width: 100%; }

  /* Ranked and weekly leaderboards use the same compact badge layout as Profiles. */
  .ranked-badges-table .badges { display: flex; flex-direction: column; align-items: flex-start; gap: .4rem; min-width: 0; white-space: normal; }
  .ranked-badges-table th:last-child, .ranked-badges-table td:last-child { min-width: 210px; text-align: left; white-space: normal; }
  .ranked-badges-table .pf-badge { display: inline-flex; align-items: center; max-width: 100%; white-space: normal; overflow-wrap: anywhere; line-height: 1.25; padding: .28rem .6rem; border-radius: 7px; }
  .ranked-badges-table .pf-badge.dxp { background: rgba(216,173,57,.18); border: 1px solid rgba(216,173,57,.42); color: #8a5a00; }
  @media (prefers-color-scheme: dark) { .ranked-badges-table .pf-badge.dxp { color: #f2c14e; border-color: rgba(242,193,78,.4); } }


/* Theme picker added by the modular theme pack */
.theme-picker {
  display:flex; align-items:center; gap:.5rem; margin-left:auto;
  color:inherit; font-size:.7rem; white-space:nowrap;
}
.theme-picker label { opacity:.72; text-transform:uppercase; letter-spacing:.08em; }
.theme-picker select {
  max-width: 180px; min-height:32px; padding:5px 28px 5px 9px;
  border:1px solid currentColor; border-radius:5px;
  background:var(--surface,#fff); color:var(--ink,#17212b);
  font:inherit; cursor:pointer;
}
.theme-picker select:focus-visible { outline:2px solid var(--accent,#1766a8); outline-offset:3px; }
@media(max-width:760px) {
  .theme-picker { margin-left:0; }
  .theme-picker label { display:none; }
  .theme-picker select { max-width:150px; }
}

/* Lighthouse improvements: reserve space for late-rendering content and controls. */
#title { min-height: 1.05em; }
#desc { min-height: 2.8em; }
.kpis { min-height: 112px; }
.chart-box { min-height: 430px; }
.canvas-wrap { min-height: 260px; }
.gamecard img { aspect-ratio: 460 / 215; }
.theme-picker label { color: inherit; }
