:root {
  --bg: #f1ede4;
  --paper: rgba(255, 251, 245, 0.86);
  --paper-strong: #fffaf2;
  --line: rgba(78, 61, 40, 0.18);
  --text: #1f1b16;
  --muted: #665b4b;
  --accent: #b3472f;
  --accent-soft: rgba(179, 71, 47, 0.12);
  --accent-cool: #215f7d;
  --accent-gold: #ab7a19;
  --danger: #b42318;
  --shadow: 0 18px 50px rgba(76, 48, 19, 0.12);
  --radius: 22px;
  --plot-frame: rgba(58, 43, 27, 0.24);
  --plot-surface: #f8f1e4;
  --plot-surface-strong: #fdf7ed;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(255, 214, 153, 0.32), transparent 28%),
    radial-gradient(circle at bottom right, rgba(33, 95, 125, 0.18), transparent 30%),
    linear-gradient(180deg, #f8f3eb 0%, var(--bg) 100%);
  color: var(--text);
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino,
    serif;
}

body {
  padding: 24px;
}

button,
input,
select {
  font: inherit;
}

code {
  padding: 0.1rem 0.35rem;
  border-radius: 999px;
  background: rgba(31, 27, 22, 0.06);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 20px;
  align-items: stretch;
  min-height: calc(100vh - 48px);
}

.control-panel,
.plot-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.control-panel {
  padding: 20px;
  display: grid;
  gap: 16px;
  height: calc(100vh - 48px);
  overflow-y: auto;
  overscroll-behavior: contain;
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.control-panel::-webkit-scrollbar {
  width: 0;
  height: 0;
}

.panel-header h1,
.plot-toolbar h2,
.card h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  letter-spacing: -0.02em;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.panel-copy,
.selection-summary,
.status-line,
.empty-state,
.range-readout,
.field-label,
label span,
dt {
  color: var(--muted);
}

.panel-link-row {
  margin: 12px 0 0;
}

.panel-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--accent-cool);
  font-size: 0.92rem;
  font-weight: 700;
  text-decoration: none;
  border-bottom: 1px solid rgba(33, 95, 125, 0.22);
  transition:
    color 120ms ease,
    border-color 120ms ease;
}

.panel-link:hover,
.panel-link:focus-visible {
  color: var(--accent);
  border-color: rgba(179, 71, 47, 0.42);
}

.card {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--paper-strong);
  padding: 16px;
}

.upload-card {
  transition:
    border-color 160ms ease,
    background 160ms ease,
    box-shadow 160ms ease;
}

.upload-card.upload-card-idle {
  border-color: rgba(179, 71, 47, 0.38);
  background:
    linear-gradient(180deg, rgba(255, 250, 242, 0.98) 0%, rgba(252, 239, 224, 0.98) 100%);
  box-shadow:
    0 0 0 1px rgba(179, 71, 47, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.65);
}

.card h2 {
  margin-bottom: 14px;
  font-size: 1.05rem;
}

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

.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.88rem;
  font-weight: 700;
}

input[type="file"],
input[type="number"],
input[type="text"],
select {
  width: 100%;
  border: 1px solid rgba(78, 61, 40, 0.24);
  border-radius: 12px;
  background: #fffdf9;
  color: var(--text);
  padding: 12px 14px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

button {
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 10px 14px;
  cursor: pointer;
  color: #fff8f1;
  background: linear-gradient(135deg, #c05633, #8f3625);
  transition:
    transform 120ms ease,
    box-shadow 120ms ease,
    opacity 120ms ease;
  box-shadow: 0 10px 24px rgba(143, 54, 37, 0.22);
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.action-row {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.status-line {
  min-height: 1.2rem;
  margin: 12px 0 0;
  font-size: 0.92rem;
}

.status-line.error {
  color: var(--danger);
}

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

.summary-grid div {
  padding: 12px;
  border-radius: 14px;
  background: rgba(179, 71, 47, 0.06);
}

dt {
  margin-bottom: 6px;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

dd {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0;
}

.checkbox-row input {
  width: 18px;
  height: 18px;
}

.range-readout {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 0.82rem;
}

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

.toggle-button {
  padding: 12px 14px;
  border: 1px solid rgba(78, 61, 40, 0.2);
  border-radius: 14px;
  color: var(--text);
  background: rgba(255, 252, 246, 0.9);
  box-shadow: none;
}

.toggle-button:hover {
  transform: translateY(-1px);
}

.toggle-button.is-active {
  color: #fff8f1;
  background: linear-gradient(135deg, #c05633, #8f3625);
  border-color: rgba(143, 54, 37, 0.34);
  box-shadow: 0 10px 24px rgba(143, 54, 37, 0.16);
}

.pill-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill-grid.empty-state {
  padding: 12px;
  border-radius: 14px;
  background: rgba(31, 27, 22, 0.04);
  font-size: 0.92rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid rgba(179, 71, 47, 0.14);
}

.pill input {
  margin: 0;
}

.pill-with-color {
  position: relative;
  gap: 10px;
  padding-right: 10px;
}

.pill-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: var(--text);
  cursor: pointer;
}

.pill-color-swatch {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  padding: 0;
  border-radius: 999px;
  border: 2px solid rgba(31, 27, 22, 0.18);
  background: #fffdf9;
  box-shadow: none;
}

.pill-color-swatch:hover {
  transform: none;
  border-color: rgba(31, 27, 22, 0.34);
}

.pill-color-swatch:focus-visible {
  outline: 2px solid rgba(179, 71, 47, 0.38);
  outline-offset: 2px;
}

.pill-color-input {
  position: absolute;
  width: 0;
  height: 0;
  padding: 0;
  opacity: 0;
  pointer-events: none;
}

.chart-panel {
  min-width: 0;
  min-height: 0;
}

.plot-card {
  overflow: hidden;
  border-color: var(--plot-frame);
  background:
    linear-gradient(180deg, rgba(255, 253, 249, 0.96) 0%, rgba(247, 238, 224, 0.96) 100%);
  box-shadow:
    0 22px 54px rgba(76, 48, 19, 0.15),
    inset 0 1px 0 rgba(255, 255, 255, 0.7);
  height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
}

.plot-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: end;
  min-height: 88px;
  padding: 20px 22px 0;
  border-bottom: 1px solid rgba(58, 43, 27, 0.12);
}

.plot-toolbar > div {
  min-width: 0;
}

.selection-summary {
  flex: 0 1 38ch;
  max-width: 38ch;
  text-align: right;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.plot-surface {
  min-height: 0;
  min-width: 0;
  flex: 1 1 auto;
  padding: 10px 12px 12px;
  overflow: auto;
  background:
    linear-gradient(180deg, rgba(255, 252, 246, 0.86) 0%, rgba(245, 236, 221, 0.78) 100%);
}

.plot-canvas {
  width: 100%;
  min-height: 100%;
  height: 100%;
}

.plot-grid {
  display: grid;
  width: 100%;
  min-width: 0;
  min-height: 100%;
  gap: var(--plot-grid-gap, 14px);
  grid-template-columns: repeat(var(--plot-columns, 4), minmax(0, 1fr));
  grid-auto-rows: var(--subplot-height, 340px);
  align-content: stretch;
}

.subplot-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  border: 1px solid rgba(58, 43, 27, 0.14);
  border-radius: 18px;
  background: rgba(255, 250, 242, 0.82);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.72);
  overflow: hidden;
}

.subplot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px 0;
}

.subplot-title {
  margin: 0;
  color: var(--text);
  font-size: 0.96rem;
  font-weight: 700;
}

.subplot-meta {
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
}

.subplot-plot {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 0;
  flex: 1 1 auto;
  padding: 4px 6px 8px;
  overflow: hidden;
}

.subplot-plot .js-plotly-plot,
.subplot-plot .plot-container,
.subplot-plot .svg-container {
  width: 100% !important;
  max-width: 100%;
  height: 100%;
}

.plot-empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: 28px;
  border: 1px dashed rgba(58, 43, 27, 0.22);
  border-radius: 18px;
  color: var(--muted);
  background: rgba(255, 252, 246, 0.72);
  text-align: center;
}

@media (max-width: 1080px) {
  body {
    padding: 16px;
  }

  .app-shell {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .control-panel {
    height: auto;
    overflow: visible;
  }

  .plot-card {
    height: auto;
  }

  .plot-toolbar {
    flex-direction: column;
    align-items: start;
    min-height: 0;
  }

  .selection-summary {
    flex: none;
    text-align: left;
    white-space: normal;
    overflow: visible;
  }
}

@media (max-width: 720px) {
  .field-grid,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .action-row {
    flex-direction: column;
  }

  .plot-surface {
    min-height: 72vh;
    flex: none;
  }

  .plot-grid {
    min-height: auto;
  }

  .subplot-plot {
    min-height: 300px;
  }
}
