:root {
  --bg: #0a0e17;
  --panel: #111827;
  --panel-alt: #162033;
  --border: #243046;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --accent: #10b981;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 13px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.hidden {
  display: none !important;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 18px;
  background: #0d1320;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
}

.brand-title {
  font-weight: 800;
  letter-spacing: 1px;
  font-size: 15px;
}

.brand-sub {
  color: var(--muted);
  font-size: 12px;
}

.tabs {
  display: flex;
  gap: 6px;
}

.tab-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
}

.tab-btn.active {
  background: var(--panel-alt);
  color: var(--text);
  border-color: var(--border);
}

.auth-bar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.workspace {
  flex: 1;
  padding: 14px;
  display: flex;
}

.tab-panel {
  display: none;
  width: 100%;
  gap: 14px;
}

.tab-panel.active {
  display: grid;
}

.arena-grid,
.replays-grid {
  grid-template-columns: 270px minmax(480px, 1fr) 340px;
}

.tournament-grid {
  grid-template-columns: 310px 1fr 370px;
}

.scripts-grid {
  grid-template-columns: 260px 1fr 340px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
}

.panel-header h3 {
  margin: 0;
  font-size: 13px;
}

.preset-box {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  margin-bottom: 8px;
  font-weight: 700;
}

.preset-grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.list-container {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.list-item {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  cursor: pointer;
  transition: border-color 0.15s;
}

.list-item:hover {
  border-color: #475569;
}

.list-item.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.4);
}

.list-item-title {
  font-weight: 600;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.list-item-sub {
  font-size: 11px;
  color: var(--muted);
}

.stage-panel {
  padding: 12px 14px;
  gap: 10px;
}

.stage-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.stage-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stage-title-row h2,
.stage-header h2 {
  margin: 0;
  font-size: 16px;
}

.muted-line {
  font-size: 12px;
  color: var(--muted);
  margin-top: 3px;
}

.controls-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.canvas-wrap {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #070a11;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  min-height: 520px;
}

canvas {
  max-width: 100%;
  max-height: 100%;
  display: block;
}

.result-overlay {
  position: absolute;
  inset: 0;
  background: rgba(8, 12, 22, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.result-card {
  background: var(--panel);
  border: 1px solid var(--primary);
  border-radius: 12px;
  padding: 20px 26px;
  max-width: 440px;
  width: 100%;
  text-align: center;
}

.event-ticker {
  padding: 8px 12px;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  color: #cbd5e1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.inspector-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}

.team-card {
  border-left: 4px solid var(--primary);
}

.actor-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  background: rgba(10, 14, 23, 0.55);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-top: 6px;
}

.actor-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.hp-bar {
  height: 6px;
  background: #1f2937;
  border-radius: 99px;
  overflow: hidden;
}

.hp-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.15s;
}

.form-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.form-row label {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.btn {
  background: #1e293b;
  color: var(--text);
  border: 1px solid #334155;
  border-radius: 6px;
  padding: 6px 11px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}

.btn:hover:not(:disabled) {
  background: #283548;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-accent {
  background: #065f46;
  border-color: #10b981;
  color: #ecfdf5;
}

.btn-warn {
  background: #78350f;
  border-color: #f59e0b;
  color: #fef3c7;
}

.btn-danger {
  background: #7f1d1d;
  border-color: #ef4444;
  color: #fee2e2;
}

.btn-sm {
  padding: 5px 10px;
}

.btn-xs {
  padding: 3px 7px;
  font-size: 11px;
}

.full-width {
  width: 100%;
}

.input,
.select-sm {
  background: #0b1120;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 9px;
  font-size: 12px;
}

.input-sm {
  padding: 4px 7px;
  width: 140px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 700;
}

.badge-muted { background: #1e293b; color: #94a3b8; }
.badge-running { background: #064e3b; color: #34d399; }
.badge-paused { background: #78350f; color: #fbbf24; }
.badge-draft { background: #1e3a8a; color: #93c5fd; }
.badge-finished { background: #3b0764; color: #d8b4fe; }
.badge-warn { background: #78350f; color: #fcd34d; }
.badge-danger { background: #7f1d1d; color: #fca5a5; }

.editor-panel {
  padding: 12px;
  gap: 10px;
}

.editor-toolbar {
  display: flex;
  gap: 8px;
}

.editor-toolbar .input {
  flex: 1;
}

.code-editor {
  flex: 1;
  min-height: 540px;
  background: #070b14;
  color: #dbeafe;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.5;
  resize: none;
}

.sdk-doc {
  margin: 0;
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  color: #93c5fd;
  line-height: 1.45;
}

.scrub-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 2px;
}

.scrub-bar input[type="range"] {
  flex: 1;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 15, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px;
  width: 420px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-card h2 {
  margin: 0;
}

.quick-codes {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--muted);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
}

.error-text {
  color: #f87171;
  font-size: 12px;
  min-height: 16px;
}

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #1e293b;
  border: 1px solid var(--primary);
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  z-index: 60;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

@media (max-width: 1180px) {
  .arena-grid,
  .tournament-grid,
  .replays-grid,
  .scripts-grid {
    grid-template-columns: 1fr;
  }
}

.table-wrap {
  flex: 1;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0b1120;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

.data-table th,
.data-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table th {
  background: var(--panel-alt);
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  position: sticky;
  top: 0;
}

.data-table tbody tr:hover {
  background: rgba(59, 130, 246, 0.08);
}

.check-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 160px;
  overflow-y: auto;
}

.check-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(10, 14, 23, 0.6);
  border: 1px solid var(--border);
  cursor: pointer;
}

.progress-bar {
  height: 8px;
  background: #1e293b;
  border-radius: 99px;
  overflow: hidden;
  margin: 8px 0;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  transition: width 0.25s;
}

.elo-pos { color: #34d399; font-weight: 700; }
.elo-neg { color: #f87171; font-weight: 700; }
.elo-zero { color: var(--muted); }
