:root {
  --bg: #eef1f5;
  --surface: #ffffff;
  --ink: #0f172a;
  --muted: #5b6475;
  --line: #d4d9e2;
  --sirc: #0b2545;
  --rival: #4b5563;
  --win: #15803d;
  --win-press: #0f5f2d;
  --loss: #c81e1e;
  --loss-press: #921616;
  --pen: #b45309;
  --accent: #0b2545;
  --radius: 12px;
  --gap: 6px;
  --label-w: 64px;
  --tap-h: 74px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
body { min-height: 100dvh; padding-bottom: env(safe-area-inset-bottom); }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
h1, h2 { margin: 0; }
h2 { font-size: 1.05rem; margin-bottom: 10px; }

.view { max-width: 1100px; margin: 0 auto; padding: 0 12px 24px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* ---------- cabeceras ---------- */
.pagehead {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 0 12px;
}
.pagehead h1 { font-size: 1.4rem; }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; margin-bottom: 12px;
}
.card summary { font-weight: 600; cursor: pointer; }
details.card[open] summary { margin-bottom: 10px; }

label { display: block; font-size: .9rem; color: var(--muted); margin-bottom: 10px; }
input {
  display: block; width: 100%; margin-top: 4px; padding: 12px;
  font: inherit; font-size: 1rem; color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 48px; padding: 10px 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface);
  font-weight: 600; cursor: pointer; color: var(--ink);
}
.btn:active { filter: brightness(.92); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.big { width: 100%; min-height: 56px; font-size: 1.1rem; }
.btn.danger { color: var(--loss); }
.filebtn { margin: 0; color: var(--ink); font-size: 1rem; }
.btnrow { display: flex; flex-wrap: wrap; gap: 8px; }
.btnrow .btn { flex: 1 1 auto; }

.iconbtn {
  width: 44px; height: 44px; flex: none; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface);
  font-size: 1.6rem; line-height: 1; cursor: pointer;
}

/* ---------- lista de partidos ---------- */
.match-list { list-style: none; margin: 0; padding: 0; }
.match-list li {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 10px 0; border-top: 1px solid var(--line);
}
.match-list li:first-child { border-top: 0; }
.match-list .m-info { flex: 1 1 100%; min-width: 0; }
.match-list .btn:not(.danger) { flex: 1; }
.match-list .m-title { font-weight: 600; }
.match-list .m-sub { font-size: .85rem; color: var(--muted); }
.match-list .btn { min-height: 44px; padding: 8px 12px; }

/* ---------- barra superior en directo ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  margin: 0 -12px 10px; padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--sirc); color: #fff;
}
.topbar .iconbtn { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.25); color: #fff; }
.clockbox { display: flex; align-items: center; gap: 4px; }
.half-pill {
  height: 44px; padding: 0 8px; border-radius: 10px; border: 0;
  background: rgba(255,255,255,.18); color: #fff; font-weight: 700;
}
.clock {
  display: flex; align-items: center; gap: 6px;
  height: 44px; padding: 0 10px; border-radius: 10px;
  border: 0; background: #fff; color: var(--sirc);
  font-weight: 800; font-size: 1.15rem; font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.clock.running { background: #d1fadf; }
.clock-icon { font-size: .8rem; }
.score {
  flex: 1; min-width: 0; text-align: center; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; font-size: .8rem;
}
.score b { font-size: 1.35rem; font-variant-numeric: tabular-nums; margin: 0 2px; }
.topbar .undo { font-size: 1.5rem; }
.score .t-sirc, .score .t-rival { display: none; }
@media (min-width: 560px) { .score .t-sirc, .score .t-rival { display: inline; } }

/* ---------- rejilla de fases ---------- */
.grid {
  display: grid;
  grid-template-columns: var(--label-w) repeat(4, minmax(0, 1fr));
  gap: var(--gap);
}
.gh {
  text-align: center; font-size: .75rem; font-weight: 700; text-transform: uppercase;
  padding: 6px 2px; border-radius: 8px; color: #fff; letter-spacing: .02em;
}
.gh.corner { background: none; color: var(--muted); display: flex; align-items: center; justify-content: center; }
.gh-sirc { grid-column: span 2; background: var(--sirc); }
.gh-rival { grid-column: span 2; background: var(--rival); }

.rowlabel {
  display: flex; align-items: center; justify-content: center;
  writing-mode: horizontal-tb; font-weight: 800; font-size: .8rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  text-align: center; padding: 2px;
}

.tap {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: var(--tap-h); padding: 4px 2px; border: 0; border-radius: 12px;
  color: #fff; cursor: pointer; user-select: none; -webkit-user-select: none;
  touch-action: manipulation;
  transition: transform .06s ease;
}
.tap:active, .tap.flash { transform: scale(.95); }
.tap .n { font-size: 1.7rem; font-weight: 800; line-height: 1.05; font-variant-numeric: tabular-nums; }
.tap .l { font-size: .72rem; font-weight: 600; opacity: .95; line-height: 1.1; text-align: center; }
.tap.win { background: var(--win); }
.tap.win:active, .tap.win.flash { background: var(--win-press); }
.tap.loss { background: var(--loss); }
.tap.loss:active, .tap.loss.flash { background: var(--loss-press); }
.tap.rival-side { box-shadow: inset 0 -5px 0 rgba(0,0,0,.28); }

.pen-row {
  display: grid; grid-template-columns: var(--label-w) minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--gap); margin-top: var(--gap);
}
.tap.pen { background: var(--pen); }
.tap.pen:active, .tap.pen.flash { background: #8a3f06; }

/* ---------- marcador y tarjetas ---------- */
.scorepad {
  display: grid; grid-template-columns: var(--label-w) 1fr;
  gap: var(--gap); margin-top: 12px;
}
.sp-team {
  display: flex; align-items: center; justify-content: center;
  font-size: .75rem; font-weight: 800; color: #fff; border-radius: 10px;
  text-align: center; padding: 2px; overflow: hidden; word-break: break-word;
}
.sp-sirc { background: var(--sirc); }
.sp-rival { background: var(--rival); }
.sp-btns { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: var(--gap); }
.sbtn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 56px; padding: 2px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.sbtn:active, .sbtn.flash { background: #dbe3ee; }
.sbtn .l { font-size: .68rem; font-weight: 700; }
.sbtn .n { font-size: 1.1rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.sbtn.yellow { background: #fde047; border-color: #eab308; }
.sbtn.red { background: #ef4444; border-color: #b91c1c; color: #fff; }

.live-actions { margin: 14px 0 12px; }

/* ---------- lista de eventos ---------- */
.evlist ol { margin: 0; padding-left: 0; list-style: none; }
.evlist li {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 0; border-top: 1px solid var(--line); font-size: .92rem;
}
.evlist li .min { width: 40px; color: var(--muted); font-variant-numeric: tabular-nums; }
.evlist li .txt { flex: 1; }
.evlist li button {
  width: 40px; height: 36px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--loss); cursor: pointer;
}
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.dot.win { background: var(--win); }
.dot.loss { background: var(--loss); }
.dot.pen { background: var(--pen); }
.dot.other { background: var(--muted); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 50;
  display: flex; align-items: center; gap: 12px;
  max-width: calc(100% - 24px); padding: 10px 10px 10px 16px;
  background: #111827; color: #fff; border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,.25); font-weight: 600;
}
.toast button {
  background: #fff; color: #111827; border: 0; border-radius: 8px;
  padding: 10px 12px; font-weight: 700; cursor: pointer;
}

/* ---------- resumen ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin-bottom: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.kpi .k { font-size: .78rem; color: var(--muted); font-weight: 600; text-transform: uppercase; }
.kpi .v { font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.kpi .s { font-size: .82rem; color: var(--muted); }

.cards-row { font-size: .95rem; margin-top: 4px; }
.cards-row b { font-variant-numeric: tabular-nums; }
.cy, .cr { display: inline-block; width: 11px; height: 15px; border-radius: 2px; margin: 0 3px 0 6px; vertical-align: -2px; }
.cy { background: #facc15; }
.cr { background: #dc2626; }

.tablewrap { overflow-x: auto; }
table.paper { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.paper th, table.paper td { border: 1px solid var(--line); padding: 6px 4px; text-align: center; font-size: .9rem; }
table.paper thead th { background: var(--sirc); color: #fff; font-size: .75rem; }
table.paper thead tr:nth-child(2) th { background: #1f2f4a; }
table.paper td.ph { font-weight: 700; text-align: left; padding-left: 8px; }
table.paper .g { color: var(--win); font-weight: 700; }
table.paper .p { color: var(--loss); font-weight: 700; }
table.paper .pct { color: var(--muted); font-size: .8rem; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: 10px; padding: 6px 0; border-top: 1px solid var(--line); font-size: .92rem; }
.timeline li:first-child { border-top: 0; }
.timeline .min { width: 40px; color: var(--muted); font-variant-numeric: tabular-nums; }
.timeline .txt { flex: 1; }
.timeline .sc { font-weight: 700; font-variant-numeric: tabular-nums; }

.bars { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; align-items: end; height: 90px; margin-top: 6px; }
.bars .b { display: flex; flex-direction: column-reverse; gap: 2px; height: 100%; }
.bars .seg { border-radius: 3px; min-height: 0; }
.bars .seg.s { background: var(--sirc); }
.bars .seg.r { background: #9ca3af; }
.bars-x { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; font-size: .7rem; color: var(--muted); text-align: center; }
.legend { display: flex; gap: 14px; font-size: .8rem; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: middle; }

/* ---------- tablet / horizontal ---------- */
@media (min-width: 700px) {
  :root { --label-w: 96px; --tap-h: 96px; --gap: 8px; }
  .tap .n { font-size: 2.2rem; }
  .tap .l { font-size: .85rem; }
  .rowlabel { font-size: 1rem; }
  .gh { font-size: .9rem; }
  .score { font-size: 1rem; }
  .score b { font-size: 1.6rem; }
  .sbtn { min-height: 64px; }
  .sbtn .l { font-size: .8rem; }
}
@media (min-width: 800px) and (orientation: landscape) {
  :root { --tap-h: 84px; }
  .live { display: grid; grid-template-columns: 3fr 2fr; gap: 0 16px; align-items: start; }
  .live .grid, .live .pen-row { grid-column: 1; }
  .live .scorepad { grid-column: 2; grid-row: 1; margin-top: 0; }
  .live .live-actions { grid-column: 2; grid-row: 2; margin-top: 0; }
  .live .evlist { grid-column: 2; grid-row: 3 / span 2; }
  .sp-btns { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 480px) {
  table.paper th, table.paper td { padding: 5px 2px; font-size: .82rem; }
  table.paper thead th { font-size: .68rem; }
  table.paper td.ph { padding-left: 4px; }
  .kpis { grid-template-columns: 1fr 1fr; }
  #sum-title { font-size: 1.15rem; }
}
/* móvil muy estrecho */
@media (max-width: 360px) {
  :root { --label-w: 52px; --gap: 4px; }
  .tap .l { font-size: .62rem; }
  .sbtn .l { font-size: .6rem; }
}

@media print {
  body { background: #fff; }
  .noprint, .iconbtn, .toast { display: none !important; }
  .card, .kpi { break-inside: avoid; border-color: #999; }
  .view { max-width: none; padding: 0; }
}
