:root {
  color-scheme: light;
  --bg: #f3f5f8;
  --panel: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #d8dee8;
  --line-soft: #edf0f4;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --ok: #15803d;
  --bad: #b91c1c;
  --warn-bg: #fff7ed;
  --ok-bg: #f0fdf4;
  --bad-bg: #fef2f2;
  --shadow: 0 10px 28px rgba(17, 24, 39, 0.07);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  font-size: 14px;
}

button,
input,
textarea {
  font: inherit;
}

.shell {
  width: min(1280px, 100%);
  margin: 0 auto;
  padding: 22px;
}

.home-shell {
  display: grid;
  min-height: 100vh;
  align-content: center;
  gap: 18px;
}

.home-topbar {
  align-items: flex-start;
}

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

.standard-card {
  display: grid;
  min-height: 190px;
  align-content: start;
  gap: 12px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  text-decoration: none;
  box-shadow: var(--shadow);
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.standard-card:hover {
  border-color: #a7b4c8;
  transform: translateY(-2px);
  box-shadow: 0 14px 34px rgba(17, 24, 39, 0.1);
}

.standard-code {
  color: var(--accent);
  font-size: 12px;
  font-weight: 760;
  letter-spacing: 0;
}

.standard-card strong {
  font-size: 22px;
  line-height: 1.22;
}

.standard-card span:last-child {
  color: var(--muted);
  line-height: 1.65;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 3px 0;
}

.brand-icon {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border-radius: 8px;
  box-shadow: 0 8px 18px rgba(17, 24, 39, 0.16);
  display: block;
}

.home-link {
  display: inline-flex;
  width: fit-content;
  min-height: 32px;
  align-items: center;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: #374151;
  font-size: 13px;
  font-weight: 760;
  text-decoration: none;
}

.home-link:hover {
  border-color: #a7b4c8;
}

.kicker {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.25;
  font-weight: 760;
}

h2 {
  font-size: 15px;
  font-weight: 760;
}

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

.panel,
.status-card,
.summary-grid article,
.bounds-grid article {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.left-stack {
  display: grid;
  grid-area: left;
  gap: 16px;
  position: sticky;
  top: 22px;
}

.controls {
  display: grid;
  gap: 14px;
  padding: 16px;
}

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

.panel-title.compact {
  padding: 14px 16px 0;
}

.panel-title.compact-line {
  font-size: 13px;
  font-weight: 760;
}

label {
  display: grid;
  gap: 6px;
  color: #374151;
  font-size: 13px;
  font-weight: 650;
}

.inline-field {
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.inline-field > span,
.math-nowrap {
  display: inline-block;
  white-space: nowrap;
}

[hidden] {
  display: none !important;
}

.field-note {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.35;
}

.method-panel {
  display: grid;
  gap: 10px;
}

.split-panel {
  padding: 10px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: #f8fafc;
}

.group-inputs {
  display: grid;
  gap: 8px;
}

.group-row {
  display: grid;
  grid-template-columns: 80px minmax(0, 1fr) 32px;
  gap: 8px;
  align-items: start;
}

.group-row textarea {
  min-height: 58px;
}

input,
textarea {
  width: 100%;
  border: 1px solid #cfd7e3;
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input {
  height: 36px;
  padding: 0 10px;
}

textarea {
  min-height: 88px;
  padding: 10px;
  line-height: 1.55;
  resize: vertical;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

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

#validationForm[data-scenario="upper"] [data-spec-field="usl"] {
  grid-column: 2;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef2f7;
}

.segmented.small {
  grid-template-columns: repeat(2, 1fr);
}

.segmented label {
  display: flex;
  min-height: 32px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--muted);
  border-radius: 6px;
  font-weight: 700;
}

.segmented input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.segmented label:has(input:checked) {
  background: #fff;
  color: var(--text);
  box-shadow: 0 1px 4px rgba(17, 24, 39, 0.12);
}

.primary-button,
.subtle-button {
  min-height: 36px;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
  font-weight: 760;
}

.primary-button {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 1px;
  min-width: 120px;
  color: #fff;
  background: var(--accent);
}

.primary-button small {
  color: rgba(255, 255, 255, 0.82);
  font-size: 11px;
  line-height: 1;
  font-weight: 650;
}

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

.subtle-button {
  padding: 0 12px;
  color: #374151;
  border: 1px solid var(--line);
  background: #fff;
}

.subtle-button.mini {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.icon-button {
  width: 32px;
  min-height: 32px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
}

.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.38;
}

.action-row {
  display: grid;
  position: relative;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.main-stack {
  display: grid;
  grid-area: results;
  gap: 12px;
}

.status-card {
  display: grid;
  gap: 4px;
  padding: 13px 16px;
  box-shadow: none;
}

.status-card span,
.summary-grid span,
.bounds-grid span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.status-card strong {
  font-size: 14px;
  line-height: 1.45;
  font-weight: 720;
}

.status-card.pass {
  border-color: #bbf7d0;
  background: var(--ok-bg);
}

.status-card.fail {
  border-color: #fecaca;
  background: var(--bad-bg);
}

.summary-grid {
  display: grid;
  grid-template-columns: 0.7fr 1fr 1fr 1fr 1.15fr 0.9fr minmax(180px, 1.45fr);
  gap: 10px;
}

.summary-grid article,
.bounds-grid article {
  display: grid;
  gap: 5px;
  min-height: 70px;
  padding: 12px 14px;
  box-shadow: none;
}

.summary-grid strong,
.bounds-grid strong {
  overflow-wrap: anywhere;
  font-size: 18px;
  line-height: 1.25;
  font-weight: 760;
}

.summary-grid .claim {
  border-color: #bfdbfe;
  background: #eff6ff;
}

.iec-summary-grid {
  grid-template-columns: 0.7fr 1fr 1fr 1fr 1fr 1fr 0.8fr 0.9fr minmax(180px, 1.4fr);
}

.iec-summary-grid article > span,
.iec-bounds-grid article > span {
  white-space: nowrap;
}

.iec-summary-grid article > strong {
  overflow-wrap: normal;
  white-space: nowrap;
}

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

  .summary-grid .claim {
    grid-column: span 3;
  }
}

.chart-panel {
  overflow: hidden;
  box-shadow: none;
}

#chart {
  display: block;
  width: 100%;
  height: 390px;
}

#iecOcChart {
  display: block;
  width: 100%;
  height: 390px;
}

.hover-capture {
  fill: transparent;
  pointer-events: all;
}

.hover-line {
  stroke: #475569;
  stroke-width: 1;
  stroke-dasharray: 4 4;
}

.hover-dot {
  fill: #111827;
  stroke: #fff;
  stroke-width: 2;
}

.hover-dot-coverage {
  fill: #111827;
}

.hover-label-box {
  fill: #111827;
  opacity: 0.9;
}

.hover-label {
  fill: #fff;
  font-size: 12px;
  font-weight: 700;
}

.chart-head-meta {
  display: grid;
  gap: 6px;
  justify-items: end;
  color: var(--muted);
  font-size: 12px;
}

.chart-meta-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
}

.chart-meta-row > span:not(.legend-item) {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  font-weight: 700;
}

.chart-head-meta strong {
  color: var(--text);
  font-weight: 760;
}

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

.legend-item::before {
  content: "";
  width: 18px;
  border-top: 2px dashed currentColor;
}

.legend-item.tolerance {
  color: var(--bad);
}

.legend-item.spec {
  color: #111827;
}

.legend-item.oc-coverage {
  color: #111827;
}

.legend-item.oc-coverage::before {
  border-top-style: solid;
}

.legend-item.oc-boundary {
  color: var(--bad);
}

.legend-item.oc-declared {
  color: var(--accent);
}

.axis {
  stroke: #aab3c2;
  stroke-width: 1;
}

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

.curve {
  fill: none;
  stroke: #1f2937;
  stroke-width: 2.2;
}

.oc-curve {
  stroke: var(--accent);
}

.oc-curve.coverage {
  stroke: #111827;
}

.area {
  fill: rgba(37, 99, 235, 0.11);
}

.marker.mean {
  stroke: #6b7280;
  stroke-dasharray: 3 6;
}

.marker.tolerance {
  stroke: var(--bad);
  stroke-width: 2;
  stroke-dasharray: 7 5;
}

.marker.spec {
  stroke: #111827;
  stroke-width: 2;
  stroke-dasharray: 2 5;
}

.marker.boundary {
  stroke: var(--bad);
  stroke-width: 1.8;
  stroke-dasharray: 7 5;
}

.marker.declared {
  stroke: var(--accent);
  stroke-width: 1.8;
  stroke-dasharray: 3 5;
}

.oc-marker.boundary {
  fill: var(--bad);
}

.oc-marker.declared {
  fill: var(--accent);
}

.sample-dot {
  fill: var(--accent);
  opacity: 0.68;
}

.chart-label {
  fill: #374151;
  font-size: 12px;
  font-weight: 700;
}

.tick-label {
  fill: #6b7280;
  font-size: 11px;
}

.bounds-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.iec-bounds-grid article:first-child {
  border-color: #bfdbfe;
  background: #eff6ff;
}

.extra-result {
  display: grid;
  gap: 10px;
  padding: 14px 16px;
  box-shadow: none;
}

.extra-result[hidden] {
  display: none !important;
}

.extra-result h3 {
  margin: 0;
  font-size: 14px;
}

.result-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.result-table th,
.result-table td {
  padding: 8px 6px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
}

.result-table th {
  color: var(--muted);
  font-weight: 760;
}

.result-row {
  cursor: pointer;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

.result-row:hover {
  background: #f8fafc;
}

.result-row.selected {
  background: #eff6ff;
  box-shadow: inset 3px 0 0 var(--accent);
}

.rank-summary {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  color: #374151;
  font-size: 13px;
}

.rank-summary span {
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f8fafc;
}

.result-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 760;
}

.result-badge.pass {
  color: var(--ok);
  background: var(--ok-bg);
}

.result-badge.fail {
  color: var(--bad);
  background: var(--bad-bg);
}

.result-badge.neutral {
  color: #374151;
  background: #f3f4f6;
}

.theory-panel {
  box-shadow: none;
}

.theory-panel summary {
  display: flex;
  position: relative;
  min-height: 52px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 16px;
  cursor: pointer;
  list-style: none;
}

.theory-panel summary::-webkit-details-marker {
  display: none;
}

.theory-panel summary::after {
  content: "+";
  display: grid;
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--muted);
  font-weight: 760;
}

.theory-panel[open] summary::after {
  content: "-";
}

.theory-panel summary span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.theory-panel summary strong {
  margin-right: auto;
  color: var(--text);
  font-size: 14px;
  font-weight: 760;
}

.theory-content {
  display: grid;
  gap: 0;
  padding: 0 16px 16px;
  border-top: 1px solid var(--line-soft);
  color: #374151;
  line-height: 1.68;
}

.theory-section {
  display: grid;
  gap: 9px;
  padding: 15px 0;
  border-bottom: 1px solid var(--line-soft);
}

.theory-section:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.theory-section h3 {
  margin: 0;
  color: #111827;
  font-size: 13px;
  font-weight: 760;
  letter-spacing: 0;
}

.theory-section p {
  margin: 0;
}

.theory-content var,
.theory-content .math,
.equation,
.equation-list {
  color: #111827;
  font-family: "Times New Roman", "STIX Two Text", "Cambria Math", serif;
  font-size: 1.04em;
  font-style: italic;
}

.theory-content .math {
  display: inline-block;
  padding: 0 2px;
  white-space: nowrap;
}

.equation,
.equation-list {
  overflow-x: auto;
  padding: 10px 12px;
  border: 1px solid #e5e7eb;
  border-radius: 7px;
  background: #f8fafc;
  font-size: 17px;
  line-height: 1.45;
  overflow-wrap: normal;
  white-space: nowrap;
}

.equation {
  text-align: center;
}

.equation-list {
  display: grid;
  gap: 6px;
  text-align: left;
}

@media (max-width: 1000px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-areas:
      "left"
      "results";
  }

  .left-stack {
    position: static;
  }

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

}

@media (max-width: 620px) {
  .shell {
    padding: 14px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  h1 {
    font-size: 20px;
  }

  .field-grid,
  .summary-grid,
  .bounds-grid,
  .home-grid {
    grid-template-columns: 1fr;
  }

  #validationForm[data-scenario="upper"] [data-spec-field="usl"] {
    grid-column: auto;
  }

  .theory-panel summary {
    align-items: flex-start;
    flex-direction: column;
    padding: 12px 16px;
  }

  .theory-panel summary::after {
    position: absolute;
    right: 16px;
  }
}
