:root {
  --bg: #0b1220;
  --surface: #131d2e;
  --surface-2: #1a2639;
  --line: #26344b;
  --text: #e8edf5;
  --muted: #8d9bb3;
  --accent: #f99e1a;
  --accent-text: #1a1206;
  --blue: #4aa3ff;
  --success: #3ccf8e;
  --danger: #ff5c6c;
  --radius: 10px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; display: flex; flex-direction: column; line-height: 1.45; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.7rem; margin: 0 0 0.75rem; letter-spacing: 0.01em; }
h2 { font-size: 1.15rem; margin: 0 0 0.75rem; }
h3 { font-size: 0.78rem; margin: 0 0 0.6rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.nav {
  display: flex; align-items: center; gap: 1.5rem; padding: 0.75rem 1.5rem;
  background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10;
}
.brand { color: var(--text); font-weight: 700; font-size: 1.1rem; display: flex; align-items: center; gap: 0.15rem; }
.brand:hover { text-decoration: none; }
.brand-mark { background: var(--accent); color: var(--accent-text); border-radius: 6px; padding: 0.05rem 0.4rem; font-style: italic; }
.nav-links { display: flex; gap: 1rem; flex: 1; }
.nav-links a, .nav-user a { color: var(--muted); }
.nav-links a[aria-current="page"] { color: var(--text); }
.nav-user { display: flex; align-items: center; gap: 1rem; }
.nav-user .user-name { color: var(--text); font-weight: 600; }

.page { flex: 1; width: 100%; max-width: 1400px; margin: 0 auto; padding: 1.5rem; }
.footer { text-align: center; color: var(--muted); font-size: 0.8rem; padding: 1.5rem; }

.button, button.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  background: var(--accent); color: var(--accent-text); border: 0; border-radius: 8px;
  padding: 0.55rem 1rem; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
.button:hover { filter: brightness(1.08); text-decoration: none; }
.button:disabled { opacity: 0.5; cursor: default; }
.button.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); }
.button.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.button.small { padding: 0.3rem 0.65rem; font-size: 0.85rem; }
.nav .button.small { color: var(--accent-text); }
.link-button { background: none; border: 0; color: var(--muted); font: inherit; cursor: pointer; padding: 0; }
.link-button:hover { color: var(--text); }
.link-button.small { font-size: 0.8rem; }

.muted { color: var(--muted); }
.small { font-size: 0.8rem; }
.strong { font-weight: 700; }
.error { color: var(--danger); }
.success { color: var(--success); }
.hint { display: block; color: var(--muted); font-size: 0.8rem; margin-top: 0.2rem; }
.empty { color: var(--muted); padding: 3rem 1rem; text-align: center; }
.banner { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.7rem 1rem; }
.row { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1.25rem; }
.panel.narrow { max-width: 520px; }
.auth-card { max-width: 420px; margin: 2rem auto; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 2rem; }

.form { display: flex; flex-direction: column; gap: 0.9rem; margin-bottom: 1rem; }
.form.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 0.9rem 1.25rem; }
.form.inline { flex-direction: row; flex-wrap: wrap; align-items: center; margin-top: 1rem; }
.form .wide { grid-column: 1 / -1; }
.form label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.88rem; font-weight: 600; }
.form label.check { flex-direction: row; align-items: center; gap: 0.5rem; font-weight: 500; align-self: end; padding-bottom: 0.5rem; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 7px; padding: 0.5rem 0.6rem; font-weight: 400;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; }
input[type="checkbox"] { width: 1.05rem; height: 1.05rem; accent-color: var(--accent); }
input.short { width: 6rem; }
.match-form { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }

.button.google { background: #fff; color: #1f1f1f; width: 100%; }
.google-g { font-weight: 800; color: #4285f4; }
.divider { display: flex; align-items: center; gap: 0.75rem; color: var(--muted); margin: 1rem 0; font-size: 0.85rem; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--line); }

.tag { display: inline-block; border-radius: 999px; padding: 0.1rem 0.55rem; font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; }
.tag-open { background: rgba(60, 207, 142, 0.15); color: var(--success); }
.tag-draft { background: rgba(141, 155, 179, 0.15); color: var(--muted); }
.tag-archived { background: rgba(74, 163, 255, 0.15); color: var(--blue); }
.tag-final { background: var(--surface-2); color: var(--muted); }
.tag-live { background: rgba(255, 92, 108, 0.15); color: var(--danger); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem; color: var(--text); }
.tournament-card { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.tournament-card:hover { border-color: var(--accent); text-decoration: none; }
.card-title { font-weight: 600; }

/* ----- Tournament header ----- */
.hero {
  display: grid; grid-template-columns: 1fr auto; gap: 1rem 2rem; align-items: center;
  background: linear-gradient(135deg, var(--surface) 0%, var(--surface-2) 100%);
  border: 1px solid var(--line); border-top: 3px solid var(--accent); border-radius: var(--radius);
  padding: 1.4rem 1.5rem 1rem; margin-bottom: 1rem;
}
.hero h1 { margin: 0 0 0.2rem; font-size: 1.9rem; }
.hero-text p { margin: 0; }
.stats { display: flex; gap: 0.6rem; }
.stat {
  display: flex; flex-direction: column; gap: 0.15rem; min-width: 92px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 0.55rem 0.8rem;
}
.stat-label { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.stat-value { font-size: 1.45rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat-value small { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.stat-bar { height: 3px; background: var(--line); border-radius: 2px; overflow: hidden; margin-top: 0.2rem; }
.stat-bar span { display: block; height: 100%; background: var(--accent); }
.stat.points { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.stat.points .stat-label { color: var(--accent-text); opacity: 0.75; }
.rules {
  grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 0.4rem 1.4rem; align-items: center;
  border-top: 1px solid var(--line); padding-top: 0.8rem; font-size: 0.85rem; font-weight: 600;
}
.rules .muted { font-weight: 400; }
.rules-admin { margin-left: auto; font-size: 0.8rem; }
.diamond { color: var(--blue); margin-right: 0.3rem; font-size: 0.8em; }

.banner-panel {
  background: rgba(74, 163, 255, 0.07); border: 1px solid rgba(74, 163, 255, 0.35); border-radius: var(--radius);
  padding: 0.8rem 1.1rem; margin-bottom: 1rem;
}
.banner-title { margin: 0; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--blue); }
.banner-body { margin: 0.2rem 0 0; }

/* ----- Tabs ----- */
.main-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; margin-bottom: 1rem; }
.main-tab {
  text-align: center; padding: 0.8rem; border-radius: var(--radius); font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted); background: var(--surface); border: 1px solid var(--line);
}
.main-tab:hover { color: var(--text); text-decoration: none; }
.main-tab.active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.stage-tabs { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.stage-tab {
  font: inherit; font-size: 0.85rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  background: var(--surface); color: var(--muted); border: 1px solid var(--line); border-radius: 7px;
  padding: 0.4rem 0.9rem; cursor: pointer;
}
.stage-tab:hover { color: var(--text); }
.stage-tab.active { color: var(--accent); border-color: var(--accent); background: rgba(249, 158, 26, 0.08); }

/* ----- Bracket ----- */
.tree-scroll { overflow-x: auto; padding-bottom: 0.75rem; margin-bottom: 1.5rem; }
.round-label {
  position: absolute; top: 0; display: inline-block; max-width: 264px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em;
  background: var(--surface-2); color: var(--text); border-radius: 6px; padding: 0.3rem 0.7rem;
}
.round-label.final { background: var(--accent); color: var(--accent-text); }
.round-label.static { position: static; margin-bottom: 0.6rem; }
.tree { position: relative; }
.connectors { position: absolute; inset: 0; overflow: visible; pointer-events: none; }
.connector { stroke-linejoin: round; }
.connector { fill: none; stroke: var(--line); stroke-width: 2; }
.connector.done { stroke: rgba(249, 158, 26, 0.6); }
.tree-slot { position: absolute; width: 264px; }
.round-block { margin-bottom: 1.5rem; }
.round-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(264px, 1fr)); gap: 0.9rem; }
.slot { position: relative; }

.match {
  height: 124px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; display: flex; flex-direction: column;
}
.match.open { border-color: rgba(249, 158, 26, 0.45); }
.match.scored { border-color: rgba(60, 207, 142, 0.55); }
.match.exact { border-color: var(--accent); box-shadow: 0 0 0 1px rgba(249, 158, 26, 0.35); }
.match-inner { display: flex; flex-direction: column; height: 100%; }
.team-row {
  height: 46px; display: flex; align-items: center; gap: 0.6rem; padding: 0 0.8rem 0 0.7rem;
  background: none; border: 0; border-left: 3px solid transparent; border-bottom: 1px solid var(--line);
  color: var(--text); font: inherit; text-align: left; width: 100%; cursor: pointer;
}
.team-row:disabled { cursor: default; }
.team-row:not(:disabled):hover, .team-row.selecting { background: var(--surface-2); }
.team-row.winner, .team-row.picked { border-left-color: var(--accent); }
.team-row.winner .team-label { font-weight: 700; }
.team-row.loser { color: var(--muted); }
.team-row.tbd { color: var(--muted); }
.team-badge {
  width: 26px; height: 26px; flex: none; display: grid; place-items: center; border-radius: 6px;
  background: var(--surface-2); font-size: 0.8rem; font-weight: 800; color: #fff;
}
.team-row.tbd .team-badge { visibility: hidden; }
.team-logo { width: 26px; height: 26px; flex: none; object-fit: contain; }
.admin-logo { width: 28px; height: 28px; object-fit: contain; vertical-align: middle; }
.file-button { position: relative; overflow: hidden; }
.file-button input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.team-label { flex: 1; font-weight: 600; letter-spacing: 0.02em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.team-row .diamond { margin: 0; }
.team-row .score { min-width: 1.2rem; text-align: right; font-weight: 700; font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.team-row.winner .score { color: var(--accent); }
.score.predicted { color: var(--blue); font-weight: 600; font-size: 0.95rem; }
.match-foot {
  flex: 1; display: flex; align-items: center; gap: 0.6rem; padding: 0 0.8rem; white-space: nowrap;
  font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted);
}
.foot-status { margin-left: auto; }
.foot-status .locks, .foot-status .cta { color: var(--accent); }
.foot-status .live { color: var(--danger); }
.points { border-radius: 5px; padding: 0.05rem 0.4rem; font-weight: 700; }
.points.exact { background: var(--accent); color: var(--accent-text); }
.points.winner { background: rgba(60, 207, 142, 0.18); color: var(--success); }
.points.none { background: var(--surface-2); color: var(--muted); }

.picker-backdrop { position: fixed; inset: 0; background: transparent; border: 0; z-index: 20; cursor: default; }
.picker-pop {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 30;
  background: var(--surface-2); border: 1px solid var(--accent); border-radius: var(--radius);
  padding: 0.7rem; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45); display: flex; flex-direction: column; gap: 0.5rem;
}
.picker-head { display: flex; justify-content: space-between; align-items: center; font-weight: 700; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; }
.picker-close { background: none; border: 0; color: var(--muted); font-size: 1.2rem; cursor: pointer; line-height: 1; }
.picker-chips { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.picker-pop .link-button { align-self: flex-start; }
.chip {
  background: var(--bg); border: 1px solid var(--line); color: var(--text); border-radius: 6px;
  padding: 0.35rem 0.75rem; font: inherit; font-weight: 600; font-variant-numeric: tabular-nums; cursor: pointer;
}
.chip:hover { border-color: var(--accent); }
.chip.selected { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.legend { color: var(--muted); font-size: 0.85rem; }

.leaderboard, .table { width: 100%; border-collapse: collapse; }
.leaderboard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.leaderboard th, .leaderboard td, .table th, .table td { padding: 0.6rem 0.8rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.leaderboard th, .table th { color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 700; }
.leaderboard tr:last-child td, .table tr:last-child td { border-bottom: 0; }
.leaderboard tr.me td { background: rgba(249, 158, 26, 0.08); }
.leaderboard .rank { display: inline-grid; place-items: center; min-width: 1.8rem; height: 1.8rem; border-radius: 6px; font-weight: 700; }
.leaderboard tr.top-1 .rank { background: var(--accent); color: var(--accent-text); }
.leaderboard tr.top-2 .rank { background: #c9d3e3; color: #111; }
.leaderboard tr.top-3 .rank { background: #c47f43; color: #111; }
.leaderboard .player { font-weight: 600; }
.leaderboard .num, .table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table input { width: 100%; }

.admin-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.admin-head h1, .admin-head h2 { margin: 0; }
.warnings { color: var(--muted); font-size: 0.85rem; max-height: 14rem; overflow-y: auto; }

@media (max-width: 640px) {
  .nav { gap: 0.75rem; padding: 0.6rem 1rem; flex-wrap: wrap; }
  .page { padding: 1rem; }
  .hero { grid-template-columns: 1fr; }
  .stats { flex-wrap: wrap; }
  .table { display: block; overflow-x: auto; }
}
