:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --surface-strong: #ffffff;
  --ink: #20231f;
  --muted: #687066;
  --line: #d9d2c3;
  --line-strong: #b7ac99;
  --accent: #1f7a5c;
  --accent-dark: #11523c;
  --accent-soft: #dceee7;
  --amber: #bf6f19;
  --amber-soft: #fff1db;
  --danger: #a33a2d;
  --danger-soft: #fae6e2;
  --shadow: 0 18px 50px rgba(48, 42, 31, 0.12);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(31, 122, 92, 0.08), transparent 320px),
    var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

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

button {
  border: 0;
}

.app-header {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-start;
  width: min(1540px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 20px;
}

.app-header h1 {
  margin: 4px 0 8px;
  font-size: clamp(2rem, 4vw, 4rem);
  line-height: 0.98;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0;
  color: var(--accent-dark);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.lede {
  max-width: 820px;
  margin: 0;
  color: #4d554b;
  font-size: 1.02rem;
}

.header-actions,
.test-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.primary-button,
.secondary-button {
  min-height: 42px;
  border-radius: var(--radius);
  padding: 0 16px;
  cursor: pointer;
  font-weight: 800;
  transition: transform 120ms ease, box-shadow 120ms ease, background-color 120ms ease;
}

.primary-button {
  color: white;
  background: var(--accent);
  box-shadow: 0 10px 24px rgba(31, 122, 92, 0.22);
}

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

.secondary-button {
  color: var(--ink);
  background: var(--surface-strong);
  border: 1px solid var(--line);
}

.secondary-button:hover {
  border-color: var(--line-strong);
  transform: translateY(-1px);
}

.primary-button.small {
  min-height: 36px;
  padding: 0 13px;
}

.studio {
  display: grid;
  grid-template-columns: minmax(360px, 0.95fr) minmax(420px, 1.05fr);
  gap: 20px;
  width: min(1540px, calc(100% - 32px));
  margin: 0 auto 28px;
  align-items: start;
}

.editor-pane,
.preview-pane {
  min-width: 0;
}

.form-panel,
.preview-sticky {
  background: rgba(255, 253, 248, 0.92);
  border: 1px solid rgba(185, 174, 154, 0.72);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.form-panel {
  padding: 18px;
  margin-bottom: 16px;
}

.section-heading {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 12px;
  align-items: start;
  margin-bottom: 16px;
}

.section-heading.compact {
  margin-bottom: 12px;
}

.section-heading h2,
.preview-heading h2 {
  margin: 0;
  font-size: 1.18rem;
  line-height: 1.2;
  letter-spacing: 0;
}

.section-heading p,
.self-test-panel p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.step-badge {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  color: var(--accent-dark);
  background: var(--accent-soft);
  border: 1px solid #b9dfd0;
  border-radius: 50%;
  font-weight: 900;
}

.field-grid,
.nutrition-grid {
  display: grid;
  gap: 12px;
}

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

.field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.field span,
.mini-heading {
  color: #30362f;
  font-size: 0.82rem;
  font-weight: 850;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  min-height: 42px;
  color: var(--ink);
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 11px;
  outline: none;
}

.field textarea {
  resize: vertical;
  min-height: 96px;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 122, 92, 0.14);
}

.field small {
  color: var(--muted);
  font-size: 0.78rem;
}

.allergen-box {
  margin-top: 12px;
  padding: 12px;
  background: #f7f4ed;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.chip,
.muted-chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.8rem;
  font-weight: 800;
}

.chip {
  color: #56360e;
  background: var(--amber-soft);
  border: 1px solid #e3c08b;
}

.muted-chip {
  color: var(--muted);
  background: white;
  border: 1px solid var(--line);
}

.reference-details,
.advanced-nutrition,
.explainers details {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
}

summary {
  cursor: pointer;
  padding: 11px 12px;
  color: #30362f;
  font-weight: 850;
}

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

.reference-item {
  display: grid;
  gap: 3px;
  padding: 9px;
  background: #faf8f3;
  border: 1px solid #ece5d8;
  border-radius: var(--radius);
}

.reference-item strong {
  font-size: 0.8rem;
}

.reference-item span {
  color: var(--muted);
  font-size: 0.76rem;
}

.nutrition-grid {
  margin-top: 12px;
}

.explainers {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.explainers details {
  margin-top: 0;
}

.explainers p {
  margin: 0;
  padding: 0 12px 12px;
  color: var(--muted);
  font-size: 0.84rem;
}

.advanced-nutrition .nutrition-grid {
  padding: 0 12px 12px;
}

.option-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.check-field {
  display: flex;
  gap: 9px;
  align-items: center;
  min-height: 40px;
  padding: 9px 10px;
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: #30362f;
  font-size: 0.86rem;
  font-weight: 760;
}

.check-field input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.energy-card {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 14px;
  padding: 14px;
  color: #0f3e2e;
  background: var(--accent-soft);
  border: 1px solid #b9dfd0;
  border-radius: var(--radius);
}

.energy-card span {
  display: block;
  font-size: 0.8rem;
  font-weight: 850;
}

.energy-card strong {
  display: block;
  margin-top: 4px;
  font-size: 1.4rem;
  line-height: 1.1;
}

.energy-card p {
  max-width: 360px;
  margin: 0;
  color: #32594b;
  font-size: 0.82rem;
}

.test-summary {
  display: inline-grid;
  place-items: center;
  min-height: 34px;
  border-radius: 999px;
  padding: 4px 12px;
  color: var(--muted);
  background: var(--surface-strong);
  border: 1px solid var(--line);
  font-weight: 900;
}

.test-summary.pass {
  color: #0f5138;
  background: #dff4e9;
  border-color: #a8dcc0;
}

.test-summary.fail {
  color: #7d1f1b;
  background: var(--danger-soft);
  border-color: #e3aaa2;
}

.test-results {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.test-result {
  display: grid;
  grid-template-columns: 60px 1fr;
  gap: 10px;
  align-items: center;
  padding: 9px 10px;
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 0.84rem;
}

.test-result span {
  font-weight: 950;
}

.test-result.pass span {
  color: var(--accent-dark);
}

.test-result.fail span {
  color: var(--danger);
}

.test-result em {
  grid-column: 2;
  color: var(--danger);
  font-style: normal;
}

.preview-sticky {
  position: sticky;
  top: 16px;
  padding: 18px;
}

.preview-heading {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 12px;
}

.preview-heading h2 {
  margin-top: 3px;
}

.validation-panel {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  padding: 12px;
  background: var(--amber-soft);
  border: 1px solid #e3c08b;
  border-radius: var(--radius);
  color: #56360e;
}

.validation-panel.ok {
  color: #0f5138;
  background: #e3f4eb;
  border-color: #a8dcc0;
}

.validation-panel strong {
  font-size: 0.88rem;
}

.validation-panel span,
.validation-panel li {
  font-size: 0.82rem;
}

.validation-panel ul {
  margin: 0;
  padding-left: 18px;
}

.label-preview {
  max-width: 640px;
  margin: 0 auto;
  padding: 28px;
  color: #111;
  background: #fff;
  border: 1px solid #cfcfcf;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.12);
}

.label-title {
  padding-bottom: 12px;
  border-bottom: 3px solid #111;
}

.label-title h3 {
  margin: 0;
  font-size: clamp(1.55rem, 3vw, 2.3rem);
  line-height: 1.02;
  letter-spacing: 0;
}

.label-title p {
  margin: 7px 0 0;
  font-size: 1rem;
  font-weight: 700;
}

.label-line,
.label-block {
  padding: 10px 0;
  border-bottom: 1px solid #111;
}

.label-line {
  font-size: 0.98rem;
}

.label-block p {
  margin: 6px 0 0;
}

.label-block > strong,
.label-line > strong {
  font-weight: 950;
}

.allergy-advice {
  font-size: 0.9rem;
}

.allergen-hit {
  font-weight: 950;
  background: #fff0b5;
  padding: 0 1px;
}

.nutrition-table {
  width: 100%;
  margin-top: 8px;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.nutrition-table th,
.nutrition-table td {
  padding: 7px 8px;
  border: 1px solid #111;
  text-align: left;
  vertical-align: top;
}

.nutrition-table th {
  color: #fff;
  background: #111;
  font-weight: 950;
}

.nutrition-table td:nth-child(n + 2),
.nutrition-table th:nth-child(n + 2) {
  text-align: right;
  white-space: nowrap;
}

.nutrition-table .energy-row td {
  font-weight: 950;
}

.nutrition-table .indent {
  padding-left: 26px;
}

.nutrition-table tfoot td {
  font-size: 0.76rem;
  text-align: left;
  border-top: 2px solid #111;
}

.label-foot {
  display: grid;
  gap: 4px;
  margin-top: 12px;
  color: #333;
  font-size: 0.78rem;
}

.app-footer {
  width: min(1540px, calc(100% - 32px));
  margin: 0 auto 32px;
  color: #5a6257;
  font-size: 0.86rem;
}

.app-footer p {
  margin: 0;
}

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

  .preview-sticky {
    position: static;
  }

  .label-preview {
    max-width: none;
  }
}

@media (max-width: 760px) {
  .app-header {
    display: grid;
  }

  .header-actions {
    width: 100%;
  }

  .header-actions .primary-button,
  .header-actions .secondary-button {
    flex: 1 1 150px;
  }

  .studio,
  .app-header,
  .app-footer {
    width: min(100% - 20px, 1540px);
  }

  .form-panel,
  .preview-sticky {
    padding: 14px;
  }

  .field-grid.two,
  .nutrition-grid,
  .explainers,
  .option-row,
  .reference-grid {
    grid-template-columns: 1fr;
  }

  .energy-card {
    display: grid;
  }

  .label-preview {
    padding: 18px;
  }

  .nutrition-table {
    font-size: 0.84rem;
  }

  .nutrition-table th,
  .nutrition-table td {
    padding: 6px;
  }
}
