@font-face {
  font-family: "Barlow Condensed";
  src: url("/fonts/barlow-condensed-700.woff2") format("woff2");
  font-style: normal;
  font-weight: 700;
  font-display: swap;
}

:root {
  color-scheme: light;
  --primary: oklch(0.544 0.169 31.3);
  --primary-strong: oklch(0.47 0.158 31.3);
  --primary-soft: oklch(0.94 0.035 31.3);
  --canvas: oklch(1 0 0);
  --surface: oklch(0.97 0.006 31.3);
  --surface-raised: oklch(0.99 0.002 31.3);
  --ink: oklch(0.19 0.015 31.3);
  --muted: oklch(0.43 0.02 31.3);
  --line: oklch(0.875 0.012 31.3);
  --success: oklch(0.48 0.11 146);
  --success-soft: oklch(0.94 0.025 146);
  --warning: oklch(0.62 0.14 75);
  --warning-soft: oklch(0.95 0.038 75);
  --danger: oklch(0.52 0.19 25);
  --white: oklch(1 0 0);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --z-sticky: 20;
  --z-dialog: 50;
  --z-toast: 70;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
    --primary: oklch(0.68 0.16 31.3);
    --primary-strong: oklch(0.74 0.145 31.3);
    --primary-soft: oklch(0.23 0.04 31.3);
    --canvas: oklch(0.12 0 0);
    --surface: oklch(0.17 0.008 31.3);
    --surface-raised: oklch(0.205 0.01 31.3);
    --ink: oklch(0.95 0.004 31.3);
    --muted: oklch(0.72 0.012 31.3);
    --line: oklch(0.31 0.012 31.3);
    --success: oklch(0.72 0.12 146);
    --success-soft: oklch(0.22 0.035 146);
    --warning: oklch(0.78 0.13 75);
    --warning-soft: oklch(0.24 0.04 75);
  --danger: oklch(0.72 0.17 25);
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100vh;
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.5;
  text-rendering: optimizeLegibility;
}

button,
input,
select {
  font: inherit;
}

button,
a,
input,
select {
  -webkit-tap-highlight-color: transparent;
}

button,
a {
  touch-action: manipulation;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid color-mix(in oklch, var(--primary) 48%, transparent);
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

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

h1,
h2,
h3 {
  line-height: 1.12;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

h1 {
  margin-bottom: var(--space-3);
  font-size: 2.25rem;
}

h2 {
  margin-bottom: var(--space-4);
  font-size: 1.45rem;
}

h3 {
  margin-bottom: var(--space-2);
  font-size: 1.05rem;
}

p {
  margin-bottom: var(--space-4);
}

.skip-link {
  position: fixed;
  top: var(--space-2);
  left: var(--space-2);
  z-index: 100;
  transform: translateY(-150%);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  background: var(--ink);
  color: var(--canvas);
}

.skip-link:focus {
  transform: translateY(0);
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
  padding: 10px max(var(--space-4), env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
  background: var(--canvas);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-weight: 800;
  text-decoration: none;
}

.brand-wordmark {
  display: block;
  width: 148px;
}

.brand-compact {
  display: none;
  width: 36px;
  height: 36px;
}

.brand-asset {
  display: block;
  width: 100%;
  height: auto;
}

.brand-asset-dark {
  display: none;
}

:root[data-theme="dark"] .brand-asset-light {
  display: none;
}

:root[data-theme="dark"] .brand-asset-dark {
  display: block;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.theme-switch {
  display: grid;
  grid-template-columns: repeat(3, auto);
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}

.theme-option {
  min-height: 30px;
  padding: 0 8px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.theme-option[aria-pressed="true"] {
  background: var(--ink);
  color: var(--canvas);
}

.connection {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.connection::before {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  content: "";
}

.connection.offline::before {
  background: var(--warning);
}

.page {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: var(--space-5) max(var(--space-4), env(safe-area-inset-left)) calc(92px + env(safe-area-inset-bottom));
}

.page-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.page-heading p {
  max-width: 62ch;
  margin-bottom: 0;
  color: var(--muted);
}

.context-label {
  margin: 0 0 6px;
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 800;
}

.button,
.icon-button,
.score-button,
.tab,
.queue-control,
.court-choice {
  border: 0;
  cursor: pointer;
  transition: background-color 160ms var(--ease-out), color 160ms var(--ease-out), transform 120ms var(--ease-out), border-color 160ms var(--ease-out);
}

.button:active,
.icon-button:active,
.score-button:active,
.queue-control:active,
.court-choice:active {
  transform: translateY(1px);
}

.button {
  display: inline-flex;
  min-height: 46px;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0 17px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-weight: 750;
}

.button:hover {
  background: color-mix(in oklch, var(--surface) 82%, var(--primary));
}

.button.primary {
  background: var(--primary);
  color: var(--white);
}

.button.primary:hover {
  background: var(--primary-strong);
}

.button.secondary {
  border-color: var(--line);
  background: transparent;
}

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

.button.small {
  min-height: 38px;
  padding: 0 12px;
  font-size: 0.9rem;
}

.button.wide {
  width: 100%;
}

.icon-button {
  display: inline-grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink);
  font-size: 1.35rem;
}

.icon-button:hover {
  background: var(--surface);
}

.status-badge {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-strong);
  font-size: 0.78rem;
  font-weight: 800;
}

.status-badge.completed {
  background: var(--success-soft);
  color: var(--success);
}

.list-section {
  margin-top: var(--space-7);
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.section-heading h2,
.section-heading p {
  margin-bottom: 0;
}

.tournament-list {
  overflow: hidden;
  border-top: 1px solid var(--line);
}

.tournament-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--space-4);
  align-items: center;
  min-height: 84px;
  padding: var(--space-4) 0;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  text-decoration: none;
}

.tournament-row:hover .row-title {
  color: var(--primary);
}

.row-title {
  margin: 0 0 4px;
  font-size: 1.05rem;
  font-weight: 800;
}

.row-meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.row-arrow {
  color: var(--primary);
  font-size: 1.4rem;
}

.setup-panel {
  margin: var(--space-7) 0;
  padding: var(--space-5);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.form-grid {
  display: grid;
  gap: var(--space-4);
}

.form-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field {
  display: grid;
  gap: 7px;
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 700;
}

.field input,
.field select,
.score-correction input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--canvas);
  color: var(--ink);
  padding: 0 12px;
}

.field input::placeholder {
  color: var(--muted);
  opacity: 1;
}

.field input:focus,
.field select:focus,
.score-correction input:focus {
  border-color: var(--primary);
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
  margin-top: var(--space-4);
}

.form-error {
  min-height: 1.4em;
  margin: var(--space-2) 0;
  color: var(--danger);
  font-size: 0.9rem;
}

.tournament-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

.tournament-header h1 {
  margin-bottom: 8px;
}

.tournament-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.tabs {
  display: flex;
  gap: var(--space-1);
  overflow-x: auto;
  margin: 0 calc(-1 * var(--space-4)) var(--space-5);
  padding: 0 var(--space-4) var(--space-2);
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  flex: 0 0 auto;
  min-height: 42px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font-weight: 750;
}

.tab.active {
  background: var(--ink);
  color: var(--canvas);
}

.courts {
  display: grid;
  gap: var(--space-4);
}

.court {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface-raised);
}

.court-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: 52px;
  padding: 0 var(--space-4);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.court-heading h2 {
  margin: 0;
  font-size: 1rem;
}

.match-state {
  color: var(--primary);
  font-size: 0.8rem;
  font-weight: 800;
}

.scoreboard {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.team-score {
  display: grid;
  align-content: start;
  min-width: 0;
  padding: var(--space-5) var(--space-4);
  text-align: center;
}

.team-score + .team-score {
  border-left: 1px solid var(--line);
}

.team-name {
  min-height: 2.4em;
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 1.05rem;
  font-weight: 850;
  line-height: 1.2;
}

.player-names {
  min-height: 2.6em;
  margin: 6px 0 var(--space-3);
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.3;
}

.score {
  font-family: "Barlow Condensed", "Arial Narrow", sans-serif;
  font-size: 5rem;
  font-weight: 700;
  line-height: 0.9;
  font-variant-numeric: tabular-nums;
}

.score-controls {
  display: grid;
  grid-template-columns: 1fr 48px;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

.score-button {
  min-height: 52px;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: var(--white);
  font-size: 1.25rem;
  font-weight: 850;
}

.score-button.undo {
  background: var(--surface);
  color: var(--ink);
  font-size: 1.1rem;
}

.timer-zone {
  display: grid;
  gap: var(--space-3);
  justify-items: center;
  padding: var(--space-5) var(--space-4);
  border-top: 1px solid var(--line);
  background: var(--ink);
  color: var(--canvas);
  text-align: center;
}

.timer-zone.expired {
  background: var(--primary);
  color: var(--white);
}

.timer {
  font-family: "Barlow Condensed", "Arial Narrow", sans-serif;
  font-size: 3.8rem;
  font-weight: 700;
  line-height: 0.9;
  letter-spacing: 0.01em;
  font-variant-numeric: tabular-nums;
}

.timer-caption {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 700;
}

.match-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-2);
}

.timer-zone .button.secondary {
  border-color: color-mix(in oklch, currentColor 35%, transparent);
  color: inherit;
}

.empty-court {
  display: grid;
  gap: var(--space-4);
  min-height: 300px;
  align-content: center;
  justify-items: center;
  padding: var(--space-6) var(--space-4);
  text-align: center;
}

.next-match {
  display: grid;
  gap: 8px;
  width: min(100%, 420px);
}

.next-match strong {
  font-size: 1.25rem;
}

.next-match span {
  color: var(--muted);
}

.queue-list,
.team-list,
.results-list {
  border-top: 1px solid var(--line);
}

.queue-row,
.team-row,
.result-row {
  display: grid;
  gap: var(--space-3);
  align-items: center;
  min-height: 72px;
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--line);
}

.queue-row {
  grid-template-columns: 42px minmax(0, 1fr) auto;
}

.queue-order {
  color: var(--muted);
  font-family: "Barlow Condensed", "Arial Narrow", sans-serif;
  font-size: 1.4rem;
  font-weight: 700;
}

.queue-title,
.team-row h3,
.result-row h3 {
  margin: 0;
}

.queue-meta,
.team-row p,
.result-row p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.queue-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.queue-control,
.court-choice {
  display: inline-grid;
  min-width: 38px;
  min-height: 38px;
  place-items: center;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-weight: 800;
}

.court-choice.active {
  background: var(--primary);
  color: var(--white);
}

.standings-wrap {
  overflow-x: auto;
  margin: 0 calc(-1 * var(--space-4));
  padding: 0 var(--space-4);
}

.standings {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.standings th,
.standings td {
  padding: 13px 10px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}

.standings th {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.standings th:nth-child(2),
.standings td:nth-child(2) {
  width: 100%;
  text-align: left;
}

.standings .rank {
  color: var(--muted);
  font-family: "Barlow Condensed", "Arial Narrow", sans-serif;
  font-size: 1.25rem;
  font-weight: 700;
}

.standings .total {
  color: var(--primary);
  font-weight: 900;
}

.tie-note {
  display: inline-block;
  margin-left: 6px;
  color: var(--warning);
  font-size: 0.72rem;
  font-weight: 850;
}

.bracket {
  display: grid;
  gap: var(--space-4);
  margin-top: var(--space-6);
}

.bracket-stage {
  padding: var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}

.bracket-stage h3 {
  color: var(--muted);
  font-size: 0.82rem;
}

.bracket-match {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px var(--space-3);
  padding: var(--space-2) 0;
}

.bracket-match + .bracket-match {
  border-top: 1px solid var(--line);
}

.bracket-score {
  font-weight: 900;
}

.team-row {
  grid-template-columns: minmax(0, 1fr) auto;
}

.score-correction {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
}

.score-correction input {
  width: 58px;
  min-height: 40px;
  padding: 0 8px;
  text-align: center;
}

.empty-state {
  padding: var(--space-7) var(--space-4);
  color: var(--muted);
  text-align: center;
}

.offline-banner {
  padding: 10px var(--space-4);
  background: var(--warning-soft);
  color: var(--ink);
  text-align: center;
  font-size: 0.9rem;
  font-weight: 750;
}

.bottom-nav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: var(--z-sticky);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2px;
  padding: 8px max(8px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  border-top: 1px solid var(--line);
  background: var(--canvas);
}

.bottom-nav .tab {
  min-height: 48px;
  padding: 0 6px;
  font-size: 0.82rem;
}

.auth-dialog {
  width: min(440px, calc(100% - 32px));
  padding: 0;
  border: 0;
  border-radius: var(--radius-lg);
  background: var(--canvas);
  color: var(--ink);
  box-shadow: 0 6px 8px color-mix(in oklch, var(--ink) 22%, transparent);
}

.auth-dialog::backdrop {
  background: color-mix(in oklch, var(--ink) 58%, transparent);
}

.auth-dialog form {
  padding: var(--space-5);
}

.dialog-heading {
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

.dialog-heading h2 {
  margin: 0;
}

.toast {
  position: fixed;
  right: var(--space-4);
  bottom: calc(80px + env(safe-area-inset-bottom));
  z-index: var(--z-toast);
  max-width: min(420px, calc(100% - 32px));
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: var(--ink);
  color: var(--canvas);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 180ms var(--ease-out), transform 180ms var(--ease-out);
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.loading {
  display: grid;
  min-height: 60vh;
  place-items: center;
  color: var(--muted);
  font-weight: 750;
}

@media (min-width: 760px) {
  .page {
    padding-top: var(--space-6);
    padding-bottom: var(--space-7);
  }

  .courts {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .courts.single {
    grid-template-columns: minmax(0, 720px);
    justify-content: center;
  }

  .score {
    font-size: 6rem;
  }

  .bracket {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .bottom-nav {
    position: static;
    width: min(1180px, 100%);
    margin: -8px auto var(--space-5);
    padding: 0 max(var(--space-4), env(safe-area-inset-left));
    border: 0;
    background: transparent;
  }

  .bottom-nav .tab {
    border: 1px solid var(--line);
  }

  .bottom-nav .tab.active {
    border-color: var(--ink);
  }

  .toast {
    bottom: var(--space-5);
  }
}

@media (max-width: 560px) {
  .brand-wordmark {
    display: none;
  }

  .brand-compact {
    display: block;
  }

  .theme-option {
    padding-inline: 6px;
    font-size: 0.68rem;
  }

  .connection span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .connection {
    width: 34px;
    justify-content: center;
    padding: 0;
  }

  .page-heading,
  .tournament-header {
    display: grid;
  }

  .form-grid.two {
    grid-template-columns: 1fr;
  }

  .queue-row {
    grid-template-columns: 34px minmax(0, 1fr);
  }

  .queue-actions {
    grid-column: 2;
    justify-content: flex-start;
  }

  .result-row {
    align-items: start;
  }

  .empty-court {
    min-height: 180px;
  }

  .score-correction {
    justify-content: flex-start;
  }
}

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