:root {
  --bg: #f4f5f7;
  --card: #fff;
  --line: #dde1e7;
  --wire: #b9c0cb;
  --text: #1d2433;
  --muted: #8a93a3;
  --green: #2f8a45;
  --blue: #2f5fd0;
  --orange: #ef7a35;
  --orange-2: #f29a4f;
  --me: #fff4d6;
  --banner: #fdf1c7;
  --danger: #c53b32;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'Barlow', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; cursor: pointer; }
[hidden] { display: none !important; }

.banner {
  background: var(--banner);
  text-align: center;
  font-weight: 700;
  font-size: 1.15rem;
  padding: 10px 16px;
  color: #6b5210;
}

.top {
  position: sticky; top: 0; z-index: 20;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 0 16px;
  height: 56px;
}
.brand { font-weight: 700; font-size: 1.15rem; white-space: nowrap; }
.tabs { display: flex; gap: 4px; height: 100%; }
.tabs a {
  display: flex; align-items: center; gap: 6px;
  padding: 0 14px;
  text-decoration: none; color: #5b6475; font-weight: 500;
  border-bottom: 2px solid transparent;
}
.tabs a.active { color: var(--blue); border-bottom-color: var(--blue); }
.status { justify-self: end; display: flex; align-items: center; gap: 10px; font-size: .85rem; color: var(--muted); }
.live i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--green); margin-right: 4px; }
.live.off i { background: #c9ced6; }
.admin-pill { background: var(--text); color: #fff; border-radius: 99px; padding: 2px 8px; font-weight: 600; font-size: .75rem; }

main { padding: 16px 16px 100px; }

.section-head { display: flex; justify-content: space-between; align-items: center; margin: 8px 0 10px; }
.section-head h2 { font-size: .8rem; letter-spacing: .08em; text-transform: uppercase; color: #5b6475; margin: 0; }
.ghost {
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 10px; font-size: .85rem; color: #3b4456;
}

.bracket-scroll { overflow-x: auto; margin-bottom: 28px; -webkit-overflow-scrolling: touch; }
.bracket { position: relative; transform-origin: 0 0; }
.bracket svg { position: absolute; inset: 0; overflow: visible; pointer-events: none; }
.bracket svg path { fill: none; stroke: var(--wire); stroke-width: 1.5; }
.col-head {
  position: absolute; top: 0;
  text-align: center; font-size: .72rem; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: #5b6475;
}

.match {
  position: absolute;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
  box-shadow: 0 1px 0 rgba(20, 30, 50, .03);
}
.match.ready { border-color: var(--orange-2); box-shadow: 0 0 0 2px rgba(239, 122, 53, .15); cursor: pointer; }
.match.done { cursor: pointer; }
.match.skipped { opacity: .45; }
.match .mid {
  position: absolute; top: -7px; right: 6px;
  font-size: 9px; color: var(--muted); background: var(--bg); padding: 0 3px; border-radius: 3px;
  border: 1px solid var(--line); line-height: 12px;
}
.row { display: grid; grid-template-columns: 24px 1fr 22px; align-items: center; height: 27px; padding: 0 6px 0 0; }
.row + .row { border-top: 1px solid #eef0f3; }
.row .seed { font-size: 10px; color: var(--muted); text-align: center; }
.row .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.row .score { text-align: right; font-weight: 700; }
.row.win .name, .row.win .score { color: var(--green); font-weight: 700; }
.row.lose .name { color: #4b5363; }
.row.lose .score { color: #4b5363; }
.row.tbd .name { color: #b2b8c3; font-style: italic; font-weight: 400; }
.row.me { background: var(--me); }
.row:first-child { border-radius: 6px 6px 0 0; }
.row:last-child { border-radius: 0 0 6px 6px; }

.legend { font-size: .85rem; color: var(--muted); }
.key { display: inline-block; width: 14px; height: 10px; border-radius: 3px; vertical-align: -1px; margin-right: 4px; }
.key.ready { border: 1.5px solid var(--orange-2); background: #fff; }

/* Record */
.record { max-width: 640px; margin: 0 auto; }
.label { font-size: .75rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: #5b6475; margin: 6px 0 8px; }
.search {
  width: 100%; padding: 12px 14px; font: inherit; font-size: 1rem;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card); margin-bottom: 12px;
}
.names { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.names button, .choice {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 8px; font-weight: 600; color: var(--text);
}
.names button:hover, .choice:hover { border-color: #b9c0cb; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 14px; }
.card h3 { margin: 0 0 4px; font-size: 1.25rem; }
.sub { color: var(--muted); font-size: .9rem; }
.me-line { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
.linkish { background: none; border: none; color: var(--blue); padding: 0; font-weight: 500; }
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin-top: 12px; }
.choice.sel { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(47, 95, 208, .15); color: var(--blue); }
.primary {
  width: 100%; margin-top: 14px; padding: 13px; border: none; border-radius: 10px;
  background: var(--blue); color: #fff; font-weight: 700; font-size: 1rem;
}
.primary:disabled { background: #b9c4dd; cursor: default; }
.danger { background: var(--danger); }
.error { color: var(--danger); margin-top: 10px; font-weight: 500; }
.ready-list { display: grid; gap: 8px; }
.ready-list button { text-align: left; display: flex; justify-content: space-between; gap: 8px; }
.history { list-style: none; padding: 0; margin: 8px 0 0; }
.history li { padding: 6px 0; border-top: 1px solid #eef0f3; font-size: .95rem; }

/* Feed */
.feed { list-style: none; margin: 0 auto; padding: 0; max-width: 900px; }
.feed li {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 11px 4px; border-bottom: 1px solid var(--line); font-size: .95rem;
}
.feed b { color: var(--green); }
.feed .meta { color: var(--muted); }
.feed time { color: var(--muted); white-space: nowrap; font-size: .85rem; }
.empty { color: var(--muted); text-align: center; padding: 40px 0; }

/* Rules */
.rules { max-width: 640px; margin: 0 auto; }
.rules .card { display: flex; gap: 14px; align-items: flex-start; }
.rules .card h3 { font-size: 1.1rem; margin: 2px 0 2px; }
.rules .card p { margin: 0; color: #4b5363; line-height: 1.45; }
.rule-icon { font-size: 1.5rem; line-height: 1; }
.rules a { color: var(--blue); }

/* Floating button */
.fab {
  position: fixed; right: 18px; bottom: 18px; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  background: linear-gradient(135deg, var(--orange), var(--orange-2));
  color: #fff; text-decoration: none; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  padding: 13px 20px; border-radius: 99px; box-shadow: 0 6px 18px rgba(239, 122, 53, .35);
}
.fab .ball { width: 14px; height: 14px; border-radius: 50%; background: #fff; }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(20, 26, 38, .45); display: grid; place-items: center; padding: 16px; }
.modal-card { position: relative; background: var(--card); border-radius: 14px; padding: 20px; width: min(440px, 100%); max-height: 90vh; overflow: auto; }
.modal-x { position: absolute; top: 8px; right: 10px; border: none; background: none; font-size: 1.6rem; color: var(--muted); }

@media (max-width: 640px) {
  .top { grid-template-columns: 1fr auto; height: auto; padding: 8px 12px 0; row-gap: 4px; }
  .brand { font-size: 1rem; }
  .tabs { grid-column: 1 / -1; grid-row: 2; justify-content: space-around; height: 42px; }
  .tabs a { padding: 0 6px; gap: 4px; font-size: .95rem; }
  main { padding: 12px 12px 100px; }
  .fab { right: 12px; bottom: 12px; padding: 12px 16px; font-size: .85rem; }
}

@media (max-width: 420px) {
  .tabs a span { display: none; }
}
