/* ============================================================
   Robot Sumo — Design System
   Clean, minimal, light, neutral, lots of whitespace.
   ============================================================ */
:root {
  /* warm neutral surfaces */
  --bg:        oklch(98.6% 0.004 90);
  --surface:   oklch(100% 0 0);
  --surface-2: oklch(97% 0.004 90);
  --sunken:    oklch(95.2% 0.005 90);

  --ink:       oklch(24% 0.012 60);
  --ink-2:     oklch(44% 0.012 60);
  --ink-3:     oklch(62% 0.010 60);
  --ink-4:     oklch(74% 0.008 60);

  --line:      oklch(91% 0.005 80);
  --line-2:    oklch(86% 0.006 80);

  /* accent (tomato red — the sumo ring). Overridable via tweaks */
  --accent:        oklch(60% 0.197 33);
  --accent-strong: oklch(53% 0.205 33);
  --accent-soft:   oklch(95% 0.045 33);
  --accent-ink:    oklch(100% 0 0);

  --win:   oklch(56% 0.13 155);
  --win-soft: oklch(95% 0.045 155);
  --loss:  oklch(60% 0.02 60);
  --gold:  oklch(72% 0.13 85);

  --r-sm: 6px;
  --r:    9px;
  --r-lg: 14px;
  --r-xl: 20px;

  --shadow-sm: 0 1px 2px oklch(24% 0.012 60 / 0.05), 0 1px 3px oklch(24% 0.012 60 / 0.04);
  --shadow:    0 2px 4px oklch(24% 0.012 60 / 0.04), 0 6px 16px oklch(24% 0.012 60 / 0.06);
  --shadow-lg: 0 8px 24px oklch(24% 0.012 60 / 0.10), 0 2px 6px oklch(24% 0.012 60 / 0.06);

  --mono: 'IBM Plex Mono', ui-monospace, monospace;
  --sans: 'Space Grotesk', system-ui, sans-serif;
  --serif: 'Spectral', Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
::selection { background: var(--accent-soft); }

button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }

/* ---------- App shell ---------- */
.app { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 8px 28px;
  border-bottom: 1px solid var(--line);
  background: oklch(99.5% 0.004 90 / 0.85);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 40; overflow: hidden;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: auto; height: 104px; max-height: 100%; border-radius: var(--r-sm);
  flex: none; display: block; object-fit: contain;
}
.brand-title { font-weight: 600; font-size: 15px; letter-spacing: -0.01em; line-height: 1; }
.brand-sub { font-family: var(--mono); font-size: 10.5px; color: var(--ink-3); letter-spacing: 0.06em; text-transform: uppercase; margin-top: 3px; }

.nav { display: flex; gap: 4px; margin-left: 8px; }
.nav-btn {
  border: none; background: transparent; color: var(--ink-2);
  font-size: 13.5px; font-weight: 500; padding: 8px 14px; border-radius: var(--r-sm);
  display: flex; align-items: center; gap: 8px; transition: all .14s ease;
}
.nav-btn:hover { background: var(--surface-2); color: var(--ink); }
.nav-btn.active { background: var(--ink); color: var(--surface); }
.nav-btn .count {
  font-family: var(--mono); font-size: 11px; padding: 1px 6px; border-radius: 20px;
  background: var(--sunken); color: var(--ink-3);
}
.nav-btn.active .count { background: oklch(100% 0 0 / 0.2); color: oklch(100% 0 0 / 0.85); }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink);
  font-size: 13px; font-weight: 500; padding: 9px 16px; border-radius: var(--r-sm);
  transition: all .14s ease; display: inline-flex; align-items: center; gap: 8px; white-space: nowrap;
}
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.btn.primary:hover { background: oklch(34% 0.012 60); }
.btn.accent { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.accent:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn.sm { padding: 6px 11px; font-size: 12px; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.main { flex: 1; min-height: 0; }

/* ---------- generic ---------- */
.eyebrow {
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--ink-3);
}
.empty-hint { color: var(--ink-3); font-size: 14px; }

/* scrollbars */
::-webkit-scrollbar { height: 12px; width: 12px; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 20px; border: 3px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--ink-4); }
::-webkit-scrollbar-track { background: transparent; }

/* ============================================================
   TEAMS / SETUP
   ============================================================ */
.setup-wrap { max-width: 1080px; margin: 0 auto; padding: 44px 28px 80px; }
.setup-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 28px; flex-wrap: wrap; }
.setup-head h1 { font-size: 30px; font-weight: 600; letter-spacing: -0.02em; margin: 6px 0 0; }
.setup-head p { color: var(--ink-2); font-size: 14.5px; max-width: 52ch; margin: 8px 0 0; line-height: 1.5; }

.setup-grid { display: grid; grid-template-columns: 1.35fr 1fr; gap: 28px; align-items: start; }
@media (max-width: 880px) { .setup-grid { grid-template-columns: 1fr; } }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--shadow-sm);
}
.card-head { padding: 18px 22px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-head h2 { font-size: 15px; font-weight: 600; margin: 0; }
.card-body { padding: 18px 22px; }

.add-row { display: flex; gap: 10px; }
.text-input {
  flex: 1; border: 1px solid var(--line-2); border-radius: var(--r-sm);
  padding: 11px 14px; font-size: 14px; color: var(--ink); background: var(--surface-2);
  transition: all .14s ease; min-width: 0;
}
.text-input:focus { outline: none; border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px var(--accent-soft); }
.text-input::placeholder { color: var(--ink-4); }

.team-list { list-style: none; margin: 18px 0 0; padding: 0; display: flex; flex-direction: column; gap: 7px; }
.team-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r);
  background: var(--surface); transition: box-shadow .14s ease, border-color .14s ease, transform .1s ease;
}
.team-row.dragging { opacity: 0.35; }
.team-row.drag-over { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.drag-handle { color: var(--ink-4); cursor: grab; display: flex; flex: none; }
.drag-handle:active { cursor: grabbing; }
.seed-badge {
  font-family: var(--mono); font-size: 12px; font-weight: 600; color: var(--ink-2);
  width: 30px; height: 30px; flex: none; display: grid; place-items: center;
  background: var(--sunken); border-radius: var(--r-sm);
}
.team-name-input {
  flex: 1; border: none; background: transparent; font-size: 14.5px; font-weight: 500;
  color: var(--ink); padding: 4px 2px; min-width: 0;
}
.team-name-input:focus { outline: none; }
.icon-btn {
  border: none; background: transparent; color: var(--ink-4); width: 30px; height: 30px;
  border-radius: var(--r-sm); display: grid; place-items: center; flex: none; transition: all .14s ease;
}
.icon-btn:hover { background: var(--accent-soft); color: var(--accent-strong); }

.setup-aside .stat-row { display: flex; align-items: baseline; justify-content: space-between; padding: 11px 0; border-bottom: 1px dashed var(--line); }
.setup-aside .stat-row:last-child { border-bottom: none; }
.stat-label { font-size: 13.5px; color: var(--ink-2); }
.stat-val { font-family: var(--mono); font-size: 14px; font-weight: 600; color: var(--ink); }
.preset-row { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 4px; }
.chip {
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink-2);
  font-family: var(--mono); font-size: 12px; padding: 6px 11px; border-radius: 20px; transition: all .14s ease;
}
.chip:hover { border-color: var(--accent); color: var(--accent-strong); }

.start-cta { margin-top: 24px; display: flex; gap: 12px; align-items: center; }
.start-cta .btn.accent { padding: 13px 22px; font-size: 14.5px; }

/* ============================================================
   BRACKET
   ============================================================ */
.bracket-page { display: flex; flex-direction: column; height: calc(100vh - 63px); }
.bracket-toolbar {
  display: flex; align-items: center; gap: 16px; padding: 12px 24px;
  border-bottom: 1px solid var(--line); background: var(--surface);
}
.bracket-toolbar .legend { display: flex; gap: 16px; margin-left: auto; align-items: center; }
.legend-item { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--ink-2); }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }

.bracket-scroll { flex: 1; overflow: auto; padding: 28px 40px 60px; position: relative; }
.bracket-canvas { position: relative; width: max-content; min-width: 100%; transform-origin: top left; }

.bracket-section-label {
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ink-3); margin: 0 0 14px; display: flex; align-items: center; gap: 10px;
}
.bracket-section-label::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.bracket-section-label .badge {
  background: var(--ink); color: var(--surface); padding: 2px 9px; border-radius: 20px;
  font-size: 10px; letter-spacing: 0.1em;
}
.bracket-section-label.lower .badge { background: var(--accent); }

.bracket-region { margin-bottom: 40px; }

.rounds-row { display: flex; gap: 0; align-items: stretch; }
.round-col { display: flex; flex-direction: column; flex: none; width: 220px; padding: 0 18px; }
.round-title {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--ink-3); text-align: center; margin-bottom: 10px; height: 16px;
}
.round-matches { flex: 1; display: flex; flex-direction: column; justify-content: space-around; gap: 14px; }

/* match card */
.match {
  background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--r);
  overflow: hidden; box-shadow: var(--shadow-sm); position: relative; transition: box-shadow .15s ease, border-color .15s ease;
  z-index: 2;
}
.match.playable { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow-sm); }
.match.done { border-color: var(--line); }
.match.highlight { border-color: var(--ink); box-shadow: 0 0 0 3px var(--sunken); }
.match-tag {
  position: absolute; top: -8px; left: 10px; font-family: var(--mono); font-size: 9px;
  letter-spacing: 0.08em; color: var(--ink-4); background: var(--bg); padding: 0 5px;
}
.slot {
  display: flex; align-items: center; gap: 9px; padding: 9px 11px; cursor: pointer;
  transition: background .12s ease; min-height: 38px;
}
.slot + .slot { border-top: 1px solid var(--line); }
.slot:hover.clickable { background: var(--surface-2); }
.slot.winner { background: var(--win-soft); }
.slot.winner .slot-name { font-weight: 600; color: var(--ink); }
.slot.loser .slot-name { color: var(--ink-4); text-decoration: line-through; text-decoration-color: var(--line-2); }
.slot.empty { cursor: default; }
.slot.empty .slot-name { color: var(--ink-4); font-style: italic; }
.slot.bye .slot-name { color: var(--ink-4); }
.slot-seed {
  font-family: var(--mono); font-size: 10px; color: var(--ink-4); width: 16px; flex: none; text-align: right;
}
.slot-name { font-size: 13px; color: var(--ink); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.slot-mark {
  width: 18px; height: 18px; border-radius: 50%; flex: none; display: grid; place-items: center;
  border: 1.5px solid var(--line-2); transition: all .12s ease;
}
.slot.clickable:hover .slot-mark { border-color: var(--accent); }
.slot.winner .slot-mark { background: var(--win); border-color: var(--win); color: #fff; }
.match.playable .slot.clickable { position: relative; }

.gf-region { display: flex; align-items: center; gap: 18px; }
.gf-note { font-size: 12px; color: var(--ink-3); max-width: 200px; line-height: 1.5; }
.reset-tag {
  font-family: var(--mono); font-size: 9px; color: var(--accent-strong); background: var(--accent-soft);
  padding: 2px 7px; border-radius: 20px; letter-spacing: 0.06em; display: inline-block;
}

.champion-banner {
  display: flex; align-items: center; gap: 16px; padding: 16px 22px; margin-bottom: 24px;
  background: var(--ink); color: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow);
}
.champion-banner .trophy { font-size: 22px; }
.champion-banner .ch-label { font-family: var(--mono); font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: oklch(100% 0 0 / 0.6); }
.champion-banner .ch-name { font-size: 22px; font-weight: 600; letter-spacing: -0.01em; }

svg.connectors { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1; overflow: visible; }
svg.connectors path { fill: none; stroke: var(--line-2); stroke-width: 1.5; }
svg.connectors path.drop { stroke: var(--accent); stroke-dasharray: 3 4; opacity: 0.55; }

/* ============================================================
   STANDINGS
   ============================================================ */
.standings-wrap { max-width: 920px; margin: 0 auto; padding: 44px 28px 80px; }
.standings-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 24px; }
.standings-head h1 { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; margin: 0; }
table.standings { width: 100%; border-collapse: collapse; }
table.standings th {
  text-align: left; font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--ink-3); font-weight: 500; padding: 10px 14px; border-bottom: 1px solid var(--line-2);
}
table.standings th.num, table.standings td.num { text-align: center; }
table.standings td { padding: 13px 14px; border-bottom: 1px solid var(--line); font-size: 14px; }
table.standings tr:hover td { background: var(--surface-2); }
.rank-num { font-family: var(--mono); font-weight: 600; color: var(--ink-3); }
.rank-1 .rank-num { color: var(--gold); }
.std-name { font-weight: 600; }
.std-seed { font-family: var(--mono); font-size: 11px; color: var(--ink-4); margin-left: 8px; }
.wl { font-family: var(--mono); font-weight: 600; }
.wl.w { color: var(--win); }
.wl.l { color: var(--accent-strong); }
.status-pill {
  font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.05em; text-transform: uppercase;
  padding: 3px 10px; border-radius: 20px; font-weight: 500;
}
.status-pill.champion { background: var(--ink); color: var(--surface); }
.status-pill.active { background: var(--win-soft); color: var(--win); }
.status-pill.eliminated { background: var(--sunken); color: var(--ink-3); }

/* ============================================================
   CERTIFICATE
   ============================================================ */
.cert-page { max-width: 1100px; margin: 0 auto; padding: 36px 28px 80px; }
.cert-toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; flex-wrap: wrap; }
.cert-toolbar .seg { display: flex; gap: 4px; background: var(--sunken); padding: 4px; border-radius: var(--r); }
.cert-toolbar .seg button {
  border: none; background: transparent; padding: 7px 14px; border-radius: var(--r-sm);
  font-size: 13px; font-weight: 500; color: var(--ink-2);
}
.cert-toolbar .seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

.cert-stage { display: flex; justify-content: center; }
.cert-scale-box { flex: none; }
.cert-scale { transform-origin: top left; flex: none; }
.certificate {
  width: 960px; height: 680px; background: var(--surface); position: relative;
  border: 1px solid var(--line); box-shadow: var(--shadow-lg);
  padding: 54px; display: flex; flex-direction: column; align-items: center; text-align: center;
}
.cert-inner-border { position: absolute; inset: 22px; border: 1.5px solid var(--ink); pointer-events: none; }
.cert-inner-border::before { content: ''; position: absolute; inset: 6px; border: 1px solid var(--line-2); }
.cert-corner { position: absolute; width: 18px; height: 18px; border: 2px solid var(--accent); }
.cert-corner.tl { top: 30px; left: 30px; border-right: none; border-bottom: none; }
.cert-corner.tr { top: 30px; right: 30px; border-left: none; border-bottom: none; }
.cert-corner.bl { bottom: 30px; left: 30px; border-right: none; border-top: none; }
.cert-corner.br { bottom: 30px; right: 30px; border-left: none; border-top: none; }

.cert-mark { width: 54px; height: 54px; border-radius: 50%; border: 3px solid var(--ink); display: grid; place-items: center; margin-top: 18px; position: relative; }
.cert-mark::after { content: ''; width: 18px; height: 18px; border-radius: 50%; background: var(--accent); }
.cert-org { font-family: var(--mono); font-size: 12px; letter-spacing: 0.22em; text-transform: uppercase; color: var(--ink-2); margin-top: 18px; }
.cert-title { font-family: var(--serif); font-size: 44px; font-weight: 600; letter-spacing: 0.01em; margin: 6px 0 2px; white-space: nowrap; }
.cert-sub { font-family: var(--serif); font-style: italic; font-size: 17px; color: var(--ink-2); }
.cert-presented { font-family: var(--mono); font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink-3); margin-top: 30px; }
.cert-recipient { font-family: var(--serif); font-size: 54px; font-weight: 600; letter-spacing: -0.01em; margin: 8px 0; line-height: 1.05; }
.cert-recipient-rule { width: 360px; height: 2px; background: var(--accent); margin: 4px auto 0; }
.cert-citation { font-family: var(--serif); font-size: 17px; color: var(--ink-2); max-width: 56ch; line-height: 1.55; margin: 22px auto 0; }
.cert-citation .place { font-weight: 600; color: var(--ink); font-style: italic; }
.cert-footer { margin-top: auto; display: flex; justify-content: space-between; align-items: flex-end; width: 100%; padding: 0 14px; }
.cert-sign { text-align: center; }
.cert-sign-line { width: 200px; height: 1px; background: var(--ink-3); margin-bottom: 7px; }
.cert-sign-label { font-family: var(--mono); font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-3); }
.cert-sign-name { font-family: var(--serif); font-size: 15px; color: var(--ink); margin-bottom: 4px; }
.cert-seal { width: 78px; height: 78px; border-radius: 50%; border: 2px solid var(--accent); display: grid; place-items: center; text-align: center; color: var(--accent-strong); position: relative; }
.cert-seal .seal-rank { font-family: var(--serif); font-size: 26px; font-weight: 600; line-height: 1; }
.cert-seal .seal-txt { font-family: var(--mono); font-size: 7.5px; letter-spacing: 0.12em; text-transform: uppercase; margin-top: 2px; }

.cert-empty { text-align: center; padding: 80px 20px; color: var(--ink-3); }

/* print */
@media print {
  @page { size: landscape; margin: 0; }
  body * { visibility: hidden; }
  .cert-scale-box { width: auto !important; height: auto !important; }
  .cert-scale { transform: none !important; }
  .certificate, .certificate * { visibility: visible; }
  .certificate { position: fixed; inset: 0; margin: auto; box-shadow: none; border: none; }
  .tweak-host, .topbar, .cert-toolbar { display: none !important; }
}

/* fade-in */
@keyframes fadeUp { from { transform: translateY(6px); } to { transform: none; } }
/* Animate transform only — never opacity — so content is always visible even if
   the animation clock is throttled (offscreen tab) and holds the start frame. */
.fade-up { animation: fadeUp .3s ease; }
