:root {
  --clay: #c25a3a;
  --clay-deep: #9c4429;
  --clay-soft: #f6eae2;
  --bg: #f4ece4;
  --ball: #d6e64f;
  --ball-deep: #c2d23c;
  --ink: #2c2722;
  --muted: #8a7d70;
  --line: #ece1d6;
  --card: #ffffff;
  --ok: #2f8f57;
  --warn: #cf9320;
  --bad: #c0392b;

  --radius: 18px;
  --radius-sm: 11px;
  --shadow-sm: 0 1px 2px rgba(156, 68, 41, .06);
  --shadow: 0 4px 18px rgba(156, 68, 41, .09), 0 1px 3px rgba(156, 68, 41, .05);
  --shadow-lg: 0 18px 44px rgba(156, 68, 41, .18), 0 3px 10px rgba(156, 68, 41, .08);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

/* ───────────────── animations ───────────────── */
@keyframes fadeUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes pop    { from { opacity: 0; transform: scale(.94); } to { opacity: 1; transform: scale(1); } }
@keyframes bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-9px); } }
@keyframes spin   { to { transform: rotate(360deg); } }
@keyframes shake  { 10%, 90% { transform: translateX(-1px); } 20%, 80% { transform: translateX(2px); }
                    30%, 50%, 70% { transform: translateX(-5px); } 40%, 60% { transform: translateX(5px); } }
@keyframes pulse  { 0% { box-shadow: 0 0 0 0 currentColor; } 70% { box-shadow: 0 0 0 6px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }

/* ───────────────── tennis ball ───────────────── */
.ball { width: 30px; height: 30px; flex: none; display: inline-flex; filter: drop-shadow(0 2px 3px rgba(0,0,0,.18)); }
.ball svg { width: 100%; height: 100%; display: block; }
.ball-lg { width: 78px; height: 78px; animation: bounce 2.4s ease-in-out infinite; }

/* ───────────────── login gate ───────────────── */
.login {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  padding: 24px; background: var(--clay); overflow: hidden;
}
/* minimalist court drawn with solid lines only — no gradients */
.login-court { position: absolute; inset: 7%; border: 2px solid rgba(255,255,255,.16); border-radius: 6px; }
.login-court::before { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: rgba(255,255,255,.16); }
.login-court::after  { content: ""; position: absolute; top: 50%; left: 0; right: 0; height: 2px; margin-top: -1px; background: rgba(255,255,255,.12); }

.login-card {
  position: relative; z-index: 1; width: 100%; max-width: 360px;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  padding: 34px 30px 28px; text-align: center;
  animation: pop .42s cubic-bezier(.2, .8, .25, 1) both;
}
.login-card.shake { animation: shake .5s ease; }
.login-card h1 { margin: 16px 0 4px; font-size: 22px; letter-spacing: .2px; }
.login-sub { margin: 0 0 22px; font-size: 13px; color: var(--muted); }

.field { position: relative; margin-bottom: 14px; }
.field input {
  width: 100%; font-size: 15px; font-family: inherit; color: var(--ink);
  padding: 13px 64px 13px 15px; border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  background: #fdfaf6; transition: border-color .18s ease, box-shadow .18s ease;
}
.field input:focus { outline: 0; border-color: var(--clay); box-shadow: 0 0 0 4px rgba(194,90,58,.14); }
.pw-toggle {
  position: absolute; right: 7px; top: 50%; transform: translateY(-50%);
  border: 0; background: transparent; cursor: pointer; color: var(--muted);
  font: 600 12px/1 var(--font); padding: 7px 9px; border-radius: 8px; transition: color .15s, background .15s;
}
.pw-toggle:hover { color: var(--clay-deep); background: var(--clay-soft); }
.login-error { margin: 14px 0 0; font-size: 13px; font-weight: 600; color: var(--bad); }

/* ───────────────── app shell entrance ───────────────── */
#app { display: block; }

/* ───────────────── topbar ───────────────── */
.topbar {
  position: relative; z-index: 1;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px 24px; background: var(--clay); color: #fff; box-shadow: var(--shadow);
  animation: fadeUp .4s ease both;
}
.brand { display: flex; align-items: center; gap: 13px; }
.brand h1 { margin: 0; font-size: 19px; letter-spacing: .2px; }
.brand .sub { margin: 2px 0 0; font-size: 12px; color: rgba(255,255,255,.82); }
.topbar-right { display: flex; align-items: center; gap: 10px; }

/* ───────────────── buttons ───────────────── */
.btn {
  appearance: none; border: 0; cursor: pointer;
  background: var(--ball); color: #2c3a08; font-weight: 700; font-size: 13px;
  padding: 9px 16px; border-radius: 999px; box-shadow: var(--shadow-sm);
  transition: transform .12s ease, box-shadow .18s ease, background .18s ease, filter .18s ease;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 8px 18px rgba(156,68,41,.18); background: var(--ball-deep); }
.btn:active { transform: translateY(0); box-shadow: var(--shadow-sm); }
.btn:disabled { opacity: .6; cursor: default; transform: none; box-shadow: var(--shadow-sm); }
.btn-block { width: 100%; padding: 13px; font-size: 15px; margin-top: 4px; }
.btn-ghost { background: rgba(255,255,255,.16); color: #fff; box-shadow: none; }
.btn-ghost:hover { background: rgba(255,255,255,.28); }
.btn-icon { background: rgba(255,255,255,.12); color: #fff; box-shadow: none; padding: 9px 13px; }
.btn-icon:hover { background: rgba(255,255,255,.24); }

/* ───────────────── pills ───────────────── */
.pill {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12px; font-weight: 700; letter-spacing: .3px;
  padding: 6px 12px; border-radius: 999px; background: rgba(255,255,255,.16); color: #fff;
}
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill-ok   { color: #ecffd8; } .pill-ok::before   { animation: pulse 2s ease-out infinite; }
.pill-warn { color: #ffe6b0; }
.pill-bad  { color: #ffd2cb; } .pill-bad::before  { animation: pulse 1.3s ease-out infinite; }
.pill-muted{ color: rgba(255,255,255,.85); }

/* ───────────────── layout ───────────────── */
.wrap { position: relative; z-index: 1; max-width: 1080px; margin: 0 auto; padding: 26px 20px 40px; }

.stats { display: grid; gap: 14px; margin-bottom: 18px; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); animation: fadeUp .5s .04s ease both; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); transition: transform .16s ease, box-shadow .2s ease;
}
.stat:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.stat .label { font-size: 11px; text-transform: uppercase; letter-spacing: .7px; color: var(--muted); }
.stat .value { font-size: 26px; font-weight: 800; margin-top: 6px; line-height: 1.1; }
.stat .meta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.stat .value small { font-size: 14px; font-weight: 600; color: var(--muted); }

.grid { display: grid; gap: 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow); min-width: 0;
  transition: transform .16s ease, box-shadow .2s ease;
  animation: fadeUp .5s ease both;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.grid > .card:nth-child(1) { animation-delay: .06s; }
.grid > .card:nth-child(2) { animation-delay: .12s; }
.grid > .card:nth-child(3) { animation-delay: .18s; }
.grid > .card:nth-child(4) { animation-delay: .24s; }
.grid > .card:nth-child(5) { animation-delay: .30s; }
.span-2 { grid-column: 1 / -1; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.card-head h2 { margin: 0; font-size: 15px; }
.hint { font-size: 12px; color: var(--muted); }

/* ───────────────── runs table ───────────────── */
.table-scroll { overflow-x: auto; }
table.runs { width: 100%; border-collapse: collapse; font-size: 13px; }
table.runs th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); padding: 8px 10px; border-bottom: 2px solid var(--line); white-space: nowrap;
}
table.runs td { padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.runs tbody tr { transition: background .15s ease; }
table.runs tbody tr:hover { background: var(--clay-soft); }
table.runs tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.tag { display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .3px; padding: 2px 9px; border-radius: 999px; }
.tag-success   { background: #e4f4ea; color: var(--ok); }
.tag-nochanges { background: #eef0f2; color: #5a6470; }
.tag-failed    { background: #fbe4e0; color: var(--bad); }
.tag-running   { background: #fff2d9; color: var(--warn); }
.tag-trigger   { background: var(--clay-soft); color: var(--clay-deep); }

/* ───────────────── key/values ───────────────── */
.kv { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; font-size: 13px; font-weight: 600; text-align: right; }

.players { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  font-size: 12px; font-weight: 600; padding: 4px 11px; border-radius: 999px;
  background: var(--clay-soft); color: var(--clay-deep); border: 1px solid var(--line);
  transition: transform .14s ease;
}
.chip:hover { transform: translateY(-2px); }

/* ───────────────── health checks ───────────────── */
.checks { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.checks li { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.checks .name { font-weight: 600; }
.checks .desc { color: var(--muted); margin-left: auto; text-align: right; font-size: 12px; }
.led { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.led-ok   { background: var(--ok);   color: rgba(47,143,87,.5);  animation: pulse 2.4s ease-out infinite; }
.led-warn { background: var(--warn); color: rgba(207,147,32,.5); }
.led-bad  { background: var(--bad);  color: rgba(192,57,43,.5);  animation: pulse 1.4s ease-out infinite; }

/* ───────────────── next match ───────────────── */
.next-match .nm-title { font-size: 16px; font-weight: 800; }
.next-match .nm-row { font-size: 13px; color: var(--ink); margin-top: 6px; }
.next-match .nm-row span { color: var(--muted); }
.next-match.empty { color: var(--muted); font-size: 13px; }

/* ───────────────── notifications ───────────────── */
.notes { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.notes li {
  display: flex; align-items: center; gap: 10px; font-size: 13px;
  padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fdfaf6;
  transition: transform .14s ease, box-shadow .18s ease;
}
.notes li:hover { transform: translateX(3px); box-shadow: var(--shadow-sm); }
.notes .who { color: var(--muted); }
.notes .ago { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
.notes .fail { color: var(--bad); font-weight: 700; }

.foot { margin-top: 22px; text-align: center; color: var(--muted); font-size: 12px; }
.foot .dot { margin: 0 8px; }
.empty-row td { color: var(--muted); text-align: center; padding: 18px; }

/* ───────────────── tab nav ───────────────── */
.tabnav { display: flex; gap: 6px; }
.tab {
  appearance: none; border: 0; cursor: pointer;
  background: rgba(255,255,255,.14); color: #fff; font-weight: 700; font-size: 13px;
  padding: 8px 16px; border-radius: 999px; transition: background .15s ease, transform .12s ease;
}
.tab:hover { background: rgba(255,255,255,.26); transform: translateY(-1px); }
.tab.is-active { background: var(--ball); color: #2c3a08; }

/* ───────────────── stats toolbar ───────────────── */
.stats-toolbar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 12px;
  margin-bottom: 18px; animation: fadeUp .4s ease both;
}
.seg { display: inline-flex; background: var(--clay-soft); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.seg-btn {
  border: 0; cursor: pointer; background: transparent; color: var(--clay-deep);
  font-weight: 700; font-size: 13px; padding: 7px 16px; border-radius: 999px; transition: all .15s ease;
}
.seg-btn.is-active { background: var(--clay); color: #fff; box-shadow: var(--shadow-sm); }
.lvl-pick { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 8px; }
.lvl-pick select {
  font: inherit; font-size: 13px; color: var(--ink); padding: 8px 12px;
  border: 1.5px solid var(--line); border-radius: var(--radius-sm); background: #fdfaf6; cursor: pointer;
}
.lvl-pick select:focus { outline: 0; border-color: var(--clay); box-shadow: 0 0 0 3px rgba(194,90,58,.14); }
.stats-toolbar .btn-recompute { margin-left: auto; background: var(--clay-soft); color: var(--clay-deep); box-shadow: var(--shadow-sm); }
.stats-toolbar .btn-recompute:hover { background: #efe0d4; }

/* ───────────────── watched players ───────────────── */
.watched-card { margin-bottom: 16px; animation: fadeUp .5s ease both; }
.watched-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(264px, 1fr)); }
.wcard {
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 14px 16px; background: #fdfaf6;
  transition: transform .14s ease, box-shadow .18s ease;
}
.wcard:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.wcard.is-empty { color: var(--muted); }
.wname { font-size: 15px; font-weight: 800; margin-bottom: 11px; }
.wdiscs { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }
.wdisc { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 11px; }
.wdh { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .5px; color: var(--clay-deep); margin-bottom: 8px; }
.wstat { display: grid; grid-template-columns: 1fr auto auto; align-items: baseline; gap: 8px; margin-bottom: 5px; }
.wlab { font-size: 11px; color: var(--muted); }
.wstat b { font-size: 15px; font-variant-numeric: tabular-nums; }
.wtt { font-size: 11px; color: var(--muted); }
.wform { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 9px; }
.fb { width: 17px; height: 17px; border-radius: 5px; font-size: 10px; font-weight: 800; color: #fff;
  display: inline-flex; align-items: center; justify-content: center; }
.fb-w { background: var(--ok); } .fb-l { background: var(--bad); }

/* ───────────────── leaderboards ───────────────── */
.boards { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(296px, 1fr)); margin-bottom: 16px; }
.board { animation: fadeUp .5s ease both; }
.blist { list-style: none; margin: 0; padding: 0; }
.brow { display: grid; grid-template-columns: 22px 1fr auto; align-items: center; gap: 10px; padding: 7px 6px; border-radius: 8px; }
.brow + .brow { border-top: 1px solid var(--line); }
.brow.is-watched { background: linear-gradient(90deg, rgba(214,230,79,.30), rgba(214,230,79,.05)); }
.brank { font-size: 12px; font-weight: 700; color: var(--muted); text-align: center; }
.bmain { min-width: 0; }
.bname { font-size: 13px; font-weight: 600; display: flex; flex-direction: column; }
.bname { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brow.is-watched .bname { color: var(--clay-deep); }
.bctx { font-size: 11px; font-weight: 500; color: var(--muted); }
.btrack { height: 4px; background: var(--clay-soft); border-radius: 999px; margin-top: 5px; overflow: hidden; }
.bfill { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--clay), var(--clay-deep)); }
.bnum { font-size: 16px; font-weight: 800; font-variant-numeric: tabular-nums; }
.bempty { color: var(--muted); font-size: 13px; padding: 10px 0; list-style: none; }

/* ───────────────── charts ───────────────── */
.charts-card { animation: fadeUp .5s ease both; }
.charts-grid { display: grid; gap: 20px 24px; grid-template-columns: repeat(auto-fit, minmax(236px, 1fr)); }
.chart h3 { font-size: 13px; margin: 0 0 12px; }
.hbars { display: grid; gap: 8px; }
.hbar { display: grid; grid-template-columns: 78px 1fr 34px; align-items: center; gap: 9px; font-size: 12px; }
.hbl { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbt { height: 9px; background: var(--clay-soft); border-radius: 999px; overflow: hidden; }
.hbf { display: block; height: 100%; border-radius: 999px; }
.hbf-clay { background: linear-gradient(90deg, var(--clay), var(--clay-deep)); }
.hbf-ball { background: linear-gradient(90deg, var(--ball), var(--ball-deep)); }
.hbv { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.donut-wrap { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.donut { width: 116px; height: 116px; border-radius: 50%; position: relative; flex: none; }
.donut::before { content: ""; position: absolute; inset: 21px; background: var(--card); border-radius: 50%; }
.donut span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 19px; }
.donut-legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; font-size: 13px; }
.donut-legend li { display: flex; align-items: center; gap: 7px; }
.dot-sw { width: 11px; height: 11px; border-radius: 3px; flex: none; }

@media (max-width: 720px) {
  .grid { grid-template-columns: 1fr; }
  .kv dd { text-align: left; }
  .topbar { flex-wrap: wrap; }
  .tabnav { order: 3; width: 100%; justify-content: center; }
  .wdiscs { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
