:root {
  color-scheme: dark;
  --bg: #0f1117;
  --panel: #171a22;
  --box: #1e222c;
  --box-hover: #242938;
  --border: #2b3140;
  --line: #394052;
  --text: #e7e9ef;
  --muted: #8a93a6;
  --faint: #5b6375;
  --win: #3ecf8e;
  --win-bg: #1d3b2f;
  --accent: #7aa2ff;
  --gold: #f5c451;
  --live: #ff5c6c;
  --radius: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  min-height: 100vh;
}
button, input { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.2; }

.center { max-width: 560px; margin: 18vh auto 0; padding: 0 16px; text-align: center; }
.center h1 { font-size: 28px; margin-bottom: 10px; }
.center p { color: var(--muted); }

.wrap { max-width: 1600px; margin: 0 auto; padding: 24px 16px 64px; }

/* Header */
.top { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; justify-content: space-between; }
.title h1 { font-size: clamp(22px, 4vw, 32px); font-weight: 800; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip { background: var(--panel); border: 1px solid var(--border); border-radius: 999px; padding: 3px 10px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.status { display: inline-flex; align-items: center; gap: 7px; font-weight: 700; color: var(--text); }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status.live .dot { background: var(--live); box-shadow: 0 0 0 0 rgba(255, 92, 108, .6); animation: pulse 1.6s infinite; }
.status.finished .dot { background: var(--gold); }
.status.upcoming .dot { background: var(--accent); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(255, 92, 108, .55); } 70% { box-shadow: 0 0 0 8px rgba(255, 92, 108, 0); } 100% { box-shadow: 0 0 0 0 rgba(255, 92, 108, 0); } }

.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 7px 12px; cursor: pointer; text-decoration: none; color: var(--text); font-size: 14px; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { background: var(--box-hover); }
.btn:focus-visible, .match:focus-visible, .tab:focus-visible, .search input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Progress and info row */
.info { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-top: 18px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; min-width: 0; }
.stat .k { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.stat .v { font-size: 18px; font-weight: 700; margin-top: 2px; overflow-wrap: anywhere; }
.bar { height: 6px; background: var(--box); border-radius: 99px; margin-top: 8px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--win); border-radius: 99px; transition: width .4s ease; }

/* Champion */
.champion { margin-top: 18px; border: 1px solid rgba(245, 196, 81, .45); background: linear-gradient(135deg, rgba(245, 196, 81, .14), rgba(245, 196, 81, .03)); border-radius: 12px; padding: 16px 20px; display: flex; flex-wrap: wrap; align-items: center; gap: 16px 28px; }
.champion .crown { width: 40px; height: 40px; flex: none; }
.champion .who { font-size: clamp(20px, 3.4vw, 26px); font-weight: 800; color: var(--gold); overflow-wrap: anywhere; }
.champion .lbl { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.champion .podium { display: flex; flex-wrap: wrap; gap: 6px 24px; color: var(--muted); }
.champion .podium b { color: var(--text); font-weight: 600; }

/* Live strip */
.strip { margin-top: 18px; }
.strip h2 { font-size: 14px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 8px; }
.strip .row { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 4px; }
.strip .card { flex: none; background: var(--panel); border: 1px solid var(--border); border-left: 3px solid var(--live); border-radius: var(--radius); padding: 8px 12px; cursor: pointer; text-align: left; min-width: 200px; }
.strip .card.next { border-left-color: var(--accent); }
.strip .card .r { font-size: 12px; color: var(--muted); }
.strip .card .p { font-weight: 600; }

/* Toolbar */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 26px 0 12px; }
.search { position: relative; flex: 1 1 220px; max-width: 360px; }
.search input { width: 100%; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 32px 8px 12px; }
.search input::placeholder { color: var(--faint); }
.search .clear { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); background: none; border: 0; color: var(--muted); cursor: pointer; padding: 4px 8px; }
.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 2px; }
.seg button { background: none; border: 0; padding: 6px 12px; border-radius: 6px; cursor: pointer; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--box-hover); color: var(--text); }
.hint { color: var(--faint); font-size: 13px; }

/* Sections */
.section { margin-top: 22px; }
.section > h2 { font-size: 16px; font-weight: 700; margin-bottom: 10px; color: var(--muted); }

/* Bracket canvas */
.scroller { overflow: auto; border: 1px solid var(--border); border-radius: 12px; background: radial-gradient(1200px 500px at 50% 0%, #141824, var(--bg)); cursor: grab; overscroll-behavior: contain; }
.scroller.dragging { cursor: grabbing; user-select: none; }
.canvas { position: relative; margin: 0 auto; }
.canvas svg.lines { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
.canvas svg.lines path { fill: none; stroke: var(--line); stroke-width: 1.5; transition: stroke .2s, opacity .2s; }
.canvas svg.lines path.on { stroke: var(--accent); stroke-width: 2.25; }
.canvas svg.lines path.won { stroke: #4b5568; }
.roundlbl { position: absolute; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; white-space: nowrap; }
.roundlbl.right { text-align: right; }
.finallbl { position: absolute; font-size: 13px; font-weight: 800; color: var(--gold); letter-spacing: .12em; text-align: center; }

.match { position: absolute; background: var(--box); border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; padding: 0; text-align: left; transition: transform .15s, border-color .15s, opacity .2s, box-shadow .2s; }
.match:hover { border-color: #3e4659; transform: translateY(-1px); }
.match.live { border-color: var(--live); box-shadow: 0 0 0 1px rgba(255, 92, 108, .35), 0 0 18px rgba(255, 92, 108, .18); }
.match.final { border-color: rgba(245, 196, 81, .6); box-shadow: 0 0 22px rgba(245, 196, 81, .22); }
.match.dim { opacity: .28; }
.match.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 0 16px rgba(122, 162, 255, .25); opacity: 1; }
.match .side { display: flex; align-items: center; gap: 8px; height: 30px; padding: 0 10px; min-width: 0; }
.match .side + .side { border-top: 1px solid var(--border); }
.match .side.won { background: var(--win-bg); }
.match .side:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.match .side:last-child { border-radius: 0 0 var(--radius) var(--radius); }
.match .seed { color: var(--faint); font-size: 11px; width: 18px; flex: none; text-align: right; }
.match .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.match .nm.tbd { color: var(--faint); font-style: italic; }
.match .side.won .nm { color: var(--text); font-weight: 700; }
.match .side.lost .nm { color: var(--muted); }
.match .sc { font-weight: 700; font-size: 13px; color: var(--muted); flex: none; }
.match .side.won .sc { color: var(--win); }
.match .tag { position: absolute; top: -9px; right: 8px; font-size: 10px; font-weight: 800; letter-spacing: .08em; padding: 1px 6px; border-radius: 4px; background: var(--live); color: #fff; }
.match .side.me .nm { color: var(--accent); }

/* Rounds (list) view */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 10px; }
.tab { flex: none; background: var(--panel); border: 1px solid var(--border); border-radius: 999px; padding: 5px 12px; cursor: pointer; color: var(--muted); font-size: 13px; }
.tab[aria-selected="true"] { color: var(--text); border-color: var(--accent); }
.list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.list .match { position: relative; width: auto; }

/* Tables */
.tables { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.table { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.table h3 { font-size: 14px; padding: 10px 14px; border-bottom: 1px solid var(--border); color: var(--muted); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 8px 12px; text-align: right; white-space: nowrap; }
th { color: var(--faint); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
th:nth-child(2), td:nth-child(2) { text-align: left; width: 100%; white-space: normal; overflow-wrap: anywhere; }
th:first-child, td:first-child { text-align: center; width: 36px; color: var(--faint); }
tbody tr { border-top: 1px solid var(--border); cursor: pointer; }
tbody tr:hover { background: var(--box); }
tbody tr.removed td { color: var(--faint); text-decoration: line-through; }
tbody tr.on td:nth-child(2) { color: var(--accent); font-weight: 700; }
tbody tr.top1 td:first-child { color: var(--gold); font-weight: 800; }

/* Match detail */
.sheet { position: fixed; inset: 0; background: rgba(5, 6, 10, .6); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.sheet[hidden] { display: none; }
.sheet .panel { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; width: min(440px, 100%); padding: 18px; box-shadow: 0 20px 60px rgba(0, 0, 0, .5); }
.sheet .head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.sheet .head h3 { font-size: 17px; }
.sheet .x { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 22px; line-height: 1; padding: 2px 6px; }
.sheet .vs { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: center; margin: 18px 0 12px; text-align: center; }
.sheet .vs .n { font-weight: 700; font-size: 16px; overflow-wrap: anywhere; }
.sheet .vs .n.won { color: var(--win); }
.sheet .vs .n.tbd { color: var(--faint); font-weight: 400; font-style: italic; }
.sheet .vs .s { font-size: 26px; font-weight: 800; letter-spacing: .04em; }
.sheet dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: 14px; }
.sheet dt { color: var(--muted); }
.sheet dd { margin: 0; text-align: right; overflow-wrap: anywhere; }

.foot { margin-top: 36px; color: var(--faint); font-size: 13px; display: flex; flex-wrap: wrap; gap: 8px 18px; justify-content: space-between; }
.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); background: var(--box-hover); border: 1px solid var(--border); padding: 8px 14px; border-radius: 8px; font-size: 14px; z-index: 20; }
.toast[hidden] { display: none; }
.empty { color: var(--muted); background: var(--panel); border: 1px dashed var(--border); border-radius: 12px; padding: 28px; text-align: center; }

@media (max-width: 640px) {
  .wrap { padding-top: 16px; }
  .actions .btn span.long { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
