:root {
  color-scheme: light;
  --field-label-width: 168px;
  --field-control-width: 300px;
  --bg: #f5f7f8;
  --panel: #ffffff;
  --control: #ffffff;
  --image-bg: #ffffff;
  --ink: #172026;
  --muted: #65717b;
  --line: #d7dee3;
  --accent: #d38521;
  --accent-dark: #8c4d12;
  --on-accent: #ffffff;
  --ok: #1f7a4d;
  --warn: #a15d00;
  --bad: #a12a2a;
  --soft: #eef2f4;
  --shadow: 0 12px 30px rgba(20, 32, 38, 0.08);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --field-label-width: 168px;
  --field-control-width: 300px;
  --bg: #101418;
  --panel: #171d22;
  --control: #11171d;
  --image-bg: #f6f7f8;
  --ink: #e9eef2;
  --muted: #9aa8b3;
  --line: #2c3842;
  --accent: #d89238;
  --accent-dark: #f0b35f;
  --on-accent: #11171d;
  --ok: #62c88f;
  --warn: #dfa34a;
  --bad: #e06c6c;
  --soft: #202a33;
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

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

button,
.file-button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--control);
  color: var(--ink);
  padding: 8px 12px;
  cursor: pointer;
}

button:hover,
.file-button:hover {
  border-color: var(--accent);
}

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

.file-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 24px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.1;
  font-weight: 700;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-logo {
  width: 150px;
  height: 40px;
  flex: 0 0 auto;
  object-fit: contain;
}

.brand-text {
  min-width: 0;
}

.topbar-actions,
.section-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.topbar-actions {
  justify-content: flex-end;
}

.status-message {
  min-height: 20px;
  color: var(--ok);
  font-size: 12px;
  font-weight: 600;
}

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

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.theme-swatch {
  width: 16px;
  height: 16px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: linear-gradient(90deg, var(--ink) 0 50%, var(--bg) 50% 100%);
}

.baseline-loader {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 8px;
  align-items: end;
  margin-bottom: 12px;
}

.baseline-loader label {
  margin: 0;
}

.preset-detail {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.workspace {
  display: grid;
  grid-template-columns: 280px minmax(620px, 1fr) 360px;
  gap: 14px;
  padding: 14px;
  min-height: 0;
}

.workflow-panel,
.editor-panel,
.reference-panel {
  min-width: 0;
}

.workflow-panel,
.reference-panel {
  position: sticky;
  top: 14px;
  align-self: start;
  max-height: calc(100vh - 28px);
  overflow: auto;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  border-radius: 8px;
  padding: 14px;
}

.workflow-panel h2,
.reference-panel h2,
.section-heading h2 {
  margin: 0;
  font-size: 16px;
}

.wizard-progress,
.wizard-intro {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.workflow-list {
  margin: 12px 0;
  padding: 0;
  list-style: none;
}

.workflow-list li {
  padding: 0;
  border-bottom: 1px solid var(--soft);
}

.workflow-list button {
  width: 100%;
  min-height: 54px;
  display: grid;
  grid-template-columns: 24px 1fr auto;
  gap: 8px;
  align-items: center;
  border: 0;
  border-radius: 6px;
  background: transparent;
  padding: 8px 0;
  text-align: left;
}

.workflow-list li.active button {
  background: var(--soft);
  padding-inline: 8px;
}

.workflow-list strong {
  display: block;
  font-size: 13px;
}

.workflow-list span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.status-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  color: var(--on-accent);
  font-size: 12px;
  background: var(--muted);
}

.status-ok {
  background: var(--ok);
}

.status-warn {
  background: var(--warn);
}

.status-bad {
  background: var(--bad);
}

.derived-box {
  margin-top: 14px;
  padding: 12px;
  background: var(--soft);
  border-radius: 6px;
}

.derived-box h3,
.reference-panel h3,
.form-band h3 {
  margin: 0 0 10px;
  font-size: 14px;
}

.form-band h3 {
  margin-bottom: 16px;
}

.derived-box dl {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 10px;
  margin: 0;
}

.derived-box dt {
  color: var(--muted);
}

.derived-box dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.editor-panel {
  display: grid;
  gap: 14px;
  align-content: start;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

#profileForm,
.preview-panel {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  border-radius: 8px;
  padding: 14px;
}

#profileForm.inactive {
  display: none;
}

.form-band {
  display: none;
  padding: 0;
  border-bottom: 0;
}

.form-band.active-step {
  display: block;
}

.step-note {
  margin: 0 0 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--soft);
  color: var(--muted);
  font-size: 13px;
}

label {
  display: grid;
  gap: 4px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--control);
  color: var(--ink);
  padding: 8px 9px;
  min-height: 36px;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(211, 133, 33, 0.25);
  border-color: var(--accent);
}

.field-group {
  max-width: 560px;
  margin-bottom: 18px;
}

.field-group:last-child {
  margin-bottom: 0;
}

.field-group h4 {
  margin: 0 0 8px;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  font-size: 13px;
}

.field-group-note {
  max-width: calc(var(--field-label-width) + var(--field-control-width) + 42px);
  margin: -2px 0 10px 26px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.field-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 26px;
}

.field-list li {
  padding-left: 4px;
}

.field-list li::marker {
  color: var(--accent);
  font-weight: 700;
}

.field-list label {
  grid-template-columns: var(--field-label-width) var(--field-control-width);
  align-items: center;
  gap: 12px;
}

.field-list label > span {
  color: var(--muted);
}

.field-label {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: fit-content;
  max-width: 100%;
}

.help-trigger {
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--soft);
  color: var(--accent-dark);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  cursor: help;
}

.help-trigger:focus {
  outline: 2px solid rgba(211, 133, 33, 0.3);
  outline-offset: 2px;
}

.field-tooltip {
  position: absolute;
  left: 0;
  top: calc(100% + 7px);
  z-index: 20;
  display: none;
  width: min(330px, calc(100vw - 48px));
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  box-shadow: var(--shadow);
  color: var(--ink);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
}

.field-label:hover .field-tooltip,
.field-label:focus-within .field-tooltip,
.field-label.open .field-tooltip {
  display: block;
}

.field-list input,
.field-list select,
.field-list textarea {
  width: 100%;
}

.field-list textarea {
  min-height: 88px;
}

.field-action-row {
  margin: 8px 0 0 calc(30px + var(--field-label-width) + 12px);
}

.field-action-row button {
  width: var(--field-control-width);
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  color: var(--muted);
}

.toggle-row label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 13px;
}

.toggle-row input {
  width: auto;
  min-height: 0;
}

.contact-editor {
  display: grid;
  gap: 14px;
}

.contact-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0 0 calc(30px + var(--field-label-width) + 12px);
}

.contact-actions button,
.contact-card-header button {
  min-height: 32px;
  padding: 6px 10px;
  font-size: 12px;
}

.contact-card {
  display: grid;
  gap: 8px;
}

.contact-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.contact-card h5 {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.contact-card h5 span {
  color: var(--accent);
  font-weight: 800;
}

.contact-card .field-list {
  margin-left: 0;
}

.preview-panel {
  display: none;
  min-height: 520px;
  grid-template-rows: auto 1fr;
}

.preview-panel.active-step {
  display: grid;
}

#xmlPreview {
  width: 100%;
  min-height: 470px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  line-height: 1.4;
  white-space: pre;
  overflow: auto;
}

.wizard-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 10px;
}

#wizardStepHint {
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.summary-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 4px 10px;
  background: var(--soft);
  color: var(--muted);
  font-size: 12px;
}

.guide-summary {
  margin: 8px 0 12px;
  color: var(--muted);
}

.step-visual {
  min-height: 220px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  overflow: hidden;
}

.step-visual img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  background: var(--image-bg);
}

.visual-caption {
  padding: 8px 10px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.guide-list {
  margin: 0 0 14px;
  padding-left: 18px;
}

.guide-list li {
  margin-bottom: 8px;
}

.axis-visual,
.contact-visual,
.export-visual {
  min-height: 220px;
  display: grid;
  place-items: center;
  padding: 18px;
}

.axis-card {
  position: relative;
  width: min(260px, 100%);
  aspect-ratio: 1;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.axis-line {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 42%;
  height: 3px;
  transform-origin: left center;
  background: var(--accent);
}

.axis-x {
  transform: rotate(0deg);
}

.axis-y {
  transform: rotate(-35deg);
  background: var(--ok);
}

.axis-z {
  transform: rotate(-90deg);
  background: var(--bad);
}

.axis-label {
  position: absolute;
  font-size: 12px;
  font-weight: 700;
}

.axis-label.x {
  right: 12px;
  top: 48%;
}

.axis-label.y {
  right: 24px;
  top: 30%;
}

.axis-label.z {
  left: calc(50% + 8px);
  top: 8px;
}

.cg-dot {
  position: absolute;
  left: calc(50% - 7px);
  top: calc(50% - 7px);
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(211, 133, 33, 0.2);
}

.contact-sketch {
  position: relative;
  width: min(280px, 100%);
  height: 170px;
  border-bottom: 4px solid var(--line);
}

.contact-body {
  position: absolute;
  left: 50%;
  top: 24px;
  width: 170px;
  height: 46px;
  border: 2px solid var(--accent);
  border-radius: 50% 50% 42% 42%;
  transform: translateX(-50%);
}

.contact-leg {
  position: absolute;
  top: 70px;
  width: 3px;
  height: 64px;
  background: var(--muted);
}

.contact-leg.left {
  left: 88px;
}

.contact-leg.right {
  right: 88px;
}

.contact-wheel {
  position: absolute;
  bottom: 22px;
  width: 28px;
  height: 28px;
  border: 3px solid var(--ink);
  border-radius: 50%;
}

.contact-wheel.left {
  left: 74px;
}

.contact-wheel.right {
  right: 74px;
}

.export-visual code {
  display: block;
  width: min(280px, 100%);
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--control);
  color: var(--ink);
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  white-space: pre-wrap;
}

.diagram-library {
  margin-top: 10px;
}

.reference-panel figure {
  margin: 0 0 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: var(--image-bg);
}

.reference-panel img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  background: var(--image-bg);
}

.reference-panel figcaption {
  padding: 8px 10px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

#diagramSelect {
  max-width: 190px;
}

.validation-list,
.tuning-list {
  margin: 0 0 14px;
  padding-left: 18px;
}

.validation-list li,
.tuning-list li {
  margin-bottom: 6px;
}

.validation-list .ok {
  color: var(--ok);
}

.validation-list .warn {
  color: var(--warn);
}

.validation-list .bad {
  color: var(--bad);
}

@media (max-width: 1340px) {
  .workspace {
    grid-template-columns: 220px minmax(0, 1fr);
  }

  .reference-panel {
    position: static;
    grid-column: 1 / -1;
    max-height: none;
  }
}

@media (max-width: 840px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-brand {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

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

  .baseline-loader {
    grid-template-columns: 1fr;
  }

  .workflow-panel {
    position: static;
    max-height: none;
  }

  .grid.two,
  .grid.three,
  .grid.four,
  .contact-row {
    grid-template-columns: 1fr;
  }

  .field-group {
    max-width: none;
  }

  .field-list label {
    grid-template-columns: minmax(120px, var(--field-label-width)) minmax(0, var(--field-control-width));
  }

  .section-heading,
  .toggle-row {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 620px) {
  .field-list {
    padding-left: 22px;
  }

  .field-group-note {
    margin-left: 22px;
  }

  .field-list label {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .field-action-row {
    margin-left: 26px;
  }

  .field-action-row button {
    width: 100%;
  }
}
