:root {
  --bg: #f4f4f6;
  --surface: #ffffff;
  --surface-muted: #ececf0;
  --border: #e3e3e8;
  --text: #1a1a1f;
  --text-muted: #6b6b76;
  --accent: #ff5e1f;
  --accent-soft: #fff1ea;
  --group-a: #2f6df6;
  --group-b: #7a3cf6;
  --success: #1a8754;
  --danger: #c4314b;
  --zone-final: #16a34a;
  --zone-semi: #ca8a04;
  --zone-ll: #64748b;
  --hero-bg: linear-gradient(135deg, #0b1426 0%, #1e293b 60%, #2d3a52 100%);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 12px rgba(0, 0, 0, 0.04);
  --radius: 8px;
  --radius-lg: 14px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }
html, body { overflow-x: clip; }

body {
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.45;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  cursor: pointer;
}

input {
  font: inherit;
}

/* ---------- Hero ---------- */
.hero {
  background: var(--hero-bg);
  color: white;
  position: relative;
  overflow: hidden;
}
.hero::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--group-a), var(--accent), var(--group-b));
}
.hero__inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: var(--space-5) var(--space-4);
  display: grid;
  gap: var(--space-3);
}
.hero__top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.hero__title {
  margin: 0;
  font-size: 1.75rem;
  letter-spacing: -0.01em;
  font-weight: 700;
}
.hero__phase {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  background: rgba(255, 255, 255, 0.12);
  padding: 5px 12px;
  border-radius: 999px;
  color: rgba(255, 255, 255, 0.92);
  white-space: nowrap;
  margin-left: auto;
}
.hero__trophy-link {
  position: absolute;
  top: var(--space-5);
  right: var(--space-4);
  display: block;
  line-height: 0;
  z-index: 1;
  border-radius: 8px;
  transition: transform 160ms ease, filter 160ms ease;
}
.hero__trophy-link:hover,
.hero__trophy-link:focus-visible {
  transform: translateY(-2px) scale(1.04);
}
.hero__trophy-link:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.85);
  outline-offset: 4px;
}
.hero__trophy {
  height: clamp(48px, 9vw, 96px);
  width: auto;
  display: block;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.35));
}
.hero__logo-link {
  position: absolute;
  top: 50%;
  left: var(--space-4);
  transform: translateY(-50%);
  display: block;
  line-height: 0;
  z-index: 1;
  border-radius: 8px;
  transition: transform 160ms ease, filter 160ms ease;
}
.hero__logo-link:hover,
.hero__logo-link:focus-visible {
  transform: translateY(-50%) scale(1.04);
}
.hero__logo-link:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.85);
  outline-offset: 4px;
}
.hero__logo {
  height: clamp(44px, 7vw, 72px);
  width: auto;
  display: block;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.3));
}
.hero__top,
.hero__stats,
.hero__progress {
  margin-left: clamp(170px, 25vw, 280px);
}
.hero__top {
  padding-right: clamp(56px, 11vw, 80px);
}
@media (max-width: 719px) {
  .hero__logo-link {
    top: var(--space-3);
    left: var(--space-3);
    transform: none;
  }
  .hero__logo-link:hover,
  .hero__logo-link:focus-visible {
    transform: scale(1.04);
  }
  .hero__logo {
    height: 28px;
    filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.3));
  }
  .hero__trophy {
    height: 40px;
  }
  .hero__top,
  .hero__stats,
  .hero__progress {
    margin-left: 0;
  }
  .hero__top {
    padding-right: 56px;
    padding-top: 32px;
  }
}
@media (min-width: 1250px) {
  .hero__top { padding-right: 0; }
}
@media (min-width: 1700px) {
  .hero__top,
  .hero__stats,
  .hero__progress { margin-left: 0; }
  .hero__logo-link {
    left: calc((100% - 1100px) / 4);
    transform: translate(-50%, -50%);
  }
  .hero__logo-link:hover,
  .hero__logo-link:focus-visible {
    transform: translate(-50%, -50%) scale(1.04);
  }
}
.hero__stats {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-5);
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.7);
}
.hero__stat {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
}
.hero__stat-label {
  color: rgba(255, 255, 255, 0.7);
}
.hero__stat-value {
  color: white;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.hero__progress {
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
  margin-top: var(--space-1);
}
.hero__progress-fill {
  height: 100%;
  background: var(--accent);
  transition: width 240ms ease;
}

/* ---------- App container ---------- */
.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: var(--space-5) var(--space-4) var(--space-7);
}
.app__loading {
  color: var(--text-muted);
  text-align: center;
  padding: var(--space-7) 0;
}

/* ---------- Group overview cards ---------- */
.group-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}
@media (min-width: 720px) {
  .group-grid { grid-template-columns: 1fr 1fr; }
}

.group-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow);
}
.group-card__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}
.group-card__title {
  margin: 0;
  font-size: 1.25rem;
  letter-spacing: -0.01em;
}
.group-card__title--a { color: var(--group-a); }
.group-card__title--b { color: var(--group-b); }
.group-card__count {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.standings {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
.standings th, .standings td {
  text-align: left;
  padding: var(--space-2) var(--space-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.standings th {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.standings td.num, .standings th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.standings tr:last-child td { border-bottom: none; }
.standings__team {
  font-weight: 500;
}
.standings td.standings__rank,
.standings th.standings__rank {
  color: var(--text-muted);
  width: 1.75rem;
  position: relative;
  padding-left: 10px;
}
.standings tr[data-zone] .standings__rank::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 2px;
  background: transparent;
}
.standings tr[data-zone="final"] .standings__rank::before { background: var(--zone-final); }
.standings tr[data-zone="semi"]  .standings__rank::before { background: var(--zone-semi); }
.standings tr[data-zone="ll"]    .standings__rank::before { background: var(--zone-ll); }
.standings__dash {
  color: var(--text-muted);
}

/* ---------- Qualification legend ---------- */
.qualification-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  margin: 0 0 var(--space-4);
  padding: var(--space-3) var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.82rem;
  color: var(--text-muted);
}
.qualification-legend__item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.qualification-legend__dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  display: inline-block;
}
.qualification-legend__dot--final { background: var(--zone-final); }
.qualification-legend__dot--semi  { background: var(--zone-semi); }
.qualification-legend__dot--ll    { background: var(--zone-ll); }

/* ---------- Group card meta ---------- */
.group-card__meta {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.group-card__note {
  color: var(--text-muted);
  margin: 0 0 var(--space-3);
  font-size: 0.88rem;
}

/* ---------- Match list ---------- */
.matches-section {
  margin-bottom: var(--space-6);
}
.matches-section__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  background: var(--surface-muted);
  border-radius: var(--radius);
  margin-bottom: var(--space-3);
}
.matches-section__title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.matches-section__leg {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: var(--space-3) var(--space-1) var(--space-2);
  margin-top: var(--space-2);
}
.matches-section__leg:first-of-type {
  margin-top: 0;
}

.match-filters {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}
.match-filters__chips {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.match-filters__team {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 0.88rem;
  color: var(--text-muted);
}
.match-filters__select {
  font: inherit;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  min-width: 180px;
}
.match-filters__select:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: transparent;
}
.chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.88rem;
  color: var(--text);
}
.chip--active {
  background: var(--text);
  color: var(--surface);
  border-color: var(--text);
}

.match-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4) var(--space-5);
  margin-bottom: var(--space-2);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  transition: border-color 120ms ease, transform 120ms ease;
}
.match-card[data-group="A"] { border-left-color: var(--group-a); }
.match-card[data-group="B"] { border-left-color: var(--group-b); }
.match-card:hover {
  border-color: var(--accent);
}
.match-card[data-group="A"]:hover { border-left-color: var(--group-a); }
.match-card[data-group="B"]:hover { border-left-color: var(--group-b); }
.match-card__row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  width: 100%;
  gap: var(--space-4);
}
.match-card__team {
  font-weight: 500;
  font-size: 1.02rem;
}
.match-card__team--left { text-align: right; }
.match-card__team--right { text-align: left; }
.match-card__team-members {
  display: block;
  font-size: 0.78rem;
  font-weight: 400;
  color: var(--text-muted);
  margin-top: 2px;
}
.match-card__score {
  font-variant-numeric: tabular-nums;
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--text);
  min-width: 4rem;
  text-align: center;
}
.match-card__score--pending {
  color: var(--text-muted);
  font-weight: 400;
}
.match-card__meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.match-card__meta-dot {
  margin: 0 6px;
}

.empty-state {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  text-align: center;
  color: var(--text-muted);
}

/* ---------- Setup wizard ---------- */
.setup {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow);
}
.setup__name-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.setup__name-row label {
  font-weight: 600;
  white-space: nowrap;
}
.setup__name-input {
  flex: 1;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
}
.setup__name-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.setup__intro {
  color: var(--text-muted);
  margin-top: 0;
}
.setup__groups {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-5);
  margin: var(--space-5) 0;
}
@media (min-width: 720px) {
  .setup__groups { grid-template-columns: 1fr 1fr; }
}
.setup-group {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
}
.setup-group__title {
  margin: 0 0 var(--space-3);
  font-size: 1.1rem;
}
.setup-team {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3);
  margin-bottom: var(--space-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.setup-team__info { flex: 1; min-width: 0; }
.setup-team__name { font-weight: 500; }
.setup-team__members {
  font-size: 0.85rem;
  color: var(--text-muted);
}
.setup-team__remove {
  background: transparent;
  border: none;
  color: var(--danger);
  font-size: 1.1rem;
  padding: 4px 8px;
}
.setup-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-2);
  margin-top: var(--space-3);
}
.setup-form input {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: var(--surface);
}
.setup-form input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: transparent;
}
.setup-form__actions {
  display: flex;
  justify-content: flex-end;
}
.setup__actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  margin-top: var(--space-4);
}
.setup__error {
  color: var(--danger);
  font-size: 0.9rem;
  margin: var(--space-3) 0 0;
}

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  padding: 10px 16px;
  font-weight: 500;
  font-size: 0.95rem;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}
.btn:hover { border-color: var(--text-muted); }
.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}
.btn--primary:hover {
  background: #e84e10;
  border-color: #e84e10;
}
.btn--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}
.btn--danger {
  background: var(--danger);
  border-color: var(--danger);
  color: white;
}
.btn--danger:hover {
  background: #a62740;
  border-color: #a62740;
}
.btn--small {
  padding: 6px 12px;
  font-size: 0.88rem;
}

/* ---------- Footer ---------- */
.app-footer {
  margin-top: var(--space-7);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: center;
}

/* ---------- Manage-teams list ---------- */
.manage-teams__list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 25, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  z-index: 50;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.18);
}
.modal--wide {
  max-width: 560px;
}
.modal__title {
  margin: 0 0 var(--space-2);
  font-size: 1.15rem;
}
.modal__teams {
  font-size: 0.92rem;
  color: var(--text-muted);
  margin-bottom: var(--space-4);
}
.modal__score-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.modal__team-label {
  font-weight: 500;
  text-align: center;
}
.modal__team-label--left { text-align: right; }
.modal__team-label--right { text-align: left; }
.modal__score-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  font-size: 1.6rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}
.modal__score-input::-webkit-outer-spin-button,
.modal__score-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.modal__score-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: transparent;
}
.modal__colon {
  font-size: 1.6rem;
  color: var(--text-muted);
}
.modal__actions {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  margin-top: var(--space-3);
}
.modal__actions-right {
  display: flex;
  gap: var(--space-2);
}

/* ---------- Stepper (score input) ---------- */
.stepper {
  display: flex;
  align-items: stretch;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  height: 64px;
}
.stepper:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: transparent;
}
.stepper__btn {
  background: var(--surface-muted);
  border: none;
  width: 48px;
  font-size: 1.6rem;
  line-height: 1;
  color: var(--text);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
  user-select: none;
  touch-action: manipulation;
}
.stepper__btn:hover {
  background: var(--accent-soft);
  color: var(--accent);
}
.stepper__btn:active {
  background: var(--accent);
  color: white;
}
.stepper__value {
  flex: 1;
  min-width: 0;
  text-align: center;
  font-size: 1.7rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  background: transparent;
  border: none;
  outline: none;
  width: 100%;
  padding: 0;
  color: var(--text);
  -moz-appearance: textfield;
}
.stepper__value::-webkit-outer-spin-button,
.stepper__value::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* ---------- Mobile-friendly standings ---------- */
@media (max-width: 600px) {
  .standings .col-detail { display: none; }
  .standings th, .standings td {
    padding: var(--space-2) 6px;
  }
}
