:root {
  --bg: #0f1115;
  --surface: #1a1d24;
  --surface-2: #232733;
  --text: #eef1f6;
  --muted: #9aa3b2;
  --accent: #ff7a1a;      /* naranja baloncesto */
  --accent-soft: #ff7a1a22;
  --ok: #37c871;
  --bad: #f2555a;
  --line: #2b2f3a;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5f8; --surface: #ffffff; --surface-2: #eef0f4;
    --text: #141821; --muted: #5d6676; --line: #e3e6ec; --accent-soft: #ff7a1a1a;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  padding-bottom: calc(64px + var(--safe-bottom));
  overscroll-behavior-y: contain;
}

/* ---- Topbar ---- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(140%) blur(12px);
  border-bottom: 1px solid var(--line);
  padding-top: var(--safe-top);
}
.topbar-inner {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; max-width: 760px; margin: 0 auto;
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 700; letter-spacing: -0.2px; }
.live-badge {
  color: #fff; background: var(--bad); font-size: 11px; font-weight: 700;
  padding: 3px 8px; border-radius: 999px; animation: pulse 1.6s infinite;
}
@keyframes pulse { 50% { opacity: .55; } }

/* ---- Layout ---- */
.view { max-width: 760px; margin: 0 auto; padding: 16px; }
.loading { color: var(--muted); text-align: center; padding: 48px 0; }
.err { color: var(--bad); background: var(--surface); border: 1px solid var(--line);
  padding: 14px; border-radius: var(--radius); }
h2.section { font-size: 13px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin: 22px 4px 10px; font-weight: 700; }

/* ---- Cards ---- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; margin-bottom: 12px;
}
.card.tap { cursor: pointer; transition: transform .08s, background .15s; }
.card.tap:active { transform: scale(.985); background: var(--surface-2); }

/* ---- Match card ---- */
.match { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }
.match .side { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.match .side.right { }
.match .logo { width: 46px; height: 46px; border-radius: 10px; background: var(--surface-2);
  object-fit: contain; }
.match .tname { font-size: 12px; color: var(--text); font-weight: 600; line-height: 1.2; }
.match .center { text-align: center; min-width: 76px; }
.match .score { font-size: 24px; font-weight: 800; letter-spacing: -0.5px; }
.match .score .w { color: var(--ok); }
.match .vs { color: var(--muted); font-weight: 700; }
.match .when { font-size: 12px; color: var(--muted); margin-top: 2px; }
.badge { display: inline-block; font-size: 10px; font-weight: 800; padding: 2px 7px;
  border-radius: 999px; text-transform: uppercase; letter-spacing: .04em; }
.badge.live { background: var(--bad); color: #fff; }
.badge.fin { background: var(--surface-2); color: var(--muted); }
.badge.prox { background: var(--accent-soft); color: var(--accent); }
.match-meta { color: var(--muted); font-size: 12px; margin-top: 10px;
  display: flex; gap: 6px; align-items: center; justify-content: center; }

/* ---- Resumen ---- */
.hero { text-align: center; padding: 18px 14px; }
.hero .sub { color: var(--muted); font-size: 13px; }
.pill-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 10px; }
.pill { background: var(--surface-2); border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600; }
.pill b { color: var(--accent); }

/* ---- Table (clasificación) ---- */
.table { width: 100%; border-collapse: collapse; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { padding: 10px 8px; text-align: center; font-size: 13px; border-bottom: 1px solid var(--line); }
.table th { color: var(--muted); font-weight: 700; font-size: 11px; text-transform: uppercase; }
.table td.name { text-align: left; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.table td.name img { width: 22px; height: 22px; border-radius: 5px; background: var(--surface-2); object-fit: contain; }
.table tr.ours td { background: var(--accent-soft); }
.table tr:last-child td { border-bottom: none; }
.pos { font-weight: 800; color: var(--muted); }

/* ---- Avatares (foto con iniciales debajo por si no carga) ---- */
.av { position: relative; display: inline-grid; place-items: center; flex: none;
  width: 42px; height: 42px; border-radius: 50%; overflow: hidden; background: var(--surface-2); }
.av img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.av-i { font-size: 13px; font-weight: 800; color: var(--muted); }
.av-s { width: 28px; height: 28px; }
.av-s .av-i { font-size: 10px; }
.av-xl { width: 76px; height: 76px; }
.av-xl .av-i { font-size: 22px; }
.star .av, .player-head .av { box-shadow: 0 0 0 2px var(--accent); }

/* ---- Player rows ---- */
.plist { display: flex; flex-direction: column; gap: 8px; }
.prow { display: grid; grid-template-columns: 42px 1fr auto 12px; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.tap { cursor: pointer; }
.prow.tap:active, .glog.tap:active { background: var(--surface-2); }
.prow.star { border-color: var(--accent); background: var(--accent-soft); }
.prow .pname { font-weight: 600; font-size: 14px; }
.pstat { color: var(--muted); font-size: 12px; }
.prow .pmain { text-align: right; }
.prow .pmain b { font-size: 17px; }
.dor { color: var(--muted); font-weight: 700; font-size: 12px; }
.chev { color: var(--muted); font-size: 18px; }

/* ---- Ficha de jugador ---- */
.player-head { display: flex; align-items: center; gap: 14px; }
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 6px; text-align: center; }
.tile-v { font-size: 20px; font-weight: 800; letter-spacing: -0.3px; }
.tile-l { font-size: 11px; color: var(--muted); font-weight: 600; }
.tile-e { font-size: 10px; color: var(--muted); margin-top: 2px; opacity: .8; }
.stat-list > div { display: flex; justify-content: space-between; padding: 7px 2px;
  border-bottom: 1px solid var(--line); font-size: 14px; }
.stat-list > div:last-child { border-bottom: none; }
.stat-list span { color: var(--muted); }
.stat-list small { color: var(--muted); font-weight: 500; }
.glog { display: grid; grid-template-columns: 52px 1fr auto; gap: 10px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.glog-date { font-weight: 700; font-size: 14px; display: flex; flex-direction: column; }
.glog-date span { font-size: 11px; color: var(--muted); font-weight: 600; }
.glog-rival { font-size: 13px; font-weight: 600; }
.glog-pts { text-align: right; }
.glog-pts b { font-size: 18px; }

/* ---- Gráficas (SVG) ---- */
.chart { display: block; width: 100%; height: auto; }
.chart .bar { fill: var(--accent); }
.chart .bar-v { fill: var(--text); font-size: 10px; font-weight: 700; }
.chart .bar-l { fill: var(--muted); font-size: 9px; }
.chart .grid { stroke: var(--line); stroke-dasharray: 3 3; }
.chart .ln-ours { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; }
.chart .ln-rival { fill: none; stroke: var(--muted); stroke-width: 2; stroke-linejoin: round; }
.legend { display: flex; gap: 6px; align-items: center; justify-content: center; font-size: 12px;
  color: var(--muted); margin-top: 6px; }
.legend span { display: inline-block; width: 14px; height: 3px; border-radius: 2px; margin-left: 8px; }
.lg-ours { background: var(--accent); }
.lg-rival { background: var(--muted); }

/* ---- Partido: pestañas, filtros, comparativa, jugadas ---- */
.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface-2);
  border-radius: 10px; padding: 3px; margin: 14px 0 4px; }
.seg button { appearance: none; border: none; background: none; color: var(--muted); font: inherit;
  font-size: 13px; font-weight: 700; padding: 8px 0; border-radius: 8px; cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px #0003; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 8px 0 2px; scrollbar-width: none; }
.chip { appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  font: inherit; font-size: 12px; font-weight: 700; padding: 6px 12px; border-radius: 999px;
  white-space: nowrap; cursor: pointer; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.cmp { width: 100%; border-collapse: collapse; font-size: 14px; }
.cmp td, .cmp th { padding: 8px 4px; border-bottom: 1px solid var(--line); }
.cmp tr:last-child td, .cmp tr:last-child th { border-bottom: none; }
.cmp td { width: 32%; text-align: center; font-weight: 700; }
.cmp th { color: var(--muted); font-weight: 600; font-size: 12px; text-align: center; }
.cmp thead td { font-size: 12px; color: var(--muted); }
.pbp-list { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.pbp-q { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin: 14px 4px 4px; }
.pbp-mark { text-align: center; font-size: 12px; color: var(--muted); padding: 4px; }
.pbp { display: grid; grid-template-columns: 40px 28px 1fr auto; gap: 8px; align-items: center;
  background: var(--surface); border-radius: 10px; padding: 7px 10px; border-left: 3px solid transparent; }
.pbp.ours { border-left-color: var(--accent); }
.pbp.rival { border-left-color: var(--line); }
.pbp.star { background: var(--accent-soft); }
.pbp-t { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.pbp-a { font-size: 13px; font-weight: 600; }
.pbp.pts .pbp-a b { color: var(--ok); }
.pbp-s { font-weight: 800; font-size: 14px; font-variant-numeric: tabular-nums; }

/* ---- Momento del partido en directo ---- */
.momento { text-align: center; margin-top: 10px; display: flex; flex-direction: column; gap: 2px; }
.momento b { color: var(--bad); font-size: 15px; letter-spacing: -0.2px; }
.momento span { color: var(--muted); font-size: 11px; }
.live-when { color: var(--bad); font-weight: 700; }
.q-live { outline: 1px solid var(--bad); }
.q-live em { color: var(--bad); font-style: normal; font-size: 10px; font-weight: 700; }

/* ---- Mapas ---- */
.maps { display: flex; gap: 8px; justify-content: center; margin-top: 10px; }
.map-btn { flex: 1; max-width: 150px; text-align: center; text-decoration: none; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px; font-size: 13px; font-weight: 700; }
.map-btn:active { background: var(--accent-soft); }

/* ---- Aviso flotante ---- */
.toast { position: fixed; left: 50%; bottom: calc(80px + var(--safe-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-size: 13px; font-weight: 600; z-index: 50; max-width: 90vw; }

/* ---- Boxscore ---- */
.box { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -16px; padding: 0 16px; }
.box table { border-collapse: collapse; width: 100%; font-size: 12px; min-width: 460px; }
.box th, .box td { padding: 7px 6px; text-align: center; border-bottom: 1px solid var(--line); white-space: nowrap; }
.box th { color: var(--muted); font-size: 10px; text-transform: uppercase; position: sticky; top: 0; background: var(--surface); }
.box td.pn { text-align: left; font-weight: 600; position: sticky; left: 0; background: var(--surface); }
.box .pn-in { display: inline-flex; align-items: center; gap: 6px; }
.box tr.tap:active td { background: var(--surface-2); }
.box tr.star td { background: var(--accent-soft); }
.quarters { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 12px 0; }
.q { background: var(--surface-2); border-radius: 8px; padding: 6px 10px; font-size: 12px; font-weight: 600; }
.q span { color: var(--muted); font-weight: 500; }

/* ---- Tabbar ---- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(140%) blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
}
.tab {
  appearance: none; background: none; border: none; color: var(--muted);
  padding: 8px 0 7px; font-size: 10.5px; font-weight: 600; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px; font-family: inherit;
}
.tab .tab-ico { font-size: 20px; filter: grayscale(1) opacity(.7); }
.tab.active { color: var(--accent); }
.tab.active .tab-ico { filter: none; }

/* ---- Back button ---- */
.back { display: inline-flex; align-items: center; gap: 6px; color: var(--accent);
  background: none; border: none; font-size: 15px; font-weight: 600; padding: 4px 0;
  margin-bottom: 8px; cursor: pointer; font-family: inherit; }

.spark { display: block; width: 100%; height: 80px; margin-top: 8px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.left { text-align: left !important; }
.mb8 { margin-bottom: 8px; }
.note { margin-top: 14px; font-size: 12px; }
.hero-title { font-size: 20px; font-weight: 800; }

/* ---- Salir ---- */
.logout {
  margin-left: auto; appearance: none; background: none; border: 1px solid var(--line);
  color: var(--muted); font: inherit; font-size: 12px; font-weight: 600;
  padding: 4px 10px; border-radius: 999px; cursor: pointer;
}

/* ---- Acceso ---- */
.login-body { padding-bottom: 0; min-height: 100vh; display: grid; place-items: center; }
.login {
  width: 100%; max-width: 340px; padding: 24px 20px;
  padding-top: calc(24px + var(--safe-top)); text-align: center;
}
.login-logo { width: 72px; height: 72px; border-radius: 18px; }
.login h1 { font-size: 22px; margin: 14px 0 20px; }
.login form { display: flex; flex-direction: column; gap: 10px; text-align: left; }
.login label { font-size: 13px; color: var(--muted); font-weight: 600; }
.login input {
  font: inherit; font-size: 17px; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
}
.login input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.login button {
  font: inherit; font-size: 16px; font-weight: 700; padding: 12px; border: none;
  border-radius: 12px; background: var(--accent); color: #fff; cursor: pointer;
}
.login button:disabled { opacity: .6; }
.login-msg { color: var(--bad); min-height: 1.4em; font-size: 14px; margin: 4px 0 0; }
