:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #141820;
  --muted: #5f6b7a;
  --line: #d8dde5;
  --foreign: #1f77b4;
  --home: #d62728;
  --nash: #111111;
  --trial: #f0a202;
  --accent: #15507e;
  --shadow: 0 10px 25px rgba(26, 33, 46, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

.shell {
  width: min(1440px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 32px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}

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

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

h1 {
  margin-bottom: 0;
  font-size: clamp(1.7rem, 3vw, 2.7rem);
  line-height: 1.05;
  letter-spacing: 0;
  overflow-wrap: break-word;
}

h2 {
  margin-bottom: 8px;
  font-size: 1rem;
  line-height: 1.2;
}

p {
  color: var(--muted);
  line-height: 1.45;
}

.status {
  min-width: 170px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #edf3f2;
  color: #1f5b54;
  font-size: 0.9rem;
  font-weight: 700;
  text-align: center;
}

.status.busy {
  background: #fff8e8;
  color: #7a5600;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metric,
.plot-panel,
.control-panel,
.table-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.metric {
  min-height: 82px;
  padding: 14px 16px;
}

.metric-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  font-size: clamp(1.05rem, 2vw, 1.45rem);
  line-height: 1.15;
  overflow-wrap:normal;word-break:normal;hyphens:none;-webkit-hyphens:none;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
  align-items: start;
}

.plot-panel,
.table-panel {
  padding: 18px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
}

.panel-head p {
  margin-bottom: 0;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px 14px;
  min-width: 260px;
  color: var(--muted);
  font-size: 0.9rem;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  width: 20px;
  height: 4px;
  border-radius: 999px;
  background: currentColor;
}

.swatch.foreign {
  color: var(--foreign);
}

.swatch.home {
  color: var(--home);
}

.swatch.nash {
  height: 10px;
  width: 10px;
  color: var(--nash);
}

.swatch.trial {
  height: 10px;
  width: 10px;
  color: var(--trial);
}

.chart-wrap {
  width: 100%;
  min-width: 0;
  margin-top: 12px;
  aspect-ratio: 1.42;
  overflow: hidden;
}

#chart {
  width: 100%;
  height: 100%;
  display: block;
  user-select: none;
}

.axis text,
.tick-label {
  fill: var(--muted);
  font-size: 14px;
}

.axis-label {
  fill: var(--ink);
  font-size: 17px;
  font-weight: 700;
}

.grid-line {
  stroke: #e6e9ee;
  stroke-width: 1;
}

.axis-line {
  stroke: #1d2430;
  stroke-width: 1.5;
}

.curve-foreign {
  fill: none;
  stroke: var(--foreign);
  stroke-width: 4;
}

.curve-home {
  fill: none;
  stroke: var(--home);
  stroke-width: 4;
  stroke-dasharray: 10 7;
}

.br-line {
  stroke: #9aa5b2;
  stroke-width: 1.5;
  stroke-dasharray: 5 5;
}

.point-label {
  fill: var(--ink);
  font-size: 16px;
  font-weight: 700;
}

.trial-point {
  cursor: grab;
  touch-action: none;
}

.trial-point:active {
  cursor: grabbing;
}

.control-panel {
  padding: 16px;
}

.control-section + .control-section {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

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

.section-head h2 {
  margin-bottom: 0;
}

button {
  border: 1px solid #b8c6d4;
  border-radius: 8px;
  background: #eef5f4;
  color: #1f5b54;
  font: inherit;
  font-size: 0.86rem;
  font-weight: 800;
  padding: 8px 10px;
  cursor: pointer;
}

button:hover {
  background: #e3efed;
}

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

.control-grid {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  grid-template-columns: 1fr auto;
  min-width: 0;
  gap: 8px 10px;
  align-items: center;
  color: var(--ink);
  font-weight: 700;
}

output {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  grid-column: 1 / -1;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: 30px;
  accent-color: var(--accent);
}

.checkline {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.checkline input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.microcopy {
  margin: -2px 0 14px;
  color: var(--muted);
  font-size: 0.88rem;
}

.trial-readout {
  display: grid;
  gap: 10px;
  margin: 16px 0 0;
}

.trial-readout div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid #edf0f4;
}

.trial-readout dt {
  color: var(--muted);
  font-size: 0.88rem;
}

.trial-readout dd {
  margin: 0;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.equations p {
  margin-bottom: 10px;
  color: #344054;
  font-size: 0.93rem;
}

.table-panel {
  margin-top: 16px;
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
  font-size: 0.94rem;
}

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

th:first-child,
td:first-child,
th:nth-child(2),
td:nth-child(2) {
  text-align: left;
}

th {
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

td {
  font-variant-numeric: tabular-nums;
}

tr.trial-row td {
  background: #fff9e9;
}

@media (max-width: 1050px) {
  .metrics {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .metric.wide {
    grid-column: span 2;
  }

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

  .control-panel {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
  }

  .control-section + .control-section {
    margin-top: 0;
    padding-top: 0;
    border-top: 0;
  }

  .section-head {
    display: block;
  }

  .section-head button {
    margin-top: 8px;
    width: 100%;
  }
}

@media (max-width: 720px) {
  .shell {
    width: min(100vw - 16px, 1440px);
    padding: 12px 0 24px;
  }

  .topbar,
  .panel-head {
    display: block;
  }

  h1 {
    font-size: clamp(1.55rem, 8vw, 2.1rem);
  }

  .eyebrow {
    font-size: 0.72rem;
  }

  .status {
    margin-top: 12px;
    width: 100%;
  }

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

  .metric {
    min-height: 74px;
    padding: 12px;
  }

  .metric.wide {
    grid-column: span 2;
  }

  .workspace {
    gap: 12px;
  }

  .control-panel {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .control-section + .control-section {
    margin-top: 18px;
    padding-top: 18px;
    border-top: 1px solid var(--line);
  }

  .legend {
    justify-content: flex-start;
    min-width: 0;
    margin-top: 12px;
    font-size: 0.84rem;
  }

  .chart-wrap {
    aspect-ratio: auto;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
  }

  #chart {
    min-width: 620px;
    height: 440px;
  }

  .plot-panel,
  .table-panel,
  .control-panel {
    padding: 12px;
  }

  .section-head {
    display: flex;
  }

  .section-head button {
    width: auto;
    margin-top: 0;
  }

  button {
    min-height: 40px;
  }

  label {
    gap: 7px 10px;
  }

  input[type="range"] {
    min-height: 40px;
  }

  .trial-readout div {
    align-items: flex-start;
  }

  table {
    min-width: 720px;
  }
}

@media (max-width: 600px) {
  .shell {
    width: min(calc(100% - 16px), 374px);
    margin-left: 8px;
    margin-right: auto;
  }

  h1 {
    font-size: 1.82rem;
    line-height: 1.08;
  }

  .section-head {
    display: block;
  }

  .section-head button {
    width: 100%;
    margin-top: 8px;
  }

  #chart {
    min-width: 560px;
    height: 400px;
  }
}

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

  .metric.wide {
    grid-column: auto;
  }

  .section-head {
    display: block;
  }

  .section-head button {
    width: 100%;
    margin-top: 8px;
  }

  #chart {
    min-width: 560px;
    height: 400px;
  }
}

@media (pointer: coarse) {
  button,
  input,
  .checkline input {
    min-height: 44px;
  }
}
