:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-strong: #edf3f6;
  --ink: #151923;
  --muted: #5f6b78;
  --line: #d8e1ea;
  --accent: #007f73;
  --accent-soft: #dff4ef;
  --coral: #d86f45;
  --indigo: #4d5fd7;
  --shadow: 0 18px 50px rgba(17, 24, 39, 0.1);
  --radius: 8px;
  --max-width: 1220px;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111419;
  --surface: #1a1f27;
  --surface-strong: #222a35;
  --ink: #f5f7fb;
  --muted: #b5bfcb;
  --line: #323b48;
  --accent: #45c7b5;
  --accent-soft: #143a36;
  --coral: #ff9b70;
  --indigo: #9aa5ff;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(90deg, rgba(0, 127, 115, 0.07), transparent 32%),
    linear-gradient(180deg, rgba(216, 111, 69, 0.08), transparent 38%),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.55;
}

a {
  color: inherit;
}

button,
textarea,
select,
input {
  font: inherit;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem max(1rem, calc((100vw - var(--max-width)) / 2));
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface), transparent 8%);
  backdrop-filter: blur(16px);
}

.brand,
.app-header nav {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.brand,
.app-header a {
  text-decoration: none;
}

.brand span {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--surface);
  font-weight: 900;
}

.app-header nav a,
.theme-toggle,
.example-row button,
.table-heading button {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
  min-height: 38px;
  padding: 0.55rem 0.75rem;
  text-decoration: none;
}

.app-shell {
  width: min(var(--max-width), calc(100% - 2rem));
  margin: 0 auto;
  padding: 4rem 0 5rem;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 1rem;
  align-items: end;
  margin-bottom: 1rem;
}

.eyebrow {
  margin: 0 0 0.7rem;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

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

h1 {
  max-width: 11ch;
  margin-bottom: 1rem;
  font-size: clamp(2.5rem, 7vw, 5rem);
  line-height: 0.96;
}

h2 {
  margin-bottom: 0.6rem;
  font-size: 1.35rem;
}

.hero p,
.status,
.metric-grid p,
.legend,
td {
  color: var(--muted);
}

.hero-card,
.input-panel,
.settings-panel,
.metric-grid article,
.spectrum-panel,
.composition-panel,
.table-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface), transparent 2%);
  box-shadow: var(--shadow);
}

.hero-card,
.metric-grid article {
  padding: 1rem;
}

.hero-card span,
.metric-grid span {
  display: block;
  color: var(--coral);
  font-size: 1.8rem;
  font-weight: 900;
  line-height: 1;
  overflow-wrap: anywhere;
}

.hero-card p,
.metric-grid p {
  margin: 0.45rem 0 0;
}

.control-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.9fr);
  gap: 1rem;
  margin-bottom: 1rem;
}

.input-panel,
.settings-panel,
.spectrum-panel,
.composition-panel,
.table-panel {
  padding: 1rem;
}

.input-panel label,
.settings-panel label span:first-child {
  display: block;
  margin-bottom: 0.45rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  padding: 0.75rem;
}

textarea {
  min-height: 140px;
  resize: vertical;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 1rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.example-row,
.field-row,
.legend,
.table-heading {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.example-row {
  margin: 0.75rem 0;
}

.field-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 1rem;
}

.slider-label {
  display: grid;
  gap: 0.7rem;
  margin-top: 1rem;
}

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

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.8rem;
  margin-bottom: 1rem;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.8rem;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.86rem;
  font-weight: 800;
}

.legend i {
  display: inline-block;
  width: 18px;
  height: 4px;
  border-radius: 10px;
}

.profile-key {
  background: var(--accent);
}

.centroid-key {
  background: var(--coral);
}

.spectrum-panel {
  margin-bottom: 1rem;
}

.spectrum-panel canvas {
  width: 100%;
  height: min(460px, 52vh);
  min-height: 300px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
}

.data-grid {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 1rem;
}

.composition-list {
  display: grid;
  gap: 0.5rem;
}

.element-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  padding: 0.65rem;
}

.element-row strong {
  color: var(--accent);
}

.table-heading {
  justify-content: space-between;
  margin-bottom: 0.8rem;
}

.table-wrap {
  max-height: 440px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

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

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

th {
  position: sticky;
  top: 0;
  background: var(--ink);
  color: var(--surface);
  font-size: 0.78rem;
}

tbody tr:nth-child(even) td {
  background: color-mix(in srgb, var(--surface-strong), transparent 42%);
}

.status.is-error {
  color: var(--coral);
  font-weight: 800;
}

@media (max-width: 980px) {
  .hero,
  .control-grid,
  .data-grid {
    grid-template-columns: 1fr;
  }

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

  h1 {
    max-width: 14ch;
  }
}

@media (max-width: 640px) {
  .app-header,
  .app-header nav,
  .field-row,
  .metric-grid {
    align-items: stretch;
    flex-direction: column;
    grid-template-columns: 1fr;
  }

  .app-shell {
    padding-top: 2.5rem;
  }

  h1 {
    font-size: 2.5rem;
  }

  th,
  td {
    white-space: normal;
  }
}
