:root {
  color-scheme: light;
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-alt: #f4f7f6;
  --ink: #1d2528;
  --muted: #657174;
  --line: #d9dfdc;
  --accent: #0d7a75;
  --accent-dark: #085d59;
  --danger: #b83232;
  --shadow: 0 14px 40px rgba(19, 36, 38, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

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

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-dark);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.15;
}

h1 {
  font-size: clamp(2rem, 4vw, 3.4rem);
}

h2 {
  font-size: 1.25rem;
}

h3 {
  font-size: 1rem;
}

p {
  margin: 8px 0 0;
  color: var(--muted);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  margin-top: 16px;
  padding: 18px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}

.setup-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(160px, 240px));
  gap: 14px;
  margin-bottom: 16px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

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

input:focus,
select:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(13, 122, 117, 0.16);
}

button {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
  padding: 9px 14px;
}

button:hover {
  background: var(--accent-dark);
}

.secondary-button {
  background: #e9eeee;
  color: var(--ink);
}

.secondary-button:hover {
  background: #dce4e2;
}

.table-wrap {
  overflow-x: auto;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 18px;
}

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

th,
td {
  border: 1px solid var(--line);
  padding: 8px;
  text-align: right;
  vertical-align: middle;
}

th {
  background: var(--surface-alt);
  color: #263133;
  font-weight: 700;
}

td:first-child,
th:first-child {
  text-align: left;
}

td input,
td select {
  min-width: 110px;
}

.actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 16px;
}

.message {
  display: none;
  border-radius: 6px;
  margin-bottom: 14px;
  padding: 10px 12px;
}

.message.show {
  display: block;
}

.message.error {
  background: #fff2f2;
  color: var(--danger);
}

.message.success {
  background: #eef8f6;
  color: var(--accent-dark);
}

.results {
  display: grid;
  gap: 16px;
}

.result-step {
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.result-step:first-child {
  border-top: 0;
  padding-top: 0;
}

.formula {
  align-items: center;
  background: #f2f0e9;
  border-radius: 6px;
  color: #344044;
  display: inline-flex;
  flex-wrap: wrap;
  gap: 9px;
  line-height: 1.2;
  margin: 8px 0 12px;
  overflow-x: auto;
  max-width: 100%;
  padding: 10px 12px;
  vertical-align: middle;
}

.math-var,
.math-symbol,
.math-op {
  display: inline-flex;
  align-items: center;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.12rem;
  font-style: italic;
}

.math-symbol,
.math-op {
  font-style: normal;
}

.fraction {
  display: inline-grid;
  grid-template-rows: auto auto;
  justify-items: center;
  min-width: 54px;
  vertical-align: middle;
}

.fraction-top,
.fraction-bottom {
  align-items: center;
  display: inline-flex;
  gap: 6px;
  justify-content: center;
  padding: 2px 8px;
  white-space: nowrap;
}

.fraction-top {
  border-bottom: 1px solid #344044;
  width: 100%;
}

.radical {
  align-items: stretch;
  display: inline-flex;
}

.radical-symbol {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.45rem;
  line-height: 1;
  transform: translateY(1px);
}

.radical-body {
  align-items: center;
  border-top: 1px solid #344044;
  display: inline-flex;
  gap: 5px;
  padding: 2px 4px 0 3px;
}

sub,
sup {
  font-size: 0.68em;
  line-height: 0;
}

.rank-one {
  background: #edf8f5;
  font-weight: 700;
}

.analytics-section {
  display: grid;
  gap: 12px;
}

.analytics-controls {
  display: grid;
  grid-template-columns: minmax(180px, 320px);
  gap: 14px;
}

.analytics-controls.two-columns {
  grid-template-columns: repeat(2, minmax(180px, 280px));
}

.analytics-note {
  margin-top: 0;
}

.bar-chart {
  display: grid;
  gap: 12px;
}

.bar-row {
  display: grid;
  gap: 6px;
}

.bar-label {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.bar-label span {
  color: var(--ink);
  font-weight: 700;
}

.bar-label strong {
  color: var(--accent-dark);
  font-variant-numeric: tabular-nums;
}

.bar-track {
  background: #e8eeeb;
  border-radius: 999px;
  height: 18px;
  overflow: hidden;
}

.bar-fill {
  background: linear-gradient(90deg, #0d7a75, #40a89c);
  border-radius: inherit;
  height: 100%;
  min-width: 2px;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

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

.legend-dot {
  border-radius: 999px;
  display: inline-block;
  height: 10px;
  width: 10px;
}

.option-dot {
  background: #8d9699;
}

.best-dot {
  background: #2563eb;
}

.pis-dot {
  background: #168a46;
}

.nis-dot {
  background: #d13d3d;
}

.scatter-plot {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow-x: auto;
  padding: 10px;
}

.scatter-plot svg {
  display: block;
  min-width: 720px;
  width: 100%;
}

.plot-bg {
  fill: #fbfcfb;
}

.axis-tick line {
  stroke: #e1e6e3;
  stroke-width: 1;
}

.axis-tick text,
.axis-label,
.scatter-point text {
  fill: #526164;
  font-size: 13px;
}

.x-tick-label {
  text-anchor: middle;
}

.y-tick-label {
  text-anchor: end;
}

.axis-line {
  stroke: #9aa6a4;
  stroke-width: 1.4;
}

.axis-label {
  font-weight: 700;
  text-anchor: middle;
}

.scatter-point circle {
  stroke: #fff;
  stroke-width: 2;
}

.scatter-point.option circle {
  fill: #8d9699;
}

.scatter-point.best circle {
  fill: #2563eb;
}

.scatter-point.pis circle {
  fill: #168a46;
}

.scatter-point.nis circle {
  fill: #d13d3d;
}

.scatter-point.best text,
.scatter-point.pis text,
.scatter-point.nis text {
  fill: #1d2528;
  font-weight: 700;
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 18px;
  }

  .topbar,
  .panel-heading,
  .actions {
    align-items: stretch;
    flex-direction: column;
  }

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

  .analytics-controls,
  .analytics-controls.two-columns {
    grid-template-columns: 1fr;
  }

  button {
    width: 100%;
  }
}
