:root {
  --bg: #eef3f9;
  --panel: #ffffff;
  --line: #cfdae8;
  --text: #152533;
  --muted: #5d7288;
  --accent: #0a718d;
  --danger: #a93838;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Avenir Next", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: radial-gradient(circle at top, #f7fbff 0%, var(--bg) 55%);
  min-height: 100vh;
}

.app-header {
  padding: 1rem 1rem 0.5rem;
}

.app-header h1 {
  margin: 0 0 0.35rem;
  font-size: 1.45rem;
}

.app-header p {
  margin: 0;
  color: var(--muted);
  line-height: 1.4;
}

.layout {
  display: grid;
  gap: 1rem;
  grid-template-columns: minmax(280px, 360px) 1fr;
  padding: 0.75rem 1rem 1rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.9rem;
  box-shadow: 0 8px 18px rgba(20, 37, 51, 0.06);
}

.panel h2 {
  margin: 0 0 0.7rem;
  font-size: 1rem;
}

.controls h2:not(:first-child) {
  margin-top: 1rem;
}

.input-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.5rem;
  align-items: center;
}

.nm-input-row {
  grid-template-columns: auto minmax(60px, 1fr) auto minmax(60px, 1fr) auto;
}

.control-grid {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 0.35rem 0.55rem;
  align-items: center;
}

.control-grid .spacer {
  width: 0;
}

label {
  font-size: 0.84rem;
  color: var(--muted);
}

input[type="text"],
input[type="number"],
input[list] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.44rem 0.52rem;
  color: var(--text);
  background: #fff;
}

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

output {
  color: var(--muted);
  font-size: 0.84rem;
  width: 3rem;
  text-align: right;
}

button {
  border: 0;
  border-radius: 8px;
  padding: 0.5rem 0.72rem;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-size: 0.9rem;
}

button:hover {
  filter: brightness(1.06);
}

.ghost {
  background: #e8f0fa;
  color: #24415a;
}

.action-row {
  margin-top: 0.6rem;
  display: flex;
  justify-content: flex-end;
}

.status {
  margin: 0.45rem 0 0;
  min-height: 1.2rem;
  color: var(--muted);
  font-size: 0.84rem;
}

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

.species-list {
  display: grid;
  gap: 0.55rem;
}

.species-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem;
  background: #fbfdff;
}

.species-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
}

.species-title {
  font-weight: 600;
  font-size: 0.94rem;
}

.species-type {
  color: var(--muted);
  font-size: 0.8rem;
}

.mini-btn {
  background: #e7edf7;
  color: #2e4a63;
  font-size: 0.78rem;
  padding: 0.35rem 0.5rem;
}

.species-grid {
  margin-top: 0.45rem;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.25rem 0.55rem;
  align-items: center;
}

.empty-note {
  color: var(--muted);
  font-size: 0.84rem;
  margin: 0;
}

.chart-panel {
  min-height: 460px;
}

.plot-wrap {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: linear-gradient(180deg, #f8fbff 0%, #ffffff 100%);
  min-height: 390px;
}

#plotSvg {
  width: 100%;
  height: 390px;
  display: block;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 0.8rem;
  margin-top: 0.55rem;
  font-size: 0.82rem;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.42rem;
  color: var(--muted);
}

.swatch {
  width: 14px;
  height: 6px;
  border-radius: 3px;
  display: inline-block;
}

.table-wrap {
  overflow-x: auto;
}

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

th,
td {
  border: 1px solid var(--line);
  padding: 0.42rem 0.5rem;
  text-align: left;
  white-space: nowrap;
}

thead {
  background: #f4f8fd;
}

.app-footer {
  color: var(--muted);
  font-size: 0.82rem;
  padding: 0 1rem 1rem;
}

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

  .controls {
    order: 2;
  }

  .chart-panel {
    order: 1;
  }

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

  .nm-input-row {
    grid-template-columns: auto 1fr auto 1fr;
  }

  .nm-input-row button {
    grid-column: 1 / -1;
  }

  .control-grid .spacer {
    display: none;
  }

  #plotSvg {
    height: 330px;
  }
}
