:root {
  color-scheme: dark;
  --bg: #071019;
  --surface: #0d1924;
  --surface-raised: #112130;
  --line: #203649;
  --line-soft: #162a3a;
  --text: #edf7ff;
  --muted: #8fa7b9;
  --cyan: #48d8ff;
  --blue: #4d7dff;
  --green: #4fe5a3;
  --amber: #ffca72;
  --red: #ff6b79;
  --radius: 12px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    linear-gradient(rgba(72, 216, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(72, 216, 255, 0.025) 1px, transparent 1px),
    radial-gradient(circle at 85% -20%, rgba(77, 125, 255, 0.2), transparent 34rem),
    var(--bg);
  background-size: 32px 32px, 32px 32px, auto, auto;
  color: var(--text);
  font-size: 16px;
}

button { font: inherit; }
body.dialog-open { overflow: hidden; }

.shell { width: min(1480px, calc(100% - 40px)); margin: 0 auto; padding-bottom: 48px; }

.topbar {
  min-height: 94px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid var(--line-soft);
}

.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(72, 216, 255, 0.55);
  border-radius: 10px;
  background: linear-gradient(145deg, rgba(72, 216, 255, 0.18), rgba(77, 125, 255, 0.06));
  color: var(--cyan);
  font-weight: 800;
  box-shadow: inset 0 0 20px rgba(72, 216, 255, 0.08), 0 0 22px rgba(72, 216, 255, 0.07);
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(1.2rem, 2vw, 1.55rem); font-weight: 680; letter-spacing: -0.025em; }
h2 { font-size: 1.08rem; font-weight: 670; letter-spacing: -0.015em; }
h3 { font-size: 1rem; font-weight: 670; letter-spacing: -0.01em; }
.eyebrow { margin-bottom: 4px; color: var(--cyan); font-size: 0.72rem; font-weight: 730; letter-spacing: 0.14em; }

.runner-state {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 0.88rem;
}

.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 12px var(--amber); }
.runner-state.online .status-dot { background: var(--green); box-shadow: 0 0 12px var(--green); }
.runner-state.offline .status-dot { background: var(--red); box-shadow: 0 0 12px var(--red); }

.overview {
  display: grid;
  grid-template-columns: minmax(300px, 1.65fr) repeat(3, minmax(150px, 1fr));
  gap: 12px;
  margin: 28px 0 16px;
}

.metric, .panel {
  border: 1px solid var(--line-soft);
  background: linear-gradient(145deg, rgba(17, 33, 48, 0.92), rgba(10, 23, 34, 0.96));
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.14);
}

.metric { min-height: 132px; padding: 20px; border-radius: var(--radius); }
.metric-live { position: relative; overflow: hidden; }
.metric-live::after {
  content: "";
  position: absolute;
  inset: auto -50px -90px auto;
  width: 210px;
  height: 210px;
  border: 1px solid rgba(72, 216, 255, 0.12);
  border-radius: 50%;
  box-shadow: 0 0 55px rgba(72, 216, 255, 0.05);
}
.metric-label { color: var(--muted); font-size: 0.78rem; font-weight: 630; letter-spacing: 0.04em; text-transform: uppercase; }
.metric-value { margin-top: 12px; font-size: clamp(1.8rem, 3vw, 2.35rem); font-weight: 720; line-height: 1; letter-spacing: -0.04em; }
.metric-value small { color: var(--muted); font-size: 0.88rem; font-weight: 520; letter-spacing: 0; }
.metric-meta { position: relative; z-index: 1; margin-top: 10px; color: var(--muted); font-size: 0.78rem; }
.current-match { position: relative; z-index: 1; margin-top: 12px; font-size: clamp(1.12rem, 2.1vw, 1.55rem); font-weight: 680; letter-spacing: -0.025em; }
.versus { padding: 0 8px; color: var(--cyan); font-size: 0.72em; font-weight: 650; letter-spacing: 0.08em; }
.current-live { position: relative; z-index: 1; display: grid; gap: 7px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line-soft); }
.current-live[hidden] { display: none; }
.live-stat { display: grid; grid-template-columns: minmax(28px, auto) minmax(96px, 1fr) minmax(28px, auto); align-items: center; gap: 9px; font-size: 0.75rem; font-variant-numeric: tabular-nums; }
.live-stat > strong:last-child { text-align: right; }
.live-stat strong { color: #d9eaf4; font-weight: 720; }
.live-stat strong small { margin-left: 2px; color: var(--green); font-size: 0.62rem; }
.live-stat-center { display: grid; grid-template-columns: minmax(72px, auto) minmax(38px, 1fr); align-items: center; gap: 8px; color: var(--muted); font-size: 0.66rem; text-align: center; text-transform: uppercase; }
.live-stat progress { width: 100%; height: 5px; overflow: hidden; border: 0; border-radius: 999px; appearance: none; background: var(--blue); }
.live-stat progress::-webkit-progress-bar { border-radius: 999px; background: var(--blue); }
.live-stat progress::-webkit-progress-value { border-radius: 999px; background: var(--cyan); }
.live-stat progress::-moz-progress-bar { border-radius: 999px; background: var(--cyan); }
.live-no-ratio { color: #5f788b; font-size: 0.58rem; text-transform: none; }
.live-caption, .live-unavailable { color: #718a9d; font-size: 0.66rem; }

.workspace { display: grid; grid-template-columns: minmax(0, 2.25fr) minmax(320px, 0.85fr); gap: 16px; }
.panel { border-radius: var(--radius); overflow: hidden; }
.panel-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; padding: 20px 22px 16px; border-bottom: 1px solid var(--line-soft); }
.panel-heading.compact { align-items: center; }

.filters { display: flex; padding: 3px; border: 1px solid var(--line); border-radius: 8px; background: rgba(4, 13, 21, 0.48); }
.filter { padding: 7px 10px; border: 0; border-radius: 5px; background: transparent; color: var(--muted); cursor: pointer; font-size: 0.78rem; }
.filter:hover { color: var(--text); }
.filter.active { background: var(--surface-raised); color: var(--cyan); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25); }
.filter:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px 16px; border-bottom: 1px solid var(--line-soft); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-size: 0.72rem; font-weight: 650; letter-spacing: 0.05em; text-transform: uppercase; }
td { font-size: 0.88rem; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background 120ms ease; }
tbody tr:hover { background: rgba(72, 216, 255, 0.035); }
.numeric { text-align: right; font-variant-numeric: tabular-nums; }
.rank-col { width: 44px; color: #6d879a; }
.bot-cell { min-width: 210px; }
.bot-link { width: 100%; padding: 0; border: 0; background: transparent; color: inherit; cursor: pointer; text-align: left; }
.bot-link:hover .bot-name { color: var(--cyan); }
.bot-link:focus-visible { border-radius: 5px; outline: 2px solid var(--cyan); outline-offset: 4px; }
.bot-name { display: flex; align-items: center; gap: 9px; font-weight: 640; }
.race-badge { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 5px; background: #182c3c; color: var(--cyan); font-size: 0.68rem; font-weight: 760; }
.bot-category { display: block; margin: 4px 0 0 31px; color: var(--muted); font-size: 0.72rem; }
.elo { color: var(--text); font-weight: 700; }
.delta-positive { color: var(--green); }
.delta-negative { color: var(--red); }
.delta-neutral { color: #6d879a; }
.winrate { color: #b8cad7; }
.empty { padding: 36px 20px; color: var(--muted); text-align: center; }

.rail { display: grid; align-content: start; gap: 16px; }
.match-feed { padding: 4px 20px 12px; }
.match-item { padding: 15px 0; border-bottom: 1px solid var(--line-soft); }
.match-item:last-child { border-bottom: 0; }
.match-main { display: grid; grid-template-columns: minmax(0, 1fr) 44px minmax(0, 1fr); align-items: center; gap: 8px; font-size: 0.82rem; }
.match-main span:last-child { text-align: right; }
.match-main .winner { color: var(--text); font-weight: 690; }
.match-main .loser { color: var(--muted); }
.match-player { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-mark { min-width: 0; color: var(--cyan); text-align: center; font-size: 0.7rem; font-weight: 740; white-space: nowrap; }
.match-meta { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; margin-top: 7px; color: #718a9d; font-size: 0.7rem; }
.match-meta span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.match-meta span:last-child { white-space: nowrap; }

.health-panel { padding: 20px 22px; }
.health-list { margin: 18px 0 0; }
.health-list div { display: flex; justify-content: space-between; gap: 18px; padding: 9px 0; border-top: 1px solid var(--line-soft); }
.health-list dt, .health-list dd { margin: 0; font-size: 0.79rem; }
.health-list dt { color: var(--muted); }
.health-list dd { color: #c5d6e2; font-variant-numeric: tabular-nums; }

.error-toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: 360px;
  padding: 12px 15px;
  border: 1px solid rgba(255, 107, 121, 0.38);
  border-radius: 8px;
  background: #2b1118;
  color: #ffd8dc;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: 180ms ease;
  font-size: 0.82rem;
}
.error-toast.visible { opacity: 1; transform: translateY(0); }

.bot-history-dialog { position: fixed; z-index: 20; inset: 0; display: grid; place-items: center; padding: 24px; visibility: hidden; pointer-events: none; }
.bot-history-dialog.open { visibility: visible; pointer-events: auto; }
.dialog-backdrop { position: absolute; inset: 0; width: 100%; border: 0; background: rgba(2, 8, 13, 0.76); opacity: 0; transition: opacity 180ms ease; }
.bot-history-dialog.open .dialog-backdrop { opacity: 1; }
.bot-history-panel {
  position: relative;
  width: min(1040px, 100%);
  max-height: min(860px, calc(100vh - 48px));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #0a1621;
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.52);
  opacity: 0;
  transform: translateY(18px) scale(0.985);
  transition: opacity 180ms ease, transform 220ms ease;
}
.bot-history-dialog.open .bot-history-panel { opacity: 1; transform: translateY(0) scale(1); }
.bot-history-header { min-height: 108px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 24px 28px; border-bottom: 1px solid var(--line-soft); }
.bot-history-header h2 { font-size: 1.38rem; }
.bot-history-subtitle { margin-top: 7px; color: var(--muted); font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.dialog-close { display: grid; place-items: center; width: 38px; height: 38px; flex: 0 0 auto; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--muted); cursor: pointer; font-size: 1.5rem; line-height: 1; }
.dialog-close:hover { border-color: var(--cyan); color: var(--text); }
.dialog-close:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
.bot-history-scroll { max-height: calc(min(860px, 100vh - 48px) - 108px); overflow-y: auto; }
.bot-profile { display: grid; grid-template-columns: minmax(240px, 0.8fr) minmax(0, 1.7fr); gap: 24px; padding: 24px 28px; border-bottom: 1px solid var(--line-soft); background: linear-gradient(135deg, rgba(72, 216, 255, 0.045), transparent 60%); }
.bot-profile-facts { margin: 0; }
.bot-profile-facts div { display: grid; grid-template-columns: 108px minmax(0, 1fr); gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line-soft); }
.bot-profile-facts div:last-child { border-bottom: 0; }
.bot-profile-facts dt, .bot-profile-facts dd { margin: 0; font-size: 0.78rem; }
.bot-profile-facts dt { color: var(--muted); }
.bot-profile-facts dd { min-width: 0; overflow-wrap: anywhere; color: #c9dbe7; }
.bot-profile-facts .bot-rating-value { font-size: 0.96rem; font-weight: 760; font-variant-numeric: tabular-nums; }
.bot-profile-facts .delta-positive { color: var(--green); }
.bot-profile-facts .delta-negative { color: var(--red); }
.bot-profile-facts .delta-neutral { color: #c9dbe7; }
.bot-profile-notes { display: grid; gap: 12px; }
.bot-profile-notes article { padding: 15px 17px; border: 1px solid var(--line-soft); border-radius: 9px; background: rgba(7, 16, 25, 0.48); color: #c9dbe7; font-size: 0.82rem; line-height: 1.55; }
.profile-note-label { margin-bottom: 6px; color: var(--cyan); font-size: 0.68rem; font-weight: 720; letter-spacing: 0.08em; text-transform: uppercase; }
.history-heading { display: flex; align-items: center; justify-content: space-between; padding: 20px 28px 10px; }
.history-columns, .history-game { display: grid; grid-template-columns: 92px minmax(150px, 1.35fr) minmax(125px, 1fr) 62px 126px 78px; align-items: center; gap: 14px; }
.history-columns { padding: 12px 28px; border-bottom: 1px solid var(--line-soft); color: var(--muted); font-size: 0.68rem; font-weight: 650; letter-spacing: 0.05em; text-transform: uppercase; }
.bot-history-body { min-height: 112px; }
.history-game { min-height: 62px; padding: 12px 28px; border-bottom: 1px solid var(--line-soft); font-size: 0.8rem; }
.history-game:hover { background: rgba(72, 216, 255, 0.03); }
.history-result { font-size: 0.72rem; font-weight: 720; }
.outcome-win { color: var(--green); }
.outcome-draw { color: var(--amber); }
.outcome-loss { color: var(--red); }
.history-opponent { min-width: 0; overflow: hidden; color: var(--text); font-weight: 630; text-overflow: ellipsis; white-space: nowrap; }
.history-versus, .history-map, .history-duration, .history-date { color: var(--muted); font-weight: 450; }
.history-duration, .history-date, .history-delta { font-variant-numeric: tabular-nums; }
.history-delta { text-align: right; }

@media (max-width: 1040px) {
  .overview { grid-template-columns: repeat(3, 1fr); }
  .metric-live { grid-column: 1 / -1; }
  .workspace { grid-template-columns: 1fr; }
  .rail { grid-template-columns: 1.2fr 0.8fr; }
}

@media (max-width: 700px) {
  .shell { width: min(100% - 24px, 1480px); }
  .topbar { min-height: 80px; }
  .runner-state span:last-child { display: none; }
  .overview { grid-template-columns: 1fr 1fr; margin-top: 18px; }
  .metric-live { grid-column: 1 / -1; }
  .metric { min-height: 116px; padding: 16px; }
  .overview .metric:nth-child(2) { grid-column: 1 / -1; }
  .panel-heading { align-items: stretch; flex-direction: column; padding: 18px 16px 14px; }
  .filters { width: 100%; }
  .filter { flex: 1; }
  th, td { padding: 12px 11px; }
  .record-col, .games-col { display: none; }
  .rail { grid-template-columns: 1fr; }
  .health-panel { padding: 18px; }
  .bot-history-dialog { padding: 8px; }
  .bot-history-panel { width: 100%; max-height: calc(100vh - 16px); border-radius: 11px; }
  .bot-history-header { min-height: 96px; padding: 19px 18px; }
  .bot-history-scroll { max-height: calc(100vh - 112px); }
  .bot-profile { grid-template-columns: 1fr; gap: 16px; padding: 18px; }
  .bot-profile-facts div { grid-template-columns: 116px minmax(0, 1fr); }
  .history-heading { padding: 18px 18px 8px; }
  .history-columns { display: none; }
  .history-game { grid-template-columns: 1fr auto; gap: 6px 16px; padding: 14px 18px; }
  .history-result { grid-column: 1; grid-row: 1; }
  .history-opponent { grid-column: 1; grid-row: 2; }
  .history-map { grid-column: 1; grid-row: 3; }
  .history-duration { grid-column: 2; grid-row: 3; text-align: right; }
  .history-date { grid-column: 2; grid-row: 2; text-align: right; }
  .history-delta { grid-column: 2; grid-row: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
