:root {
  --bg: #0f172a;
  --surface: #1b2436;
  --surface-2: #232f47;
  --border: #2f3c58;
  --text: #e9edf5;
  --text-dim: #9aa5b8;
  --accent: #22c55e;
  --accent-dark: #0d4f3c;
  --danger: #ef4444;
  --white-badge: #f5f0e6;
  --black-badge: #1e293b;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 80px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--accent-dark);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar h1 { font-size: 1.1rem; margin: 0; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.role-badge {
  font-size: 0.72rem;
  padding: 4px 10px;
  border-radius: 20px;
  background: rgba(255,255,255,0.12);
  color: var(--text-dim);
  white-space: nowrap;
}
.role-badge.admin { background: var(--accent); color: #06280f; font-weight: 600; }

.tabs {
  display: flex;
  overflow-x: auto;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 52px;
  z-index: 9;
}
.tab-btn {
  flex: 1 0 auto;
  padding: 12px 10px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.85rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

main { padding: 14px; max-width: 720px; margin: 0 auto; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.row-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.row-form input {
  flex: 1 1 140px;
}

input, select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px;
  border-radius: var(--radius);
  font-size: 0.95rem;
  width: 100%;
}

label {
  display: block;
  font-size: 0.82rem;
  color: var(--text-dim);
  margin-bottom: 10px;
}
label input, label select { margin-top: 4px; }

.btn {
  border: none;
  border-radius: var(--radius);
  padding: 11px 16px;
  font-size: 0.92rem;
  cursor: pointer;
  font-weight: 600;
}
.btn.primary { background: var(--accent); color: #06280f; }
.btn.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid rgba(255,255,255,0.3); }
.btn.small { padding: 6px 10px; font-size: 0.78rem; }
.btn.full { width: 100%; margin-top: 10px; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.file-label {
  display: block;
  text-align: center;
  margin-top: 10px;
}

.hint { color: var(--text-dim); font-size: 0.8rem; line-height: 1.4; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }

table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { padding: 9px 8px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-dim); font-weight: 600; background: var(--surface); position: sticky; top: 0; }
tbody tr:last-child td { border-bottom: none; }
tbody tr.inactive { opacity: 0.45; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}
.card h3 { margin-top: 0; }

.pairing-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
}
.pairing-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.side {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}
.side .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.color-badge {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  flex-shrink: 0;
  border: 1px solid var(--border);
}
.color-badge.w { background: var(--white-badge); }
.color-badge.b { background: var(--black-badge); }
.vs { color: var(--text-dim); font-size: 0.75rem; padding: 0 4px; }
.result-select { margin-top: 10px; }
.bye-card {
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 10px;
  color: var(--text-dim);
  font-size: 0.88rem;
}

.round-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.round-header h2 { margin: 0; font-size: 1.05rem; }
.badge-round {
  background: var(--surface-2);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 0.78rem;
  color: var(--text-dim);
}

.history-round {
  margin-bottom: 16px;
}
.history-round h3 {
  font-size: 0.92rem;
  margin-bottom: 6px;
  color: var(--text-dim);
}
.history-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.86rem;
  gap: 8px;
}
.history-row:last-child { border-bottom: none; }
.result-tag {
  font-weight: 600;
  color: var(--accent);
  flex-shrink: 0;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 4px 8px;
}
.icon-btn.danger { color: var(--danger); }

.hidden { display: none !important; }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 0.85rem;
  z-index: 50;
  box-shadow: 0 4px 14px rgba(0,0,0,0.4);
}

.empty-state {
  text-align: center;
  color: var(--text-dim);
  padding: 40px 16px;
  font-size: 0.9rem;
}
