:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #657386;
  --border: #d9e0e8;
  --accent: #0f766e;
  --accent-soft: #d9f2ee;
  --warn: #a15c00;
  --warn-bg: #fff4dc;
  --shadow: 0 18px 45px rgba(38, 52, 69, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
}

.app {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}

header {
  display: flex;
  gap: 24px;
  align-items: flex-start;
  justify-content: space-between;
  padding: 24px 28px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 760;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0 0 8px;
  font-size: clamp(24px, 3vw, 38px);
  line-height: 1.05;
  font-weight: 760;
  letter-spacing: 0;
}

.subtitle {
  max-width: 820px;
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
}

.formula {
  min-width: 330px;
  max-width: 460px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfcfd;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.45;
  color: #263445;
}

main {
  display: grid;
  grid-template-columns: minmax(260px, 340px) minmax(360px, 1fr);
  gap: 18px;
  padding: 18px;
  min-height: 0;
  overflow: hidden;
}

.controls,
.plot-shell {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.controls {
  padding: 18px;
  align-self: stretch;
  min-height: 0;
  overflow-y: auto;
  scrollbar-gutter: stable;
}

.field {
  margin-bottom: 16px;
}

label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

select,
input[type="range"] {
  width: 100%;
}

select {
  min-height: 38px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}

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

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin: 18px 0 14px;
}

.section-head.compact {
  margin-top: 20px;
}

.section-head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.primary-value {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  font-weight: 760;
}

.parameter-panel {
  display: grid;
  gap: 16px;
}

.range-row {
  display: grid;
  gap: 7px;
}

.select-row {
  display: grid;
  gap: 7px;
}

.range-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
}

.range-label {
  color: var(--muted);
  font-weight: 650;
}

.range-value {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  font-weight: 760;
}

.ticks {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.stats {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
}

.stat {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.stat span:first-child {
  color: var(--muted);
}

.stat span:last-child {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  text-align: right;
}

.note {
  margin: 0;
  padding: 12px 13px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: #17433f;
  font-size: 13px;
  line-height: 1.45;
}

.network-note {
  margin-top: 12px;
  background: var(--warn-bg);
  color: var(--warn);
}

.plot-shell {
  min-height: 0;
  overflow-y: auto;
  scrollbar-gutter: stable;
}

#plot {
  width: 100%;
  height: min(760px, calc(100vh - 150px));
  min-height: 540px;
}

.material-preview {
  border-top: 1px solid var(--border);
  padding: 18px;
  background: #fbfcfd;
}

.preview-head {
  display: grid;
  grid-template-columns: auto minmax(320px, 520px);
  gap: 16px;
  margin-bottom: 14px;
}

.preview-head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.preview-controls {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) minmax(120px, 1fr) minmax(120px, 1fr);
  gap: 12px;
  align-items: end;
}

.preview-slider {
  display: grid;
  gap: 6px;
}

.preview-slider label,
.preview-slider output {
  margin: 0;
  font-size: 12px;
}

.preview-slider output {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  font-weight: 760;
}

#materialPreview {
  display: block;
  width: 100%;
  height: 360px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #eef2f6;
  cursor: grab;
  touch-action: none;
}

#materialPreview:active {
  cursor: grabbing;
}

.preview-caption {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.status {
  display: none;
  margin: 18px;
  padding: 14px 16px;
  border: 1px solid #f2c86f;
  border-radius: 8px;
  background: var(--warn-bg);
  color: var(--warn);
  font-size: 14px;
  line-height: 1.45;
}

.status[data-visible="true"] {
  display: block;
}

@media (max-width: 920px) {
  header,
  main {
    padding-left: 14px;
    padding-right: 14px;
  }

  header {
    display: grid;
  }

  .formula {
    min-width: 0;
    max-width: none;
    overflow-x: auto;
  }
  #plot {
    height: 64vh;
    min-height: 420px;
  }

  .plot-shell {
    min-height: 420px;
  }

  .preview-head {
    grid-template-columns: 1fr;
  }

  .preview-controls {
    grid-template-columns: 1fr;
  }

  #materialPreview {
    height: 300px;
  }
}

@media (max-width: 680px) {
  body {
    overflow: auto;
  }

  .app {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  main {
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .controls,
  .plot-shell {
    max-height: none;
    overflow: visible;
  }
}
