:root {
  color-scheme: light;
  --page: #ffffff;
  --surface: #ffffff;
  --surface-soft: #f7f9f8;
  --ink: #171c1a;
  --muted: #67706c;
  --line: #dce2df;
  --line-strong: #bfc9c4;
  --accent: #de2910;
  --accent-dark: #b91f0b;
  --success: #20735a;
  --warning: #a74524;
  --radius: 8px;
  --shadow: none;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--page);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

p {
  margin: 0;
}

.builder-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
  gap: 14px;
  width: 100%;
  margin: 0 auto;
  padding: 12px;
}

.control-card,
.preview-card {
  min-width: 0;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.preview-card {
  position: static;
}

.control-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-height: 30px;
  margin-bottom: 4px;
}

.text-button {
  min-height: 30px;
  padding: 0 4px;
  color: var(--muted);
  background: transparent;
  border: 0;
  font-size: 0.8rem;
  font-weight: 760;
}

.text-button:hover {
  color: var(--ink);
}

form {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}

fieldset {
  display: grid;
  align-content: start;
  gap: 7px;
  margin: 0;
  padding: 10px 0;
  border: 0;
  border-top: 1px solid var(--line);
}

fieldset:first-child {
  padding-top: 0;
  border-top: 0;
}

fieldset:last-child > .option-stack {
  grid-template-columns: 150px minmax(0, 1fr);
}

legend {
  width: 100%;
  margin-bottom: 4px;
  padding: 0;
  color: #343c38;
  font-size: 0.86rem;
  font-weight: 820;
  text-transform: uppercase;
}

.field-grid {
  display: grid;
  gap: 7px;
}

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

.field {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  min-width: 0;
  color: #3b4540;
  font-size: 0.88rem;
  font-weight: 700;
}

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

input[type="number"],
input[type="text"] {
  width: 100%;
  min-width: 0;
  min-height: 40px;
  padding: 0 12px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  font-size: 1rem;
  outline: none;
}

input:focus-visible,
button:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(222, 41, 16, 0.17);
  outline-offset: 2px;
}

input[aria-invalid="true"] {
  color: var(--warning);
  border-color: var(--warning);
  background: #fff7f4;
}

.input-with-unit {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.input-with-unit > span {
  min-width: 26px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 760;
  text-align: right;
}

.field-help,
.download-help {
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.35;
}

.field-help {
  margin-left: 162px;
}

.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 7px 20px;
  padding: 2px 0;
}

.segmented label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  cursor: pointer;
}

.segmented input {
  position: static;
  inline-size: 18px;
  block-size: 18px;
  flex: 0 0 auto;
  margin: 0;
  opacity: 1;
  pointer-events: auto;
  accent-color: var(--accent);
}

.segmented span {
  display: inline;
  min-height: 0;
  padding: 0;
  color: #47514c;
  background: transparent;
  border: 0;
  border-radius: 0;
  font-size: 0.9rem;
  font-weight: 680;
  text-align: left;
}

.segmented input:checked + span {
  color: var(--ink);
  background: transparent;
  border-color: transparent;
  font-weight: 800;
}

.dynamic-fields {
  padding-top: 2px;
}

.dynamic-fields[hidden] {
  display: none;
}

.option-stack {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
}

.option-label {
  color: #3b4540;
  font-size: 0.88rem;
  font-weight: 700;
}

.advanced-details {
  margin-top: 2px;
  padding: 0;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 9px;
}

.advanced-details summary {
  padding: 10px 12px;
  color: #3f4944;
  font-size: 0.86rem;
  font-weight: 760;
  cursor: pointer;
}

.advanced-fields {
  display: grid;
  gap: 7px;
  padding: 2px 12px 12px;
}

.advanced-fields .field {
  grid-template-columns: 138px minmax(0, 1fr);
}

.summary-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 9px 11px;
  color: var(--muted);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 9px;
  font-size: 0.86rem;
}

.summary-strip strong {
  color: var(--ink);
}

.validation-message {
  min-height: 1.2em;
  margin-top: 6px;
  color: var(--warning);
  font-size: 0.84rem;
  font-weight: 680;
  line-height: 1.4;
}

.canvas-frame {
  width: 100%;
  margin: 0 auto;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1800 / 1070;
  background: #ffffff;
  box-shadow: none;
}

.primary-button {
  width: 100%;
  min-height: 46px;
  margin-top: 10px;
  padding: 0 18px;
  color: #ffffff;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 9px;
  font-size: 1rem;
  font-weight: 820;
}

.primary-button:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.download-help {
  margin-top: 7px;
  text-align: center;
}

.usage-note {
  margin: 9px auto 0;
  max-width: 680px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
  text-align: center;
}

.usage-note a {
  color: var(--accent-dark);
  font-weight: 760;
}

@media (max-width: 620px) {
  .builder-shell {
    width: 100%;
    padding: 10px;
  }

  .control-card,
  .preview-card {
    padding: 12px;
  }

  .field {
    grid-template-columns: 112px minmax(0, 1fr);
    gap: 8px;
  }

  .advanced-fields .field {
    grid-template-columns: 100px minmax(0, 1fr);
  }

  fieldset {
    padding: 10px 0;
  }

  .option-stack,
  fieldset:last-child > .option-stack {
    grid-template-columns: minmax(0, 1fr);
    align-items: stretch;
    gap: 4px;
  }

  .field-grid.two-columns {
    gap: 7px;
  }

  .field-help {
    margin-left: 120px;
  }
}
