/* ========== Tokens ========== */
:root {
  --bg: #0b0f14;
  --fg: #e9edf5;
  --accent: #35c07a;
  --accent-soft: rgba(53, 192, 122, 0.15);
  --accent-border: rgba(53, 192, 122, 0.45);

  --card-bg: rgba(255, 255, 255, 0.05);
  --card-border: rgba(255, 255, 255, 0.10);
  --soft-bg: rgba(255, 255, 255, 0.06);
  --soft-border: rgba(255, 255, 255, 0.12);
  --hover-bg: rgba(255, 255, 255, 0.12);

  --row-border: rgba(255, 255, 255, 0.07);
  --shadow-card: 0 12px 40px rgba(0, 0, 0, 0.25);

  --radius-sm: 12px;
  --radius-md: 14px;
  --radius-lg: 18px;

  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --t: 180ms;

  --topbar-bg: rgba(11, 15, 20, 0.55);
  --topbar-border: rgba(255, 255, 255, 0.08);
  --thead-bg: rgba(11, 15, 20, 0.4);
  --placeholder-color: rgba(255, 255, 255, 0.49); /* 4.6:1 on every field fill, public and admin */
  --input-border: rgba(255, 255, 255, 0.33); /* text-field outline: 3.1:1 on the page, a card or a form */
  --btn-border: rgba(255, 255, 255, 0.15);
  --btn-bg: rgba(255, 255, 255, 0.08);
  --input-focus-bg: rgba(255, 255, 255, 0.08);
  --footer-border: rgba(255, 255, 255, 0.08);
  --chart-bg: rgba(0, 0, 0, 0.18);
  --tip-bg: rgba(11, 15, 20, 0.96);
}

/* ========== Base ========== */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
/* clip (unlike hidden) creates no scroll container: the page scrolls on the window */
html, body { overflow-x: clip; }
body {
  margin: 0;
  position: relative;
  z-index: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, "Helvetica Neue", sans-serif;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  transition: background var(--t) var(--ease), color var(--t) var(--ease);
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(1200px 600px at 30% 0%, rgba(53, 192, 122, 0.30), transparent 60%),
    radial-gradient(900px 500px at 70% 10%, rgba(53, 192, 122, 0.22), transparent 60%);
  animation: bgPulse 8s ease-in-out infinite;
  will-change: opacity, transform;
}
@keyframes bgPulse {
  0%, 100% { opacity: 0.55; transform: translate3d(0, 0, 0) scale(1); }
  50%      { opacity: 1.00; transform: translate3d(0, 0, 0) scale(1.04); }
}
h1, h2, h3 { letter-spacing: -0.01em; }
::selection { background: var(--accent-soft); color: #fff; }
/* Off screen but still read by screen readers (e.g. the role=status announcements) */
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}

/* ========== Layout ========== */
.container { max-width: 1180px; margin: 0 auto; padding: 0 16px; }

.topbar {
  padding: 18px 0;
  border-bottom: 1px solid var(--topbar-border);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  background: var(--topbar-bg);
}
.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.brand h1 { margin: 0; font-size: 22px; }
.subtitle { margin: 6px 0 0; opacity: 0.75; font-size: 13px; }
.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.grid {
  display: grid;
  grid-template-columns: minmax(340px, 1fr) minmax(440px, 2.2fr) 260px;
  gap: 16px;
  padding: 16px 0 28px;
}
/* Desktop (>= 1100px): 3 columns. The grid spans the viewport less its scrollbar, up to 1180px
 * (this padding shorthand drops .container's side gutter). The first column stays at its 340px
 * minimum, the last is 260px, and the middle one gets the rest: grid width - 632px (with the two
 * 16px gaps). Its 440px minimum fits all 3 in a 1072px grid, so they fit from a 1100px viewport
 * with a 17px scrollbar (a 1083px grid). Under 1100px the tablet and phone layouts take over
 * (see the end of this file). */

/* ========== Inputs ========== */
input[type="search"] {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--input-border);
  background: var(--soft-bg);
  color: inherit;
  outline: none;
  min-width: 240px;
  transition: border-color var(--t) var(--ease), background var(--t) var(--ease), box-shadow var(--t) var(--ease);
}
input[type="search"]::placeholder { color: var(--placeholder-color); opacity: 1; } /* Firefox dims placeholders by default */
input[type="search"]:focus {
  border-color: var(--accent-border);
  background: var(--input-focus-bg);
  box-shadow: 0 0 0 3px rgba(53, 192, 122, 0.15);
}
/* The soft border and ring alone stay under 3:1; text fields match :focus-visible on click too */
input[type="search"]:focus-visible { border-color: var(--accent); }

/* ========== Card ========== */
.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 14px;
  box-shadow: var(--shadow-card);
  transition: border-color var(--t) var(--ease);
  scroll-margin-top: calc(var(--topbar-h, 96px) + 12px);
}
.card h2 { margin: 0 0 12px; font-size: 18px; }
.card h3 { margin: 16px 0 10px; font-size: 15px; opacity: 0.95; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* ========== Buttons ========== */
.btn {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--btn-border);
  background: var(--btn-bg);
  color: inherit;
  cursor: pointer;
  font: inherit;
  transition: background var(--t) var(--ease), border-color var(--t) var(--ease), transform var(--t) var(--ease);
}
.btn:hover { background: var(--hover-bg); }
.btn:active { transform: translateY(1px); }
/* Accent outline, outside the button: reaches 3:1 on the page and on accent-filled buttons */
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ========== Table ========== */
.tableWrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left;
  font-size: 12px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  opacity: 0.8;
  padding: 10px 8px;
  border-bottom: 1px solid var(--card-border);
  position: sticky;
  top: 0;
  background: var(--thead-bg);
  backdrop-filter: blur(4px);
}
tbody td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--row-border);
  font-size: 13px;
  white-space: nowrap;
}
tbody td:nth-child(2) { width: 99%; white-space: nowrap; }
tbody tr { cursor: pointer; transition: background var(--t) var(--ease); }
tbody tr:hover { background: var(--soft-bg); }
tbody tr.active { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
/* The nickname is a button (js/app.js renderTable) that looks like plain text; its row shows the focus */
.row-pick { all: unset; cursor: pointer; }
tbody tr:has(.row-pick:focus-visible) { outline: 2px solid var(--accent); outline-offset: -2px; }
.right { text-align: right; }
.rank-1 { background: rgba(255, 215, 0, 0.10); }
.rank-2 { background: rgba(180, 200, 230, 0.10); }
.rank-3 { background: rgba(205, 127, 50, 0.10); }
.delta-pos { color: #52d18a; }
.delta-neg { color: #ff7676; }
.delta-zero { opacity: 0.6; }

/* ========== Stats ========== */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 10px; }
.stat {
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: var(--soft-bg);
  border: 1px solid var(--card-border);
  text-align: center;
  transition: border-color var(--t) var(--ease), transform var(--t) var(--ease);
}
.stat:hover { border-color: var(--soft-border); }
.stat span { display: block; font-size: 12px; opacity: 0.75; }
.stat strong { display: block; font-size: 18px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat-note {
  display: block; margin-top: 2px;
  font-size: 11px; line-height: 1.3; opacity: 0.7;
  font-variant-numeric: tabular-nums; text-wrap: balance;
}
/* Live rating: a small dot, accent-coloured (and gently breathing) while the tile shows
 * results of the current work day, muted otherwise. */
.live-dot {
  display: inline-block; width: 7px; height: 7px; margin-right: 6px; vertical-align: 1px;
  border-radius: 50%; background: rgba(255, 255, 255, 0.35);
}
.stat-live.is-today .live-dot {
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(53, 192, 122, 0.18);
  animation: liveDot 2.8s ease-in-out infinite;
}
@keyframes liveDot { 50% { opacity: 0.5; } }
@media (prefers-reduced-motion: reduce) {
  .stat-live.is-today .live-dot { animation: none; }
}

/* ========== Period switch ========== */
.dateRange {
  display: flex; align-items: center; gap: 6px; flex-shrink: 0;
}
.dateRange input[type="date"] {
  padding: 6px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--input-border); background: var(--soft-bg);
  color: inherit; font: inherit; font-size: 13px; cursor: pointer; outline: none;
  transition: border-color var(--t) var(--ease), box-shadow var(--t) var(--ease);
  color-scheme: dark;
}
.dateRange input[type="date"]:focus {
  border-color: var(--accent-border);
  box-shadow: 0 0 0 3px rgba(53,192,122,0.15);
}
.dateRange input[type="date"]:focus-visible { border-color: var(--accent); } /* 3:1, as the search field */
.date-sep { opacity: 0.4; font-size: 13px; }

/* ========== Leaderboard: month picker and freshness line ========== */
#monthPick {
  margin: 0 0 12px; max-width: 100%;
  padding: 6px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--input-border); background: var(--soft-bg);
  color: inherit; font: inherit; font-size: 13px; cursor: pointer; outline: none;
  transition: border-color var(--t) var(--ease), box-shadow var(--t) var(--ease);
  color-scheme: dark;
}
#monthPick:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(53,192,122,0.15); }
/* "Results up to ... · updated ..." under the heading; the second line flags a sheet that has
 * had no new results since before the previous work day */
.freshness { margin: -4px 0 10px; font-size: 12px; line-height: 1.4; opacity: 0.75; font-variant-numeric: tabular-nums; }
.freshness-stale { display: block; }

/* ========== Chart ========== */
.chartWrap {
  position: relative; margin: 12px 0 6px; padding: 8px; height: 420px;
  border-radius: var(--radius-md); border: 1px solid var(--card-border);
  background: var(--chart-bg);
}
@media (max-width: 1099.98px) { .chartWrap { height: 300px; } }
#chart { display: block; width: 100%; height: 100%; cursor: crosshair; }
.chartTip {
  position: absolute; z-index: 5;
  background: var(--tip-bg);
  border: 1px solid var(--accent-border); border-radius: 10px;
  padding: 6px 10px; font-size: 12px; pointer-events: none;
  white-space: nowrap; transform: translate(-50%, calc(-100% - 14px));
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.45);
  font-variant-numeric: tabular-nums; line-height: 1.3;
}
.chartTip[hidden] { display: none; }
.chartTip strong { display: block; color: var(--accent); font-size: 14px; font-weight: 700; }
.chartTip span { display: block; opacity: 0.7; font-size: 11px; }

/* ========== History ========== */
#history { list-style: none; padding: 0; margin: 0; max-height: 320px; overflow-y: auto; }
#history:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#history li {
  display: flex; align-items: center;
  padding: 7px 0; border-bottom: 1px dashed var(--card-border);
  font-size: 13px; font-variant-numeric: tabular-nums;
}
#history li:last-child { border-bottom: none; }
#history li span:first-child {
  flex: 1;
  color: rgba(255, 255, 255, 0.50);
  font-size: 12px;
}
#history li span:last-child {
  flex: 2;
  text-align: left;
  white-space: nowrap;
}
.hist-reset-col {
  flex: 0 0 60px;
  font-size: 11px;
  opacity: 0.5;
  text-align: center;
  white-space: nowrap; /* "✎ adjusted" stays on one line */
}
.hist-rank {
  flex: 1;
  font-size: 12px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.46); /* 4.6:1 on the card */
  text-align: left;
}
.hist-arrow {
  color: var(--accent);
  font-style: normal;
  margin: 0 5px;
}
.hist-reset-col[title] { cursor: help; }
/* "set to 1200 (from 1150) at 15:04" under the change of a day with a manual set */
.hist-note {
  display: block; margin-top: 2px;
  font-size: 11px; line-height: 1.35; opacity: 0.7;
  white-space: normal;
}

/* ========== Matches ==========
 * One row per match: date and time, opponent, score, points; a match that did not count gets
 * a note with the reason on a line of its own. */
#matches { list-style: none; padding: 0; margin: 0; max-height: 320px; overflow-y: auto; }
#matches:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#matches li {
  display: grid; grid-template-columns: 8.5em minmax(0, 1fr) auto 3.5em; gap: 2px 10px; align-items: baseline;
  padding: 7px 8px 7px 0; /* right: room for an overlay scrollbar over the points column */
  border-bottom: 1px dashed var(--card-border);
  font-size: 13px; font-variant-numeric: tabular-nums;
}
#matches li:last-child { border-bottom: none; }
#matches li > span:first-child { color: rgba(255, 255, 255, 0.50); font-size: 12px; }
#matches li > span:nth-child(2) { overflow-wrap: anywhere; }
#matches li > span:nth-child(4) { text-align: right; }
#matches .match-note { grid-column: 2 / -1; font-size: 11px; line-height: 1.35; opacity: 0.7; }
#matches .match-empty { display: block; opacity: 0.7; }
.more-btn { display: block; width: 100%; margin-top: 8px; font-size: 13px; }
.more-btn[hidden] { display: none; }

/* ========== Photo card ========== */
.photoWrap {
  width: 100%; aspect-ratio: 1 / 1; border-radius: var(--radius-lg);
  overflow: hidden; border: 1px solid var(--card-border);
  background: rgba(0, 0, 0, 0.25);
  display: flex; align-items: center; justify-content: center;
}
#playerPhoto { width: 100%; height: 100%; object-fit: cover; transition: transform 400ms var(--ease), opacity 200ms var(--ease); }
#playerPhoto:hover { transform: scale(1.02); }
.photoMeta { margin-top: 10px; }
.photoNick { font-weight: 700; font-size: 16px; }
.photoGroup { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.groupDot {
  width: 10px; height: 10px; border-radius: 50%; background: #7A8196;
  border: 1px solid rgba(255, 255, 255, 0.25);
  transition: background var(--t) var(--ease), box-shadow var(--t) var(--ease);
}
.groupName { font-size: 13px; opacity: 0.9; }
.group-label { font-size: 12px; opacity: 0.5; text-transform: uppercase; letter-spacing: 0.05em; }

/* ========== Player Achievements ========== */
.player-achievements { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; min-height: 0; }
.player-achievements:empty { display: none; }
.ach-badge { position: relative; display: inline-flex; align-items: center; justify-content: center; cursor: default; }
.ach-badge img {
  width: 36px; height: 36px; border-radius: 50%; object-fit: cover;
  border: 2px solid rgba(53, 210, 110, 0.5); background: rgba(0,0,0,0.3);
  transition: transform var(--t) var(--ease), border-color var(--t) var(--ease), box-shadow var(--t) var(--ease);
}
.ach-badge:hover img { transform: scale(1.12); border-color: rgba(53, 210, 110, 0.9); box-shadow: 0 0 12px rgba(53, 210, 110, 0.4); }
.ach-badge-tip {
  position: absolute; bottom: calc(100% + 7px); left: 50%; transform: translateX(-50%);
  white-space: nowrap; background: var(--tip-bg);
  border: 1px solid rgba(53, 210, 110, 0.4); color: var(--fg);
  font-size: 11px; font-weight: 600; padding: 4px 9px; border-radius: 8px;
  pointer-events: none; opacity: 0; transition: opacity 150ms ease; z-index: 10;
}
/* Shown on hover and on keyboard focus; it never takes the pointer, so it cannot cover a click
 * on the badge above it. */
.ach-badge:hover .ach-badge-tip { opacity: 1; }
.ach-badge:focus-visible .ach-badge-tip { opacity: 1; }
.ach-badge.tip-dismissed .ach-badge-tip { opacity: 0; } /* Escape (js/app.js) */
.ach-badge--link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 50%; }
.ach-badge--link { text-decoration: none; cursor: pointer; }
.ach-badge--link img { border-color: rgba(53, 210, 110, 0.7); box-shadow: 0 0 8px rgba(53, 210, 110, 0.25); }
.ach-badge--link:hover img { border-color: rgba(53, 210, 110, 1); box-shadow: 0 0 16px rgba(53, 210, 110, 0.5); }

/* ========== Footer ========== */
footer { padding: 14px 0 20px; text-align: center; opacity: 0.7; border-top: 1px solid var(--footer-border); font-size: 13px; }

/* ========== Scrollbar ========== */
#history, #matches, .tableWrap { scrollbar-width: thin; scrollbar-color: rgba(53, 192, 122, 0.5) transparent; }
#history::-webkit-scrollbar, #matches::-webkit-scrollbar, .tableWrap::-webkit-scrollbar { width: 5px; height: 5px; }
#history::-webkit-scrollbar-track, #matches::-webkit-scrollbar-track, .tableWrap::-webkit-scrollbar-track { background: transparent; border-radius: 99px; }
#history::-webkit-scrollbar-thumb, #matches::-webkit-scrollbar-thumb, .tableWrap::-webkit-scrollbar-thumb { background: rgba(53, 192, 122, 0.35); border-radius: 99px; }
#history::-webkit-scrollbar-thumb:hover, #matches::-webkit-scrollbar-thumb:hover, .tableWrap::-webkit-scrollbar-thumb:hover { background: rgba(53, 192, 122, 0.7); }

/* ========== Player of the Week ========== */
.week-banner {
  background: linear-gradient(90deg, rgba(53,192,122,0.08) 0%, rgba(53,192,122,0.04) 100%);
  border-bottom: 1px solid rgba(53,192,122,0.2); padding: 10px 0;
  animation: fadeIn 400ms var(--ease) both;
}
.week-banner:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.week-inner { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.week-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent); opacity: 0.9; white-space: nowrap; }
.week-player { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.week-avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; border: 2px solid rgba(53,192,122,0.5); background: rgba(0,0,0,0.3); flex-shrink: 0; }
.week-nick { font-weight: 700; font-size: 15px; }
.week-delta { font-size: 13px; color: var(--accent); font-weight: 600; }
.week-rating { font-size: 13px; opacity: 0.6; margin-left: auto; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ========== Mini Card ========== */
.mini-card {
  position: fixed; z-index: 500; background: var(--card-bg);
  border: 1px solid rgba(53,192,122,0.3); border-radius: var(--radius-md);
  padding: 12px; width: 200px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5), 0 0 0 1px rgba(53,192,122,0.1);
  pointer-events: none; animation: fadeIn 150ms var(--ease) both;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.mini-avatar { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; border: 2px solid rgba(53,192,122,0.4); background: rgba(0,0,0,0.3); display: block; margin: 0 auto 10px; }
.mini-body { text-align: center; }
.mini-nick { font-weight: 700; font-size: 14px; margin-bottom: 4px; }
.mini-rating { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--accent); margin-bottom: 6px; }
.mini-row { display: flex; align-items: center; justify-content: center; gap: 6px; margin-bottom: 4px; }
.mini-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.mini-group { font-size: 12px; opacity: 0.8; }

/* ========== Compare button ========== */
.cmp-btn {
  display: inline-flex; align-items: center; justify-content: center;
  height: 18px; padding: 0 7px; border-radius: 99px;
  background: transparent; border: 1px solid rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.51); font-size: 10px; font-weight: 600; /* 4.6:1 on every row, the active one included */
  letter-spacing: 0.04em; text-transform: uppercase;
  cursor: pointer; transition: all var(--t) var(--ease);
  vertical-align: middle; margin-left: 6px; flex-shrink: 0; white-space: nowrap;
}
[data-theme="light"] .cmp-btn { border-color: rgba(0,0,0,0.15); color: rgba(0,0,0,0.35); }
.cmp-btn:hover { background: rgba(53,192,122,0.12); border-color: rgba(53,192,122,0.5); color: var(--accent); }
.cmp-btn.selected { background: rgba(53,192,122,0.12); border-color: var(--accent); color: var(--accent); } /* a lighter fill keeps the accent text at 4.6:1 on the active row */
.cmp-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* Keyboard focus on the row's nickname reveals it too; a mouse click (no :focus-visible) does not */
tr:not(:hover):not(:has(:focus-visible)) .cmp-btn:not(.selected):not(:focus-visible) { opacity: 0; }
/* Touch screens have no hover to reveal the "vs" button, whatever their width. Shown in full:
 * any dimming takes its small text under 4.5:1. */
@media (hover: none) {
  tr:not(:hover):not(:has(:focus-visible)) .cmp-btn:not(.selected):not(:focus-visible) { opacity: 1; }
}

/* ========== Comparison Modal ========== */
.compare-modal { position: fixed; inset: 0; z-index: 600; display: flex; align-items: center; justify-content: center; padding: 20px; }
.compare-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.7); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.compare-box {
  position: relative; z-index: 1; background: var(--bg);
  border: 1px solid var(--card-border); border-radius: var(--radius-lg);
  padding: 28px; width: 100%; max-width: 640px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.6);
  animation: fadeIn 250ms var(--ease) both; max-height: 90vh; overflow-y: auto;
}
.compare-close {
  position: absolute; top: 16px; right: 16px;
  background: var(--soft-bg); border: 1px solid var(--soft-border);
  color: inherit; width: 32px; height: 32px; border-radius: 50%;
  cursor: pointer; font-size: 14px; display: flex; align-items: center; justify-content: center;
  transition: background var(--t) var(--ease);
}
.compare-close:hover { background: rgba(255,118,118,0.15); border-color: rgba(255,118,118,0.4); color: #ff7676; }
.compare-title { margin: 0 0 20px; font-size: 17px; text-align: center; }
.compare-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.compare-col { background: var(--card-bg); border: 1px solid var(--card-border); border-radius: var(--radius-md); padding: 16px; text-align: center; }
.compare-col.winner { border-color: rgba(53,192,122,0.45); background: rgba(53,192,122,0.05); }
.compare-col-avatar { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; border: 2px solid var(--card-border); background: rgba(0,0,0,0.3); display: block; margin: 0 auto 10px; }
.compare-col.winner .compare-col-avatar { border-color: rgba(53,192,122,0.6); }
.compare-col-nick { font-weight: 700; font-size: 15px; margin-bottom: 14px; }
.compare-stat { margin-bottom: 10px; }
.compare-stat-label { font-size: 11px; opacity: 0.5; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 3px; }
.compare-stat-val { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.compare-badge-spacer { height: 22px; }
.compare-winner-badge { display: inline-block; font-size: 11px; font-weight: 700; color: var(--accent); background: rgba(53,192,122,0.12); border: 1px solid rgba(53,192,122,0.3); border-radius: 99px; padding: 2px 10px; margin-bottom: 10px; }
/* Head to head, under the two columns */
.compare-h2h { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--card-border); font-size: 13px; text-align: center; }
.compare-h2h h3, .compare-h2h h4 { margin: 0 0 8px; font-size: 11px; opacity: 0.6; text-transform: uppercase; letter-spacing: 0.05em; }
.compare-h2h h4 { margin-top: 14px; }
.compare-h2h p { margin: 0; line-height: 1.5; overflow-wrap: anywhere; }
.compare-h2h-total { opacity: 0.7; white-space: nowrap; }
.compare-h2h ul { list-style: none; margin: 0 auto; padding: 0; max-width: 420px; text-align: left; }
.compare-h2h li {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 6px 0; border-bottom: 1px dashed var(--card-border); font-variant-numeric: tabular-nums;
}
.compare-h2h li:last-child { border-bottom: none; }
.compare-h2h li span:first-child { opacity: 0.7; white-space: nowrap; }
.compare-h2h li span:last-child { min-width: 0; text-align: right; overflow-wrap: anywhere; }

/* ========== Loading Overlay ========== */
.loading-overlay {
  position: fixed; inset: 0; z-index: 999; background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  transition: opacity 400ms ease, visibility 400ms ease;
  touch-action: none;
  overflow: hidden;
}
.loading-overlay.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.loading-box {
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  animation: loading-glow 2s ease-in-out infinite;
}
.loading-spinner {
  width: 48px; height: 48px; border-radius: 50%;
  border: 3px solid rgba(53, 192, 122, 0.15);
  border-top-color: var(--accent);
  animation: spin 800ms linear infinite;
}
.loading-text { font-size: 18px; font-weight: 700; letter-spacing: 0.02em; color: var(--fg); }
.loading-sub { font-size: 13px; opacity: 0.5; animation: pulse 1.5s ease-in-out infinite; } /* 4.7:1 at its dimmest */

/* ========== Back to top ========== */
.back-to-top {
  position: fixed; bottom: 20px; right: 16px; z-index: 100;
  display: none; width: 42px; height: 42px; border-radius: 50%;
  background: var(--accent); border: none; color: #0b0f14;
  font-size: 20px; line-height: 1; cursor: pointer;
  box-shadow: 0 4px 16px rgba(53,192,122,0.4);
  align-items: center; justify-content: center;
  transition: transform var(--t) var(--ease), opacity var(--t) var(--ease);
}
.back-to-top.visible { display: flex; }
.back-to-top:hover { transform: translateY(-2px); }

/* ========== Load notice ========== */
.load-notice {
  position: fixed; left: 16px; bottom: 20px; z-index: 100;
  max-width: calc(100% - 90px); padding: 10px 14px;
  border-radius: var(--radius-sm); background: var(--tip-bg);
  border: 1px solid rgba(255,118,118,0.45); color: #ff9a9a;
  font-size: 13px; cursor: pointer;
  box-shadow: 0 8px 22px rgba(0,0,0,0.45);
  animation: fadeIn 250ms var(--ease) both;
}

/* ========== Alpha notice ==========
 * Both pages (admin.html loads this file too). The strip is the first child of <body>, in
 * normal flow, so the sticky headers below it still stick to the top. The watermark covers
 * the viewport above everything, modals and overlays included (body is a stacking context),
 * and ignores the pointer, so the page stays readable and clickable. */
.alpha-strip {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
  gap: 4px 10px;
  padding: 6px 16px;
  padding: 6px max(16px, env(safe-area-inset-right)) 6px max(16px, env(safe-area-inset-left));
  background: #231b07;
  border-bottom: 1px solid rgba(245, 181, 61, 0.35);
  color: #f5dfae;
  font-size: 12px; line-height: 1.4; text-align: center;
}
.alpha-strip strong {
  flex: none;
  padding: 1px 8px; border-radius: 99px;
  background: #f5b53d; color: #1a1204;
  font-size: 11px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase;
}
body::after {
  content: "";
  position: fixed; inset: 0; z-index: 2147483647;
  pointer-events: none;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='360' height='220'%3E%3Ctext x='180' y='110' transform='rotate(-24 180 110)' text-anchor='middle' dominant-baseline='middle' font-family='system-ui,-apple-system,Segoe UI,Roboto,Arial,sans-serif' font-size='15' font-weight='700' letter-spacing='2' fill='%23ffffff' fill-opacity='0.06'%3EALPHA PRODUCT %C2%B7 NOT FINAL%3C/text%3E%3C/svg%3E") repeat;
}
@media print {
  body::after {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='360' height='220'%3E%3Ctext x='180' y='110' transform='rotate(-24 180 110)' text-anchor='middle' dominant-baseline='middle' font-family='system-ui,-apple-system,Segoe UI,Roboto,Arial,sans-serif' font-size='15' font-weight='700' letter-spacing='2' fill='%23000000' fill-opacity='0.08'%3EALPHA PRODUCT %C2%B7 NOT FINAL%3C/text%3E%3C/svg%3E");
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  .alpha-strip { background: none; color: #000; border-bottom-color: #000; }
  .alpha-strip strong { background: none; color: #000; border: 1px solid #000; }
}

/* ========== Tablet and phone (< 1100px) ==========
 * Every rule here sits in a max-width query, so the desktop layout (>= 1100px, 3 columns; see
 * .grid) is untouched, and uses public-page selectors, since admin.html loads this file too.
 * Breakpoints (scrollToProfile in js/app.js uses the same): phone < 768px, tablet 768-1099px. */
@media (max-width: 1099.98px) {
  /* Keep the 16px side gutter (.grid's padding shorthand otherwise zeroes .container's), and
   * let no card's content widen its column past the viewport. */
  .grid { grid-template-columns: minmax(0, 1fr); padding-left: 16px; padding-right: 16px; }
  .grid > .card { min-width: 0; }

  /* Leaderboard: long nicknames wrap instead of widening the table; rows and the "vs"
   * button are comfortable to tap (the button's ::before extends its hit area to 40px+). */
  #leaderboard tbody td { padding-top: 8px; padding-bottom: 8px; }
  #leaderboard tbody td:nth-child(2) { white-space: normal; overflow-wrap: anywhere; }
  #leaderboard .cmp-btn {
    position: relative; height: 26px; min-width: 36px; padding: 0 10px; margin-left: 8px; font-size: 11px;
  }
  #leaderboard .cmp-btn::before { content: ""; position: absolute; inset: -7px -4px; }

  .week-info { min-width: 0; }
  .week-nick { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  #profileTitle { min-width: 0; overflow-wrap: anywhere; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .photoNick { overflow-wrap: anywhere; }
  /* Achievement names: laid out only while shown, so a badge near the edge never widens the page */
  .ach-badge-tip { display: none; width: max-content; max-width: min(220px, 70vw); white-space: normal; text-align: center; }
  .ach-badge:hover .ach-badge-tip, .ach-badge:focus-visible .ach-badge-tip { display: block; }

  .back-to-top {
    right: calc(16px + env(safe-area-inset-right, 0px));
    bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  }
  .load-notice {
    left: calc(16px + env(safe-area-inset-left, 0px));
    bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    max-width: calc(100% - 90px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
  }
}
/* Touch screens under 1100px: finger-sized date inputs; iOS zooms into inputs under 16px */
@media (max-width: 1099.98px) and (pointer: coarse) {
  .actions input[type="search"], .dateRange input[type="date"], #monthPick { font-size: 16px; }
  .dateRange input[type="date"] { min-height: 40px; padding-top: 9px; padding-bottom: 9px; }
  #monthPick, .more-btn { min-height: 44px; }
}

/* ========== Tablet (768-1099px) ==========
 * Two columns: the leaderboard on the left; on the right the selected player's photo card,
 * compact, as a header above their profile. A tap on a row then shows the player beside the
 * list instead of below it, and the photo no longer fills the width as a giant square. */
@media (min-width: 768px) and (max-width: 1099.98px) {
  .grid {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.45fr);
    grid-template-rows: auto 1fr; /* the long leaderboard's extra height goes to the profile row */
    grid-template-areas: "board photo" "board profile";
    align-items: start;
  }
  .leaderboardCard { grid-area: board; }
  .profileCard { grid-area: profile; }
  .photoCard { grid-area: photo; display: grid; grid-template-columns: 112px minmax(0, 1fr); gap: 14px; align-items: center; }
  .photoWrap { width: 112px; height: 112px; aspect-ratio: unset; border-radius: var(--radius-md); }
  .photoMeta { margin-top: 0; }
  .player-achievements { margin-top: 10px; }
}

/* ========== Mobile ========== */
/* Phone (< 768px): one column; the topbar stacks (title, then full-width search + buttons). */
@media (max-width: 767.98px) {
  .topbar { padding: 12px 0; }
  .topbar-row { gap: 8px; }
  .brand h1 { font-size: 18px; }
  .subtitle { display: none; }
  .actions { width: 100%; gap: 8px; }
  .actions input[type="search"] { flex: 1; min-width: 0; font-size: 16px; }

  .grid { grid-template-columns: minmax(0, 1fr); gap: 12px; padding: 12px 16px 20px; }
  .card { padding: 12px; }
  .card h2 { font-size: 16px; }

  .card-head { gap: 8px 12px; }
  .dateRange { width: 100%; }
  .dateRange input[type="date"] { flex: 1 1 0; min-width: 0; padding: 9px 8px; font-size: 16px; }

  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .stat strong { font-size: 16px; }

  .chartWrap { height: clamp(200px, 58vw, 260px); }
  #history, #matches { max-height: 240px; }
  #history li { flex-wrap: wrap; row-gap: 2px; }

  .photoCard { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 12px; align-items: start; }
  .photoWrap { width: 110px; height: 110px; aspect-ratio: unset; border-radius: var(--radius-md); }
  .photoMeta { margin-top: 0; }
  .photoCard h2 { display: none; }

  .week-inner { gap: 6px 10px; }
  .week-rating { display: none; }

  .compare-modal {
    padding: 12px;
    padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
             max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  }
  .compare-box { padding: 18px 12px; max-height: 100%; }
  .compare-close { top: 8px; right: 8px; width: 40px; height: 40px; }
  .compare-title { padding: 0 44px; }
  .compare-grid { gap: 8px; }
  .compare-col { padding: 12px 8px; }
  .compare-col-avatar { width: 48px; height: 48px; }
  .compare-col-nick { overflow-wrap: anywhere; }
  .compare-stat-val { font-size: 15px; }

  .mini-card { display: none !important; }
  tr:not(:hover):not(:has(:focus-visible)) .cmp-btn:not(.selected):not(:focus-visible) { opacity: 1; }
}

/* Small phones (< 480px) */
@media (max-width: 479.98px) {
  .week-label { flex-basis: 100%; }

  /* History rows on two lines: date, rank and tag, then the change (and any set note) */
  #history { max-height: 276px; }
  #history li { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; column-gap: 10px; }
  #history li > span:last-child { grid-column: 1 / -1; }
  .hist-reset-col { text-align: right; }

  /* Match rows on two lines: date and time, then opponent, score and points (and any note) */
  #matches { max-height: 276px; }
  #matches li { grid-template-columns: minmax(0, 1fr) auto 3.5em; }
  #matches li > span:first-child, #matches .match-note { grid-column: 1 / -1; }

  /* Compare: the two players stacked, each with its stats in a 3 x 2 grid */
  .compare-grid { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .compare-col { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px 6px; padding: 12px 10px; }
  .compare-col > :not(.compare-stat) { grid-column: 1 / -1; }
  .compare-badge-spacer { display: none; }
  .compare-winner-badge { justify-self: center; margin-bottom: 0; }
  .compare-col-avatar { width: 44px; height: 44px; margin: 0 auto; }
  .compare-col-nick { margin-bottom: 2px; }
  .compare-stat { margin-bottom: 0; }
  .compare-stat-label { font-size: 10px; letter-spacing: 0.03em; }
  .compare-stat-val { font-size: 14px; }
}
/* Narrowest phones (< 360px): the two date inputs stack (From above To) */
@media (max-width: 359.98px) {
  .dateRange { flex-wrap: wrap; }
  .dateRange input[type="date"] { flex-basis: 100%; }
  .date-sep { display: none; }
}

/* ========== Animations ========== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse {
  0%, 100% { opacity: 0.5; }
  50%       { opacity: 0.9; }
}
@keyframes loading-glow {
  0%, 100% {
    filter:
      drop-shadow(0 0 24px rgba(53, 192, 122, 0.42))
      drop-shadow(0 0 64px rgba(53, 192, 122, 0.18));
  }
  50% {
    filter:
      drop-shadow(0 0 40px rgba(53, 192, 122, 0.96))
      drop-shadow(0 0 110px rgba(53, 192, 122, 0.48))
      drop-shadow(0 0 180px rgba(53, 192, 122, 0.18));
  }
}
