:root {
  color-scheme: light;
  --bg: #f3f5f2;
  --panel: #ffffff;
  --ink: #182326;
  --muted: #667579;
  --line: #d9e0dd;
  --accent: #0e7c66;
  --accent-2: #3157a4;
  --gold: #b7791f;
  --danger: #c2413a;
  --soft-green: #e4f4ed;
  --soft-blue: #e7edf8;
  --soft-gold: #f8efd9;
  --soft-red: #fae8e6;
  --shadow: 0 18px 48px rgba(24, 35, 38, 0.11);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.modal-open {
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: center;
  padding: 14px clamp(14px, 4vw, 42px);
  border-bottom: 1px solid rgba(217, 224, 221, 0.9);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
}

.brand-mark {
  display: grid;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-weight: 850;
  letter-spacing: 0;
}

h1 {
  overflow: hidden;
  font-size: clamp(20px, 3.5vw, 30px);
  line-height: 1.05;
  letter-spacing: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand p,
.panel-heading p,
.field span,
.stat-label,
.prediction-meta,
.chart-note,
.muted {
  color: var(--muted);
}

.brand p,
.panel-heading p {
  margin-top: 3px;
  font-size: 13px;
}

.toolbar {
  display: inline-grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}

.nav-button {
  min-height: 36px;
  padding: 6px 13px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 760;
}

.nav-button.is-active {
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(24, 35, 38, 0.12);
}

main {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 18px clamp(12px, 4vw, 32px) 36px;
}

.hero-summary {
  display: grid;
  grid-template-columns: 1.6fr repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.hero-summary div {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.hero-summary span {
  display: block;
  overflow: hidden;
  font-size: clamp(22px, 4vw, 34px);
  font-weight: 850;
  line-height: 1;
  letter-spacing: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hero-summary small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
  text-transform: uppercase;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.wide-panel {
  grid-column: 1 / -1;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

h2 {
  font-size: 19px;
  line-height: 1.2;
  letter-spacing: 0;
}

.field {
  display: grid;
  gap: 5px;
}

.field span {
  font-size: 11px;
  font-weight: 780;
  text-transform: uppercase;
}

.compact-field {
  width: min(220px, 44vw);
}

input,
select {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
}

.leaderboard-list,
.results-list {
  display: grid;
}

.leader-row {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) repeat(4, minmax(58px, auto));
  gap: 10px;
  align-items: center;
  width: 100%;
  min-height: 64px;
  padding: 10px 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.leader-row:last-child,
.result-row:last-child {
  border-bottom: 0;
}

.leader-row:hover,
.leader-row:focus-visible {
  background: var(--soft-green);
  outline: none;
}

.rank-badge {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 8px;
  background: var(--soft-blue);
  color: var(--accent-2);
  font-weight: 850;
}

.rank-badge.is-top {
  background: var(--soft-gold);
  color: var(--gold);
}

.entrant-name {
  overflow: hidden;
  font-size: 16px;
  font-weight: 820;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.entrant-subline {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.stat {
  display: grid;
  justify-items: end;
  gap: 2px;
  font-variant-numeric: tabular-nums;
}

.stat-value {
  font-weight: 850;
}

.stat-label {
  font-size: 11px;
  font-weight: 720;
  text-transform: uppercase;
}

.points-pill,
.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 30px;
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--soft-blue);
  font-weight: 850;
  font-variant-numeric: tabular-nums;
}

.status-pill.is-complete {
  background: var(--soft-green);
  color: var(--accent);
}

.status-pill.is-live {
  background: var(--soft-red);
  color: var(--danger);
}

.result-row {
  display: grid;
  grid-template-columns: 52px 92px minmax(0, 1fr) 92px 74px;
  gap: 10px;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.fixture-title {
  overflow: hidden;
  font-weight: 780;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fixture-time {
  color: var(--muted);
  font-size: 12px;
}

.score {
  justify-self: end;
  font-size: 18px;
  font-weight: 850;
  font-variant-numeric: tabular-nums;
}

.charts-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 0.62fr);
  gap: 16px;
}

.chart-frame {
  min-height: 300px;
  padding: 14px;
}

.line-chart {
  display: block;
  width: 100%;
  height: auto;
  min-height: 300px;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-top: 10px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

.pie-frame {
  display: grid;
  align-content: start;
  gap: 12px;
}

.pie-chart {
  display: block;
  width: min(260px, 100%);
  height: auto;
  margin: 0 auto;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
}

.modal.is-open {
  display: block;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(14, 24, 28, 0.48);
}

.modal-panel {
  position: absolute;
  top: 5vh;
  right: clamp(12px, 4vw, 42px);
  bottom: 5vh;
  width: min(620px, calc(100vw - 24px));
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.modal-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.modal-heading p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.icon-button {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 24px;
  line-height: 1;
}

#entrantDetail {
  height: calc(100% - 76px);
  overflow: auto;
  padding: 16px;
}

.detail-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.detail-stats div,
.bonus-box {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}

.detail-stats strong {
  display: block;
  font-size: 22px;
  line-height: 1;
}

.detail-stats span,
.bonus-box span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 720;
  text-transform: uppercase;
}

.bonus-box {
  margin-bottom: 12px;
}

.bonus-main {
  margin-top: 6px;
  font-weight: 760;
}

.prediction-list {
  display: grid;
  gap: 8px;
}

.prediction-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.prediction-title {
  overflow: hidden;
  font-weight: 760;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.prediction-meta {
  margin-top: 3px;
  font-size: 12px;
}

.prediction-score {
  display: grid;
  justify-items: end;
  gap: 3px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.prediction-score strong {
  font-size: 17px;
}

.prediction-points {
  color: var(--accent);
  font-size: 12px;
  font-weight: 850;
}

.modal-handle {
  display: none;
}

@media (max-width: 820px) {
  .topbar {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .toolbar {
    width: 100%;
  }

  .nav-button {
    min-height: 42px;
  }

  .hero-summary {
    grid-template-columns: repeat(2, 1fr);
  }

  .panel-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .compact-field {
    width: 100%;
  }

  .leader-row {
    grid-template-columns: 46px minmax(0, 1fr) auto;
    min-height: 72px;
  }

  .leader-row .stat:not(.primary-stat) {
    display: none;
  }

  .result-row {
    grid-template-columns: 38px minmax(0, 1fr) auto;
    gap: 8px;
  }

  .result-row .group-cell,
  .result-row .status-cell {
    display: none;
  }

  .score {
    font-size: 16px;
  }

  .charts-grid {
    grid-template-columns: 1fr;
  }

  .modal-panel {
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    max-height: 88vh;
    border-radius: 8px 8px 0 0;
  }

  .modal-handle {
    display: block;
    width: 42px;
    height: 4px;
    margin: 9px auto 0;
    border-radius: 999px;
    background: var(--line);
  }
}

@media (max-width: 520px) {
  main {
    padding-inline: 10px;
  }

  .brand-mark {
    flex-basis: 40px;
    width: 40px;
    height: 40px;
  }

  .hero-summary {
    gap: 8px;
  }

  .hero-summary div {
    padding: 11px;
  }

  .hero-summary span {
    font-size: 22px;
  }

  .panel-heading {
    padding: 14px;
  }

  .leader-row,
  .result-row {
    padding-inline: 10px;
  }

  .detail-stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .prediction-row {
    grid-template-columns: 1fr;
  }

  .prediction-score {
    justify-items: start;
    grid-template-columns: auto auto;
    gap: 10px;
  }
}
