:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #18202b;
  --muted: #637083;
  --line: #d9e0ea;
  --primary: #2f6f73;
  --primary-dark: #24585b;
  --accent: #c65f32;
  --warn: #a83d46;
  --soft-green: #e6f2ee;
  --soft-blue: #e9f0fb;
  --shadow: 0 14px 36px rgba(24, 32, 43, 0.11);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

button,
input,
select {
  font: inherit;
}

button,
select,
input {
  border: 1px solid var(--line);
  border-radius: 8px;
}

button {
  min-height: 42px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  padding: 0.62rem 0.85rem;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  transition: background 120ms ease, border-color 120ms ease, transform 120ms ease;
}

button:hover {
  background: #f1f5f9;
  border-color: #c5d0de;
}

button:active {
  transform: translateY(1px);
}

button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(47, 111, 115, 0.24);
  outline-offset: 2px;
}

.segmented button.active,
.run-button-row > button.active,
.reset-stack button.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.segmented button.active:hover,
.run-button-row > button.active:hover,
.reset-stack button.active:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
}

.app-shell {
  width: min(1600px, 100%);
  margin: 0 auto;
  padding: 18px;
}

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

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

h1 {
  font-size: clamp(1.7rem, 2.2vw, 2.4rem);
  letter-spacing: 0;
}

h2 {
  font-size: 1rem;
  margin-bottom: 10px;
}

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

.subtle,
.scenario-copy,
.field-help {
  color: var(--muted);
}

.status-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.status-strip span {
  min-width: 72px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  padding: 6px 10px;
  text-align: center;
}

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

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

.chamber-panel {
  overflow: hidden;
}

#chamberCanvas {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 2;
  background: #dce4ee;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.control-panel {
  display: grid;
  gap: 12px;
  padding: 12px;
}

.panel-section {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.button-row,
.run-button-row,
.button-grid,
.export-row {
  display: grid;
  gap: 8px;
}

.button-row,
.run-button-row {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.reset-stack {
  display: grid;
  gap: 6px;
}

.reset-stack button {
  min-height: 34px;
  padding: 0.34rem 0.55rem;
  font-size: 0.88rem;
}

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

.segmented {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  margin-top: 10px;
}

.segmented button {
  min-width: 0;
  padding-inline: 0.35rem;
}

.routine-picker,
.inline-form,
.setup-duration {
  display: grid;
  gap: 8px;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
}

.toggle-row input {
  width: 20px;
  height: 20px;
  accent-color: var(--primary);
}

.bar-settings-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 54px;
  gap: 4px 10px;
  align-items: end;
  margin: 8px 0;
}

.bar-number-field {
  display: grid;
  gap: 3px;
}

.vary-heading {
  align-self: end;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1;
  padding-bottom: 6px;
  text-align: center;
}

.vary-check {
  display: grid;
  min-height: 40px;
  place-items: center;
}

.vary-check input {
  width: 22px;
  height: 22px;
  accent-color: var(--primary);
}

.routine-picker select,
.inline-form input,
.setup-duration input,
.bar-settings-grid input,
.bar-settings-grid select,
.batch-controls input,
.batch-controls select {
  width: 100%;
  min-height: 40px;
  padding: 0.55rem 0.7rem;
  background: #fff;
}

.scenario-copy {
  min-height: 42px;
  margin-top: 8px;
  font-size: 0.92rem;
}

.field-help {
  margin-bottom: 8px;
  font-size: 0.86rem;
}

.setup-duration {
  margin-top: 10px;
}

.setup-duration .field-help {
  margin-bottom: 0;
}

.bar-help {
  margin-top: 8px;
  margin-bottom: 0;
}

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

.metric {
  border-radius: 8px;
  background: var(--soft-blue);
  padding: 9px;
}

.metric strong {
  display: block;
  font-size: 1.25rem;
}

.metric span {
  color: var(--muted);
  font-size: 0.82rem;
}

.event-log {
  display: grid;
  gap: 6px;
  min-height: 140px;
  max-height: 220px;
  overflow: auto;
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
}

.event-log li::marker {
  color: var(--primary);
}

.hidden {
  display: none;
}

.instructor-panel {
  margin-top: 16px;
  padding: 14px;
}

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

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

.wide {
  grid-column: 1 / -1;
}

.variable-list,
.concept-list,
.tuning-list {
  display: grid;
  gap: 8px;
}

.variable,
.concept,
.tuning-item {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 6px;
}

.concept {
  display: block;
  color: var(--muted);
}

.batch-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  align-items: end;
}

.export-row {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 10px;
}

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

.figure {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfe;
}

.bar-row {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) 64px;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 6px;
}

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

.bar-fill {
  height: 100%;
  background: var(--accent);
}

.line-chart {
  display: block;
  width: 100%;
  height: auto;
  margin-top: 8px;
}

.chart-axis {
  stroke: #c6d0dd;
  stroke-width: 2;
}

.chart-line {
  fill: none;
  stroke: var(--accent);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 4;
}

.chart-caption {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 4px;
}

.table-wrap {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  max-height: 260px;
  overflow-x: auto;
  overflow-y: auto;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  scrollbar-width: thin;
}

.table-wrap:empty {
  display: none;
}

table {
  min-width: 760px;
  width: max-content;
  border-collapse: collapse;
  font-size: 0.82rem;
  background: #fff;
}

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

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

th {
  position: sticky;
  top: 0;
  background: #edf2f7;
  color: #334155;
  z-index: 1;
}

.batch-preview {
  height: 190px;
  max-height: 190px;
  scrollbar-gutter: stable;
}

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

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

@media (max-width: 720px) {
  .app-shell {
    padding: 10px;
  }

  .topbar,
  .instructor-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .status-strip {
    justify-content: flex-start;
  }

  .control-panel,
  .instructor-grid,
  .batch-controls,
  .export-row,
  .figures {
    grid-template-columns: 1fr;
  }

  .button-row,
  .run-button-row,
  .button-grid,
  .bar-settings-grid {
    grid-template-columns: 1fr;
  }
}
