:root {
  --bg: #f6f7f3;
  --card: #ffffff;
  --text: #171717;
  --muted: #5f666d;
  --line: #dedbd2;
  --soft: #f4f2ec;
  --primary: #0f766e;
  --primary-hover: #115e59;
  --accent: #d97706;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background:
    linear-gradient(rgba(23, 23, 23, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23, 23, 23, 0.035) 1px, transparent 1px),
    var(--bg);
  background-size: 48px 48px;
  color: var(--text);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(246, 247, 243, 0.9);
  backdrop-filter: blur(16px);
}

.brand {
  color: var(--text);
  font-weight: 800;
  text-decoration: none;
}

.container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 16px 44px;
}

.hero {
  max-width: 760px;
  margin-bottom: 20px;
}

.eyebrow {
  display: inline-flex;
  margin: 0 0 12px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1, h2, h3 { margin: 0; line-height: 1.05; }
h1 { font-size: clamp(38px, 7vw, 72px); letter-spacing: -0.02em; }
h2 { font-size: 26px; }
h3 { margin-top: 28px; margin-bottom: 12px; font-size: 18px; }

.muted {
  color: var(--muted);
  line-height: 1.6;
}

.note {
  min-height: 22px;
  color: var(--muted);
  font-size: 14px;
}

.card {
  margin-bottom: 16px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  box-shadow: 0 1px 2px rgba(23, 23, 23, 0.04);
}

.hidden { display: none; }

.groupPanel {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.calibrationPanel {
  display: grid;
  gap: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.sectionHead,
.taskHeader {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.trialCount {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 7px;
  color: #363b40;
  font-size: 14px;
  font-weight: 650;
}

label.check {
  flex-direction: row;
  align-items: center;
  min-height: 42px;
  margin-top: 22px;
}

input, select, button {
  font: inherit;
}

input, select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #c9c4b8;
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}

input[type="file"] {
  max-width: 520px;
  border-style: dashed;
  background: var(--soft);
}

input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

input[type="range"] {
  padding: 0;
  accent-color: var(--primary);
}

label small {
  color: var(--muted);
  font-weight: 500;
  line-height: 1.4;
}

.rangeLabel {
  display: grid;
  grid-template-columns: minmax(120px, 180px) minmax(180px, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.rangeLabel output {
  min-width: 64px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--soft);
  color: var(--text);
  font-variant-numeric: tabular-nums;
  text-align: center;
}

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

button {
  min-height: 42px;
  padding: 10px 14px;
  border: 1px solid #c9c4b8;
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font-weight: 750;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: var(--primary);
}

button.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

button.primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

button.secondary {
  background: #fff;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

button[aria-busy="true"] {
  position: relative;
  opacity: 0.78;
}

button[aria-busy="true"]::after {
  content: "";
  width: 0.9em;
  height: 0.9em;
  margin-left: 0.55em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 999px;
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 14px;
  color: var(--muted);
  font-weight: 650;
}

.display {
  min-height: 68px;
  margin: 14px 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  font-size: 38px;
  font-weight: 800;
  letter-spacing: 4px;
  text-align: center;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, minmax(76px, 128px));
  justify-content: center;
  gap: 8px;
}

.keypad button {
  min-height: 48px;
}

pre {
  overflow-x: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #171717;
  color: #f8fafc;
  font-size: 14px;
  line-height: 1.5;
}

.tableWrap,
.plotWrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.plotWrap svg {
  display: block;
  min-width: 780px;
  width: 100%;
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  background: #fff;
}

th, td {
  padding: 9px 8px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  text-align: center;
  vertical-align: middle;
}

th:last-child, td:last-child { border-right: none; }
tr:last-child td { border-bottom: none; }
th {
  background: var(--soft);
  color: #363b40;
  font-weight: 800;
}

small {
  color: var(--muted);
}

@media (max-width: 720px) {
  .sectionHead,
  .taskHeader,
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .card {
    padding: 16px;
  }

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