:root {
  --bg: #0b1020;
  --surface: #141b31;
  --surface-2: #1c2542;
  --line: #27315a;
  --text: #eef1fa;
  --muted: #98a2c3;
  --garnet: #a50044;
  --garnet-2: #cd1257;
  --blue: #1d5fc0;
  --gold: #edbb00;
  --ok: #3ccf8e;
  --radius: 16px;
  --tabbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
  padding-bottom: calc(var(--tabbar-h) + var(--safe-b));
}
button { font: inherit; color: inherit; }
a { color: inherit; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
svg .fill { fill: currentColor; stroke: none; }
[hidden] { display: none !important; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
  background: linear-gradient(180deg, var(--bg) 70%, rgba(11, 16, 32, 0.85));
  backdrop-filter: blur(8px);
}
.topbar h1 { margin: 0; font-size: 20px; letter-spacing: 0.2px; display: flex; align-items: center; gap: 10px; }
.crest {
  width: 26px; height: 26px; border-radius: 8px;
  background: linear-gradient(90deg, var(--blue) 0 25%, var(--garnet) 25% 50%, var(--blue) 50% 75%, var(--garnet) 75%);
  box-shadow: inset 0 0 0 2px var(--gold);
}
.topbar-actions { display: flex; gap: 4px; }
.icon-btn {
  width: 44px; height: 44px; border: 0; border-radius: 12px; background: transparent;
  display: grid; place-items: center; cursor: pointer; color: var(--muted);
}
.icon-btn:active { background: var(--surface); }
.icon-btn.spinning svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

main { padding: 4px 16px 24px; max-width: 640px; margin: 0 auto; }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: rgba(20, 27, 49, 0.96); border-top: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
.tab {
  position: relative; flex: 1; border: 0; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: 12px; font-weight: 600;
}
.tab[aria-current="page"] { color: var(--text); }
.tab[aria-current="page"] svg { color: var(--gold); }
.badge {
  position: absolute; top: 8px; left: calc(50% + 6px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--garnet-2); color: #fff; font-size: 11px; line-height: 18px; text-align: center;
}

/* ---------- Common ---------- */
.section-title {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 18px 2px 10px; font-size: 13px; font-weight: 700; letter-spacing: 0.8px;
  text-transform: uppercase; color: var(--muted);
}
.section-title .count { color: var(--text); }
.empty {
  text-align: center; padding: 28px 20px; border-radius: var(--radius);
  background: var(--surface); border: 1px dashed var(--line); color: var(--muted);
}
.empty .big { font-size: 40px; display: block; margin-bottom: 6px; }
.empty strong { color: var(--text); display: block; font-size: 18px; margin-bottom: 4px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface-2); cursor: pointer; text-decoration: none; font-weight: 600;
}
.btn.primary { background: var(--garnet); border-color: var(--garnet); color: #fff; }
.btn.block { width: 100%; }
.error { color: #ff9aa9; }

/* ---------- Next match strip ---------- */
.next-match {
  display: flex; align-items: center; gap: 10px; margin-top: 12px; padding: 10px 14px;
  border-radius: 12px; background: var(--surface); font-size: 14px; color: var(--muted);
}
.next-match b { color: var(--text); font-weight: 600; }

/* ---------- Recap cards ---------- */
.cards { display: grid; gap: 14px; }
.card {
  position: relative; border-radius: var(--radius); overflow: hidden;
  background: var(--surface); border: 1px solid var(--line);
  transition: transform 0.25s, opacity 0.25s;
}
.card.leaving { transform: translateX(40px); opacity: 0; }
.card-link { display: block; text-decoration: none; }
.thumb { position: relative; aspect-ratio: 16 / 9; background: linear-gradient(135deg, var(--blue), var(--garnet)); overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.spoiler-free .thumb img { filter: blur(18px) saturate(1.2); transform: scale(1.15); opacity: 0.7; }
.thumb .play {
  position: absolute; inset: 0; display: grid; place-items: center;
}
.thumb .play span {
  width: 64px; height: 64px; border-radius: 50%; background: rgba(0, 0, 0, 0.55);
  display: grid; place-items: center; backdrop-filter: blur(4px);
}
.thumb .play svg { width: 30px; height: 30px; margin-left: 4px; }
.thumb .matchup-overlay {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 26px 14px 10px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.75));
  font-weight: 800; font-size: 19px; letter-spacing: 0.2px;
}
.chip {
  position: absolute; top: 10px; left: 10px; padding: 3px 9px; border-radius: 99px;
  background: var(--gold); color: #1b1400; font-size: 11px; font-weight: 800; letter-spacing: 0.5px;
}
.card-body { padding: 12px 14px 14px; display: flex; gap: 10px; align-items: flex-start; }
.card-text { flex: 1; min-width: 0; }
.card-meta { color: var(--muted); font-size: 14px; }
.card-teaser { margin-top: 4px; font-size: 14px; }
.barca { color: var(--text); }
.check-btn {
  flex: none; width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--muted); display: grid; place-items: center; cursor: pointer;
}
.check-btn:active { color: var(--ok); border-color: var(--ok); }

/* ---------- Watched rows ---------- */
.rows { display: grid; gap: 2px; border-radius: var(--radius); overflow: hidden; }
.row { display: flex; align-items: center; gap: 10px; padding: 10px 6px 10px 14px; background: var(--surface); }
.row-link { flex: 1; min-width: 0; text-decoration: none; display: flex; align-items: center; gap: 12px; }
.row-tick { color: var(--ok); flex: none; }
.row-tick svg { width: 20px; height: 20px; }
.row-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-meta { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .icon-btn svg { width: 20px; height: 20px; }
.more { margin-top: 10px; }

/* ---------- Matches ---------- */
.fixture { display: grid; gap: 10px; padding: 14px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); }
.fixture + .fixture { margin-top: 10px; }
.fixture-head { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--muted); }
.fixture-head .comp { font-weight: 700; color: var(--text); }
.fixture-teams { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }
.team { display: flex; align-items: center; gap: 8px; min-width: 0; font-weight: 600; }
.team.away { flex-direction: row-reverse; text-align: right; }
.team img { width: 28px; height: 28px; object-fit: contain; flex: none; }
.team span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kickoff { text-align: center; font-weight: 800; font-size: 18px; padding: 4px 10px; border-radius: 10px; background: var(--surface-2); }
.fixture.live .kickoff { background: var(--garnet); }
.fixture-venue { font-size: 13px; color: var(--muted); }

/* ---------- Table ---------- */
.summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 8px; }
.stat { padding: 12px 6px; border-radius: 14px; background: var(--surface); text-align: center; }
.stat b { display: block; font-size: 22px; }
.stat span { font-size: 12px; color: var(--muted); }
.table-wrap { position: relative; margin-top: 4px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
th { font-size: 11px; color: var(--muted); font-weight: 700; text-align: right; padding: 6px 4px; }
td { padding: 8px 4px; text-align: right; border-top: 1px solid var(--line); }
th:nth-child(2), td:nth-child(2) { text-align: left; }
td:first-child { width: 30px; text-align: center; position: relative; }
td:first-child::before { content: ""; position: absolute; left: 0; top: 6px; bottom: 6px; width: 3px; border-radius: 2px; background: var(--zone, transparent); }
td.team-cell { display: flex; align-items: center; gap: 8px; }
td.team-cell img { width: 20px; height: 20px; object-fit: contain; }
tr.is-barca td { background: rgba(165, 0, 68, 0.25); font-weight: 700; }
td.pts { font-weight: 800; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 12px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.spoiler-guard {
  position: absolute; inset: 0; z-index: 2; display: grid; place-content: center; gap: 12px; text-align: center;
  padding: 24px; border-radius: var(--radius); background: rgba(11, 16, 32, 0.6); backdrop-filter: blur(14px);
}
.spoiler-guard p { margin: 0; }
.blurred { filter: blur(6px); pointer-events: none; user-select: none; }

/* ---------- Sheet / dialogs ---------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, 0.55); }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-height: 88dvh; overflow: auto;
  max-width: 640px; margin: 0 auto; padding: 8px 18px calc(22px + var(--safe-b));
  border-radius: 22px 22px 0 0; background: var(--surface); border-top: 1px solid var(--line);
  animation: up 0.22s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.sheet .grabber { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 12px; }
.sheet h2 { margin: 4px 0 14px; font-size: 20px; }
.sheet h3 { margin: 20px 0 8px; font-size: 14px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--muted); }
.sheet p { margin: 8px 0; }
.sheet ol { padding-left: 20px; margin: 8px 0; }
.sheet li { margin: 6px 0; }
.sheet .actions { display: grid; gap: 10px; margin-top: 16px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; }
.switch-row small { display: block; color: var(--muted); }
.switch { position: relative; width: 52px; height: 32px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 16px; background: var(--line); transition: 0.2s; pointer-events: none; }
.switch span::after { content: ""; position: absolute; top: 4px; left: 4px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: 0.2s; }
.switch input:checked + span { background: var(--garnet); }
.switch input:checked + span::after { transform: translateX(20px); }
.focus-matchup { font-size: 24px; font-weight: 800; margin: 6px 0 2px; }
code { background: var(--surface-2); padding: 2px 6px; border-radius: 6px; font-size: 13px; word-break: break-all; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(var(--tabbar-h) + var(--safe-b) + 12px); z-index: 30;
  max-width: 480px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 10px 10px 16px; border-radius: 14px; background: #f4f6fc; color: #0b1020; font-weight: 600;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}
.toast button { border: 0; background: none; color: var(--garnet); font-weight: 800; padding: 8px 10px; cursor: pointer; }

.loading { padding: 30px; text-align: center; color: var(--muted); }
