:root {
  color-scheme: light;
  --bg: #f7f5f1;
  --surface: #fffdfa;
  --surface-2: #ebe7df;
  --ink: #20201d;
  --muted: #67645c;
  --line: #d7d0c6;
  --accent: #0f766e;
  --accent-strong: #0b5d56;
  --warn: #b45309;
  --danger: #b42318;
  --good: #107569;
  --bar: #d95f3d;
  --bar-soft: #e4a24a;
  --shadow: 0 18px 45px rgba(52, 47, 39, 0.11);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

.app-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 28px 32px 18px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 3vw, 3rem);
  letter-spacing: 0;
  line-height: 1;
}

h2 {
  margin-bottom: 8px;
  font-size: 1.08rem;
  letter-spacing: 0;
}

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

.runtime-status {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  gap: 10px;
  color: var(--muted);
  font-size: 0.92rem;
  white-space: nowrap;
}

.runtime-status span:first-child {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--warn);
}

.runtime-status[data-state="ready"] span:first-child {
  background: var(--good);
}

.runtime-status[data-state="error"] span:first-child {
  background: var(--danger);
}

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

.tabbar {
  display: inline-flex;
  gap: 4px;
  margin-bottom: 18px;
  padding: 4px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 8px;
}

.context-strip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(240px, 0.45fr);
  gap: 20px;
  align-items: start;
  margin-bottom: 20px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.context-strip h2 {
  margin-bottom: 6px;
}

.context-strip p,
.context-strip ul {
  margin-bottom: 0;
  color: var(--muted);
}

.context-strip ul {
  display: grid;
  gap: 5px;
  padding-left: 18px;
  font-size: 0.88rem;
}

.mode-guide {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 0.45fr);
  gap: 18px;
  align-items: start;
  margin-bottom: 20px;
  padding: 14px 16px;
  border: 1px solid #c3d8d5;
  border-radius: 8px;
  background: #f4fbf9;
}

.mode-guide h2 {
  margin-bottom: 6px;
}

.mode-guide p,
.pane-note {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.state-note {
  padding-left: 14px;
  border-left: 3px solid var(--accent);
}

.pane-note {
  max-width: 760px;
  margin-top: 6px;
}

.tab-button,
.secondary,
.primary {
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 750;
  letter-spacing: 0;
  transition:
    background 140ms ease,
    color 140ms ease,
    border-color 140ms ease,
    transform 140ms ease;
}

.tab-button {
  min-height: 34px;
  padding: 0 14px;
  color: var(--muted);
  background: transparent;
}

.tab-button.active {
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(52, 47, 39, 0.12);
}

.primary {
  min-height: 42px;
  padding: 0 16px;
  color: #fff;
  background: var(--accent);
}

.primary:hover {
  background: var(--accent-strong);
  transform: translateY(-1px);
}

.secondary {
  min-height: 36px;
  padding: 0 12px;
  color: var(--ink);
  background: var(--surface);
  border-color: var(--line);
}

.secondary:hover:not(:disabled) {
  border-color: var(--accent);
}

.run-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 176px;
}

.button-label {
  white-space: nowrap;
}

.button-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.42);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

.run-button[aria-busy="true"] {
  opacity: 1;
  background: var(--accent-strong);
}

.run-button[data-busy-kind="blocked"] {
  opacity: 0.7;
}

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

.workspace {
  display: none;
  grid-template-columns: minmax(320px, 390px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.workspace.active {
  display: grid;
}

.about-layout {
  grid-template-columns: 1fr;
}

.control-panel,
.result-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.control-panel {
  position: sticky;
  top: 16px;
  max-height: calc(100svh - 34px);
  overflow: auto;
  padding: 18px;
}

.result-panel {
  min-height: 620px;
  padding: 22px;
}

.result-panel.full {
  max-width: 960px;
  min-height: auto;
}

.panel-heading,
.section-heading,
.button-row,
.export-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.section-heading {
  align-items: flex-start;
  margin-bottom: 20px;
}

.section-heading p,
.control-panel p {
  margin-bottom: 0;
  color: var(--muted);
}

.panel-kicker {
  max-width: 280px;
  font-size: 0.84rem;
  line-height: 1.35;
}

.control-group {
  margin-top: 15px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.control-group h3 {
  margin-bottom: 8px;
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 720;
}

.field {
  display: grid;
  gap: 6px;
  margin: 12px 0;
}

.label-row {
  position: relative;
  display: flex;
  min-height: 22px;
  align-items: center;
  gap: 6px;
}

.help-button {
  display: inline-grid;
  width: 18px;
  min-width: 18px;
  height: 18px;
  min-height: 18px;
  padding: 0;
  place-items: center;
  border: 1px solid #b9c9c6;
  border-radius: 50%;
  background: #f4fbf9;
  color: var(--accent);
  cursor: help;
  font-size: 0.72rem;
  font-weight: 850;
  line-height: 1;
}

.help-button:hover,
.help-button:focus-visible,
.help-button[data-open="true"] {
  border-color: var(--accent);
  background: #e7f5f2;
}

.help-tooltip {
  position: absolute;
  z-index: 5;
  top: calc(100% + 7px);
  left: 0;
  width: min(280px, calc(100vw - 72px));
  padding: 9px 10px;
  border: 1px solid #b9c9c6;
  border-radius: 6px;
  background: #102a27;
  box-shadow: 0 12px 28px rgba(32, 32, 29, 0.18);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 560;
  line-height: 1.35;
  pointer-events: none;
}

.help-tooltip[hidden] {
  display: none;
}

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

input:focus,
select:focus,
button:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.2);
  outline-offset: 1px;
}

.field-grid {
  display: grid;
  gap: 10px;
}

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

.checkline {
  display: grid;
  grid-template-columns: 18px 1fr;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-weight: 650;
}

.checkline input {
  width: 18px;
  min-height: 18px;
}

.button-row {
  margin-top: 18px;
}

.run-status-note {
  min-height: 20px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
}

.run-status-note[hidden] {
  display: none;
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}

.metric-card {
  min-height: 86px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf7;
}

.metric-card span {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 750;
}

.metric-card strong {
  display: block;
  margin-top: 8px;
  font-size: 1.32rem;
}

.empty-state {
  grid-column: 1 / -1;
  margin: 0;
  padding: 16px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fbfaf7;
  color: var(--muted);
  font-size: 0.9rem;
}

.chart-block {
  margin-top: 22px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.chart-note {
  max-width: 760px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 10px 0 14px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 680;
}

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

.legend-swatch {
  display: inline-block;
  width: 20px;
  height: 9px;
  border-radius: 999px;
  background: var(--bar);
}

.legend-swatch.reference {
  width: 2px;
  height: 18px;
  border-radius: 0;
  background: var(--accent);
}

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

.probability-row {
  display: grid;
  grid-template-columns: 72px minmax(150px, 1fr) 92px;
  gap: 12px;
  align-items: center;
}

.bar-track {
  position: relative;
  height: 30px;
  overflow: hidden;
  border-radius: 6px;
  background: #ece6dc;
}

.bar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: var(--bar);
  transition: width 260ms ease;
}

.bar-reference {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--accent);
}

.probability-label {
  color: var(--muted);
  font-weight: 720;
}

.probability-value {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.table-wrap {
  max-width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

th,
td {
  padding: 9px 11px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

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

thead th {
  position: sticky;
  top: 0;
  background: #f5f0e7;
  color: var(--muted);
}

.heatmap {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
  gap: 8px;
}

.heat-cell {
  min-height: 92px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f2ece3;
}

.heat-cell strong,
.heat-cell span {
  display: block;
}

.heat-cell strong {
  margin-bottom: 6px;
  font-size: 1.1rem;
}

.heat-cell span {
  color: var(--muted);
  font-size: 0.78rem;
}

.reference-panel {
  margin: 18px 0;
}

.workload {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfaf7;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: min(420px, calc(100vw - 40px));
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

code {
  padding: 1px 4px;
  border-radius: 4px;
  background: #eee7dc;
}

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

@media (max-width: 980px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .app-shell {
    padding: 16px;
  }

  .context-strip {
    grid-template-columns: 1fr;
  }

  .mode-guide {
    grid-template-columns: 1fr;
  }

  .state-note {
    padding-top: 10px;
    padding-left: 0;
    border-top: 3px solid var(--accent);
    border-left: 0;
  }

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

  .control-panel {
    position: static;
    max-height: none;
  }

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

@media (max-width: 620px) {
  .field-grid.two,
  .metric-strip {
    grid-template-columns: 1fr;
  }

  .section-heading,
  .panel-heading,
  .export-row {
    align-items: stretch;
    flex-direction: column;
  }

  .tabbar {
    display: grid;
    width: 100%;
    grid-template-columns: 1fr;
  }

  .probability-row {
    grid-template-columns: 1fr;
  }

  .probability-value {
    text-align: left;
  }
}
