:root {
  --bg-0: #06080d;
  --bg-1: #0a0d14;
  --bg-2: #11151f;
  --bg-3: #1a2030;
  --line: rgba(255, 255, 255, 0.08);
  --text: #e6ecf5;
  --text-dim: #8b95a8;
  --accent: #6ee7ff;
  --accent-2: #a16bff;
  --danger: #ff4d6d;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(ellipse at top, #0c1322 0%, var(--bg-0) 60%);
  color: var(--text);
  min-height: 100vh;
  overflow: hidden;
}

body {
  display: grid;
  grid-template-columns: 320px 1fr 360px;
  grid-template-rows: 56px 1fr 200px;
  grid-template-areas:
    "header header header"
    "sidebar stage rightbar"
    "sidebar stage rightbar";
  height: 100vh;
  gap: 1px;
  background: var(--line);
}

header.app-header {
  grid-area: header;
  background: var(--bg-1);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 18px;
  border-bottom: 1px solid var(--line);
}

.brand {
  font-weight: 800;
  font-size: 18px;
  letter-spacing: 2px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-transform: uppercase;
}

.brand-sub {
  color: var(--text-dim);
  font-size: 12px;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.header-spacer {
  flex: 1;
}

.tick-pill {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  background: var(--bg-3);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  color: var(--text-dim);
}

aside.sidebar {
  grid-area: sidebar;
  background: var(--bg-1);
  padding: 18px;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

main.stage {
  grid-area: stage;
  background: var(--bg-0);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#game-canvas {
  display: block;
  border-radius: 6px;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.06),
    0 0 80px rgba(110, 231, 255, 0.08);
  cursor: crosshair;
  background: #06080d;
  image-rendering: pixelated;
}

.stage-overlay {
  position: absolute;
  top: 14px;
  left: 14px;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 1px;
  text-transform: uppercase;
}

.stage-overlay .mode-name {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 3px;
  color: var(--text);
}

aside.rightbar {
  grid-area: rightbar;
  background: var(--bg-1);
  padding: 18px;
  overflow-y: auto;
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.section-title {
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 6px;
  font-weight: 700;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn {
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s;
  font-weight: 600;
}

.btn:hover {
  background: var(--bg-2);
  border-color: var(--accent);
  color: var(--accent);
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #000;
  border-color: transparent;
}

.btn.primary:hover {
  filter: brightness(1.1);
  color: #000;
}

.btn-mini {
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 11px;
  margin-top: 6px;
}

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

.slider-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
}

.slider-row .label {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  color: var(--text-dim);
  min-width: 32px;
  text-align: right;
}

select.dropdown {
  width: 100%;
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  font-size: 13px;
  cursor: pointer;
}

.toggles {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
}

.toggles label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: var(--text-dim);
}

.toggles input[type="checkbox"] {
  accent-color: var(--accent);
}

#mode-description {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
  font-style: italic;
}

.player-row {
  background: var(--player-bg, var(--bg-2));
  border-left: 3px solid var(--player-color, var(--accent));
  border-radius: 4px;
  padding: 10px 12px;
  margin-bottom: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.strat-tooltip {
  position: fixed;
  width: 300px;
  max-height: 360px;
  overflow-y: auto;
  background: var(--bg-1);
  color: var(--text);
  border: 1px solid var(--line);
  border-left: 3px solid var(--player-color, var(--accent));
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.5;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  z-index: 1000;
}

.strat-tooltip-title {
  font-weight: 700;
  font-size: 13px;
  color: var(--player-color, var(--accent));
  margin-bottom: 6px;
  letter-spacing: 0.3px;
}

.strat-tooltip-body {
  color: var(--text-dim);
  white-space: pre-wrap;
}

.player-head {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
}

.player-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  box-shadow: 0 0 8px currentColor;
}

.player-name {
  font-weight: 700;
  flex: 1;
}

.player-stat {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
  color: var(--text-dim);
}

.player-stat b {
  color: var(--text);
  font-weight: 600;
}

.strat-select {
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 4px 6px;
  font-size: 11px;
  cursor: pointer;
}

.strength-bar {
  height: 4px;
  background: var(--bg-3);
  border-radius: 2px;
  overflow: hidden;
}

.strength-fill {
  height: 100%;
  width: 0;
  transition: width 0.3s ease-out;
}

#chart-wrap {
  grid-area: rightbar;
}

#chart-canvas {
  width: 100%;
  height: 140px;
  display: block;
  border-radius: 6px;
  background: var(--bg-1);
}

.event-log {
  background: var(--bg-2);
  border-radius: 6px;
  padding: 8px;
  max-height: 160px;
  overflow-y: auto;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
}

.log-entry {
  padding: 2px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.hud-empty {
  color: var(--text-dim);
  font-style: italic;
  font-size: 12px;
}

.kbd {
  font-family: ui-monospace, monospace;
  font-size: 10px;
  background: var(--bg-3);
  padding: 1px 5px;
  border-radius: 3px;
  color: var(--text-dim);
  border: 1px solid var(--line);
}

.legend {
  font-size: 11px;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.match-picker-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.match-picker {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 280px;
  overflow-y: auto;
  background: var(--bg-2);
  border-radius: 6px;
  padding: 6px;
}

.match-row {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 6px 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
  transition: border-color 0.12s, background 0.12s;
}

.match-row:hover {
  border-color: var(--accent);
}

.match-row.active {
  border-color: var(--accent-2);
  background: rgba(161, 107, 255, 0.12);
}

.match-row-head {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  color: var(--text-dim);
}

.match-id {
  color: var(--text);
  font-weight: 700;
}

.match-flag {
  font-size: 9px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 1px 5px;
  color: var(--text);
}

.match-flag[data-tag="close-finish"] { color: #6ee7ff; border-color: rgba(110, 231, 255, 0.4); }
.match-flag[data-tag="runaway"] { color: #ff4d6d; border-color: rgba(255, 77, 109, 0.4); }
.match-flag[data-tag="mutual-destruction"] { color: #f97aff; border-color: rgba(249, 122, 255, 0.4); }

.match-lineup {
  font-size: 10px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.league-viewer {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.league-card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.league-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.league-map {
  font-weight: 700;
  font-size: 13px;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.league-meta {
  font-size: 10px;
  color: var(--text-dim);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}

.tier-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
}

.tier-tab {
  font-size: 10px;
  padding: 3px 6px;
  background: var(--bg-3);
  color: var(--text-dim);
  border: 1px solid var(--line);
  border-radius: 3px;
  cursor: pointer;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  transition: all 0.12s;
}

.tier-tab:hover {
  border-color: var(--accent);
  color: var(--text);
}

.tier-tab.active {
  background: var(--accent-2);
  color: #000;
  border-color: var(--accent-2);
}

.tier-list {
  margin: 0;
  padding-left: 24px;
  font-size: 11px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  color: var(--text);
  list-style: decimal;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px 8px;
}

.tier-list li {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-watch {
  font-size: 12px;
  padding: 6px;
  text-align: center;
}

@media (max-width: 1100px) {
  body {
    grid-template-columns: 1fr;
    grid-template-rows: 56px 1fr auto auto;
    grid-template-areas:
      "header"
      "stage"
      "sidebar"
      "rightbar";
    overflow: auto;
    height: auto;
  }
}
