:root {
  color-scheme: light;
  --ink: #171717;
  --muted: #67635a;
  --line: #181818;
  --grid: #cfcfcf;
  --paper: #f7f7f4;
  --surface: #ffffff;
  --surface-soft: #fbfbf8;
  --surface-warm: #f1f6f3;
  --team-a: #6aa84f;
  --team-a-soft: #d9ead3;
  --team-b: #f6a21a;
  --team-b-soft: #fce5b6;
  --winner: #12d8de;
  --gold: #c99112;
  --accent: #176a5d;
  --danger: #b13b2f;
  --danger-soft: #fff1ee;
  font-family: Arial, Helvetica, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--paper);
  color: var(--ink);
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.app-shell {
  width: min(1180px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 24px 0 48px;
}

.app-shell.home-shell { width: min(640px, calc(100vw - 28px)); }

.topbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: 14px;
  margin-bottom: 24px;
}

.home-shell .topbar { grid-template-columns: 1fr; }

.home-button {
  min-width: 84px;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-weight: 850;
}

.home-button[hidden] { display: none; }

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 5px; font-size: clamp(1.8rem, 4vw, 2.65rem); line-height: 1; }
h2 { margin-bottom: 0; font-size: 1.1rem; }
h3 { margin-bottom: 0; font-size: 0.95rem; }
.subtitle { margin: 0; color: var(--muted); font-weight: 700; }

.icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.home-view,
.detail-view,
.player-summary,
.stats-screen { display: grid; gap: 22px; }

.home-toolbar {
  display: flex;
  justify-content: flex-end;
}

.tournament-index {
  width: 100%;
  display: grid;
  gap: 22px;
}

.index-head,
.index-row {
  display: grid;
  align-items: center;
  gap: 18px;
  background: var(--surface);
}

.index-head {
  grid-template-columns: minmax(0, 1fr) minmax(150px, 0.65fr) 92px;
  min-height: 38px;
  padding: 0 24px 8px;
  border-bottom: 2px solid var(--line);
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 900;
}

.index-head span,
.tournament-summary span,
.section-heading h2,
.primary-button,
.ghost-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.index-row {
  width: 100%;
  min-height: 74px;
  padding: 13px 22px;
  color: var(--ink);
  text-align: left;
  grid-template-columns: minmax(0, 1fr) minmax(150px, 0.65fr) 92px;
  border: 3px solid var(--line);
  transition: transform 140ms ease, background 140ms ease, box-shadow 140ms ease;
}

.index-row:hover { transform: translateY(-2px); background: var(--surface-warm); box-shadow: 0 8px 0 rgba(23, 23, 23, 0.08); }
.index-row:focus-visible { outline: 3px solid rgba(23, 106, 93, 0.25); outline-offset: 3px; }
.index-row span { display: grid; gap: 3px; min-width: 0; }
.index-row strong { font-size: clamp(1.25rem, 3vw, 1.75rem); overflow-wrap: anywhere; }
.index-row small { color: var(--muted); font-size: 0.78rem; font-weight: 800; text-transform: uppercase; }
.season-status { display: inline-flex !important; align-items: center; gap: 5px !important; width: fit-content; }
.season-status.completed { color: var(--gold); }
.season-status .icon { width: 15px; height: 15px; stroke-width: 2.4; }
.row-action {
  justify-self: end;
  display: inline-flex !important;
  align-items: center;
  gap: 6px !important;
  color: var(--accent);
  font-size: 0.84rem;
  font-weight: 900;
  text-transform: uppercase;
}
.index-row:hover .row-action .icon { transform: translateX(3px); }
.row-action .icon { transition: transform 140ms ease; }
.danger-action {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 2px solid var(--danger);
  background: var(--danger-soft);
  color: var(--danger);
  padding: 0 14px;
  font-weight: 900;
}
.danger-action:hover { background: #ffe4df; }

.primary-button,
.ghost-button {
  min-height: 44px;
  border: 3px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  padding: 0 16px;
  font-weight: 900;
}
.primary-button { min-width: 230px; font-size: 1.08rem; }
.compact-button { min-width: auto; font-size: 0.98rem; }
.ghost-button { border-width: 2px; }
.primary-button:hover,
.ghost-button:hover { background: #eef6f3; }

.create-panel,
.tournament-summary,
.table-wrap,
.summary-grid,
.stats-grid {
  background: var(--surface);
  border: 2px solid var(--line);
}

.create-panel { display: grid; gap: 16px; padding: 16px; }
.section-heading { display: grid; gap: 5px; }
.section-heading p { margin: 0; color: var(--muted); font-weight: 700; line-height: 1.4; }

.create-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.create-form .wide { grid-column: 1 / -1; }
label { display: grid; gap: 5px; min-width: 0; }
label span { color: var(--muted); font-size: 0.75rem; font-weight: 900; text-transform: uppercase; }
input, select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--grid);
  background: #fff;
  color: var(--ink);
  padding: 7px 9px;
  outline: none;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(23, 106, 93, 0.14); }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.exemption-panel {
  display: grid;
  gap: 9px;
  margin: 0;
  padding: 10px;
  border: 1px solid var(--grid);
  background: var(--surface-soft);
}
.exemption-panel legend {
  padding: 0 4px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 900;
  text-transform: uppercase;
}
.exemption-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 8px;
}
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 6px 8px;
  border: 1px solid var(--grid);
  background: #fff;
}
.checkbox-row input { width: auto; min-height: 0; }
.checkbox-row span { color: var(--ink); text-transform: none; font-size: 0.9rem; }
.muted-line { margin: 0; color: var(--muted); font-weight: 700; }

.tournament-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
}

.tournament-summary div {
  min-height: 94px;
  display: grid;
  align-content: center;
  gap: 7px;
  padding: 14px 18px;
  border-left: 1px solid var(--grid);
}

.tournament-summary div:first-child { border-left: 0; }
.tournament-summary span { color: var(--muted); font-size: 0.78rem; font-weight: 900; text-transform: uppercase; }
.tournament-summary strong { font-size: clamp(1rem, 2vw, 1.35rem); line-height: 1.2; }

.detail-actions { min-height: 48px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.sheet-section { display: grid; gap: 12px; }
.table-wrap { overflow-x: auto; }

.match-table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 0.92rem;
}

.match-table th,
.match-table td {
  height: 31px;
  border: 1px solid var(--line);
  padding: 4px 6px;
  text-align: left;
  vertical-align: middle;
  overflow-wrap: anywhere;
}

.match-table th { font-weight: 900; }
.match-table thead tr:first-child th { text-align: center; font-size: 1rem; }
.match-table .match-number { width: 92px; background: #d9e8ea; text-align: right; }
.match-table .team-side-1 { background: var(--team-a); }
.match-table .team-side-2 { background: var(--team-b); }
.match-table .team-side-1-soft { background: var(--team-a-soft); }
.match-table .team-side-2-soft { background: var(--team-b-soft); }
.match-table .winner-head { background: var(--winner); font-size: 1.05rem; }
.match-table select {
  width: 100%;
  min-height: 26px;
  border: 0;
  background: transparent;
  color: var(--ink);
  outline: 1px solid transparent;
  padding: 2px;
}
.match-table select:focus { outline-color: var(--accent); background: #fff; }
.match-table td.invalid-pick {
  background: var(--danger-soft);
  box-shadow: inset 0 0 0 2px var(--danger);
}
.match-table select.invalid-select {
  color: var(--danger);
  font-weight: 900;
}
.empty-row { height: 54px; text-align: center; color: var(--muted); font-weight: 850; }

.summary-grid,
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  background: var(--surface);
}

.summary-item,
.stat-item {
  min-height: 104px;
  display: grid;
  align-content: start;
  gap: 7px;
  padding: 12px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.summary-item.has-issue { background: #fff2ef; }
.summary-item p { margin: 0; color: var(--muted); line-height: 1.35; }
.summary-item small { color: var(--danger); font-weight: 800; }
.stat-item span { color: var(--muted); font-size: 0.76rem; font-weight: 900; text-transform: uppercase; }
.stat-item strong { font-size: 1.08rem; line-height: 1.25; overflow-wrap: anywhere; }


@media (max-width: 820px) {
  .app-shell,
  .app-shell.home-shell { width: min(100vw - 16px, 1180px); padding-top: 14px; }
  .topbar { grid-template-columns: 1fr; gap: 10px; }
  .tournament-summary { grid-template-columns: 1fr 1fr; }
  .tournament-summary div:nth-child(odd) { border-left: 0; }
  .tournament-index { gap: 12px; }
  .index-head { display: none; }
  .index-row {
    grid-template-columns: 1fr;
    grid-template-areas:
      "season"
      "winner"
      "open";
    gap: 12px;
    padding: 14px;
  }
  .index-row > span:first-child { grid-area: season; }
  .index-row > span:nth-child(2) { grid-area: winner; padding-top: 10px; border-top: 1px solid var(--grid); }
  .row-action { grid-area: open; justify-self: start; }
  .primary-button { width: 100%; justify-content: center; }
  .home-toolbar { justify-content: stretch; }
}

@media (max-width: 620px) {
  .create-form { grid-template-columns: 1fr; }
  .form-actions { display: grid; }
}

@media (max-width: 520px) {
  .tournament-summary { grid-template-columns: 1fr; }
  .tournament-summary div { border-left: 0; border-top: 1px solid var(--grid); }
  .tournament-summary div:first-child { border-top: 0; }
}
