:root {
  --bg: #0f1017;
  --card: #181a24;
  --card-2: #20232f;
  --line: #2b2f3d;
  --text: #e9ebf2;
  --muted: #8d93a6;
  --accent: #ff66aa;
  --ok: #3ddc97;
  --warn: #ffc857;
  --bad: #ff5d6c;
  --radius: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

/* --- Barra superior --- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 12px 20px; border-bottom: 1px solid var(--line); background: #13141c;
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 800; font-size: 18px; letter-spacing: .02em; display: flex; align-items: center; gap: 8px; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.brand-sub { font-weight: 500; color: var(--muted); font-size: 14px; }
.pills { display: flex; gap: 8px; flex-wrap: wrap; }
.pill {
  font-size: 12px; font-weight: 600; padding: 4px 10px 4px 22px; border-radius: 999px;
  background: var(--card-2); color: var(--muted); position: relative;
}
.pill::before { content: ''; position: absolute; left: 9px; top: 50%; width: 7px; height: 7px; margin-top: -3.5px; border-radius: 50%; background: var(--muted); }
.pill.ok { color: var(--text); } .pill.ok::before { background: var(--ok); }
.pill.live { color: #fff; background: #3a1726; } .pill.live::before { background: var(--bad); box-shadow: 0 0 0 3px rgba(255,93,108,.25); }
.pill.warn::before { background: var(--warn); }
.pill.bad { color: var(--bad); } .pill.bad::before { background: var(--bad); }

/* --- Rejilla principal --- */
.layout { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(320px, 1fr); gap: 16px; padding: 16px 20px 32px; }
.col-main, .col-side { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
@media (max-width: 1000px) { .layout { grid-template-columns: 1fr; padding: 12px 16px; } }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 8px; }
h2 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.muted { color: var(--muted); font-size: 13px; }

/* --- Vista previa --- */
.preview-card { padding: 0; overflow: hidden; }
.preview { aspect-ratio: 16 / 9; background: #000; position: relative; }
.preview video { width: 100%; height: 100%; display: block; object-fit: contain; }
.preview-status {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 15px; background: #000; text-align: center; padding: 16px;
}
.preview-status[hidden] { display: none; }
.preview-badge {
  position: absolute; right: 10px; bottom: 10px; font-size: 11px; color: var(--muted);
  background: rgba(0, 0, 0, .6); padding: 3px 8px; border-radius: 6px; pointer-events: none;
}
.stats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); border-top: 1px solid var(--line); }
.stats > div { padding: 10px 14px; border-right: 1px solid var(--line); min-width: 0; }
.stats > div:last-child { border-right: 0; }
.stat-label { display: block; font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
@media (max-width: 640px) { .stats { grid-template-columns: repeat(2, 1fr); } .stats > div { border-bottom: 1px solid var(--line); } }

/* --- Botones --- */
.btn {
  appearance: none; border: 1px solid transparent; border-radius: 9px; cursor: pointer;
  background: var(--accent); color: #1a0d14; font: inherit; font-weight: 700;
  padding: 9px 14px; text-align: center; text-decoration: none; display: inline-block;
  transition: filter .15s, background .15s;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.btn.ghost { background: var(--card-2); color: var(--text); border-color: var(--line); }
.btn.danger { background: transparent; color: var(--bad); border-color: rgba(255,93,108,.45); }
.btn.stop { background: var(--bad); color: #fff; }
.btn.small { padding: 6px 10px; font-size: 12px; }
.btn.icon { width: 34px; height: 34px; padding: 0; font-size: 18px; line-height: 1; background: var(--card-2); color: var(--text); border-color: var(--line); }
.btn.wide { display: block; width: 100%; margin-top: 10px; }
.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* --- Escenas --- */
.scene-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.scene-btn {
  background: var(--card-2); color: var(--text); border: 2px solid var(--line); border-radius: 10px;
  padding: 18px 12px; font: inherit; font-weight: 700; font-size: 15px; cursor: pointer;
}
.scene-btn:hover { border-color: #444a5e; }
.scene-btn.active { border-color: var(--bad); background: #2a1620; }
.scene-btn.active::after { content: ' · EN DIRECTO'; color: var(--bad); font-size: 11px; }
.empty { color: var(--muted); }

/* --- Formularios --- */
input {
  width: 100%; background: var(--card-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; font: inherit;
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input[type=color] { width: 38px; height: 34px; padding: 2px; cursor: pointer; flex: none; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label.inline { flex-direction: row; align-items: center; gap: 8px; margin-left: auto; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }

.team-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.team-row .team-name { font-weight: 700; }
.score { display: flex; align-items: center; gap: 6px; flex: none; }
.score-val { min-width: 30px; text-align: center; font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.row-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.hint { font-size: 12px; color: var(--muted); }

/* --- Emisión --- */
.emit-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.emit-title { font-weight: 700; }
.emit-sub { font-size: 12px; color: var(--muted); }
.relay-config { margin-top: 10px; }
.relay-config summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.relay-config label { margin-top: 10px; }
.error-line { color: var(--bad); font-size: 12px; margin-top: 8px; white-space: pre-wrap; word-break: break-word; }
.error-line:empty { display: none; }

/* --- Aviso flotante --- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0;
  background: #2a2d3a; border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px;
  transition: opacity .2s, transform .2s; pointer-events: none; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: var(--bad); color: #ffd6da; }

/* --- Mappool, picks y bans --- */
:root {
  --mod-NM: #7f9cf5; --mod-HD: #f6c344; --mod-HR: #ef6461; --mod-DT: #b388ff;
  --mod-FM: #4fd1a5; --mod-EZ: #8bd450; --mod-FL: #9e9e9e; --mod-TB: #ff66aa;
}
.pool { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.pool-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.slot-btn {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; min-width: 0;
  background: var(--card-2); color: var(--text); border: 1px solid var(--line); border-left: 4px solid var(--mod);
  border-radius: 8px; padding: 6px 8px; font: inherit; text-align: left; cursor: pointer;
}
.slot-btn:hover { border-color: #444a5e; border-left-color: var(--mod); }
.slot-btn.selected { outline: 2px solid var(--accent); outline-offset: 1px; }
.slot-btn .s-top { display: flex; justify-content: space-between; width: 100%; font-weight: 800; font-size: 13px; }
.slot-btn .s-stars { color: var(--muted); font-weight: 600; }
.slot-btn .s-title { font-size: 12px; color: var(--muted); width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot-btn.used { opacity: .45; }
.slot-btn .s-tag { font-size: 10px; font-weight: 800; padding: 0 5px; border-radius: 4px; color: #10101a; background: var(--team); }
.action-bar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 10px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.action-bar .sel { margin-right: auto; color: var(--muted); }
.action-bar .sel b { color: var(--text); }
.act[data-team="teamA"] { background: var(--team-a, #ff6b6b); }
.act[data-team="teamB"] { background: var(--team-b, #6bb7ff); }
.act[data-act="ban"] { background: transparent; color: var(--text); border-color: var(--line); }
.act[data-act="ban"][data-team="teamA"] { border-color: var(--team-a, #ff6b6b); }
.act[data-act="ban"][data-team="teamB"] { border-color: var(--team-b, #6bb7ff); }
.history { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; counter-reset: h; }
.history:empty::before { content: 'Sin picks ni bans todavía'; color: var(--muted); font-size: 13px; }
.history li {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; background: var(--card-2);
  font-size: 13px; counter-increment: h; flex-wrap: wrap;
}
.history li::before { content: counter(h); color: var(--muted); font-variant-numeric: tabular-nums; width: 16px; }
.history .h-type { font-weight: 800; font-size: 11px; padding: 1px 6px; border-radius: 4px; color: #10101a; background: var(--team); }
.history .h-map { flex: 1; min-width: 120px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history .h-win { display: flex; gap: 4px; }
.history .h-win .btn { padding: 3px 8px; font-size: 12px; background: var(--card); color: var(--muted); border-color: var(--line); }
.history .h-win .btn.on { background: var(--team); color: #10101a; border-color: transparent; }
.sub { margin-top: 12px; }
.sub summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.sub .hint { margin: 8px 0; }
.sub code { background: var(--card-2); padding: 1px 5px; border-radius: 4px; }
textarea {
  width: 100%; background: var(--card-2); color: var(--text); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; font: 12px/1.5 ui-monospace, Consolas, monospace; resize: vertical;
}
textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }

.admin-link { align-self: flex-end; color: var(--muted); font-size: 12px; text-decoration: none; }
.admin-link:hover { color: var(--text); text-decoration: underline; }

/* --- Barra de sesión (usuario, rol y accesos) --- */
.session { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 13px; }
.session-user { color: var(--muted); }
.session-user b { color: var(--text); }
.session-link { color: var(--muted); text-decoration: none; }
.session-link:hover { color: var(--text); text-decoration: underline; }
.topbar-right { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }

/* El atributo hidden tiene que ganar siempre, también a .btn { display: inline-block }. */
[hidden] { display: none !important; }

/* --- Director automático --- */
.dir-row { display: flex; gap: 8px; }
.dir-row input { flex: 1; min-width: 0; }
.dir-status { font-size: 12px; color: var(--muted); margin: 8px 0 10px; }
.dir-status.error { color: var(--bad); }
.dir-settings { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; }
.dir-settings select {
  width: 100%; background: var(--card-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 8px; font: inherit;
}
.dir-settings .check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 13px; }
.dir-settings .check input { width: auto; }
.dir-log { list-style: none; margin: 12px 0 0; padding: 0; max-height: 180px; overflow-y: auto; font-size: 12px; display: flex; flex-direction: column; gap: 3px; }
.dir-log li { display: flex; gap: 8px; color: var(--text); }
.dir-log time { color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.dir-log:empty { display: none; }
.history .h-swap { padding: 2px 7px; font-size: 12px; background: var(--card); color: var(--muted); border-color: var(--line); }
