:root {
  color-scheme: light dark;
  --bg: #f2f5ee;
  --surface: #ffffff;
  --text: #18211b;
  --muted: #5d6b61;
  --line: #dde3d9;
  --hero: #14532d;
  --brand: #17633a;
  --brand-ink: #ffffff;
  --brand-soft: #e2f1e6;
  --accent: #d4ec3c;
  --warn: #8a5200;
  --warn-soft: #fdf1d8;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 4px 14px rgb(0 0 0 / 0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1411;
    --surface: #17201a;
    --text: #e9efe9;
    --muted: #9aa89e;
    --line: #2b382f;
    --hero: #0f3d22;
    --brand: #5fd08a;
    --brand-ink: #062513;
    --brand-soft: #1c3325;
    --warn: #f0b95a;
    --warn-soft: #3a2c10;
    --danger: #ff8a80;
    --danger-soft: #3b1614;
    --shadow: none;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

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

h2 {
  font-size: 1.05rem;
}

h3 {
  font-size: 0.9rem;
  margin-top: 0.75rem;
}

a {
  color: var(--brand);
}

small {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 400;
}

[hidden] {
  display: none !important;
}

.wrap {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 16px;
}

.wrap.narrow {
  max-width: 420px;
  padding-top: 12vh;
}

.loading {
  text-align: center;
  color: var(--muted);
  padding: 20vh 16px;
}

.muted {
  color: var(--muted);
  font-size: 0.88rem;
}

/* ---------- Header and navigation ---------- */

.hero {
  background: var(--hero);
  color: #fff;
  padding: 22px 0 18px;
  border-bottom: 4px solid var(--accent);
}

.hero h1 {
  font-size: 1.35rem;
  line-height: 1.2;
  text-wrap: balance;
}

.hero p {
  margin-top: 4px;
  opacity: 0.85;
  font-size: 0.9rem;
}

.hero-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.pills,
.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  margin: 14px -16px 0;
  padding: 0 16px;
}

.pill {
  flex: none;
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
}

.pill.active {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--brand-ink);
}

.when {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.85rem;
}

.tabs {
  gap: 4px;
  border-bottom: 1px solid var(--line);
}

.tab {
  flex: none;
  padding: 10px 12px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
}

.tab.active {
  color: var(--text);
  border-bottom-color: var(--brand);
}

main {
  display: grid;
  gap: 14px;
  padding: 16px 0 8px;
}

.foot {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 0 32px;
  color: var(--muted);
  font-size: 0.8rem;
}

.foot a {
  color: var(--muted);
}

/* ---------- Cards and tables ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  display: grid;
  gap: 10px;
  min-width: 0;
}

.card > .btn {
  justify-self: start;
}

.card.alert {
  background: var(--warn-soft);
  border-color: transparent;
}

.card.ok {
  background: var(--brand-soft);
  border-color: transparent;
}

.card ul,
.card ol {
  padding-left: 1.2rem;
  display: grid;
  gap: 6px;
}

.card ul.plain {
  list-style: none;
  padding: 0;
  gap: 4px;
}

.plain small {
  display: inline;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.table th,
.table td {
  padding: 8px 5px;
  text-align: center;
  border-top: 1px solid var(--line);
  vertical-align: top;
}

.table th {
  border-top: 0;
  padding-top: 0;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.table th,
.table td {
  white-space: nowrap;
}

.table .l {
  text-align: left;
  width: 100%;
  white-space: normal;
}

.table td:first-child {
  color: var(--muted);
}

.tname {
  font-weight: 600;
}

.pos {
  color: var(--brand);
  font-weight: 600;
}

.neg {
  color: var(--danger);
}

tr.mine td {
  background: var(--brand-soft);
}

.note {
  font-style: italic;
}

.badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--brand);
  color: var(--brand-ink);
  font-size: 0.68rem;
  font-weight: 700;
  vertical-align: 1px;
}

.badge.soft {
  background: transparent;
  color: var(--brand);
  box-shadow: inset 0 0 0 1px var(--brand);
}

.badge.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.legend {
  color: var(--muted);
  font-size: 0.8rem;
}

.seeds b {
  font-weight: 600;
}

.champion {
  text-align: center;
  background: var(--hero);
  color: #fff;
  border: 0;
  border-bottom: 4px solid var(--accent);
  gap: 2px;
  padding: 18px 16px;
}

.champion span {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
}

.champion strong {
  font-size: 1.4rem;
}

.champion small {
  color: #fff;
  opacity: 0.8;
}

/* ---------- Matches ---------- */

.day {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-top: 4px;
}

.match-list {
  display: grid;
  gap: 10px;
}

.match {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 14px;
  min-width: 0;
}

.mc-head {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 2px 12px;
  color: var(--muted);
  font-size: 0.78rem;
  margin-bottom: 4px;
}

.mc-id {
  color: var(--text);
  margin-right: 4px;
}

.mc-team {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
}

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

.mc-team.win .name {
  font-weight: 700;
}

.mc-team.mine .name {
  color: var(--brand);
}

.name i {
  color: var(--muted);
}

.side {
  display: inline-block;
  width: 22px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
}

.seed {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  margin-right: 4px;
}

.games {
  display: flex;
  gap: 4px;
  font-variant-numeric: tabular-nums;
}

.games span {
  min-width: 28px;
  padding: 2px 0;
  border-radius: 7px;
  background: var(--bg);
  color: var(--muted);
  text-align: center;
}

.games .gw {
  background: var(--brand-soft);
  color: var(--text);
  font-weight: 700;
}

.mc-foot {
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.bracket {
  display: grid;
  gap: 14px;
}

.round {
  display: grid;
  gap: 8px;
  align-content: center;
  min-width: 0;
}

@media (min-width: 720px) {
  .bracket {
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
  }
}

/* ---------- Forms and buttons ---------- */

input,
select,
textarea,
button {
  font: inherit;
  color: inherit;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.btn:focus-visible,
.icon:focus-visible,
a:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.field {
  display: grid;
  gap: 4px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.field input,
.field select,
.field textarea {
  color: var(--text);
  font-weight: 400;
}

.field.inline {
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
}

fieldset {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px 12px;
  margin: 0;
  display: grid;
  gap: 8px;
  justify-items: start;
  min-width: 0;
}

legend {
  padding: 0 6px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.grid2,
.grid3 {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

@media (min-width: 560px) {
  .grid3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.row,
.actions,
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.row > input,
.toolbar > input {
  flex: 1 1 150px;
}

.toolbar > select {
  flex: 0 1 190px;
}

.toolbar .field {
  flex: 1;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  font-size: 0.92rem;
  text-decoration: none;
  cursor: pointer;
}

.btn.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--brand-ink);
}

.btn.danger {
  color: var(--danger);
  border-color: currentColor;
  background: transparent;
}

.btn.ghost {
  background: transparent;
  border-color: rgb(255 255 255 / 0.4);
  color: #fff;
}

.btn.small {
  min-height: 34px;
  padding: 5px 12px;
  font-size: 0.85rem;
}

.btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.icon {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
}

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

progress {
  width: 100%;
  height: 8px;
  accent-color: var(--brand);
}

details summary {
  cursor: pointer;
  color: var(--brand);
  font-weight: 600;
  font-size: 0.88rem;
}

details form,
details .row {
  margin-top: 8px;
}

details form {
  display: grid;
  gap: 8px;
  justify-items: start;
}

.empty {
  text-align: center;
  padding: 20px 0;
}

.note-warn {
  color: var(--warn);
  font-size: 0.88rem;
}

/* ---------- Admin: score entry ---------- */

.editor {
  border-color: var(--brand);
  display: grid;
  gap: 10px;
}

.editor .mc-head {
  margin: 0;
}

.score-grid {
  display: grid;
  align-items: center;
  gap: 8px;
}

.score-grid.cols-1 {
  grid-template-columns: minmax(0, 1fr) 54px;
}

.score-grid.cols-3 {
  grid-template-columns: minmax(0, 1fr) repeat(3, 54px);
}

.score-grid.cols-5 {
  grid-template-columns: minmax(0, 1fr) repeat(5, 44px);
}

.score-grid input {
  padding: 10px 4px;
  text-align: center;
  font-size: 1.15rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.gh {
  text-align: center;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}

.who {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.who .side {
  margin-right: 6px;
}

.preview {
  font-size: 0.9rem;
  color: var(--muted);
  min-height: 1.4em;
}

.preview.bad {
  color: var(--danger);
}

.slot select,
.slot input {
  flex: 1 1 110px;
  width: auto;
}

/* ---------- Admin: setup ---------- */

.day-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
  width: 100%;
}

.day-row [name='date'] {
  grid-column: 1 / -1;
}

@media (min-width: 560px) {
  .day-row {
    grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) auto minmax(0, 1fr);
  }

  .day-row [name='date'] {
    grid-column: auto;
  }
}

[data-days] {
  width: 100%;
}

.card .team-list {
  list-style: none;
  padding: 0;
  gap: 10px;
}

.team-list li {
  display: grid;
  grid-template-columns: 1.4rem minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
}

.team-list .num {
  color: var(--muted);
  font-size: 0.85rem;
  text-align: right;
}

.team-list [name='name'] {
  grid-column: 2 / -1;
}

.team-list [name='players'] {
  grid-column: 2;
}

.team-tools {
  display: flex;
  gap: 4px;
}

@media (min-width: 560px) {
  .team-list li {
    grid-template-columns: 1.4rem minmax(0, 1fr) minmax(0, 1fr) auto;
  }

  .team-list [name='name'],
  .team-list [name='players'] {
    grid-column: auto;
  }
}

.pool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 4px 16px;
}

.pool-grid h3 {
  margin: 0 0 4px;
}

.qr {
  width: 220px;
  max-width: 100%;
  background: #fff;
  border-radius: 10px;
  padding: 6px;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  max-width: min(92vw, 480px);
  padding: 12px 16px;
  border-radius: 12px;
  background: #1c2620;
  color: #fff;
  font-size: 0.92rem;
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.3);
  z-index: 10;
}

/* ---------- Printables ---------- */

.print-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.sheet {
  display: grid;
  grid-template-columns: repeat(2, 3.75in);
  justify-content: center;
  padding: 16px 0;
  color: #000;
}

.pcard {
  height: 3.3in;
  padding: 0.16in 0.18in;
  border: 1px dashed #999;
  background: #fff;
  color: #000;
  font-size: 9.5pt;
  overflow: hidden;
  break-inside: avoid;
  display: flex;
  flex-direction: column;
  gap: 0.04in;
}

.pcard header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  border-bottom: 2px solid #000;
  padding-bottom: 2px;
}

.pcard header strong {
  font-size: 15pt;
}

.pcard header span {
  font-size: 8pt;
  text-align: right;
}

.pc-meta {
  font-size: 9pt;
}

.pcard table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.03in;
}

.pcard thead th {
  font-size: 7.5pt;
  font-weight: 600;
  padding-bottom: 1px;
}

.pcard tbody th {
  text-align: left;
  font-size: 10pt;
  padding: 2px 6px 2px 0;
  line-height: 1.15;
}

.pcard tbody th small {
  font-size: 6.5pt;
  letter-spacing: 0.08em;
  color: #444;
}

.pcard tbody th em {
  display: block;
  font-size: 7.5pt;
  font-style: normal;
  font-weight: 400;
}

.pcard .blank {
  display: block;
  height: 0.2in;
  border-bottom: 1px solid #000;
}

.pcard td {
  width: 0.55in;
  height: 0.42in;
  border: 1.5px solid #000;
}

.pc-line {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  font-size: 8pt;
  margin-top: 0.07in;
  white-space: nowrap;
}

.pc-line span {
  flex: 1;
  border-bottom: 1px solid #000;
}

.pc-rules {
  margin-top: auto;
  font-size: 6.5pt;
  line-height: 1.2;
  color: #333;
}

.poster {
  max-width: 7in;
  margin: 0 auto;
  padding: 0.5in 0.25in;
  text-align: center;
  display: grid;
  gap: 0.2in;
  justify-items: center;
}

.poster h1 {
  font-size: 30pt;
  line-height: 1.1;
  text-wrap: balance;
}

.poster h2 {
  font-size: 18pt;
  text-wrap: balance;
}

.poster img {
  width: 4.5in;
  max-width: 80vw;
  background: #fff;
  padding: 8px;
}

.poster-where,
.poster-url {
  font-size: 14pt;
}

.poster-url {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  overflow-wrap: anywhere;
}

@page {
  size: letter;
  margin: 0.4in;
}

@media print {
  :root {
    color-scheme: light;
    --bg: #fff;
    --surface: #fff;
    --text: #000;
    --muted: #333;
    --line: #999;
  }

  .no-print,
  #toast {
    display: none !important;
  }

  .sheet {
    padding: 0;
  }
}
