:root {
  color-scheme: light;
  --brand: #006ccc;
  --brand-dark: #064f9f;
  --danger: #e12420;
  --ink: #222831;
  --muted: #657080;
  --line: #e3e8ef;
  --paper: #ffffff;
  --wash: #f5f7fb;
  --yellow: #ffd100;
  --purple: #712fa0;
  --green: #04a777;
  --shadow: 0 14px 36px rgba(12, 36, 68, 0.12);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html {
  min-height: 100%;
  background: var(--wash);
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  background:
    linear-gradient(135deg, rgba(0, 108, 204, 0.08), transparent 28rem),
    linear-gradient(315deg, rgba(255, 209, 0, 0.16), transparent 24rem),
    var(--wash);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, select {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

button, a {
  color: inherit;
}

svg {
  width: 1.25rem;
  height: 1.25rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  min-height: 58px;
  padding: calc(0.55rem + env(safe-area-inset-top)) calc(1rem + env(safe-area-inset-right)) 0.55rem calc(1rem + env(safe-area-inset-left));
  border-bottom: 1px solid rgba(227, 232, 239, 0.82);
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(18px);
}

.brand img {
  display: block;
  width: min(178px, 48vw);
  height: auto;
}

.tag, .progress-pill, .mini-chips span {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0.25rem 0.65rem;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
}

.app-main {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 1rem calc(1rem + env(safe-area-inset-right)) calc(5.6rem + env(safe-area-inset-bottom)) calc(1rem + env(safe-area-inset-left));
  outline: none;
  min-width: 0;
  overflow-x: hidden;
}

.page {
  display: grid;
  gap: 1rem;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

.home-hero, .area-hero {
  position: relative;
  min-height: clamp(280px, 60vh, 560px);
  overflow: hidden;
  border-radius: var(--radius);
  background: #162033;
  box-shadow: var(--shadow);
}

.area-hero {
  min-height: 260px;
}

.home-hero img, .area-hero img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.home-hero::after, .area-hero::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(8, 20, 36, 0.12), rgba(8, 20, 36, 0.76));
}

.home-hero__content, .area-hero__content {
  position: absolute;
  inset: auto 0 0;
  z-index: 1;
  padding: 1.25rem;
  color: #fff;
}

.home-hero h1, .area-hero h1 {
  max-width: 100%;
  margin: 0;
  overflow-wrap: anywhere;
  font-size: clamp(2.25rem, 8vw, 4.25rem);
  line-height: 0.98;
  letter-spacing: 0;
}

.page-heading h1 {
  margin: 0;
  font-size: clamp(2.2rem, 9vw, 5rem);
  line-height: 0.96;
  letter-spacing: 0;
}

.home-hero p {
  max-width: 36rem;
  margin: 0.75rem 0 0;
  font-size: 1.05rem;
}

.eyebrow {
  margin: 0 0 0.35rem;
  color: var(--brand);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.home-hero .eyebrow, .area-hero .eyebrow {
  color: var(--yellow);
}

.home-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
}

.action-card {
  position: relative;
  isolation: isolate;
  min-height: 168px;
  display: grid;
  align-content: space-between;
  gap: 0.55rem;
  overflow: hidden;
  border: 0;
  border-radius: var(--radius);
  padding: 1rem;
  background: var(--brand);
  box-shadow: 0 16px 34px rgba(12, 36, 68, 0.16);
  color: #fff;
  text-align: left;
  cursor: pointer;
}

.action-card::before {
  content: "";
  position: absolute;
  inset: auto -28px -44px auto;
  width: 132px;
  height: 132px;
  border: 18px solid rgba(255, 255, 255, 0.22);
  border-radius: 50%;
  z-index: -1;
}

.action-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.18), transparent 42%);
  z-index: -1;
}

.action-card--blue {
  background: linear-gradient(135deg, #006ccc, #042e8f);
}

.action-card--yellow {
  background: linear-gradient(135deg, #ffd100, #ff7a00);
  color: #241a00;
}

.action-card--purple {
  background: linear-gradient(135deg, #c43b3b, #e81616);
}

.action-card:active, .nav-item:active, .primary-button:active, .secondary-button:active, .icon-button:active {
  transform: translateY(1px);
}

.action-card__icon {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.2);
  color: currentColor;
  backdrop-filter: blur(12px);
}

.action-card__icon svg {
  width: 2rem;
  height: 2rem;
  stroke-width: 2.4;
}

.action-card__copy {
  display: grid;
  gap: 0.25rem;
}

.action-card__title {
  font-size: 1.28rem;
  font-weight: 900;
  line-height: 1;
}

.action-card__text {
  color: currentColor;
  opacity: 0.82;
  font-size: 0.92rem;
  font-weight: 750;
}

.privacy, .content-band, .setup-panel, .tournament-summary, .round, .table-section {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 8px 22px rgba(12, 36, 68, 0.07);
}

.privacy {
  padding: 1rem;
}

.privacy summary {
  cursor: pointer;
  font-weight: 900;
}

.privacy p, .copyright {
  color: var(--muted);
}

.copyright {
  margin: 0;
  text-align: center;
  font-size: 0.88rem;
}

.page-heading {
  padding: 0.4rem 0 0;
}

.page-heading--inline, .section-title--inline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.page-heading h1 {
  color: var(--ink);
}

.chipbar {
  position: sticky;
  top: calc(58px + env(safe-area-inset-top));
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  padding: 0.55rem 0;
  background: rgba(245, 247, 251, 0.9);
  backdrop-filter: blur(12px);
}

.chip-button {
  flex: 1 1 calc(33.333% - 0.45rem);
  min-width: 92px;
  min-height: 40px;
  border: 1px solid #d7e6f8;
  border-radius: 999px;
  background: #ecf5ff;
  color: var(--brand-dark);
  font-size: 0.86rem;
  font-weight: 850;
}

.chip-button[aria-current="true"] {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

.sport-list {
  display: grid;
  gap: 0.9rem;
}

.sport-card {
  display: grid;
  grid-template-columns: 1fr;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: 0 8px 22px rgba(12, 36, 68, 0.08);
  scroll-margin-top: 130px;
}

.sport-card__image {
  width: 100%;
  height: auto;
  min-height: 0;
  aspect-ratio: 16 / 9;
  object-fit: cover;
}

.sport-card__body {
  padding: 1rem;
}

.sport-card h2, .section-title h2, .tournament-summary h2, .table-section h2 {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.12;
}

.sport-card ul {
  margin: 0.8rem 0 0;
  padding-left: 1.15rem;
  color: #3c4654;
}

.sport-card li {
  margin: 0.42rem 0;
}

.tag {
  margin-bottom: 0.55rem;
  background: var(--yellow);
  color: #453900;
}

.content-band {
  padding: 1rem;
}

.section-title {
  display: grid;
  gap: 0.45rem;
  margin-bottom: 0.9rem;
}

.section-title p {
  margin: 0;
  color: var(--muted);
}

.mini-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.mini-chips span {
  background: #edf5ff;
  color: var(--brand-dark);
}

.rule-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.rule-item {
  min-height: 128px;
  padding: 0.85rem;
  border-radius: var(--radius);
  background: var(--wash);
}

.rule-item h3, .rule-item p {
  margin: 0;
}

.rule-item h3 {
  margin-bottom: 0.45rem;
  font-size: 1rem;
}

.rule-item p {
  color: #4f5a69;
}

.video-frame {
  position: relative;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius);
  background: #111;
}

.video-frame iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.supporters {
  width: 100%;
  height: auto;
  display: block;
  border-radius: var(--radius);
}

.setup-panel {
  display: grid;
  gap: 0.9rem;
  padding: 1rem;
}

.setup-note {
  margin: -0.2rem 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.field, .floating-label {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
}

input, select {
  width: 100%;
  min-height: 48px;
  border: 1px solid #d9e1eb;
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  padding: 0.7rem 0.8rem;
  font-size: 16px;
}

.switch {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 48px;
  color: var(--ink);
  font-weight: 850;
}

.switch input {
  width: 22px;
  min-height: 22px;
  accent-color: var(--brand);
}

.team-inputs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.7rem;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
}

.primary-button, .secondary-button, .icon-button {
  min-height: 46px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-weight: 900;
  cursor: pointer;
}

.primary-button {
  padding: 0.75rem 1rem;
  background: var(--brand);
  color: #fff;
}

.secondary-button {
  padding: 0.75rem 1rem;
  background: #edf5ff;
  color: var(--brand-dark);
  border-color: #d7e6f8;
}

.icon-button {
  width: 46px;
  padding: 0;
  background: var(--paper);
  border-color: var(--line);
  color: var(--brand);
  box-shadow: 0 8px 22px rgba(12, 36, 68, 0.07);
}

.icon-button.danger {
  color: var(--danger);
}

.tournament-live {
  display: grid;
  gap: 1rem;
  min-width: 0;
}

.tournament-summary {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem;
}

.summary-meta {
  margin: 0.4rem 0 0;
  color: var(--muted);
  font-weight: 750;
}

.progress-box {
  min-width: 132px;
  display: grid;
  align-content: start;
  gap: 0.45rem;
}

.progress-pill {
  align-self: start;
  background: #e9f7f2;
  color: #057253;
  white-space: nowrap;
}

.progress-track {
  overflow: hidden;
  height: 7px;
  border-radius: 999px;
  background: #dce8f1;
}

.progress-track span {
  display: block;
  height: 100%;
  min-width: 0;
  border-radius: inherit;
  background: var(--green);
  transition: width 0.2s ease;
}

.compact-title {
  margin: 0.2rem 0 -0.35rem;
}

.round-list {
  display: grid;
  gap: 0.8rem;
  min-width: 0;
}

.round {
  display: grid;
  gap: 0.55rem;
  padding: 1rem;
  min-width: 0;
}

.round h3 {
  margin: 0;
  font-size: 1.05rem;
}

.match-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 56px 12px 56px minmax(0, 1fr);
  align-items: center;
  gap: 0.35rem;
  min-height: 58px;
  padding: 0.55rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--wash);
  transition: background 0.16s ease, border-color 0.16s ease;
}

.match-row.is-complete {
  border-color: #ccebdd;
  background: #f0fbf6;
}

.team {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 0.94rem;
}

.team-b {
  text-align: right;
}

.score-input {
  min-height: 42px;
  padding: 0.35rem;
  text-align: center;
  font-weight: 900;
}

.score-divider {
  text-align: center;
  color: var(--muted);
  font-weight: 900;
}

.table-section {
  padding: 1rem;
  min-width: 0;
  overflow: hidden;
}

.table-scroll {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  width: 100%;
  max-width: 100%;
  min-width: 0;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
  table-layout: fixed;
  background: #fff;
}

th, td {
  padding: 0.62rem 0.45rem;
  border-bottom: 1px solid var(--line);
  text-align: right;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

th {
  background: var(--brand);
  color: #fff;
  font-size: 0.78rem;
}

th:nth-child(2), td:nth-child(2) {
  text-align: left;
  overflow-wrap: anywhere;
}

th:first-child, td:first-child {
  text-align: center;
  width: 42px;
}

.leader-row td {
  background: #fff9d8;
  font-weight: 900;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  padding: 0 0 env(safe-area-inset-bottom);
  background: var(--brand);
  box-shadow: 0 -12px 26px rgba(6, 79, 159, 0.22);
}

.bottom-nav__inner {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  width: min(1120px, 100%);
  margin: 0 auto;
}

.nav-item {
  min-height: 62px;
  display: grid;
  place-items: center;
  gap: 0.15rem;
  border: 0;
  background: transparent;
  color: rgba(255, 255, 255, 0.68);
  font-size: 0.72rem;
  font-weight: 850;
}

.nav-item[aria-current="page"] {
  color: #fff;
}

.nav-item__icon {
  display: grid;
  place-items: center;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(5.2rem + env(safe-area-inset-bottom));
  z-index: 50;
  max-width: calc(100vw - 2rem);
  transform: translateX(-50%) translateY(8px);
  opacity: 0;
  pointer-events: none;
  border-radius: var(--radius);
  background: #172033;
  color: #fff;
  padding: 0.7rem 0.9rem;
  box-shadow: var(--shadow);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

#toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

#export-preview {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(8, 15, 28, 0.82);
  backdrop-filter: blur(14px);
}

.export-preview__panel {
  position: relative;
  width: min(520px, 100%);
  max-height: min(92vh, 920px);
  display: grid;
  gap: 0.8rem;
  overflow: auto;
  border-radius: 16px;
  padding: 0.8rem;
  background: #101827;
  color: #fff;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.45);
}

.export-preview__panel img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 12px;
}

.export-preview__panel p {
  margin: 0;
  color: #d7deea;
  text-align: center;
  font-weight: 800;
}

.export-preview__panel a {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 46px;
  border-radius: var(--radius);
  background: var(--yellow);
  color: #241a00;
  font-weight: 950;
  text-decoration: none;
}

.export-preview__close {
  position: absolute;
  top: 0.55rem;
  right: 0.55rem;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: rgba(16, 24, 39, 0.8);
  color: #fff;
  font-size: 1.7rem;
  line-height: 1;
}

@media (max-width: 760px) {
  .app-main {
    padding-top: 0.8rem;
  }

  .home-actions, .team-inputs, .rule-grid {
    grid-template-columns: 1fr;
  }

  .sport-card__image {
    aspect-ratio: 16 / 9;
  }

  .home-hero, .area-hero {
    min-height: 360px;
  }

  .home-hero h1, .area-hero h1 {
    font-size: clamp(2rem, 11vw, 3.2rem);
  }

  .page-heading h1 {
    font-size: clamp(2rem, 13vw, 4rem);
  }

  .tournament-summary, .page-heading--inline, .section-title--inline {
    align-items: flex-start;
  }

  .tournament-summary {
    flex-direction: column;
  }

  .progress-box {
    width: 100%;
  }

  .match-row {
    grid-template-columns: minmax(0, 1fr) 50px 10px 50px minmax(0, 1fr);
    padding: 0.45rem;
  }
}

@media (max-width: 390px) {
  .chip-button {
    flex-basis: calc(50% - 0.45rem);
  }

  .action-card {
    min-height: 124px;
  }

  .match-row {
    grid-template-columns: minmax(0, 0.9fr) 46px 8px 46px minmax(0, 0.9fr);
    gap: 0.25rem;
  }
}
