:root {
  color-scheme: dark;
  --bg: #050505;
  --panel: #090806;
  --panel-2: #100d08;
  --panel-3: #171006;
  --line: #a85b2d;
  --line-soft: #4b2a17;
  --text: #f2e7cf;
  --muted: #9a7d50;
  --dim: #5d4a32;
  --accent: #ffcc19;
  --accent-2: #f08a22;
  --hot: #ff5e2f;
  --red: #ff6a2f;
  --blue: #ffb02e;
  --green: #f6d76a;
  --yellow: #fff1a6;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(rgba(255, 180, 38, 0.028) 1px, transparent 1px),
    radial-gradient(circle at 18% 0%, rgba(255, 192, 28, 0.12), transparent 34%),
    radial-gradient(circle at 90% 12%, rgba(189, 69, 26, 0.12), transparent 30%),
    var(--bg);
  background-size: 100% 4px, auto, auto, auto;
  color: var(--text);
  font-family: "IBM Plex Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  text-shadow: 0 0 9px rgba(255, 178, 38, 0.12);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 1px solid #f0a329;
  border-radius: 2px;
  background: linear-gradient(180deg, #ffd21e 0%, #f09a21 58%, #8f3c20 100%);
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.65), 0 0 18px rgba(240, 138, 34, 0.14);
  color: #130b02;
  cursor: pointer;
  font-weight: 800;
  min-height: 38px;
  padding: 8px 12px;
  text-transform: uppercase;
}

button:disabled {
  cursor: wait;
  opacity: 0.58;
}

button.copied {
  animation: copiedFlash 900ms ease-out;
  background: linear-gradient(180deg, #fff1a6 0%, #ffcc19 50%, #f08a22 100%);
  border-color: #fff1a6;
  box-shadow:
    0 0 0 2px rgba(255, 241, 166, 0.22),
    0 0 28px rgba(255, 204, 25, 0.42);
  color: #090500;
}

@keyframes copiedFlash {
  0% {
    transform: translateY(0);
  }
  35% {
    transform: translateY(-1px);
  }
  100% {
    transform: translateY(0);
  }
}

button.ghost {
  background: #080604;
  border-color: var(--line);
  box-shadow: inset 0 0 0 1px rgba(255, 205, 25, 0.08);
  color: var(--accent);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-soft);
  border-radius: 2px;
  background: #030303;
  box-shadow: inset 0 0 14px rgba(255, 145, 31, 0.04);
  color: var(--text);
  outline: none;
  padding: 9px 10px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(255, 204, 25, 0.22), inset 0 0 18px rgba(255, 145, 31, 0.08);
}

label {
  color: var(--muted);
  display: grid;
  gap: 7px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

.top-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 18px 18px 0;
}

.tab-button {
  min-width: 150px;
}

.tab-button.active {
  background: linear-gradient(180deg, #ffd21e 0%, #f09a21 58%, #8f3c20 100%);
  color: #130b02;
}

.tab-panel.hidden {
  display: none;
}

.shell {
  display: grid;
  grid-template-columns: minmax(520px, 1fr) 470px;
  gap: 18px;
  min-height: calc(100vh - 56px);
  padding: 18px;
}

.rts-shell {
  display: grid;
  grid-template-columns: minmax(620px, 1fr) 390px;
  gap: 18px;
  min-height: calc(100vh - 56px);
  padding: 18px;
}

.arena-panel,
.control-panel {
  background:
    linear-gradient(180deg, rgba(255, 172, 25, 0.035), transparent 120px),
    color-mix(in srgb, var(--panel) 94%, transparent);
  border: 1px solid var(--line);
  border-radius: 2px;
  box-shadow:
    0 0 0 1px rgba(255, 207, 40, 0.04),
    0 0 36px rgba(255, 108, 20, 0.07),
    inset 0 0 32px rgba(255, 145, 31, 0.035);
}

.arena-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: calc(100vh - 92px);
  overflow: hidden;
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  color: var(--accent);
  font-size: 34px;
  font-weight: 950;
  letter-spacing: 0;
  line-height: 0.9;
  text-shadow:
    0 2px 0 #b95720,
    0 4px 0 #5b2718,
    0 0 24px rgba(255, 204, 25, 0.28);
  text-transform: uppercase;
}

h2 {
  color: var(--accent);
  font-size: 14px;
  text-transform: uppercase;
}

#status {
  color: var(--accent-2);
  margin-top: 4px;
}

.metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.metrics span {
  background: #050403;
  border: 1px solid var(--line);
  border-radius: 2px;
  color: var(--muted);
  min-width: 96px;
  padding: 8px 10px;
  text-transform: uppercase;
}

.metrics strong {
  color: var(--accent);
  display: block;
  font-size: 17px;
}

#arena {
  align-self: center;
  display: block;
  justify-self: center;
  max-height: calc(100vh - 120px);
  max-width: 100%;
  width: min(100%, calc(100vh - 120px));
  border-top: 1px solid rgba(255, 204, 25, 0.06);
}

#rtsArena {
  align-self: center;
  border-top: 1px solid rgba(255, 204, 25, 0.06);
  display: block;
  justify-self: center;
  max-height: calc(100vh - 120px);
  max-width: 100%;
  width: min(100%, calc(100vh - 120px));
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-height: calc(100vh - 92px);
  overflow: auto;
  padding: 16px;
}

.inline {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
}

.grid-fields {
  display: grid;
  grid-template-columns: 1fr 1.5fr;
  gap: 10px;
}

.model-list,
.scoreboard {
  display: grid;
  gap: 8px;
}

.model-row {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 8px;
  align-items: center;
}

.model-row.inactive {
  opacity: 0.38;
}

.buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.speed-control {
  align-items: center;
  background: #060403;
  border: 1px solid var(--line-soft);
  border-radius: 2px;
  display: grid;
  grid-template-columns: auto 1fr 44px;
  gap: 10px;
  padding: 10px;
}

.speed-control label {
  white-space: nowrap;
}

.speed-control input {
  accent-color: var(--accent);
  padding: 0;
}

.speed-control output {
  color: var(--accent);
  font-weight: 800;
  text-align: right;
}

.score-card {
  align-items: center;
  background: #070503;
  border: 1px solid var(--line-soft);
  border-radius: 2px;
  display: grid;
  grid-template-columns: 22px 1fr auto;
  gap: 10px;
  padding: 9px;
}

.swatch {
  border: 1px solid rgba(255, 240, 190, 0.38);
  border-radius: 2px;
  box-shadow: 0 0 10px currentColor;
  height: 14px;
  width: 14px;
}

.score-card strong,
.score-card span {
  display: block;
}

.score-card span {
  color: var(--muted);
  font-size: 12px;
}

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

.section-title p {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.bot-editor-grid {
  display: grid;
  gap: 10px;
}

.bot-editor {
  color: var(--accent);
  display: grid;
  font-size: 12px;
  font-weight: 800;
  gap: 5px;
  letter-spacing: 0.08em;
}

.bot-editor.inactive {
  display: none;
}

.bot-editor textarea {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  min-height: 190px;
  resize: vertical;
}

#log {
  background: #030303;
  border: 1px solid var(--line-soft);
  border-radius: 2px;
  color: var(--muted);
  margin: 0;
  max-height: 190px;
  overflow: auto;
  padding: 10px;
  white-space: pre-wrap;
}

#rtsLog {
  background: #030303;
  border: 1px solid var(--line-soft);
  border-radius: 2px;
  color: var(--muted);
  margin: 0;
  max-height: 420px;
  overflow: auto;
  padding: 10px;
  white-space: pre-wrap;
}

.materials-panel,
.database-panel {
  min-height: calc(100vh - 56px);
  padding: 18px;
}

.materials-header,
.material-card,
.database-card {
  background:
    linear-gradient(180deg, rgba(255, 172, 25, 0.035), transparent 120px),
    color-mix(in srgb, var(--panel) 94%, transparent);
  border: 1px solid var(--line);
  border-radius: 2px;
  box-shadow:
    0 0 0 1px rgba(255, 207, 40, 0.04),
    0 0 36px rgba(255, 108, 20, 0.07),
    inset 0 0 32px rgba(255, 145, 31, 0.035);
}

.materials-header {
  align-items: center;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  padding: 16px 18px;
}

.materials-header p {
  color: var(--accent-2);
  margin-top: 4px;
}

.materials-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.database-toolbar {
  display: flex;
  justify-content: flex-end;
  margin: 0 0 12px;
}

.database-grid {
  display: grid;
  grid-template-columns: minmax(420px, 0.9fr) minmax(520px, 1.1fr);
  gap: 18px;
}

.replays-grid {
  grid-template-columns: 1fr;
}

.material-card {
  display: grid;
  grid-template-rows: auto minmax(460px, 1fr);
  min-height: calc(100vh - 176px);
  padding: 16px;
}

.database-card {
  min-height: calc(100vh - 230px);
  padding: 16px;
}

.replay-library-card {
  min-height: calc(100vh - 230px);
}

.run-list {
  display: grid;
  gap: 8px;
  max-height: calc(100vh - 292px);
  overflow: auto;
}

.run-row {
  align-items: center;
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr minmax(180px, 0.65fr);
  min-height: 64px;
  padding: 10px;
  text-align: left;
  text-transform: none;
}

.run-row strong,
.run-row span {
  display: block;
}

.run-row strong {
  color: var(--accent);
  font-size: 13px;
}

.run-row span {
  color: var(--muted);
  font-size: 11px;
  overflow-wrap: anywhere;
}

.run-score {
  text-align: right;
}

.run-details,
.empty-state {
  background: #030303;
  border: 1px solid var(--line-soft);
  border-radius: 2px;
  color: var(--muted);
  margin: 0;
  padding: 10px;
}

.run-details {
  max-height: calc(100vh - 292px);
  overflow: auto;
  white-space: pre-wrap;
}

.full-runs-grid {
  grid-template-columns: minmax(420px, 0.78fr) minmax(620px, 1.22fr);
}

.leaderboard-card {
  min-height: calc(100vh - 230px);
}

.leaderboard-list {
  max-height: calc(100vh - 292px);
  overflow: auto;
}

.leaderboard-table {
  border-collapse: collapse;
  width: 100%;
}

.leaderboard-table th,
.leaderboard-table td {
  border-bottom: 1px solid var(--line-soft);
  padding: 12px 10px;
  text-align: left;
  vertical-align: top;
}

.leaderboard-table th {
  background: #030303;
  color: var(--accent);
  font-size: 11px;
  position: sticky;
  text-transform: uppercase;
  top: 0;
  z-index: 1;
}

.leaderboard-table td {
  color: var(--text);
  font-size: 13px;
}

.leaderboard-table td:first-child,
.leaderboard-table td:nth-child(3) {
  color: var(--accent);
  font-weight: 900;
}

.leaderboard-table strong,
.leaderboard-table span {
  display: block;
}

.leaderboard-table span {
  color: var(--muted);
  font-size: 11px;
  margin-top: 3px;
  overflow-wrap: anywhere;
}

.pvp-meta {
  background: #030303;
  border: 1px solid var(--line-soft);
  border-radius: 2px;
  color: var(--muted);
  margin-bottom: 10px;
  padding: 10px;
}

.full-run-details {
  display: grid;
  gap: 12px;
}

.full-run-item {
  background: #030303;
  border: 1px solid var(--line-soft);
  border-radius: 2px;
  display: grid;
  gap: 0;
}

.full-run-item.expanded {
  border-color: var(--line);
  box-shadow: inset 0 0 18px rgba(255, 204, 25, 0.05);
}

.full-run-row {
  align-items: stretch;
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr auto;
  padding: 8px;
}

.full-run-select {
  align-items: center;
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr minmax(170px, 0.6fr);
  min-height: 56px;
  padding: 10px;
  text-align: left;
  text-transform: none;
}

.full-run-expand {
  min-width: 98px;
}

.full-run-expanded {
  border-top: 1px solid var(--line-soft);
  display: grid;
  gap: 10px;
  padding: 10px;
}

.score-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.score-chip-row span {
  background: #080604;
  border: 1px solid var(--line-soft);
  border-radius: 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  padding: 6px 8px;
}

.score-chip-row .best-score-chip {
  border-color: var(--accent);
  color: var(--accent);
}

.full-run-summary {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
}

.full-run-summary div,
.full-run-tokenline {
  background: #030303;
  border: 1px solid var(--line-soft);
  border-radius: 2px;
  padding: 10px;
}

.full-run-summary strong,
.full-run-summary span {
  display: block;
}

.full-run-summary strong {
  color: var(--accent);
  font-size: 14px;
}

.full-run-summary span,
.full-run-tokenline {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.full-run-stat-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.full-run-stat-grid span {
  background: #030303;
  border: 1px solid var(--line-soft);
  border-radius: 2px;
  color: var(--muted);
  font-size: 11px;
  padding: 9px;
  text-transform: uppercase;
}

.full-run-stat-grid strong {
  color: var(--accent);
  display: block;
  font-size: 16px;
}

.score-chart {
  background: #030303;
  border: 1px solid var(--line-soft);
  border-radius: 2px;
  display: block;
  height: auto;
  max-width: 100%;
  width: 100%;
}

.score-chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 8px;
}

.score-chart-legend span {
  align-items: center;
  color: var(--muted);
  display: inline-flex;
  font-size: 12px;
  gap: 6px;
}

.score-chart-legend i {
  border-radius: 999px;
  display: inline-block;
  height: 9px;
  width: 18px;
}

.score-chart.compact-chart {
  max-height: 130px;
}

.score-chart .axis {
  stroke: rgba(255, 204, 25, 0.22);
  stroke-width: 1;
}

.score-chart polyline {
  fill: none;
  stroke: var(--accent);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
}

.score-chart circle {
  fill: #030303;
  stroke: var(--accent-2);
  stroke-width: 2;
}

.score-chart .best-point {
  fill: var(--accent);
  stroke: var(--yellow);
}

.score-chart text {
  fill: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.full-run-table {
  border-collapse: collapse;
  width: 100%;
}

.full-run-table th,
.full-run-table td {
  border: 1px solid var(--line-soft);
  padding: 8px;
  text-align: right;
}

.full-run-table th {
  background: #080604;
  color: var(--accent);
  font-size: 11px;
  text-transform: uppercase;
}

.full-run-table td {
  background: #030303;
  color: var(--text);
  font-size: 12px;
}

.full-run-table th:first-child,
.full-run-table td:first-child {
  text-align: left;
}

.full-run-table .best-row td {
  background: rgba(255, 204, 25, 0.08);
  color: var(--accent);
}

.duel-run-table td span {
  color: var(--muted);
  display: block;
  font-size: 11px;
  margin-top: 3px;
}

.empty-state {
  color: var(--accent-2);
}

.replay-list {
  display: grid;
  gap: 10px;
  max-height: calc(100vh - 292px);
  overflow: auto;
}

.replay-item {
  align-items: center;
  background: #030303;
  border: 1px solid var(--line-soft);
  border-radius: 2px;
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr auto;
  padding: 12px;
}

.replay-item.selected {
  border-color: var(--accent);
  box-shadow: inset 0 0 18px rgba(255, 204, 25, 0.07);
}

.replay-item h2 {
  margin-bottom: 6px;
}

.replay-models,
.replay-scoreline {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  margin-top: 6px;
  overflow-wrap: anywhere;
}

.replay-scoreline {
  color: var(--accent-2);
  font-weight: 800;
}

.replay-meta {
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  font-size: 12px;
  gap: 8px;
}

.replay-meta span {
  border: 1px solid var(--line-soft);
  padding: 5px 7px;
}

#llmPrompt,
#diagnosticReport {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  min-height: 460px;
  resize: none;
}

@media (max-width: 1050px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .rts-shell {
    grid-template-columns: 1fr;
  }

  .materials-grid {
    grid-template-columns: 1fr;
  }

  .database-grid {
    grid-template-columns: 1fr;
  }

  .full-runs-grid,
  .full-run-summary,
  .full-run-stat-grid {
    grid-template-columns: 1fr;
  }

  .leaderboard-table {
    min-width: 760px;
  }

  .arena-panel,
  .control-panel {
    min-height: auto;
    max-height: none;
  }
}

@media (max-width: 620px) {
  .shell {
    padding: 10px;
  }

  .rts-shell {
    padding: 10px;
  }

  .top-tabs {
    padding: 10px 10px 0;
  }

  .materials-panel {
    padding: 10px;
  }

  .database-panel {
    padding: 10px;
  }

  .topbar,
  .materials-header,
  .inline,
  .grid-fields,
  .buttons,
  .speed-control,
  .run-row,
  .full-run-row,
  .full-run-select {
    grid-template-columns: 1fr;
  }

  .run-score {
    text-align: left;
  }

  .topbar {
    align-items: stretch;
    display: grid;
  }
}
