:root {
  color-scheme: dark;
  --bg: #0e1118;
  --panel: #171b25;
  --panel-2: #1f2531;
  --text: #f4f7fb;
  --muted: #9ba7bc;
  --line: #2b3242;
  --accent: #8fd14f;
  --accent-2: #51a8ff;
  --danger: #ff6b6b;
  --warning: #ffd166;
  --shadow: 0 18px 50px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top left, #20293a 0, #0e1118 42%, #080a0f 100%);
  color: var(--text);
  min-height: 100vh;
}
button, input, select { font: inherit; }
button { cursor: pointer; }
.brand { font-weight: 800; letter-spacing: .04em; text-transform: uppercase; color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
code { background: #0b0e14; border: 1px solid var(--line); border-radius: 7px; padding: 2px 6px; }

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(440px, 100%);
  background: rgba(23,27,37,.92);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 30px;
}
.login-card h1 { margin: 14px 0 8px; font-size: 32px; }
.form-stack { display: grid; gap: 16px; margin-top: 22px; }
label { display: grid; gap: 7px; color: var(--muted); font-size: 14px; }
input, select {
  width: 100%;
  background: #0c1018;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
}
input:focus, select:focus { border-color: var(--accent-2); box-shadow: 0 0 0 3px rgba(81,168,255,.15); }
.primary, .secondary, .ghost {
  border: 0;
  border-radius: 12px;
  padding: 12px 16px;
  font-weight: 700;
}
.primary { background: var(--accent); color: #0b1207; }
.secondary { background: var(--accent-2); color: #06101d; }
.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
.alert { padding: 12px 14px; border-radius: 12px; margin-top: 18px; }
.alert.error { background: rgba(255,107,107,.12); border: 1px solid rgba(255,107,107,.45); color: #ffdede; }
.alert.success { background: rgba(143,209,79,.12); border: 1px solid rgba(143,209,79,.45); color: #e9ffdf; }
.demo-logins { margin-top: 22px; color: var(--muted); }
.demo-logins summary { cursor: pointer; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 18px 24px;
  background: rgba(14,17,24,.86);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.pill, .badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.04);
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 11px;
  font-size: 13px;
  white-space: nowrap;
}
.pill.ok { color: #ddffd1; border-color: rgba(143,209,79,.4); }
.pill.warn { color: #ffeab0; border-color: rgba(255,209,102,.45); }
.layout {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 18px;
  padding: 18px 24px 40px;
}
.panel {
  background: rgba(23,27,37,.9);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 10px 28px rgba(0,0,0,.18);
  padding: 18px;
}
.panel h2, .panel h3 { margin: 0; }
.panel h2 { font-size: 18px; }
.panel-title-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.panel-title-row.wrap { flex-wrap: wrap; }
.status-panel, .captains-panel, .admins-panel, .log-panel { grid-column: 1; }
.teams-panel, .players-panel { grid-column: 2; }
.teams-panel { grid-row: 1 / span 3; }
.players-panel { grid-row: 4 / span 2; }
.log-panel { grid-row: 4; }
.turn-card {
  margin-top: 14px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
}
.current-captain { font-size: 26px; font-weight: 800; margin-top: 4px; }
.timer-wrap { margin-top: 16px; }
.timer { font-size: 42px; line-height: 1; font-weight: 900; font-variant-numeric: tabular-nums; }
.timer.danger { color: var(--danger); }
.timer-bar { height: 9px; background: #0d1118; border-radius: 999px; overflow: hidden; margin-top: 10px; border: 1px solid var(--line); }
.timer-bar-fill { height: 100%; width: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .2s linear; }
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.stats-grid div { background: rgba(255,255,255,.035); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.stats-grid span { display: block; color: var(--muted); font-size: 12px; }
.stats-grid strong { display: block; margin-top: 5px; font-size: 18px; }
.captains-list { display: grid; gap: 10px; margin-top: 14px; }
.captain-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  background: rgba(255,255,255,.035);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
}
.captain-card.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px rgba(143,209,79,.35); }
.status-dot { width: 10px; height: 10px; border-radius: 999px; background: #596174; }
.status-dot.online { background: var(--accent); box-shadow: 0 0 0 4px rgba(143,209,79,.13); }
.order-tag { color: var(--muted); font-size: 12px; }
.teams-grid { display: grid; grid-template-columns: repeat(2, minmax(280px, 1fr)); gap: 14px; margin-top: 14px; }
.team-card { background: rgba(255,255,255,.035); border: 1px solid var(--line); border-radius: 18px; overflow: hidden; }
.team-card.active { border-color: var(--accent); }
.team-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 14px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.025); }
.team-name { font-weight: 800; font-size: 17px; }
.team-mmr { text-align: right; font-variant-numeric: tabular-nums; }
.team-mmr strong { display: block; font-size: 19px; }
.delta.good { color: var(--accent); }
.delta.bad { color: var(--warning); }
.slots { display: grid; gap: 8px; padding: 12px; }
.slot { display: grid; grid-template-columns: 42px 1fr auto; align-items: center; gap: 10px; background: #10141d; border: 1px solid var(--line); border-radius: 13px; padding: 10px; min-height: 52px; }
.pos-badge { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 9px; background: var(--panel-2); font-weight: 800; }
.player-name { font-weight: 700; }
.priorities { display: flex; flex-wrap: wrap; gap: 5px; }
.priority-chip { display: inline-flex; min-width: 24px; height: 24px; align-items: center; justify-content: center; border-radius: 8px; background: #10141d; border: 1px solid var(--line); color: var(--muted); font-size: 12px; font-weight: 700; }
.priority-chip.best { background: rgba(143,209,79,.13); border-color: rgba(143,209,79,.35); color: #dfffd2; }
.filters { display: flex; gap: 10px; min-width: min(460px, 100%); }
.table-wrap { overflow: auto; margin-top: 14px; border: 1px solid var(--line); border-radius: 15px; }
.players-table { width: 100%; border-collapse: collapse; min-width: 680px; }
th, td { padding: 12px; text-align: left; border-bottom: 1px solid var(--line); }
th { color: var(--muted); background: #10141d; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
tr:last-child td { border-bottom: 0; }
.player-row.picked { opacity: .42; }
.pick-button { border: 1px solid rgba(143,209,79,.35); background: rgba(143,209,79,.14); color: #dfffd2; border-radius: 10px; padding: 8px 10px; font-weight: 800; }
.pick-button:disabled { opacity: .45; cursor: not-allowed; }
.log-list { display: grid; gap: 9px; margin-top: 14px; max-height: 320px; overflow: auto; }
.log-item { color: var(--muted); font-size: 13px; padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255,255,255,.025); }
.log-item strong { color: var(--text); }
.modal-backdrop[hidden], .toast[hidden] { display: none !important; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0,0,0,.62);
}
.modal { width: min(460px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); padding: 20px; }
.icon-button { border: 0; background: transparent; color: var(--text); font-size: 28px; line-height: 1; }
.position-buttons { display: grid; grid-template-columns: repeat(5, 1fr); gap: 9px; margin-top: 18px; }
.position-button { border: 1px solid var(--line); border-radius: 14px; padding: 14px 8px; background: var(--panel-2); color: var(--text); font-weight: 900; }
.position-button.recommended { border-color: rgba(143,209,79,.65); background: rgba(143,209,79,.15); }
.position-button:disabled { opacity: .35; cursor: not-allowed; }
.toast { position: fixed; right: 18px; bottom: 18px; z-index: 200; max-width: 420px; padding: 13px 15px; border-radius: 14px; border: 1px solid var(--line); background: #10141d; box-shadow: var(--shadow); }
.toast.error { border-color: rgba(255,107,107,.55); }
.toast.warning { border-color: rgba(255,209,102,.55); }
.toast.info { border-color: rgba(81,168,255,.55); }

.admin-card { width: min(620px, 100%); }
.admin-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 18px 0; }
.admin-summary div { background: rgba(255,255,255,.035); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.admin-summary strong { display: block; margin-top: 4px; }
.admin-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 18px 0 24px; }
.admin-actions form { display: inline-flex; }
button:disabled { opacity: .45; cursor: not-allowed; }
.ghost.danger { border-color: rgba(255,107,107,.45); color: #ffdede; }
.admin-order { color: var(--muted); }
a { color: #a9d2ff; }

@media (max-width: 1120px) {
  .layout { grid-template-columns: 1fr; }
  .status-panel, .captains-panel, .admins-panel, .log-panel, .teams-panel, .players-panel { grid-column: 1; grid-row: auto; }
  .teams-grid { grid-template-columns: 1fr; }
}
@media (max-width: 680px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .layout { padding: 14px; }
  .filters { flex-direction: column; min-width: 100%; }
  .stats-grid { grid-template-columns: 1fr; }
  .admin-summary { grid-template-columns: 1fr; }
  .position-buttons { grid-template-columns: repeat(3, 1fr); }
}
.captain-slot {
  display: inline-flex;
  align-items: center;
  margin-left: 6px;
  padding: 2px 7px;
  border: 1px solid rgba(143,209,79,.4);
  border-radius: 999px;
  color: #dfffd2;
  background: rgba(143,209,79,.12);
  font-size: 11px;
  font-weight: 800;
  vertical-align: middle;
}

.admin-controls {
  display: grid;
  gap: 12px;
  margin-top: 14px;
  padding: 14px;
  border: 1px solid rgba(81,168,255,.35);
  border-radius: 16px;
  background: rgba(81,168,255,.08);
}
.admin-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.admin-buttons button {
  flex: 1 1 140px;
}

.organizer-card { border-color: rgba(81,168,255,.35); }
