:root {
  --bg: #07121f;
  --bg-2: #0b1a2e;
  --panel: #0f2240;
  --panel-2: #183055;
  --line: rgba(255, 255, 255, 0.09);
  --line-2: rgba(255, 255, 255, 0.16);
  --text: #f5efe0;
  --muted: #a7b3c6;
  --dim: #6c7c95;
  --gold: #d9c49a;
  --navy-hi: #4f7fc0;
  --gold-2: #efe2c2;
  --fairway: #2fa66a;
  --red: #ff5a4f;
  --radius: 16px;
  --display: 'Bebas Neue', 'Oswald', Impact, 'Arial Narrow', sans-serif;
  --body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--body);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
img { display: block; max-width: 100%; }
button { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; }

.display { font-family: var(--display); letter-spacing: 0.02em; font-weight: 400; }

/* Buttons & inputs */
.btn {
  appearance: none;
  border: 1px solid var(--line-2);
  background: var(--panel-2);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 12px;
  font-weight: 650;
  font-size: 15px;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease, opacity 0.15s;
  touch-action: manipulation;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
.btn.primary { background: var(--gold); border-color: var(--gold); color: #0c2340; }
.btn.go { background: var(--fairway); border-color: var(--fairway); color: #fff; }
.btn.danger { background: transparent; border-color: rgba(255, 90, 79, 0.5); color: var(--red); }
.btn.ghost { background: transparent; }
.btn.small { padding: 7px 12px; font-size: 13px; border-radius: 9px; }
.btn.block { width: 100%; }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: 10px;
  padding: 11px 12px;
  width: 100%;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--gold); }
/* iPhones zoom in on any text box under 16px and don't zoom back out. */
input, select, textarea { font-size: max(16px, 1em); }
label.field { display: grid; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 600; }

input[type='range'] {
  -webkit-appearance: none;
  appearance: none;
  padding: 0;
  height: 30px;
  background: transparent;
  border: 0;
}
input[type='range']::-webkit-slider-runnable-track { height: 8px; border-radius: 99px; background: linear-gradient(90deg, var(--gold) var(--fill, 50%), rgba(255, 255, 255, 0.12) var(--fill, 50%)); }
input[type='range']::-moz-range-track { height: 8px; border-radius: 99px; background: rgba(255, 255, 255, 0.12); }
input[type='range']::-moz-range-progress { height: 8px; border-radius: 99px; background: var(--gold); }
input[type='range']::-webkit-slider-thumb { -webkit-appearance: none; width: 26px; height: 26px; margin-top: -9px; border-radius: 50%; background: #fff; border: 3px solid var(--gold); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4); }
input[type='range']::-moz-range-thumb { width: 22px; height: 22px; border-radius: 50%; background: #fff; border: 3px solid var(--gold); }

/* Avatars */
.avatar {
  --h: 215;
  position: relative;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  overflow: hidden;
  flex: none;
  background: linear-gradient(145deg, hsl(var(--h) 55% 38%), hsl(calc(var(--h) + 40) 60% 22%));
  display: grid;
  place-items: center;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar span { font-family: var(--display); font-size: 1.15em; color: rgba(255, 255, 255, 0.92); letter-spacing: 0.04em; }
.avatar.fill { width: 100%; height: 100%; border-radius: 0; }
.avatar.fill span { font-size: clamp(48px, 9vw, 140px); opacity: 0.85; }
/* Transparent card art stands in front of the Grove Street sign. */
.avatar.cutout { background: linear-gradient(165deg, #3a6ea5 0%, #1d4577 48%, #0c2240 100%); }
.avatar.cutout img { position: relative; }
.avatar.cutout:not(.fill) img { transform: scale(1.9); transform-origin: 50% 8%; }
.avatar.fill.cutout::before {
  content: '';
  position: absolute;
  inset: -2% 0;
  background: #fff;
  -webkit-mask: url(/img/grove-street-logo.svg) center 42% / 92% auto no-repeat;
  mask: url(/img/grove-street-logo.svg) center 42% / 92% auto no-repeat;
}

/* Player card */
.pcard {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr;
  border-radius: 22px;
  overflow: hidden;
  background: linear-gradient(170deg, #1b355c 0%, #0f2240 45%, #0a1628 100%);
  border: 1px solid rgba(217, 196, 154, 0.35);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
/* Card photos are cropped to 4:3 when uploaded, so every screen shows the same framing. */
.pcard-photo { aspect-ratio: 4 / 3; position: relative; overflow: hidden; }
.pcard-photo::after { content: ''; position: absolute; inset: 0; background: linear-gradient(180deg, transparent 48%, rgba(10, 22, 40, 0.55) 68%, rgba(10, 22, 40, 0.97)); }
/* Name, nickname and tags sit on the photo; the green section below holds only stats. */
.pcard-overlay { position: absolute; left: 0; right: 0; bottom: 0; z-index: 1; padding: 0 20px 14px; }
.pcard-badges { position: absolute; top: 14px; left: 14px; display: flex; gap: 8px; z-index: 2; }
.pcard-badges > div {
  display: grid;
  justify-items: center;
  padding: 6px 10px 4px;
  border-radius: 12px;
  background: rgba(7, 18, 31, 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--line-2);
  line-height: 1;
}
.pcard-badges b { font-family: var(--display); font-size: 30px; font-weight: 400; }
.pcard-badges span { font-size: 10px; letter-spacing: 0.14em; color: var(--muted); font-weight: 700; margin-top: 2px; }
.pcard-badges .ovr b { color: var(--gold); }
.pcard-body { padding: 16px 20px 20px; position: relative; z-index: 1; }
/* Names stay on one line: long ones scale down to the card's width (--len is the letter count). */
.pcard-overlay { container-type: inline-size; }
.pcard-name { --name-max: 40px; font-size: min(var(--name-max), calc(100cqi / (var(--len, 10) * 0.48))); white-space: nowrap; font-family: var(--display); font-weight: 400; line-height: 0.95; letter-spacing: 0.02em; text-shadow: 0 2px 12px rgba(0, 0, 0, 0.45); }
.pcard-nick { font-family: var(--body); color: var(--gold); font-weight: 700; font-size: 0.42em; letter-spacing: 0.02em; vertical-align: 0.35em; white-space: nowrap; }
.pcard-rounds { margin-top: 6px; font-size: 13px; font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase; color: var(--gold); text-shadow: 0 1px 8px rgba(0, 0, 0, 0.6); }
.stats { display: grid; gap: 11px; }
.stat { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; font-size: 15px; }
.pips { display: flex; gap: 5px; }
.pips i { width: 30px; height: 12px; border-radius: 3px; background: rgba(255, 255, 255, 0.12); }
.pips i.on { background: linear-gradient(90deg, var(--navy-hi), var(--gold)); box-shadow: 0 0 10px rgba(217, 196, 154, 0.25); }
.stat-label { color: var(--muted); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-track { position: relative; height: 8px; border-radius: 99px; background: rgba(255, 255, 255, 0.1); }
.stat-track b { position: absolute; inset: 0 auto 0 0; border-radius: inherit; background: linear-gradient(90deg, var(--navy-hi), var(--gold)); }
.stat-track .self { position: absolute; top: -4px; bottom: -4px; width: 2px; margin-left: -1px; background: #fff; opacity: 0.75; border-radius: 2px; }
.stat-val { font-family: var(--display); font-size: 18px; text-align: right; }
.stat-text { grid-template-columns: 7.5em 1fr; }
.fun-fact { margin: 16px 0 0; font-size: 14px; line-height: 1.45; color: #d9d4c4; font-style: italic; }

/* Toast + connection */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  background: #fff;
  color: #111;
  font-weight: 650;
  padding: 12px 18px;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  transition: 0.2s ease;
  z-index: 1000;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--red); color: #fff; }
.toast.good { background: var(--fairway); color: #fff; }

.offline-banner { display: none; }
.offline .offline-banner {
  display: block;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 999;
  background: var(--red);
  color: #fff;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  padding: 6px;
}

.team-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c, var(--gold)); flex: none; }
.empty { color: var(--dim); text-align: center; padding: 28px 12px; }


.shot-icon { width: 1.3em; height: 1.5em; flex: none; fill: none; stroke: #efe2c2; stroke-width: 4.5; stroke-linecap: round; stroke-linejoin: round; vertical-align: -0.35em; }
.shot-icon .shot-glow { stroke: rgba(239, 226, 194, 0.28); stroke-width: 10; }

/* Logo is tinted through a mask, so it follows the theme color instead of the SVG's white. */
.logo {
  display: block;
  flex: none;
  aspect-ratio: 257 / 170;
  color: var(--gold);
  background: currentColor;
  -webkit-mask: url(/img/grove-street-logo.svg) center / contain no-repeat;
  mask: url(/img/grove-street-logo.svg) center / contain no-repeat;
}
.logo.brand-big { width: 520px; max-width: 80vw; filter: drop-shadow(0 0 40px rgba(217, 196, 154, 0.35)); }
.logo.brand-lg, .logo-md { width: 170px; }
.logo.brand { width: 84px; }
.logo-kicker { width: 240px; margin-bottom: 18px; }

/* Player matrix */
.matrix-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); }
.matrix { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 14px; }
.matrix th, .matrix td { padding: 0; text-align: center; white-space: nowrap; border-bottom: 1px solid var(--line); }
.matrix tbody tr:last-child > * { border-bottom: 0; }
.matrix thead th { position: sticky; top: 0; background: var(--panel-2); z-index: 2; }
.matrix thead button { appearance: none; border: 0; background: none; color: var(--muted); font: 800 11px/1 var(--body); letter-spacing: 0.08em; padding: 12px 16px; cursor: pointer; width: 100%; touch-action: manipulation; }
.matrix thead th.on button { color: var(--gold); }
/* The sort arrow sits in the button's padding, so sorting never changes a column's width. */
.matrix .m-label { position: relative; }
.matrix .m-arrow { position: absolute; left: 100%; top: 50%; transform: translateY(-50%); margin-left: 3px; font-style: normal; font-size: 9px; letter-spacing: 0; }
.matrix thead th:first-child button { text-align: left; padding-left: 12px; }
.matrix th:first-child { position: -webkit-sticky; position: sticky; left: 0; z-index: 1; background: var(--panel); text-align: left; }
.matrix thead th:first-child { z-index: 3; background: var(--panel-2); }
.matrix td { min-width: 40px; padding: 8px 4px; font-weight: 700; font-variant-numeric: tabular-nums; }
.m-name { padding: 8px 10px 8px 12px !important; min-width: 104px; max-width: 130px; font-weight: 400; box-shadow: 1px 0 0 var(--line); }
.m-name-in { display: flex; align-items: center; gap: 8px; }
.m-name .avatar { width: 32px; height: 32px; flex: none; }
.m-name span { display: grid; min-width: 0; line-height: 1.2; }
.m-name b { font-size: 13px; white-space: normal; line-height: 1.15; }
.m-name small { font-size: 10px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--gold); }
.m-ovr { color: var(--gold); font-family: var(--display); font-size: 20px; font-weight: 400 !important; }
.m-stat { background: color-mix(in srgb, var(--fairway) calc(var(--a) * 75%), transparent); color: var(--text); }
.m-stat:empty::after { content: '–'; color: var(--dim); }
.matrix tr[data-player] { cursor: pointer; }
.matrix tr.dim td, .matrix tr.dim .m-name > * { opacity: 0.45; }
.matrix tr.you .m-name { box-shadow: inset 3px 0 0 var(--gold), 1px 0 0 var(--line); }
.view-toggle { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; margin: 4px 0 12px; }
.view-toggle button { appearance: none; padding: 10px 8px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--bg-2); color: var(--text); font-weight: 700; font-size: 14px; cursor: pointer; }
.view-toggle button.on { background: var(--gold); border-color: var(--gold); color: #0c2340; }
.m-shape .shot-icon { width: 18px; height: 21px; stroke-width: 5; vertical-align: middle; }
.m-shape .shot-icon .shot-glow { display: none; }
.m-shape:empty::after { content: '–'; color: var(--dim); }
