:root {
  color-scheme: light;
  --bg: #f6f3ec;
  --panel: #fffdf8;
  --ink: #1f2933;
  --muted: #607080;
  --line: #d9ded7;
  --accent: #0f766e;
  --accent-dark: #0b4f4a;
  --orange: #d97706;
  --red: #c2410c;
  --blue: #2563eb;
  --green-soft: #e7f5ef;
  --orange-soft: #fff4df;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.page-shell {
  width: min(1240px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 42px;
}

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

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 10px;
  font-size: 34px;
  line-height: 1.15;
}

h2 {
  margin-bottom: 14px;
  font-size: 20px;
}

h3 {
  margin-bottom: 10px;
  font-size: 15px;
}

.lead {
  max-width: 720px;
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.7;
}

.top-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.top-actions a,
button {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 14px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

button.secondary {
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

.control-panel,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.control-panel {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr 0.8fr auto;
  gap: 14px;
  align-items: end;
  margin: 20px 0;
  padding: 16px;
}

.field,
.param-grid label {
  display: grid;
  gap: 6px;
}

label,
.field label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  background: #fff;
  color: var(--ink);
}

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

.layout-grid {
  display: grid;
  grid-template-columns: minmax(260px, 320px) 1fr;
  gap: 20px;
}

.panel {
  padding: 18px;
}

.panel-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.panel-heading span,
#runMeta,
#curveMeta {
  color: var(--muted);
  font-size: 13px;
}

.param-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.level-note {
  margin-top: 14px;
  border-left: 4px solid var(--accent);
  padding: 10px 12px;
  background: var(--green-soft);
  color: var(--accent-dark);
  line-height: 1.65;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.metric {
  min-height: 84px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.metric strong {
  display: block;
  margin-bottom: 6px;
  font-size: 24px;
}

.metric span {
  color: var(--muted);
  font-size: 13px;
}

.two-column {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 16px;
}

.timeline {
  display: grid;
  gap: 8px;
  max-height: 312px;
  overflow: auto;
  padding-right: 4px;
}

.timeline-row {
  display: grid;
  grid-template-columns: 56px 1fr 72px;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}

.timeline-bar {
  height: 10px;
  border-radius: 999px;
  background: #eef2f4;
  overflow: hidden;
}

.timeline-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--blue), var(--accent));
}

.diagnosis {
  display: grid;
  gap: 10px;
  color: var(--muted);
  line-height: 1.7;
}

.diagnosis strong {
  color: var(--ink);
}

.curve-panel,
.replay-panel,
.table-panel {
  margin-top: 20px;
}

.chart {
  min-height: 330px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

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

.chart text {
  fill: var(--muted);
  font-size: 12px;
}

.curve-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.summary-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
  color: var(--muted);
  line-height: 1.5;
}

.summary-item strong {
  display: block;
  color: var(--ink);
  font-size: 18px;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 13px;
}

.badge {
  display: inline-flex;
  border-radius: 999px;
  padding: 3px 8px;
  background: var(--orange-soft);
  color: var(--red);
  font-size: 12px;
  font-weight: 700;
}

.loading {
  padding: 20px;
  color: var(--muted);
}

.replay-layout {
  display: grid;
  grid-template-columns: minmax(260px, 320px) 1fr;
  gap: 20px;
  align-items: start;
}

.replay-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  justify-content: stretch;
}

.replay-actions button {
  width: 100%;
}

.replay-step-text {
  margin: 12px 0;
  border-left: 4px solid var(--orange);
  padding: 10px 12px;
  background: var(--orange-soft);
  color: #7c2d12;
  line-height: 1.65;
}

.replay-log {
  display: grid;
  gap: 8px;
  max-height: 300px;
  overflow: auto;
  padding-right: 4px;
}

.replay-log-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.replay-log-row.active {
  border-color: rgba(15, 118, 110, 0.45);
  background: var(--green-soft);
  color: var(--accent-dark);
}

.replay-stage {
  display: grid;
  place-items: start center;
  min-height: 480px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: #f1ede4;
}

.replay-board {
  display: grid;
  grid-template-columns: repeat(var(--replay-cols, 8), minmax(34px, 58px));
  gap: 6px;
  width: min(100%, 520px);
}

.replay-cell {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border: 2px solid rgba(255, 255, 255, 0.82);
  border-radius: 4px;
  background: var(--cell-color, #fff);
  color: #fff;
  font-weight: 800;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.28);
}

.replay-cell.target-color {
  outline: 3px solid rgba(15, 118, 110, 0.52);
  outline-offset: -5px;
}

.replay-cell.blocker {
  background: #343434;
  color: #fff;
  outline: none;
}

@media (max-width: 980px) {
  .control-panel,
  .layout-grid,
  .two-column,
  .replay-layout {
    grid-template-columns: 1fr;
  }

  .button-row {
    justify-content: flex-start;
  }

  .metric-grid,
  .curve-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .replay-stage {
    min-height: auto;
  }
}

@media (max-width: 620px) {
  .page-shell {
    width: min(100% - 20px, 1240px);
    padding-top: 12px;
  }

  .topbar {
    display: grid;
  }

  h1 {
    font-size: 28px;
  }

  .param-grid,
  .metric-grid,
  .curve-summary {
    grid-template-columns: 1fr;
  }

  .replay-actions {
    grid-template-columns: 1fr;
  }

  .replay-board {
    gap: 4px;
  }
}
