:root {
  --bg: #f4f7f6; --card: #fff; --ink: #142a2b; --muted: #5d7273; --line: #dbe5e3;
  --brand: #0f3d3e; --accent: #c6f432; --accent-ink: #1a2a00; --ok: #1b8a4b; --danger: #c0392b;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0b1718; --card: #12292a; --ink: #e8f1f0; --muted: #8fa9aa; --line: #234042; --brand: #06100f; --ok: #4cd08a; --danger: #ff7b6b; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.top { position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top)); background: var(--brand); color: #fff; }
.brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 1.15rem; }
main { max-width: 760px; margin: 0 auto; padding: 16px; padding-bottom: calc(40px + env(safe-area-inset-bottom)); }
h1 { font-size: 1.5rem; margin: 4px 0 2px; }
h2 { font-size: 1.1rem; margin: 22px 0 8px; }
h3 { font-size: 1rem; margin: 0 0 8px; }
.muted { color: var(--muted); font-size: .9rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 10px 0; }
a.card { display: block; color: inherit; text-decoration: none; }
a.card:active { transform: scale(.99); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: .78rem; font-weight: 600; background: var(--line); color: var(--ink); }
.badge.live { background: var(--accent); color: var(--accent-ink); }

button, .btn { font: inherit; border: 0; border-radius: 10px; padding: 11px 16px; min-height: 44px; cursor: pointer;
  background: var(--brand); color: #fff; font-weight: 600; }
@media (prefers-color-scheme: dark) { button, .btn { background: #1d4d4f; } }
button.primary { background: var(--accent); color: var(--accent-ink); }
button.ghost { background: transparent; color: inherit; border: 1px solid currentColor; padding: 6px 12px; min-height: 36px; font-size: .9rem; }
.top button.ghost { color: #fff; }
button.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
button.small { padding: 6px 12px; min-height: 36px; font-size: .9rem; }
button:disabled { opacity: .5; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

input, select { font: inherit; width: 100%; min-height: 44px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink); }
label { display: block; font-size: .85rem; color: var(--muted); margin: 10px 0 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.tabs { display: flex; gap: 4px; overflow-x: auto; margin: 14px -16px 0; padding: 0 16px; border-bottom: 1px solid var(--line); scrollbar-width: none; }
.tabs button { background: none; color: var(--muted); border-radius: 0; border-bottom: 3px solid transparent; padding: 10px 14px; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--ink); border-color: var(--accent); }

table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: 8px 4px; text-align: center; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: .78rem; }
td.name, th.name { text-align: left; }
td.name { font-weight: 600; max-width: 38vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
tr.qual td:first-child { box-shadow: inset 4px 0 0 var(--accent); }

.match { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; width: 100%; text-align: left;
  background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin: 8px 0; font-weight: 400; }
.match.todo { border-left: 4px solid var(--accent); }
.match .t { display: flex; justify-content: space-between; gap: 8px; grid-column: 1; }
.match .t.win { font-weight: 700; }
.match .t.tbd { color: var(--muted); font-style: italic; }
.match .sc { font-variant-numeric: tabular-nums; letter-spacing: .05em; }
.match .meta { grid-column: 1 / -1; font-size: .8rem; color: var(--muted); }
.match.editable { cursor: pointer; }

.bracket { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 12px; margin: 0 -16px; padding-inline: 16px; scroll-snap-type: x mandatory; }
.bracket .col { min-width: 250px; scroll-snap-align: start; display: flex; flex-direction: column; justify-content: space-around; }
.bracket h3 { text-align: center; color: var(--muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; }

dialog { border: 0; border-radius: 18px; padding: 18px; width: min(94vw, 460px); background: var(--card); color: var(--ink); }
dialog::backdrop { background: rgba(0, 0, 0, .55); }
.sets { display: grid; grid-template-columns: auto 1fr 1fr; gap: 8px; align-items: center; }
.sets input { text-align: center; font-size: 1.2rem; }
.sets .lab { font-size: .8rem; color: var(--muted); }
.err { color: var(--danger); font-size: .9rem; min-height: 1.3em; }
#toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: var(--brand); color: #fff;
  padding: 10px 18px; border-radius: 99px; opacity: 0; pointer-events: none; transition: .25s; z-index: 20; max-width: 90vw; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.empty { text-align: center; color: var(--muted); padding: 28px 10px; }
@media (min-width: 640px) { main { padding: 24px; } .tabs { margin-inline: 0; padding-inline: 0; } .bracket { margin: 0; padding-inline: 0; } }
textarea { font: inherit; width: 100%; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink); resize: vertical; }
dialog { max-height: 92vh; overflow-y: auto; }
.tlink { color: inherit; text-decoration: none; }
a.tlink:hover { text-decoration: underline; }
.match .t.me span { background: var(--accent); color: var(--accent-ink); padding: 0 6px; border-radius: 6px; }
td.name .tlink { display: block; overflow: hidden; text-overflow: ellipsis; }
