:root {
  color-scheme: light;
  --bg: #f4f3ef;
  --surface: #fcfcfb;
  --surface-2: #efeee9;
  --border: #dddcd5;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #7a7974;
  --felt: #0f5132;
  --felt-2: #0b3d26;
  --on-felt: #f4f3ef;
  --accent: #b8860b;
  --gold: #c99a06;
  --silver: #8d8d8d;
  --bronze: #a0622d;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --bar: #2a78d6;
  --grid: #e6e5df;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #232321;
    --border: #34332f;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --text-3: #93928a;
    --felt: #0d4a2e;
    --felt-2: #08301e;
    --on-felt: #f0efec;
    --accent: #e0b23c;
    --gold: #e0b23c;
    --silver: #b5b5b5;
    --bronze: #c98450;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --bar: #3987e5;
    --grid: #2c2c29;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #34332f;
  --text: #f0efec; --text-2: #c3c2b7; --text-3: #93928a;
  --felt: #0d4a2e; --felt-2: #08301e; --on-felt: #f0efec;
  --accent: #e0b23c; --gold: #e0b23c; --silver: #b5b5b5; --bronze: #c98450;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500; --series-5: #d55181;
  --bar: #3987e5; --grid: #2c2c29; --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
}
a { color: inherit; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h2 { font-size: 1.25rem; font-weight: 650; }
h3 { font-size: 1rem; font-weight: 600; }

/* Header */
.top {
  background: radial-gradient(120% 140% at 10% 0%, var(--felt) 0%, var(--felt-2) 70%);
  color: var(--on-felt);
}
.top-inner { max-width: 1100px; margin: 0 auto; padding: calc(22px + env(safe-area-inset-top)) 16px 0; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--accent); color: #1a1a19;
  display: grid; place-items: center; font-size: 22px; font-weight: 800;
  box-shadow: inset 0 0 0 3px rgba(255,255,255,.35), inset 0 0 0 6px var(--accent), inset 0 0 0 7px rgba(0,0,0,.25);
}
.brand h1 { font-size: 1.35rem; font-weight: 750; letter-spacing: .01em; }
.brand p { margin: 0; opacity: .75; font-size: .85rem; }
.theme-btn {
  margin-left: auto; background: rgba(255,255,255,.1); color: inherit; border: 1px solid rgba(255,255,255,.2);
  border-radius: 8px; padding: 6px 10px; cursor: pointer; font: inherit; font-size: .85rem; white-space: nowrap;
}
nav.tabs { display: flex; gap: 4px; margin-top: 18px; overflow-x: auto; scrollbar-width: none; }
nav.tabs::-webkit-scrollbar { display: none; }
nav.tabs a {
  text-decoration: none; padding: 10px 14px; border-radius: 10px 10px 0 0;
  color: var(--on-felt); opacity: .78; white-space: nowrap; font-weight: 550; font-size: .92rem;
}
nav.tabs a:hover { opacity: 1; }
nav.tabs a.on { background: var(--bg); color: var(--text); opacity: 1; }

main { max-width: 1100px; margin: 0 auto; padding: 24px 16px 60px; }
.section { margin-bottom: 32px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.muted { color: var(--text-2); }
.small { font-size: .85rem; }
.note { font-size: .82rem; color: var(--text-3); margin-top: 8px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow); padding: 16px;
}

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 28px; }
.kpi { padding: 14px 16px; }
.kpi .lbl { font-size: .8rem; color: var(--text-2); }
.kpi .val { font-size: 1.8rem; font-weight: 700; margin-top: 2px; }
.kpi .sub { font-size: .8rem; color: var(--text-3); }

/* Champions */
.champs { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.champ { text-decoration: none; display: block; position: relative; transition: transform .12s, border-color .12s; }
.champ:hover { transform: translateY(-2px); border-color: var(--accent); }
.champ .yr { font-size: .8rem; color: var(--text-2); font-weight: 600; display: flex; justify-content: space-between; }
.champ .name { font-size: 1.35rem; font-weight: 750; margin: 6px 0 2px; display: flex; align-items: center; gap: 8px; }
.champ .pts { font-size: .85rem; color: var(--text-2); }
.champ .runner { font-size: .8rem; color: var(--text-3); margin-top: 8px; border-top: 1px dashed var(--border); padding-top: 8px; }
.badge {
  display: inline-block; font-size: .7rem; font-weight: 650; padding: 2px 7px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border);
}
.badge.live { color: var(--felt); border-color: currentColor; background: transparent; }
:root[data-theme="dark"] .badge.live { color: #5fd39a; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .badge.live { color: #5fd39a; } }

.medal { width: 22px; height: 22px; border-radius: 50%; display: inline-grid; place-items: center; font-size: .72rem; font-weight: 800; color: #1a1a19; flex: none; }
.m1 { background: var(--gold); } .m2 { background: var(--silver); } .m3 { background: var(--bronze); color: #fff; }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 9px 12px; text-align: right; white-space: nowrap; }
th:first-child, td:first-child, th.l, td.l { text-align: left; }
thead th {
  font-size: .76rem; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .03em;
  border-bottom: 1px solid var(--border); background: var(--surface-2); position: sticky; top: 0;
}
thead th.sortable { cursor: pointer; user-select: none; }
thead th.sortable:hover { color: var(--text); }
thead th .arr { opacity: .3; margin-left: 3px; }
thead th.sorted .arr { opacity: 1; }
tbody tr { border-bottom: 1px solid var(--grid); }
tbody tr:last-child { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td.rank { color: var(--text-3); width: 1%; }
td.player { text-align: left; }
td.player a { text-decoration: none; font-weight: 600; }
td.player a:hover { text-decoration: underline; }
td.strong { font-weight: 700; }
td.dim { color: var(--text-3); }
th[title] { text-decoration: underline dotted; text-underline-offset: 3px; }
.bar-cell { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.mini-bar { height: 6px; border-radius: 3px; background: var(--bar); opacity: .85; }

/* Controls */
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button, .seg a {
  border: 0; background: transparent; color: var(--text-2); font: inherit; font-size: .85rem; font-weight: 550;
  padding: 6px 12px; border-radius: 7px; cursor: pointer; text-decoration: none;
}
.seg .on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
select {
  font: inherit; font-size: .9rem; padding: 7px 10px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
}

/* Grid layouts */
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 800px) { .two { grid-template-columns: 1fr; } }

/* Matches list */
.matches { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 8px; }
.match { padding: 10px 12px; font-size: .86rem; border-radius: 10px; }
.match .d { color: var(--text-3); font-size: .76rem; display: flex; justify-content: space-between; }
.match .w { font-weight: 650; }
.match .w::before { content: "♠ "; color: var(--accent); }
.match .f { color: var(--text-2); }
.match .o { color: var(--text-3); font-size: .78rem; margin-top: 3px; }

/* Chart */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { fill: var(--text-2); font-size: 11px; }
.chart .axis line, .chart .grid line { stroke: var(--grid); }
.chart .lbl-strong { fill: var(--text); font-weight: 600; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .82rem; color: var(--text-2); margin-bottom: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.tip {
  position: absolute; pointer-events: none; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; font-size: .8rem;
  box-shadow: 0 4px 16px rgba(0,0,0,.15); min-width: 120px; opacity: 0; transition: opacity .1s; z-index: 5;
}
.tip .t { color: var(--text-3); font-size: .74rem; margin-bottom: 4px; }
.tip .r { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.tip .r b { font-weight: 650; }
.tip .r i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 4px; }

/* Player */
.player-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.avatar {
  width: 56px; height: 56px; border-radius: 50%; background: var(--felt); color: var(--on-felt);
  display: grid; place-items: center; font-size: 1.3rem; font-weight: 750;
}
.player-head h2 { font-size: 1.6rem; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }

/* Records */
.records { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.record .lbl { font-size: .8rem; color: var(--text-2); }
.record .who { font-size: 1.25rem; font-weight: 700; margin-top: 4px; }
.record .val { font-size: .88rem; color: var(--text-2); }
.record ol { margin: 10px 0 0; padding-left: 18px; font-size: .82rem; color: var(--text-3); }

footer { text-align: center; color: var(--text-3); font-size: .8rem; padding: 24px 16px 40px; }

@media (max-width: 560px) {
  body { font-size: 14px; }
  th, td { padding: 8px 9px; }
  .kpi .val { font-size: 1.5rem; }
  .brand p { display: none; }
}

nav.tabs a.cargar { margin-left: auto; background: var(--accent); color: #1a1a19; opacity: 1; border-radius: 10px; margin-bottom: 6px; padding: 8px 14px; align-self: center; }
nav.tabs a.cargar:hover { filter: brightness(1.08); }
.btn-cargar { text-decoration: none; background: var(--felt); color: var(--on-felt); font-weight: 600; font-size: .85rem; padding: 7px 12px; border-radius: 9px; white-space: nowrap; }
