:root {
  --bg: #0b131e;
  --panel: #111c2c;
  --panel-alt: #162336;
  --surface: #0e1825;
  --border: #24364e;
  --border-hi: #344c6c;
  --text: #e6eef8;
  --muted: #8ea3be;
  --gold: #e8be59;
  --gold-strong: #f6cf6c;
  --gold-dim: rgba(232, 190, 89, 0.16);
  --blue: #4aa8f5;
  --green: #38c982;
  --red: #f06565;
  --amber: #f59e0b;
  --radius: 8px;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13px;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
}

button,
input,
select {
  font-family: inherit;
  font-size: 12.5px;
  color: var(--text);
}

button {
  cursor: pointer;
  border: 1px solid var(--border-hi);
  background: var(--panel-alt);
  border-radius: 6px;
  padding: 6px 11px;
  transition: background 0.12s, border-color 0.12s, transform 0.05s;
}

button:hover:not(:disabled) {
  background: #1f3149;
  border-color: var(--gold);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(180deg, #e9c260, #c8962e);
  color: #0b131e;
  border-color: #f6d57a;
  font-weight: 700;
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(180deg, #f3cf6e, #d6a33a);
  color: #0b131e;
}

.btn-danger {
  background: rgba(240, 101, 101, 0.18);
  border-color: var(--red);
  color: #fca5a5;
  font-weight: 600;
}

.btn-danger:hover:not(:disabled) {
  background: rgba(240, 101, 101, 0.32);
}

.btn-sm {
  padding: 4px 8px;
  font-size: 11.5px;
}

input[type="text"],
input[type="number"],
select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 5px 7px;
  width: 100%;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--gold);
}

/* ---------- Top Navigation Bar ---------- */

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--gold);
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.nav-tabs {
  display: flex;
  gap: 4px;
  background: var(--surface);
  padding: 3px;
  border-radius: 7px;
  border: 1px solid var(--border);
}

.nav-tab {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 5px 11px;
  border-radius: 5px;
  font-weight: 600;
}

.nav-tab.active {
  background: var(--gold-dim);
  color: var(--gold-strong);
  border: 1px solid rgba(232, 190, 89, 0.35);
}

.asset-menu-wrap {
  position: relative;
}

.asset-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.asset-pill.needs-assets {
  border-color: rgba(232, 190, 89, 0.65);
  background: rgba(232, 190, 89, 0.1);
  color: var(--gold-strong);
}

.pill-caret {
  font-size: 10px;
  color: var(--muted);
  margin-left: 1px;
}

.asset-popover {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 270px;
  background: var(--panel);
  border: 1px solid var(--border-hi);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
  z-index: 50;
}

.asset-popover-status {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-bottom: 10px;
  font-size: 12px;
  color: var(--muted);
}

.asset-popover-status strong {
  color: var(--text);
}

.asset-popover-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.asset-popover-actions button:first-child {
  grid-column: span 2;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}

.dot.ok {
  background: var(--green);
  box-shadow: 0 0 8px rgba(56, 201, 130, 0.7);
}

.dot.busy {
  background: var(--amber);
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.7);
}

.dot.err {
  background: var(--red);
}

/* ---------- Main View Container ---------- */

#main-views {
  flex: 1;
  min-height: 0;
  position: relative;
}

.tool-view {
  display: none;
  height: 100%;
  width: 100%;
}

.tool-view.active {
  display: flex;
}

/* ---------- Shared Panels & Layout ---------- */

.sidebar {
  width: 320px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-right {
  width: 340px;
  flex-shrink: 0;
  background: var(--panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.scroll-area {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px;
  min-height: 0;
}

.center-stage {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

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

.section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--gold);
  font-weight: 700;
  margin: 0 0 8px 0;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.field.span-2 {
  grid-column: span 2;
}

.field > span {
  font-size: 11px;
  color: var(--muted);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  cursor: pointer;
}

.preset-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.preset-chip {
  font-size: 11.5px;
  padding: 4px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 5px;
}

.preset-chip.active {
  border-color: var(--gold);
  background: var(--gold-dim);
  color: var(--gold-strong);
}

/* ---------- Map Canvas Stage ---------- */

.canvas-wrap {
  position: relative;
  flex: 1;
  min-height: 240px;
  overflow: hidden;
}

.canvas-wrap canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
}

.canvas-wrap canvas:active {
  cursor: grabbing;
}

.tile-hud {
  position: absolute;
  left: 10px;
  bottom: 10px;
  background: rgba(11, 19, 30, 0.9);
  border: 1px solid var(--border-hi);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  pointer-events: none;
  max-width: 440px;
}

/* ---------- Result List & Cards ---------- */

.result-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 9px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}

.result-item:hover {
  border-color: var(--border-hi);
  background: var(--panel-alt);
}

.result-item.active {
  border-color: var(--gold);
  background: rgba(232, 190, 89, 0.1);
}

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

.score-badge {
  background: var(--gold-dim);
  color: var(--gold-strong);
  border: 1px solid rgba(232, 190, 89, 0.4);
  border-radius: 5px;
  padding: 1px 6px;
  font-weight: 700;
  font-family: var(--font-mono);
  font-size: 11.5px;
}

.badge-ok {
  background: rgba(56, 201, 130, 0.16);
  color: var(--green);
  border: 1px solid rgba(56, 201, 130, 0.4);
  padding: 2px 7px;
  border-radius: 5px;
  font-weight: 700;
  font-size: 11.5px;
}

.badge-warn {
  background: rgba(245, 158, 11, 0.16);
  color: var(--amber);
  border: 1px solid rgba(245, 158, 11, 0.4);
  padding: 2px 7px;
  border-radius: 5px;
  font-weight: 700;
  font-size: 11.5px;
}

.badge-err {
  background: rgba(240, 101, 101, 0.18);
  color: #fca5a5;
  border: 1px solid rgba(240, 101, 101, 0.45);
  padding: 2px 7px;
  border-radius: 5px;
  font-weight: 700;
  font-size: 11.5px;
}

.meta-line {
  font-size: 11.5px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.mono {
  font-family: var(--font-mono);
}

/* ---------- Drop Zone ---------- */

.drop-zone {
  border: 2px dashed var(--border-hi);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  margin-bottom: 10px;
  transition: border-color 0.15s, background 0.15s;
}

.drop-zone.dragover,
.drop-zone:hover {
  border-color: var(--gold);
  background: rgba(232, 190, 89, 0.08);
  color: var(--text);
}

/* ---------- Tables & Code Output ---------- */

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

table.data-table th,
table.data-table td {
  text-align: left;
  padding: 5px 7px;
  border-bottom: 1px solid var(--border);
}

table.data-table th {
  color: var(--muted);
  font-weight: 600;
  position: sticky;
  top: 0;
  background: var(--panel);
}

pre.log-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 360px;
  overflow: auto;
  margin: 0;
}

iframe.replay-frame {
  flex: 1;
  width: 100%;
  height: 100%;
  border: none;
  background: #08121c;
}

.sub-tabs {
  display: flex;
  gap: 5px;
  padding: 6px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.sub-tab {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 4px 10px;
  font-size: 12px;
}

.sub-tab.active {
  background: var(--panel-alt);
  border-color: var(--border-hi);
  color: var(--gold-strong);
}

#toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  background: var(--panel-alt);
  border: 1px solid var(--gold);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 7px;
  font-size: 12.5px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  z-index: 100;
}

.progress-strip {
  height: 3px;
  background: var(--surface);
  width: 100%;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--gold), var(--blue));
  transition: width 0.15s;
}

.kv-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 10px;
  font-size: 12px;
}

.kv-grid dt {
  color: var(--muted);
}

.kv-grid dd {
  margin: 0;
  font-family: var(--font-mono);
  word-break: break-word;
}

.setup-card {
  background: var(--surface);
  border: 1px solid rgba(232, 190, 89, 0.3);
  border-radius: var(--radius);
  padding: 9px 10px;
  margin-bottom: 10px;
}

.setup-card .kv-grid {
  margin: 0;
}

.seed-highlight {
  color: var(--gold-strong);
  font-weight: 700;
}

/* ==================== RL TRAINING DASHBOARD ==================== */

.rl-view {
  overflow-y: auto;
  display: none;
  flex: 1;
}

.rl-view.active {
  display: block;
}

.rl-shell {
  max-width: 1460px;
  margin: 0 auto;
  padding: 16px 20px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.rl-header-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
}

.rl-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.rl-run-select {
  min-width: 260px;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border-hi);
  border-radius: 6px;
  padding: 5px 9px;
}

.rl-live-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  border: 1px solid var(--border-hi);
  background: var(--surface);
}

.rl-live-pill .rl-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.rl-live-pill.live {
  border-color: rgba(56, 201, 130, 0.55);
  background: rgba(56, 201, 130, 0.14);
  color: #6ee7b7;
}

.rl-live-pill.live .rl-dot {
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
  animation: rl-pulse 1.5s infinite;
}

.rl-live-pill.done {
  border-color: rgba(74, 168, 245, 0.45);
  background: rgba(74, 168, 245, 0.12);
  color: #93c5fd;
}

.rl-live-pill.done .rl-dot {
  background: var(--blue);
}

@keyframes rl-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.85); }
}

.rl-heartbeat-line {
  font-size: 11.5px;
  color: var(--muted);
}

.rl-progress-bar {
  height: 4px;
  background: var(--panel);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.rl-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--gold), var(--green));
  transition: width 0.35s ease;
}

.rl-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 10px;
}

.rl-kpi {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 13px;
}

.rl-kpi.good {
  border-color: rgba(56, 201, 130, 0.5);
}

.rl-kpi-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.rl-kpi-val {
  font-size: 20px;
  font-weight: 700;
  margin-top: 3px;
  color: var(--text);
}

.rl-kpi-sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 3px;
}

.rl-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.rl-bottom-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

@media (max-width: 1040px) {
  .rl-grid,
  .rl-bottom-grid {
    grid-template-columns: 1fr;
  }
}

.rl-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rl-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 11.5px;
  color: var(--muted);
  margin-bottom: 4px;
}

.rl-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.rl-legend-item i {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 2px;
}

.rl-legend-item strong {
  color: var(--text);
  font-family: var(--font-mono);
}

.rl-svg {
  width: 100%;
  height: auto;
  display: block;
}

.rl-chart-empty {
  color: var(--muted);
  font-size: 12px;
  padding: 24px 8px;
  text-align: center;
}

.rl-artifact-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
  max-height: 310px;
  overflow-y: auto;
}

.rl-artifact-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
}

.rl-artifact-row.best {
  border-color: rgba(232, 190, 89, 0.55);
  background: rgba(232, 190, 89, 0.08);
}

.rl-artifact-title {
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

.rl-artifact-meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.rl-badge-gold {
  font-size: 10px;
  font-weight: 800;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--gold);
  color: #0b131e;
}

.rl-dl-btn {
  display: inline-flex;
  align-items: center;
  padding: 4px 9px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 600;
  text-decoration: none;
  color: var(--text);
  background: var(--panel-alt);
  border: 1px solid var(--border-hi);
  white-space: nowrap;
}

.rl-dl-btn:hover {
  border-color: var(--gold);
  color: var(--gold-strong);
}

.rl-phase-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-height: 310px;
  overflow-y: auto;
}

.rl-phase-row {
  display: grid;
  grid-template-columns: 104px 1fr 78px;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
}

.rl-phase-name {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rl-phase-bar {
  height: 7px;
  background: var(--surface);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.rl-phase-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--blue), var(--gold));
}

.rl-phase-val {
  text-align: right;
  font-size: 11px;
  color: var(--text);
}

.rl-phase-val small {
  color: var(--muted);
}

.rl-modal {
  position: fixed;
  inset: 0;
  background: rgba(6, 10, 18, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 200;
}

.rl-modal[hidden] {
  display: none;
}

.rl-modal-dialog {
  width: min(1280px, 95vw);
  height: min(860px, 92vh);
  background: var(--panel);
  border: 1px solid var(--border-hi);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.rl-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-alt);
}

.rl-modal-frame {
  flex: 1;
  width: 100%;
  border: 0;
  background: #0b131e;
}

.unlock-modal-dialog {
  width: min(440px, 94vw);
  background: var(--panel);
  border: 1px solid var(--border-hi);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.55);
}

.unlock-modal-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.unlock-modal-desc {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--muted);
}

.unlock-modal-status {
  min-height: 18px;
  font-size: 12px;
  color: var(--muted);
}

.unlock-modal-status.err {
  color: #f87171;
}

.unlock-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 2px;
}
