:root {
  --bg: #fafafa;
  --fg: #1a1a1a;
  --muted: #666;
  --border: #ddd;
  --accent: #2563eb;
  --accent-fg: #fff;
  --win: #16a34a;
  --loss: #dc2626;
  --draw: #ca8a04;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.5;
}

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 1.5rem;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  padding-bottom: 1rem;
  margin-bottom: 1.5rem;
}

h1 { margin: 0; font-size: 1.5rem; }
h2 { margin: 1.5rem 0 0.75rem; font-size: 1.15rem; }

button {
  font: inherit;
  padding: 0.4rem 0.9rem;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
}

button.primary {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}

button:hover { filter: brightness(0.97); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

input, textarea, select {
  font: inherit;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  width: 100%;
}

textarea { min-height: 8rem; font-family: ui-monospace, monospace; }

label {
  display: block;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
  color: var(--muted);
}

label span { display: block; margin-bottom: 0.25rem; }

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.5rem;
}

th, td {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
}

th { font-size: 0.85rem; color: var(--muted); font-weight: 500; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.match {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 0.5rem;
  background: #fff;
}

.match .player { font-weight: 500; }
.match .player.right { text-align: right; }
.match .result { display: flex; gap: 0.25rem; }
.match .result button {
  padding: 0.25rem 0.55rem;
  font-size: 0.85rem;
  min-width: 2rem;
}
.match .result button.selected[data-r="1"] { background: var(--win); color: #fff; border-color: var(--win); }
.match .result button.selected[data-r="0"] { background: var(--loss); color: #fff; border-color: var(--loss); }
.match .result button.selected[data-r="0.5"] { background: var(--draw); color: #fff; border-color: var(--draw); }

.bye {
  display: block;
  padding: 0.6rem;
  border: 1px dashed var(--border);
  border-radius: 8px;
  margin-bottom: 0.5rem;
  color: var(--muted);
  text-align: center;
  font-style: italic;
}

.row { display: flex; gap: 0.5rem; align-items: center; justify-content: space-between; margin-top: 1rem; }
.muted { color: var(--muted); font-size: 0.9rem; }

.round-nav {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.round-nav button.selected {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}

#header-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }

button.small {
  padding: 0.2rem 0.5rem;
  font-size: 0.8rem;
}

tr.dropped td { color: var(--muted); text-decoration: line-through; }
tr.dropped td:last-child { text-decoration: none; }

tr.winner td { background: #fef9c3; font-weight: 600; }
.winner-mark { color: #b45309; margin-right: 0.15rem; }

@media print {
  body { background: #fff; }
  .no-print { display: none !important; }
  header { border-bottom: 2px solid #000; }
  button { display: none; }
  .match { break-inside: avoid; }
  table { break-inside: auto; }
  tr { break-inside: avoid; }
}
