:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #f3f6fa;
  --panel: #ffffff;
  --text: #172234;
  --muted: #5d6878;
  --border: #d6dee8;
  --accent: #1557a6;
  --accent-weak: #e9f2ff;
  --success: #0f766e;
  --danger: #b42318;
  --shadow: 0 1px 2px rgba(17, 24, 39, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

.shell {
  max-width: 980px;
  margin: 0 auto;
  padding: 14px;
}

.app-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
  margin: 4px 0 12px;
}

h1, h2, p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.2;
}

h2 {
  font-size: 17px;
  line-height: 1.35;
}

.app-header p,
.report-header p,
#statusSummary {
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.5;
  font-size: 14px;
}

.status-chip {
  min-width: 88px;
  text-align: center;
  border-radius: 999px;
  padding: 8px 12px;
  border: 1px solid #bfe6d8;
  background: #e8f7ef;
  color: var(--success);
  font-weight: 700;
  white-space: nowrap;
}

.status-chip[data-state="running"],
.status-chip[data-state="sending"],
.status-chip[data-state="queued"] {
  border-color: #cfe0ff;
  background: var(--accent-weak);
  color: var(--accent);
}

.status-chip[data-state="failure"],
.status-chip[data-state="statusError"] {
  border-color: #ffd0c8;
  background: #fff0ed;
  color: var(--danger);
}

.control-panel,
.status-panel,
.report-panel,
.debug-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  margin: 12px 0;
  padding: 14px;
}

.form-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr);
  gap: 12px;
}

label,
.field-label {
  display: block;
  font-size: 13px;
  font-weight: 700;
}

label span,
.field-label {
  margin-bottom: 6px;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  background: #fff;
  color: var(--text);
  font-size: 16px;
}

.field-block {
  margin-top: 12px;
}

.race-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}

.race-button {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-weight: 700;
  padding: 8px;
}

.race-button[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.mode-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 8px;
  align-items: start;
  min-height: 84px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.mode-card input {
  width: 18px;
  min-height: 18px;
  margin: 2px 0 0;
}

.mode-card span {
  font-size: 14px;
  font-weight: 800;
}

.mode-card small {
  grid-column: 2;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.actions,
.report-header,
.status-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.actions {
  justify-content: flex-start;
  flex-wrap: wrap;
  margin-top: 14px;
}

button,
a.secondary,
.run-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 9px 12px;
  font-size: 14px;
  font-weight: 800;
  text-decoration: none;
}

button {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

button.secondary,
a.secondary,
.run-link {
  background: var(--accent-weak);
  color: var(--accent);
  border-color: #cfe0ff;
}

.run-link[hidden] {
  display: none;
}

.progress-box {
  margin-top: 10px;
}

.progress-track {
  width: min(360px, 100%);
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #edf2f7;
  border: 1px solid var(--border);
}

#progressFill {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 220ms ease;
}

#progressText,
#reportState {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.report-panel {
  padding: 0;
  overflow: hidden;
}

.report-header {
  padding: 14px;
  border-bottom: 1px solid var(--border);
}

#reportFrame {
  display: block;
  width: 100%;
  height: min(72vh, 760px);
  border: 0;
  background: #fff;
}

.debug-panel summary {
  cursor: pointer;
  font-weight: 800;
}

pre {
  margin: 12px 0 0;
  padding: 12px;
  border-radius: 8px;
  background: #111827;
  color: #fff;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
}

@media (max-width: 720px) {
  .shell {
    padding: 10px;
  }

  .app-header,
  .status-panel,
  .report-header {
    align-items: stretch;
    flex-direction: column;
  }

  .form-row,
  .mode-grid {
    grid-template-columns: 1fr;
  }

  .race-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .actions > * {
    flex: 1 1 160px;
  }

  #reportFrame {
    height: 68vh;
  }
}
