:root {
  color-scheme: light dark;
  --accent: #08775c;
  --accent-deep: #075f4a;
  --accent-soft: #d9f2e8;
  --background: #f3f7f5;
  --card: #ffffff;
  --danger: #d43b4f;
  --line: #dbe5e0;
  --muted: #61706a;
  --pitch: #27865e;
  --pitch-line: rgb(255 255 255 / 62%);
  --text: #14221d;
  --shadow: 0 8px 28px rgb(28 68 52 / 8%);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

html { background: var(--background); }

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 100% 0, rgb(8 119 92 / 10%), transparent 32rem),
    var(--background);
  color: var(--text);
}

button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }
button:focus-visible, a:focus-visible { outline: 3px solid #f0b91e; outline-offset: 3px; }

.app-header {
  position: sticky;
  z-index: 10;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 72px;
  padding: calc(10px + env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) 10px max(18px, env(safe-area-inset-left));
  border-bottom: 1px solid rgb(255 255 255 / 15%);
  background: rgb(7 95 74 / 94%);
  color: white;
  backdrop-filter: blur(18px);
}

.brand { display: flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; }
.brand img { border-radius: 11px; box-shadow: 0 4px 14px rgb(0 0 0 / 18%); }
.brand span { display: grid; }
.brand strong { font-size: 1.15rem; letter-spacing: -.02em; }
.brand small { color: rgb(255 255 255 / 72%); font-size: .7rem; }

.icon-button, .close-button, .date-arrow {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgb(255 255 255 / 12%);
  color: inherit;
  cursor: pointer;
}

.icon-button svg { width: 22px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-width: 2; }
.icon-button.is-loading svg { animation: spin .8s linear infinite; }

main { width: min(100%, 760px); min-height: 70vh; margin: auto; padding: 22px 14px 36px; }
.hero { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 14px; padding: 5px 4px 18px; }
.hero h1 { margin: 2px 0 0; font-size: clamp(1.65rem, 7vw, 2.35rem); letter-spacing: -.045em; text-transform: capitalize; }
.eyebrow { margin: 0; color: var(--accent); font-size: .72rem; font-weight: 800; letter-spacing: .16em; }

.mode-switch { display: flex; gap: 4px; padding: 4px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); box-shadow: var(--shadow); }
.mode-button { min-height: 40px; padding: 0 14px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-weight: 700; cursor: pointer; }
.mode-button.is-active { background: var(--accent-soft); color: var(--accent-deep); }
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }

.date-navigation { display: grid; grid-template-columns: 38px minmax(0, 1fr) 38px; align-items: center; gap: 4px; margin-bottom: 20px; }
.date-navigation[hidden] { display: none; }
.date-arrow { width: 38px; height: 44px; background: transparent; color: var(--muted); font-size: 2rem; }
.date-strip { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; }
.date-button { display: grid; min-width: 0; min-height: 58px; place-content: center; gap: 2px; border: 1px solid transparent; border-radius: 14px; background: transparent; color: var(--muted); cursor: pointer; }
.date-button span { overflow: hidden; font-size: .72rem; text-overflow: ellipsis; text-transform: uppercase; }
.date-button strong { color: var(--text); font-size: 1rem; }
.date-button.is-selected { border-color: var(--accent); background: var(--accent); color: white; box-shadow: 0 7px 18px rgb(8 119 92 / 24%); }
.date-button.is-selected strong { color: white; }

.status-message { margin: 0 0 14px; padding: 12px 14px; border: 1px solid #e5a4ac; border-radius: 12px; background: #fff1f3; color: #8b2331; font-size: .85rem; }
.content { display: grid; gap: 16px; }
.league-section { overflow: hidden; border: 1px solid var(--line); border-radius: 18px; background: var(--card); box-shadow: var(--shadow); }
.league-header { display: flex; align-items: center; gap: 10px; min-height: 60px; padding: 11px 15px; border-bottom: 1px solid var(--line); background: linear-gradient(105deg, rgb(8 119 92 / 8%), transparent); }
.league-header img { object-fit: contain; }
.league-header > span { display: grid; gap: 2px; }
.league-header strong { font-size: .9rem; }
.league-header small { color: var(--muted); font-size: .72rem; }
.league-placeholder { display: grid; width: 28px; height: 28px; place-items: center; color: var(--accent); }

.match-list { display: grid; }
.match-card { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) 48px; border-bottom: 1px solid var(--line); }
.match-card:last-child { border-bottom: 0; }
.match-card.is-live { box-shadow: inset 3px 0 var(--danger); }
.match-main { display: grid; gap: 8px; min-width: 0; padding: 14px 8px 14px 15px; border: 0; background: transparent; color: inherit; text-align: left; cursor: pointer; }
.match-main:active { background: rgb(8 119 92 / 6%); }
.team-row { display: grid; grid-template-columns: 34px minmax(0, 1fr) 30px; align-items: center; gap: 10px; min-height: 34px; }
.team-badge { width: 34px; height: 34px; object-fit: contain; }
.badge-placeholder { display: grid; width: 34px; height: 34px; place-items: center; color: var(--line); }
.team-name { overflow: hidden; font-size: .95rem; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.score { font-size: 1.15rem; font-variant-numeric: tabular-nums; text-align: center; }
.match-status { display: flex; align-items: center; gap: 6px; margin: 2px 0 0 44px; color: var(--muted); font-size: .75rem; font-weight: 700; }
.match-status.live, .live { color: var(--danger); }
.match-status.live .live-dot { animation: pulse 1.6s ease-out infinite; }
.favorite-button { align-self: stretch; min-width: 48px; border: 0; background: transparent; color: #7d8a85; font-size: 1.45rem; cursor: pointer; }
.favorite-button.is-favorite { color: #d69800; }

.state-card { display: grid; justify-items: center; min-height: 280px; place-content: center; padding: 34px; border: 1px solid var(--line); border-radius: 18px; background: var(--card); text-align: center; box-shadow: var(--shadow); }
.state-card h2 { margin: 15px 0 6px; font-size: 1.15rem; }
.state-card p { max-width: 28rem; margin: 0; color: var(--muted); line-height: 1.5; }
.state-icon { display: grid; width: 54px; height: 54px; place-items: center; border-radius: 50%; background: var(--accent-soft); color: var(--accent-deep); font-size: 1.5rem; font-weight: 800; }
.state-card.error .state-icon { background: #ffe5e8; color: var(--danger); }
.primary-button { min-height: 44px; margin-top: 18px; padding: 0 20px; border: 0; border-radius: 12px; background: var(--accent); color: white; font-weight: 750; cursor: pointer; }
.spinner { width: 36px; height: 36px; border: 4px solid var(--accent-soft); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
.spinner.small { display: inline-block; width: 16px; height: 16px; border-width: 2px; vertical-align: middle; }

footer { padding: 28px max(18px, env(safe-area-inset-right)) calc(28px + env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left)); color: var(--muted); font-size: .78rem; text-align: center; }
footer p { margin: 4px 0; }
.provider { opacity: .72; }

.match-dialog { width: min(calc(100% - 24px), 760px); max-height: calc(100vh - 30px); padding: 0; border: 1px solid var(--line); border-radius: 22px; background: var(--card); color: var(--text); box-shadow: 0 24px 80px rgb(0 0 0 / 28%); }
.match-dialog::backdrop { background: rgb(5 20 15 / 55%); backdrop-filter: blur(3px); }
.dialog-bar { position: sticky; z-index: 2; top: 0; display: flex; align-items: center; justify-content: space-between; min-height: 62px; padding: 9px 12px 9px 20px; border-bottom: 1px solid var(--line); background: var(--card); }
.dialog-bar h2 { margin: 0; font-size: 1rem; }
.close-button { background: var(--background); color: var(--text); font-size: 1.8rem; }
#dialogContent { padding: 22px 18px 30px; }
.detail-league { display: flex; align-items: center; justify-content: center; gap: 9px; margin-bottom: 26px; font-size: .88rem; }
.detail-league img { object-fit: contain; }
.detail-score { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: start; gap: 12px; }
.detail-score > div { display: grid; justify-items: center; gap: 10px; min-width: 0; text-align: center; }
.detail-score .team-badge, .detail-score .badge-placeholder { width: 58px; height: 58px; }
.detail-score > div strong { font-size: .86rem; overflow-wrap: anywhere; }
.detail-score p { display: grid; justify-items: center; gap: 6px; margin: 12px 0 0; }
.detail-score p > strong { font-size: 1.55rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.detail-score p > span { font-size: .74rem; font-weight: 750; }
.facts { display: grid; gap: 0; margin-top: 28px; border-top: 1px solid var(--line); }
.fact { display: flex; justify-content: space-between; gap: 20px; min-height: 48px; padding: 14px 0; border-bottom: 1px solid var(--line); font-size: .86rem; }
.fact span { color: var(--muted); }
.fact strong { text-align: right; }
.detail-note { margin: 18px 0 0; color: var(--muted); font-size: .78rem; text-align: center; }
.error-text { color: var(--danger); }
.detail-section { margin-top: 28px; }
.detail-section h3 { margin: 0 0 12px; font-size: .95rem; }
.section-empty { margin: 0; padding: 20px 14px; border: 1px dashed var(--line); border-radius: 13px; color: var(--muted); font-size: .82rem; line-height: 1.45; text-align: center; }
.stats-table { overflow: hidden; border: 1px solid var(--line); border-radius: 14px; }
.stats-head, .stat-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(120px, 1.4fr) minmax(0, 1fr); align-items: center; gap: 8px; min-height: 46px; padding: 9px 12px; text-align: center; }
.stats-head { min-height: 50px; background: var(--background); font-size: .72rem; }
.stats-head strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat-row { border-top: 1px solid var(--line); font-size: .82rem; font-variant-numeric: tabular-nums; }
.stat-row span { color: var(--muted); font-size: .76rem; }
.timeline { display: grid; gap: 0; margin: 0; padding: 0; list-style: none; }
.timeline-item { display: grid; grid-template-columns: 42px 12px minmax(0, 1fr); align-items: start; gap: 10px; min-height: 58px; padding: 8px 0; }
.timeline-item time { color: var(--muted); font-size: .78rem; font-weight: 750; text-align: right; }
.timeline-marker { width: 10px; height: 10px; margin-top: 3px; border: 2px solid var(--card); border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.timeline-item > span:last-child { display: grid; gap: 3px; padding-bottom: 11px; border-bottom: 1px solid var(--line); }
.timeline-item:last-child > span:last-child { border-bottom: 0; }
.timeline-item strong { font-size: .84rem; text-transform: capitalize; }
.timeline-item small { color: var(--muted); font-size: .75rem; line-height: 1.35; }
.timeline-item.is-rescinded { opacity: .66; }
.timeline-item.is-rescinded strong { text-decoration: line-through; }
.detail-tabs { position: sticky; z-index: 1; top: 62px; display: flex; gap: 4px; margin: 24px -18px 0; padding: 8px 14px; overflow-x: auto; border-block: 1px solid var(--line); background: var(--card); scrollbar-width: none; }
.detail-tabs::-webkit-scrollbar { display: none; }
.detail-tabs button { flex: 1 0 auto; min-height: 42px; padding: 0 14px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-size: .8rem; font-weight: 750; cursor: pointer; }
.detail-tabs button[aria-selected="true"] { background: var(--accent-soft); color: var(--accent-deep); }
.detail-panel { padding-top: 4px; }
.panel-title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
.period-stats { margin-top: 12px; border: 1px solid var(--line); border-radius: 13px; }
.period-stats > summary, .bench > summary, .unavailable > summary { display: flex; min-height: 46px; align-items: center; padding: 0 14px; color: var(--accent-deep); font-size: .8rem; font-weight: 750; cursor: pointer; }
.period-stats > h4 { margin: 16px 14px 8px; font-size: .8rem; }
.period-stats > .stats-table { margin: 0 12px 12px; }
.match-figure { margin: 0; }
.match-figure svg { display: block; width: 100%; height: auto; }
.match-figure figcaption { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px; margin-top: 8px; color: var(--muted); font-size: .72rem; text-align: center; }
.legend { display: inline-block; width: 9px; height: 9px; margin-left: 4px; border-radius: 50%; }
.legend.home { background: var(--accent); }
.legend.away { background: var(--danger); }
.pitch { color: var(--pitch-line); }
.pitch .pitch-surface { fill: var(--pitch); stroke: var(--pitch-line); }
.pitch line, .pitch rect:not(.pitch-surface), .pitch > circle { fill: none; stroke: currentColor; stroke-width: .6; }
.pitch .pitch-dot { fill: currentColor; stroke: none; }
.shot-dot circle { fill: var(--accent); fill-opacity: .75; stroke: white; stroke-width: .5; }
.shot-dot.away circle { fill: var(--danger); }
.shot-dot.is-goal circle { fill-opacity: 1; stroke: #ffd33d; stroke-width: 1.2; }
.chart { overflow: visible; border-block: 1px solid var(--line); }
.chart line { stroke: var(--line); stroke-width: .5; }
.momentum-home { fill: var(--accent); }
.momentum-away { fill: var(--danger); }
.xg-chart polyline { fill: none; stroke-width: 1.2; vector-effect: non-scaling-stroke; }
.xg-home { stroke: var(--accent); }
.xg-away { stroke: var(--danger); }
.position-pitches { display: grid; gap: 14px; }
.position-pitch { margin: 0; }
.position-pitch > strong { display: block; margin-bottom: 6px; font-size: .78rem; text-align: center; }
.position-dot circle { fill: var(--accent); stroke: white; stroke-width: .6; }
.position-dot.away circle { fill: var(--danger); }
.position-dot text { fill: white; font-size: 2.7px; font-weight: 800; text-anchor: middle; }
.lineup-banner { display: grid; gap: 4px; margin-top: 18px; padding: 13px 15px; border: 1px solid var(--line); border-radius: 13px; background: var(--accent-soft); }
.lineup-banner.predicted { border-color: #d6a72a; background: #fff7d6; color: #644b00; }
.lineup-banner strong { font-size: .85rem; }
.lineup-banner span { font-size: .74rem; line-height: 1.4; }
.lineup-grid { display: grid; gap: 16px; margin-top: 16px; }
.lineup-side { overflow: hidden; border: 1px solid var(--line); border-radius: 15px; }
.lineup-side > header { display: flex; align-items: center; gap: 10px; min-height: 62px; padding: 10px 13px; border-bottom: 1px solid var(--line); background: var(--background); }
.lineup-side h4 { margin: 0; font-size: .88rem; }
.lineup-side header small { color: var(--muted); font-size: .72rem; }
.roster { margin: 0; padding: 0; list-style: none; }
.roster li { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; align-items: center; gap: 8px; min-height: 48px; padding: 7px 12px; border-bottom: 1px solid var(--line); }
.roster li:last-child { border-bottom: 0; }
.roster li > span:nth-child(2) { display: grid; gap: 2px; }
.roster li strong { overflow: hidden; font-size: .8rem; text-overflow: ellipsis; white-space: nowrap; }
.roster li small { color: var(--muted); font-size: .68rem; }
.jersey { display: grid; width: 30px; height: 30px; place-items: center; border-radius: 9px; background: var(--accent-soft); color: var(--accent-deep); font-size: .74rem; font-weight: 800; }
.confidence { color: var(--muted); font-size: .7rem; font-variant-numeric: tabular-nums; }
.bench, .unavailable { border-top: 1px solid var(--line); }
.substitutes { background: var(--background); }
.unavailable ul { margin: 0; padding: 0 12px 10px; list-style: none; }
.unavailable li { display: grid; gap: 2px; padding: 9px 2px; border-top: 1px solid var(--line); }
.unavailable li strong { font-size: .76rem; }
.unavailable li span { color: var(--muted); font-size: .68rem; text-transform: capitalize; }
.player-stats-help { margin: 18px 0 12px; color: var(--muted); font-size: .76rem; line-height: 1.45; }
.player-stats-grid { display: grid; gap: 18px; }
.player-stats-side > h4 { margin: 0 0 8px; font-size: .88rem; }
.player-stat { border: 1px solid var(--line); border-bottom: 0; }
.player-stat:first-of-type { border-radius: 13px 13px 0 0; }
.player-stat:last-child { border-bottom: 1px solid var(--line); border-radius: 0 0 13px 13px; }
.player-stat > summary { display: flex; min-height: 54px; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 12px; cursor: pointer; }
.player-stat > summary > span:first-child { display: grid; gap: 2px; min-width: 0; }
.player-stat summary strong { overflow: hidden; font-size: .8rem; text-overflow: ellipsis; white-space: nowrap; }
.player-stat summary small { color: var(--muted); font-size: .68rem; }
.rating { display: grid; min-width: 38px; height: 30px; place-items: center; border-radius: 9px; background: var(--accent); color: white; font-size: .75rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.player-metrics { display: grid; grid-template-columns: repeat(2, 1fr); border-top: 1px solid var(--line); background: var(--background); }
.player-metrics > div { display: grid; gap: 2px; min-height: 50px; padding: 9px 12px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.player-metrics span { color: var(--muted); font-size: .66rem; }
.player-metrics strong { font-size: .78rem; font-variant-numeric: tabular-nums; }
.h2h-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin-top: 18px; }
.h2h-summary > div { display: grid; min-height: 100px; align-content: center; gap: 7px; padding: 10px; border: 1px solid var(--line); border-radius: 13px; background: var(--background); text-align: center; }
.h2h-summary strong { font-size: 1.55rem; }
.h2h-summary span { color: var(--muted); font-size: .68rem; line-height: 1.3; }
.h2h-average { margin: 12px 0 22px; color: var(--muted); font-size: .74rem; text-align: center; }
.h2h-matches h4 { margin: 0 0 8px; font-size: .88rem; }
.h2h-matches > div { display: grid; gap: 5px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.h2h-matches time { color: var(--muted); font-size: .68rem; }
.h2h-matches div > span { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 10px; font-size: .78rem; }
.h2h-matches div > span strong:nth-child(2) { padding: 5px 8px; border-radius: 8px; background: var(--background); font-variant-numeric: tabular-nums; }
.h2h-matches div > span strong:last-child { text-align: right; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgb(212 59 79 / 50%); } 100% { box-shadow: 0 0 0 7px rgb(212 59 79 / 0%); } }

@media (min-width: 620px) {
  main { padding-top: 30px; }
  .match-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .match-card:nth-child(odd) { border-right: 1px solid var(--line); }
  .match-card:nth-last-child(-n + 2) { border-bottom: 0; }
  .position-pitches, .lineup-grid, .player-stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .player-metrics { grid-template-columns: repeat(3, 1fr); }
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #3fd0a4;
    --accent-deep: #8ce8cb;
    --accent-soft: #153d32;
    --background: #0d1512;
    --card: #151f1b;
    --line: #2c3934;
    --muted: #9ba9a3;
    --pitch: #185e43;
    --text: #edf5f1;
    --shadow: none;
  }
  .status-message { border-color: #753642; background: #34191f; color: #ffb2be; }
  .state-card.error .state-icon { background: #481d24; }
  .lineup-banner.predicted { border-color: #7b671f; background: #332c13; color: #f3dc83; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
