:root {
  --court: #0b5d4e;
  --court-dark: #074034;
  --ball: #e9ff3b;
  --ball-deep: #c9e000;
  --line: #d7e0dc;
  --bg: #f3f6f4;
  --card: #ffffff;
  --ink: #16241f;
  --muted: #6c7d77;
  --win: #1f9d6b;
  --win-bg: #e7f7ef;
  --lose: #9aa7a2;
  --shadow: 0 2px 8px rgba(11, 60, 49, 0.10);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

/* ---- top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 18px;
  background: linear-gradient(120deg, var(--court) 0%, var(--court-dark) 100%);
  color: #fff; box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { font-size: 1.15rem; margin: 0; line-height: 1.1; }
.brand .sub { margin: 2px 0 0; font-size: .72rem; letter-spacing: .14em; text-transform: uppercase; color: var(--ball); opacity: .9; }
.ball {
  width: 30px; height: 30px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff 0 8%, var(--ball) 12%, var(--ball-deep) 100%);
  box-shadow: inset 0 0 0 3px rgba(11,60,49,.25);
  position: relative; flex: 0 0 auto;
}
.topbar-right { display: flex; align-items: center; gap: 10px; }
.status-text { font-size: .8rem; opacity: .9; }
.live-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ball); box-shadow: 0 0 0 0 rgba(233,255,59,.7); animation: pulse 2s infinite; }
.live-dot.stale { background: #ff8a5b; animation: none; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(233,255,59,.6);} 70%{box-shadow:0 0 0 7px rgba(233,255,59,0);} 100%{box-shadow:0 0 0 0 rgba(233,255,59,0);} }

/* ---- buttons ---- */
.btn { font: inherit; font-size: .85rem; font-weight: 600; border: 0; border-radius: 9px; padding: 8px 14px; cursor: pointer; transition: transform .05s, filter .15s, background .15s; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--ball); color: var(--court-dark); }
.btn-primary:hover { filter: brightness(1.05); }
.btn-ghost { background: rgba(255,255,255,.14); color: #fff; border: 1px solid rgba(255,255,255,.25); }
.btn-ghost:hover { background: rgba(255,255,255,.24); }
.btn-danger { background: #fff; color: #b3261e; border: 1px solid #f1c9c6; }
.btn-danger:hover { background: #fff0ef; }
.btn-sm { padding: 5px 10px; font-size: .78rem; }

/* ---- layout ---- */
main { padding: 18px; }
.centered { display: flex; align-items: center; justify-content: center; min-height: 40vh; }
.muted { color: var(--muted); }
.err { color: #b3261e; font-size: .85rem; }
.hidden { display: none !important; }

/* ---- setup ---- */
.setup { max-width: 560px; margin: 24px auto; background: var(--card); border-radius: 16px; padding: 26px; box-shadow: var(--shadow); }
.setup h2 { margin: 0 0 4px; }
.setup label { display: block; font-weight: 600; margin: 16px 0 6px; font-size: .9rem; }
.setup input[type=text], .setup textarea, #loginPass {
  width: 100%; font: inherit; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fbfdfc; color: var(--ink);
}
.setup textarea { min-height: 190px; resize: vertical; line-height: 1.5; }
.setup .hint { font-size: .8rem; color: var(--muted); margin: 6px 0 0; }
.setup-actions { display: flex; gap: 10px; align-items: center; margin-top: 20px; }
.count-pill { margin-left: auto; font-size: .85rem; color: var(--muted); }
.waiting { max-width: 460px; margin: 60px auto; text-align: center; }
.waiting .big { font-size: 3rem; }

/* ---- champion banner ---- */
.champion { max-width: 720px; margin: 0 auto 22px; text-align: center; padding: 22px; border-radius: 16px;
  background: linear-gradient(120deg, var(--ball) 0%, var(--ball-deep) 100%); color: var(--court-dark); box-shadow: var(--shadow); }
.champion .crown { font-size: 2.4rem; }
.champion h2 { margin: 4px 0; font-size: 1.9rem; }
.champion .runner { font-size: .9rem; opacity: .8; }

/* ---- bracket sections ---- */
.section { margin: 8px 0 26px; }
.section-head { display: flex; align-items: baseline; gap: 10px; margin: 0 0 10px; padding: 0 2px; }
.section-head h3 { margin: 0; font-size: 1rem; letter-spacing: .04em; text-transform: uppercase; color: var(--court); }
.section-head .tag { font-size: .72rem; color: var(--muted); }
.scroller { overflow-x: auto; overflow-y: hidden; padding-bottom: 10px; }
.canvas { position: relative; }
.canvas svg.links { position: absolute; top: 0; left: 0; overflow: visible; pointer-events: none; z-index: 0; }
.canvas svg.links path { fill: none; stroke: #aebfb8; stroke-width: 2; stroke-linejoin: round; }
.canvas .match { position: absolute; width: 180px; z-index: 1; }
.col-label { position: absolute; text-align: center; font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }

/* ---- match card ---- */
.match { background: var(--card); border: 1px solid var(--line); border-radius: 11px; box-shadow: var(--shadow); overflow: hidden; position: relative; }
.match.ready { border-color: var(--ball-deep); box-shadow: 0 0 0 2px rgba(201,224,0,.35), var(--shadow); }
.match.done { opacity: .96; }
.match-id { font-size: .62rem; color: var(--muted); padding: 4px 9px 0; letter-spacing: .04em; }
.slot { display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-top: 1px solid #eef2f0; }
.slot:first-of-type { border-top: 0; }
.slot .seed { font-size: .66rem; color: var(--muted); width: 18px; text-align: center; flex: 0 0 auto; }
.slot .name { flex: 1; font-size: .92rem; font-weight: 600; }
.slot.tbd .name, .slot.bye .name { color: var(--muted); font-weight: 500; font-style: italic; }
.slot.winner { background: var(--win-bg); }
.slot.winner .name { color: var(--win); }
.slot.loser .name { color: var(--lose); text-decoration: line-through; text-decoration-thickness: 1px; }
.slot.dropin { background: #eef6f2; border-left: 3px solid var(--court); }
.slot.dropin .name { color: var(--court); font-style: italic; font-weight: 600; font-size: .8rem; }
.slot.dropin-filled { border-left: 3px solid var(--court); }
.slot.dropin-filled .name::after { content: ' ⬇'; color: var(--court); font-size: .72rem; vertical-align: 1px; }
.col-label .sub { display: block; margin-top: 3px; font-size: .62rem; font-weight: 700; color: var(--court); letter-spacing: .02em; text-transform: none; }
.slot .pick { margin-left: auto; }
.slot button.pick { background: var(--court); color: #fff; border: 0; border-radius: 7px; font-size: .72rem; font-weight: 700; padding: 4px 9px; cursor: pointer; }
.slot button.pick:hover { background: var(--court-dark); }
.match .clear { position: absolute; top: 3px; right: 4px; background: transparent; border: 0; color: var(--muted); cursor: pointer; font-size: .8rem; padding: 2px 5px; border-radius: 6px; }
.match .clear:hover { background: #f0f3f1; color: #b3261e; }
.match.gf { border-color: var(--ball-deep); }
.match.gf .match-id { color: var(--court); font-weight: 700; }

/* ---- admin bar ---- */
.adminbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; background: #fff; border: 1px dashed var(--line); border-radius: 12px; padding: 10px 14px; margin-bottom: 18px; }
.adminbar .who { font-weight: 600; color: var(--court); font-size: .9rem; }
.adminbar .spacer { flex: 1; }

/* ---- modal ---- */
.modal { position: fixed; inset: 0; background: rgba(7,32,26,.55); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 18px; }
.modal-card { background: #fff; border-radius: 16px; padding: 24px; width: 100%; max-width: 380px; box-shadow: 0 18px 50px rgba(0,0,0,.3); }
.modal-card h2 { margin: 0 0 6px; }
.modal-card input { margin-top: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

@media (max-width: 560px) {
  .brand h1 { font-size: 1rem; }
  .status-text { display: none; }
  main { padding: 12px; }
}
