:root {
  color-scheme: dark;
}

body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  padding: 16px;
  background: #111827;
  color: #e5e7eb;
  line-height: 1.5;
}

.row {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
  align-items: end;
}

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 14px;
}

select,
input,
button {
  padding: 8px;
  border-radius: 6px;
  border: 1px solid #374151;
  background: #1f2937;
  color: #e5e7eb;
}

button {
  cursor: pointer;
}

.secondary-toggle-btn {
  align-self: end;
  background: #111827;
  border-color: #475569;
  color: #cbd5e1;
}


.field-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.field-help {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: #1f2937;
  color: #cbd5f5;
  font-size: 11px;
  font-weight: 700;
  cursor: help;
  position: relative;
}

.field-help::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 140%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 32, 0.96);
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 11px;
  color: #e6edf3;
  line-height: 1.35;
  white-space: pre-line;
  width: 300px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  z-index: 20;
}

.field-help:hover::after,
.field-help:focus-visible::after {
  opacity: 1;
}


.sim-progress {
  min-width: 240px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sim-progress-bar {
  width: 100%;
  height: 10px;
  border: 1px solid #334155;
  border-radius: 999px;
  background: #0f172a;
  overflow: hidden;
}

.sim-progress-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #22c55e, #eab308 65%, #ef4444);
  transition: width 120ms linear;
}
#status {
  margin: 8px 0;
  min-height: 20px;
}

.error {
  color: #fca5a5;
}

.panel {
  margin-top: 12px;
  border: 1px solid #374151;
  border-radius: 8px;
  padding: 12px;
  background: #0b1220;
}

.panel.is-collapsed {
  display: none;
}

.panel h3 {
  margin: 0 0 10px;
}

.warning-stack {
  display: grid;
  gap: 8px;
  margin: 6px 0 12px;
}

.warning-box,
.variability-box {
  border-radius: 8px;
  padding: 10px;
  white-space: pre-wrap;
}

.warning-box {
  border: 1px solid #7f1d1d;
  background: #450a0a;
}

.variability-box {
  border: 1px solid #1e3a8a;
  background: #172554;
}

.tab-row {
  display: flex;
  gap: 8px;
  margin-top: 6px;
  margin-bottom: 14px;
}

.tab-btn {
  font-size: 14px;
  font-weight: 600;
  padding: 8px 12px;
}

.tower-tab-row .tab-btn {
  font-size: 14px;
  font-weight: 600;
  padding: 8px 12px;
}

.tab-btn.active {
  border-color: #60a5fa;
  background: #1e3a8a;
}

.kpi-grid-core {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
}

.kpi-card {
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 10px;
  background: #020617;
}

.kpi-title {
  font-size: 13px;
  color: #93c5fd;
  margin-bottom: 6px;
}

.metric-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.metric-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 3px 0;
}

.metric-label,
.metric-value {
  white-space: nowrap;
}

.metric-dots {
  flex: 1;
  border-bottom: 1px dotted #64748b;
  transform: translateY(-3px);
}

.metric-child {
  margin-left: 16px;
  font-size: 0.9em;
  color: #94a3b8;
}

.metric-subtitle {
  margin-top: 10px;
  margin-bottom: 4px;
  color: #cbd5e1;
  font-size: 0.92rem;
}

details.panel {
  padding-top: 0;
}

details > summary {
  cursor: pointer;
  padding: 12px;
  margin: 0 -12px;
  list-style: none;
  font-weight: 600;
}

details > summary::-webkit-details-marker {
  display: none;
}

details > summary::after {
  content: '▸';
  float: right;
}

details[open] > summary::after {
  content: '▾';
}

#gallery {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: visible;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 8px;
}

.run-section {
  border: 1px solid #374151;
  border-radius: 6px;
  padding: 8px;
  background: #0f172a;
}

.run-title {
  margin-bottom: 8px;
}

.run-replay-mode {
  color: #fbbf24;
  font-weight: 700;
}

.run-replay-mode--warn {
  color: #fca5a5;
}


.run-outcome-win {
  color: #22c55e;
  font-weight: 700;
}

.run-outcome-loss {
  color: #ef4444;
  font-weight: 700;
}

.run-frames {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 8px;
}

.gallery-shot {
  min-width: 0;
}

.gallery-shot-title {
  margin-top: 4px;
  font-size: 12px;
}

.gallery-thumb {
  width: 100%;
  border-radius: 4px;
  border: 1px solid #334155;
  cursor: pointer;
  display: block;
  background: #0b1220;
}

.missing-shot {
  color: #64748b;
  text-align: center;
  border: 1px dashed #334155;
  border-radius: 4px;
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.viewer.hidden {
  display: none;
}

.viewer {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.92);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.viewer-inner {
  max-width: min(96vw, 1300px);
  max-height: 94vh;
  width: 100%;
  background: #020617;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 12px;
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 12px;
}

.viewer-main {
  position: relative;
  min-height: 420px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.viewer-main img {
  max-width: 100%;
  max-height: 78vh;
  border: 1px solid #334155;
  border-radius: 6px;
}

.viewer-controls {
  position: absolute;
  inset-inline: 8px;
  display: flex;
  justify-content: space-between;
}

.viewer-nav-btn {
  width: 40px;
  height: 40px;
  font-size: 20px;
}

.viewer-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.viewer-caption {
  margin-top: 8px;
  font-size: 13px;
  color: #cbd5e1;
}

.viewer-legend-note {
  margin-bottom: 8px;
  padding: 8px;
  border: 1px solid #334155;
  border-radius: 6px;
  background: #0f172a;
  color: #cbd5e1;
  font-size: 12px;
  line-height: 1.4;
}

.viewer-legend-note--warn {
  border-color: #7f1d1d;
  background: rgba(127, 29, 29, 0.24);
  color: #fecaca;
}

.viewer-legend-row {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  margin-bottom: 6px;
}

.viewer-legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  display: inline-block;
}

.viewer-legend-label {
  color: #cbd5e1;
  font-size: 13px;
  line-height: 1.25;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
}

#lastRunLog {
  max-height: 420px;
  overflow: auto;
  border: 1px solid #374151;
  border-radius: 6px;
  padding: 8px;
}

#debugPanel {
  display: none;
}

.build-timeline-panel {
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 10px;
  background: #020617;
}

.timeline-title {
  margin-bottom: 8px;
  color: #cbd5e1;
  font-size: 0.95rem;
}

.timeline-chart {
  width: 100%;
  height: auto;
  background: #0b1220;
  border: 1px solid #1f2937;
  border-radius: 6px;
}

.timeline-axis {
  stroke: #64748b;
  stroke-width: 1;
}

.timeline-axis-text {
  fill: #94a3b8;
  font-size: 11px;
}

.timeline-legend-item i {
  width: 10px;
  height: 10px;
  display: inline-block;
  border-radius: 50%;
}

.timeline-empty {
  color: #94a3b8;
}

.timeline-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.timeline-controls label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #cbd5e1;
  font-size: 12px;
}

.timeline-ignore-range {
  width: 180px;
}

.timeline-ignore-input {
  width: 72px;
}

.timeline-mode-select {
  min-width: 210px;
  border: 1px solid #334155;
  border-radius: 6px;
  background: #0b1220;
  color: #cbd5e1;
  padding: 4px 8px;
}

.timeline-reset-zoom {
  border: 1px solid #334155;
  border-radius: 6px;
  background: #0b1220;
  color: #cbd5e1;
  padding: 4px 10px;
}

.timeline-reset-zoom:disabled {
  opacity: 0.5;
}

.timeline-canvas-wrap {
  position: relative;
  border: 1px solid #1f2937;
  border-radius: 6px;
  background: #0b1220;
  overflow: hidden;
  height: clamp(300px, 44vh, 520px);
}

.timeline-content-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
  gap: 10px;
  align-items: stretch;
}

@media (max-width: 980px) {
  .timeline-content-layout {
    grid-template-columns: 1fr;
  }
}

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

.timeline-tooltip {
  position: absolute;
  z-index: 2;
  max-width: 210px;
  border: 1px solid #334155;
  border-radius: 6px;
  background: rgba(2, 6, 23, 0.96);
  color: #e2e8f0;
  font-size: 12px;
  line-height: 1.35;
  padding: 8px;
  pointer-events: none;
}

.timeline-tooltip.hidden {
  display: none;
}

.timeline-pie-panel {
  border: 1px solid #1f2937;
  border-radius: 6px;
  background: #0b1220;
  padding: 10px;
  height: clamp(300px, 44vh, 520px);
  display: flex;
  flex-direction: column;
}

.timeline-bars-canvas {
  width: 100%;
  height: 100%;
}

.timeline-pie-title {
  color: #cbd5e1;
  font-size: 12px;
  margin-bottom: 8px;
}

.timeline-pie-chart {
  width: 132px;
  aspect-ratio: 1;
  border-radius: 50%;
  margin: 0 auto;
  border: 1px solid #334155;
}

.timeline-pie-total {
  margin-top: 8px;
  color: #94a3b8;
  font-size: 11px;
}

.timeline-pie-legend {
  margin-top: 8px;
  display: grid;
  gap: 4px;
  max-height: 120px;
  overflow: auto;
}

.timeline-values-grid {
  max-height: 180px;
}

.timeline-pie-legend-row {
  display: grid;
  grid-template-columns: minmax(48px, auto) minmax(72px, auto) minmax(88px, auto) auto;
  gap: 6px;
  align-items: center;
  color: #cbd5e1;
  font-size: 12px;
}

.timeline-metric-caption {
  margin-top: 6px;
}

.timeline-pie-empty {
  color: #94a3b8;
  font-size: 12px;
}

.timeline-legend {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 98px;
  overflow: auto;
}

.timeline-legend-item {
  border: 1px solid #334155;
  border-radius: 999px;
  background: #0b1220;
  color: #cbd5e1;
  padding: 3px 8px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  cursor: pointer;
}

.timeline-legend-item.is-muted {
  opacity: 0.45;
}

.panel.panel--charts {
  margin-top: 0;
  margin-bottom: 12px;
}


#mergeXrayPanel {
  display: grid;
  gap: 10px;
  margin-bottom: 10px;
}

.xray-table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid #334155;
  background: #0b1220;
}

.xray-table th,
.xray-table td {
  border: 1px solid #334155;
  padding: 6px 8px;
  text-align: left;
  font-size: 12px;
}

.xray-table thead th {
  background: #111827;
  color: #cbd5e1;
}
