:root {
  --paper: #f4f2ed;
  --surface: #fffefa;
  --surface-strong: #ffffff;
  --ink: #202522;
  --muted: #69716c;
  --line: #d9dcd5;
  --line-strong: #bfc5bd;
  --teal: #177f76;
  --teal-soft: #dceee9;
  --coral: #c76545;
  --coral-soft: #f4e2da;
  --mustard: #c49a2c;
  --mustard-soft: #f4ebcb;
  --charcoal: #252c28;
  --danger: #a4473f;
  --shadow: 0 18px 50px rgba(31, 39, 34, 0.08);
  --radius: 8px;
  --sidebar-width: 184px;
  --preview-width: 346px;
}

[hidden] {
  display: none !important;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: "Manrope", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

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

button,
label,
select,
input[type="range"],
input[type="color"] {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(23, 127, 118, 0.18);
  outline-offset: 1px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  grid-template-rows: 72px minmax(0, 1fr);
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 72px;
  padding: 0 24px;
  background: rgba(255, 254, 250, 0.96);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 30;
  backdrop-filter: blur(12px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  background: var(--charcoal);
  color: white;
  border-radius: 6px;
  font-family: "Unbounded", sans-serif;
  font-size: 12px;
  box-shadow: 4px 4px 0 var(--mustard);
}

.brand strong,
.brand small {
  display: block;
  letter-spacing: 0;
}

.brand strong {
  font-family: "Unbounded", sans-serif;
  font-size: 14px;
  line-height: 1.1;
}

.brand small {
  color: var(--muted);
  margin-top: 3px;
  font-size: 10px;
  text-transform: uppercase;
}

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

.save-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  margin-right: 6px;
}

.save-status svg,
.section-badge svg,
.species-tag svg {
  width: 14px;
  height: 14px;
}

.icon-button {
  width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

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

.icon-button svg {
  width: 18px;
  height: 18px;
}

.icon-button.small {
  width: 32px;
  height: 32px;
  background: transparent;
}

.button {
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 700;
  color: var(--ink);
  background: var(--surface);
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button svg {
  width: 17px;
  height: 17px;
}

.button.compact {
  min-height: 40px;
  padding: 0 14px;
  font-size: 12px;
}

.button.primary {
  background: var(--teal);
  color: white;
  box-shadow: 0 8px 20px rgba(23, 127, 118, 0.18);
}

.button.dark {
  background: var(--charcoal);
  color: white;
}

.button.ghost {
  background: transparent;
  border-color: var(--line);
}

.step-nav {
  grid-column: 1;
  grid-row: 2;
  padding: 22px 12px;
  border-right: 1px solid var(--line);
  background: var(--surface);
  position: sticky;
  top: 72px;
  height: calc(100vh - 72px);
  overflow-y: auto;
}

.step-link {
  width: 100%;
  min-height: 48px;
  border: 0;
  border-radius: 6px;
  padding: 0 12px;
  margin-bottom: 4px;
  background: transparent;
  display: grid;
  grid-template-columns: 18px 18px 1fr;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  text-align: left;
  font-size: 12px;
  font-weight: 700;
  transition: background 160ms ease, color 160ms ease;
}

.step-link svg {
  width: 17px;
  height: 17px;
}

.step-link:hover {
  background: #f4f5f1;
  color: var(--ink);
}

.step-link.active {
  background: var(--charcoal);
  color: white;
}

.step-number {
  font-size: 9px;
  font-weight: 700;
  opacity: 0.55;
}

.workspace {
  grid-column: 2;
  grid-row: 2;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(560px, 1fr) var(--preview-width);
  gap: 20px;
  padding: 20px;
  align-items: start;
}

.editor-panel {
  min-width: 0;
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

#characterForm {
  min-height: calc(100vh - 188px);
}

.form-step {
  display: none;
  padding: 34px 38px 28px;
  animation: stepIn 220ms ease;
}

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

@keyframes stepIn {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

.section-heading,
.subsection-title,
.preview-identity,
.preview-topline,
.quality-row,
.range-label,
.prompt-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.section-heading {
  padding-bottom: 26px;
  margin-bottom: 26px;
  border-bottom: 1px solid var(--line);
}

.section-heading h1 {
  margin: 6px 0 8px;
  max-width: 640px;
  font-family: "Unbounded", sans-serif;
  font-size: 25px;
  line-height: 1.28;
  letter-spacing: 0;
}

.section-heading p {
  margin: 0;
  max-width: 700px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.65;
}

.eyebrow {
  color: var(--teal);
  font-size: 9px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

.section-badge {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 9px;
  border-radius: 4px;
  background: var(--teal-soft);
  color: #125f59;
  font-size: 9px;
  font-weight: 800;
  text-transform: uppercase;
}

.section-badge.coral {
  background: var(--coral-soft);
  color: #8a422b;
}

.section-badge.mustard {
  background: var(--mustard-soft);
  color: #735a18;
}

.section-badge.teal {
  background: var(--teal-soft);
}

.form-grid {
  display: grid;
  gap: 16px;
  margin-bottom: 16px;
}

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

.form-grid.three-col {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.field {
  display: block;
  margin-bottom: 16px;
}

.field > span:first-child,
.choice-group legend {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 7px;
  color: #454d48;
  font-size: 11px;
  font-weight: 800;
}

.field input[type="text"],
.field textarea,
.field select,
.prompt-output {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfbf8;
  color: var(--ink);
  transition: border-color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.field input[type="text"],
.field select {
  height: 44px;
  padding: 0 12px;
}

.field textarea {
  min-height: 88px;
  padding: 11px 12px;
  line-height: 1.55;
  resize: vertical;
}

.field input[type="text"]:hover,
.field textarea:hover,
.field select:hover {
  border-color: var(--line-strong);
}

.field input[type="text"]:focus,
.field textarea:focus,
.field select:focus {
  background: white;
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(23, 127, 118, 0.08);
}

.highlight-field {
  padding: 14px;
  background: var(--mustard-soft);
  border-left: 3px solid var(--mustard);
  border-radius: 0 6px 6px 0;
}

.highlight-field textarea {
  background: rgba(255, 255, 255, 0.7);
}

.choice-group {
  min-width: 0;
  margin: 24px 0 0;
  padding: 0;
  border: 0;
}

.segmented {
  display: inline-flex;
  min-width: 0;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f4f5f1;
}

.segmented.wide {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.segmented label {
  min-width: 0;
}

.segmented input,
.mode-card input,
.toggle-row input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 11px;
  border-radius: 4px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  white-space: nowrap;
}

.segmented span svg {
  width: 15px;
  height: 15px;
}

.segmented input:checked + span {
  background: white;
  color: var(--ink);
  box-shadow: 0 2px 8px rgba(28, 35, 31, 0.08);
}

.range-field {
  margin: 20px 0 24px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fafaf7;
}

.range-label {
  align-items: center;
  margin-bottom: 11px;
  font-size: 11px;
  font-weight: 800;
}

.range-label output {
  color: var(--teal);
  font-size: 11px;
}

input[type="range"] {
  width: 100%;
  height: 4px;
  margin: 0;
  appearance: none;
  background: linear-gradient(to right, var(--teal) var(--range-fill, 50%), #dfe3dd var(--range-fill, 50%));
  border-radius: 2px;
}

input[type="range"]::-webkit-slider-thumb {
  width: 17px;
  height: 17px;
  appearance: none;
  border: 3px solid white;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 0 1px var(--teal), 0 2px 5px rgba(0, 0, 0, 0.15);
}

.range-scale {
  display: flex;
  justify-content: space-between;
  margin-top: 9px;
  color: #929993;
  font-size: 9px;
}

.trait-ranges {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 20px 0;
}

.compact-range {
  margin: 0;
}

.dynamic-species-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 16px;
}

.color-grid {
  margin-top: 2px;
}

.color-control {
  height: 44px;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfbf8;
}

.color-control input[type="color"] {
  width: 42px;
  height: 44px;
  border: 0;
  padding: 0;
  background: transparent;
}

.color-control input[type="text"] {
  height: 42px;
  border: 0;
  border-left: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
}

.state-voice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.api-status {
  min-height: 54px;
  display: flex;
  align-items: center;
  gap: 11px;
  margin-bottom: 22px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fafaf7;
}

.api-status.ready {
  border-color: #b9d9d1;
  background: var(--teal-soft);
}

.api-status.offline {
  border-color: #e1c6b8;
  background: var(--coral-soft);
}

.api-status-icon {
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 5px;
  background: white;
  color: var(--teal);
}

.api-status-icon svg {
  width: 16px;
  height: 16px;
}

.api-status strong,
.api-status small {
  display: block;
}

.api-status strong {
  font-size: 10px;
}

.api-status small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 9px;
}

.avatar-workbench {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(280px, 0.85fr);
  gap: 22px;
  align-items: start;
}

.avatar-controls {
  min-width: 0;
}

.avatar-subtitle {
  align-items: center;
}

.reference-counter {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
}

.reference-dropzone {
  min-height: 116px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  margin-bottom: 12px;
  border: 1px dashed var(--line-strong);
  border-radius: 6px;
  background: #fafaf7;
  text-align: center;
  transition: border-color 160ms ease, background 160ms ease;
}

.reference-dropzone:hover,
.reference-dropzone.dragging {
  border-color: var(--teal);
  background: var(--teal-soft);
}

.reference-dropzone strong {
  font-size: 11px;
}

.reference-dropzone small {
  color: var(--muted);
  font-size: 9px;
}

.dropzone-icon {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 5px;
  background: white;
  color: var(--teal);
  box-shadow: 0 3px 10px rgba(27, 36, 31, 0.06);
}

.dropzone-icon svg {
  width: 17px;
  height: 17px;
}

.reference-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 22px;
}

.reference-item {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #edf0ec;
}

.reference-item img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.reference-item-actions {
  position: absolute;
  left: 6px;
  right: 6px;
  bottom: 6px;
  display: flex;
  justify-content: space-between;
  gap: 4px;
}

.reference-action {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 5px;
  background: rgba(32, 37, 34, 0.78);
  color: white;
  backdrop-filter: blur(8px);
}

.reference-action svg {
  width: 14px;
  height: 14px;
}

.avatar-style-group {
  margin-top: 0;
}

.avatar-style-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 20px;
}

.avatar-style-grid label {
  min-width: 0;
}

.avatar-style-grid input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.avatar-style-grid label > span {
  min-height: 82px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fafaf7;
  transition: border-color 160ms ease, background 160ms ease;
}

.avatar-style-grid input:checked + span {
  border-color: var(--teal);
  background: var(--teal-soft);
  box-shadow: inset 0 0 0 1px var(--teal);
}

.avatar-style-grid svg {
  width: 16px;
  height: 16px;
  margin-bottom: 8px;
  color: var(--teal);
}

.avatar-style-grid strong,
.avatar-style-grid small {
  display: block;
}

.avatar-style-grid strong {
  max-width: 100%;
  overflow: hidden;
  font-size: 9px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.avatar-style-grid small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 8px;
}

.avatar-options {
  margin-bottom: 4px;
}

.compiled-avatar-prompt {
  min-height: 94px;
  margin: 4px 0 16px;
  padding: 12px;
  border-left: 3px solid var(--mustard);
  border-radius: 0 6px 6px 0;
  background: var(--mustard-soft);
}

.compiled-avatar-prompt p {
  margin: 7px 0 0;
  color: #5b543e;
  font-size: 9px;
  line-height: 1.55;
}

.avatar-generate-button {
  width: 100%;
}

.avatar-result {
  position: sticky;
  top: 104px;
  min-height: 430px;
  aspect-ratio: 1 / 1.18;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background:
    repeating-linear-gradient(90deg, transparent 0, transparent 31px, rgba(31,37,34,0.04) 32px),
    repeating-linear-gradient(0deg, transparent 0, transparent 31px, rgba(31,37,34,0.04) 32px),
    #edf2ee;
}

.avatar-result > img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.avatar-result-empty,
.avatar-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 24px;
  text-align: center;
}

.avatar-result-empty > span {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: white;
  color: var(--teal);
}

.avatar-result-empty svg {
  width: 22px;
  height: 22px;
}

.avatar-result-empty strong,
.avatar-loading strong {
  font-size: 11px;
}

.avatar-result-empty small,
.avatar-loading small {
  max-width: 210px;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.45;
}

.avatar-result-actions {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  display: flex;
  justify-content: flex-end;
  gap: 7px;
}

.avatar-result-actions .button,
.avatar-result-actions .icon-button {
  box-shadow: 0 5px 16px rgba(0, 0, 0, 0.18);
}

.avatar-loading {
  background: rgba(244, 242, 237, 0.92);
  backdrop-filter: blur(8px);
  z-index: 4;
}

.loading-ring {
  width: 38px;
  height: 38px;
  border: 3px solid rgba(23, 127, 118, 0.18);
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: loadingSpin 850ms linear infinite;
}

@keyframes loadingSpin {
  to { transform: rotate(360deg); }
}

.state-field {
  margin: 0;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fafaf7;
}

.state-field svg {
  width: 14px;
  height: 14px;
  color: var(--coral);
}

.relationship-block {
  margin: 8px 0 22px;
  padding: 20px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.subsection-title {
  align-items: flex-end;
  margin-bottom: 16px;
}

.subsection-title h2 {
  margin: 4px 0 0;
  font-family: "Unbounded", sans-serif;
  font-size: 15px;
  letter-spacing: 0;
}

.relation-summary,
.issue-count {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
}

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

.mode-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 24px;
}

.mode-card {
  min-height: 126px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfbf8;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.mode-card:hover {
  transform: translateY(-2px);
  border-color: var(--line-strong);
}

.mode-card.selected {
  border-color: var(--teal);
  background: var(--teal-soft);
  box-shadow: inset 0 0 0 1px var(--teal);
}

.mode-card strong,
.mode-card small {
  display: block;
}

.mode-card strong {
  margin-top: 12px;
  font-size: 11px;
}

.mode-card small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.35;
}

.mode-icon {
  width: 31px;
  height: 31px;
  display: grid;
  place-items: center;
  border-radius: 5px;
  background: white;
  color: var(--teal);
}

.mode-icon svg {
  width: 16px;
  height: 16px;
}

.mode-controls {
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.toggle-list {
  border-top: 1px solid var(--line);
  margin-top: 8px;
}

.toggle-row {
  min-height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--line);
}

.toggle-row strong,
.toggle-row small {
  display: block;
}

.toggle-row strong {
  font-size: 11px;
}

.toggle-row small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 9px;
}

.toggle {
  position: relative;
  width: 38px;
  height: 22px;
  flex: 0 0 auto;
  border-radius: 11px;
  background: #ced3ce;
  transition: background 160ms ease;
}

.toggle::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  top: 3px;
  left: 3px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
  transition: transform 160ms ease;
}

.toggle-row input:checked + .toggle {
  background: var(--teal);
}

.toggle-row input:checked + .toggle::after {
  transform: translateX(16px);
}

.prompt-heading {
  align-items: center;
}

.score-pill {
  width: 68px;
  height: 68px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  align-content: center;
  border-radius: 50%;
  border: 5px solid var(--teal-soft);
  color: var(--teal);
}

.score-pill span,
.score-pill small {
  display: block;
  text-align: center;
}

.score-pill span {
  font-family: "Unbounded", sans-serif;
  font-size: 18px;
}

.score-pill small {
  color: var(--muted);
  font-size: 7px;
  text-transform: uppercase;
}

.prompt-toolbar {
  align-items: center;
  margin-bottom: 12px;
}

.prompt-format span {
  min-height: 34px;
}

.prompt-output {
  min-height: 520px;
  padding: 18px;
  background: #202522;
  color: #edf0ec;
  border-color: #202522;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  line-height: 1.6;
  resize: vertical;
}

.quality-panel {
  margin-top: 24px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}

.issue-list {
  display: grid;
  gap: 8px;
}

.issue-item {
  min-height: 44px;
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fafaf7;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.4;
}

.issue-item .issue-icon {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--mustard-soft);
  color: #7a5b0d;
}

.issue-item.ok .issue-icon {
  background: var(--teal-soft);
  color: var(--teal);
}

.issue-item svg {
  width: 13px;
  height: 13px;
}

.editor-footer {
  min-height: 68px;
  padding: 12px 20px;
  border-top: 1px solid var(--line);
  background: #fafaf7;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.step-dots {
  display: flex;
  gap: 6px;
}

.step-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #d2d6d1;
}

.step-dot.active {
  width: 18px;
  border-radius: 3px;
  background: var(--teal);
}

.preview-panel {
  width: var(--preview-width);
  position: sticky;
  top: 92px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  box-shadow: var(--shadow);
  transition: width 180ms ease, opacity 180ms ease;
}

.preview-panel.collapsed {
  width: 52px;
  min-height: 52px;
  overflow: hidden;
}

.preview-panel.collapsed > :not(.preview-topline) {
  display: none;
}

.preview-panel.collapsed .preview-topline .eyebrow {
  display: none;
}

.avatar-stage {
  --avatar-primary: #c76545;
  --avatar-accent: #e6c86f;
  position: relative;
  height: 308px;
  margin-top: 12px;
  overflow: hidden;
  border-radius: 6px;
  background:
    linear-gradient(rgba(255,255,255,0.55), rgba(255,255,255,0.1)),
    repeating-linear-gradient(90deg, transparent 0, transparent 31px, rgba(31,37,34,0.045) 32px),
    repeating-linear-gradient(0deg, transparent 0, transparent 31px, rgba(31,37,34,0.045) 32px),
    var(--teal-soft);
}

.preview-avatar-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 8;
  object-fit: cover;
}

.avatar-empty-preview {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
}

.avatar-empty-preview span {
  width: 62px;
  height: 62px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(32, 37, 34, 0.12);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.68);
}

.avatar-empty-preview svg {
  width: 26px;
  height: 26px;
}

.avatar-empty-preview strong {
  font-size: 10px;
}

.avatar-sun {
  position: absolute;
  width: 150px;
  height: 150px;
  left: 50%;
  top: 38px;
  transform: translateX(-50%);
  border: 1px solid rgba(32, 37, 34, 0.14);
  border-radius: 50%;
  background: var(--mustard-soft);
}

.avatar {
  position: absolute;
  width: 240px;
  height: 275px;
  left: 50%;
  bottom: -12px;
  transform: translateX(-50%);
}

.avatar-body {
  position: absolute;
  width: 132px;
  height: 120px;
  left: 54px;
  bottom: 0;
  border-radius: 54px 54px 0 0;
  background: var(--charcoal);
}

.avatar-neck {
  position: absolute;
  width: 45px;
  height: 55px;
  left: 98px;
  top: 124px;
  background: var(--avatar-primary);
  z-index: 2;
}

.avatar-head {
  position: absolute;
  width: 108px;
  height: 128px;
  left: 66px;
  top: 27px;
  border-radius: 47% 47% 43% 43%;
  background: var(--avatar-primary);
  box-shadow: inset 0 -12px 0 rgba(49, 35, 28, 0.08);
  z-index: 4;
}

.avatar-ear {
  position: absolute;
  width: 48px;
  height: 70px;
  top: -40px;
  overflow: hidden;
  background: var(--avatar-primary);
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
  z-index: -1;
}

.avatar-ear.left {
  left: 2px;
  transform: rotate(-14deg);
}

.avatar-ear.right {
  right: 2px;
  transform: rotate(14deg);
}

.avatar-ear span {
  position: absolute;
  width: 25px;
  height: 42px;
  left: 12px;
  top: 17px;
  background: var(--avatar-accent);
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
  opacity: 0.7;
}

.avatar-hair {
  position: absolute;
  width: 104px;
  height: 53px;
  left: 2px;
  top: -2px;
  border-radius: 48px 48px 52% 28%;
  background: #3f332e;
  clip-path: polygon(0 0, 100% 0, 100% 58%, 82% 42%, 69% 78%, 54% 43%, 37% 75%, 24% 44%, 0 66%);
}

.avatar-face-mark {
  position: absolute;
  width: 18px;
  height: 58px;
  left: 45px;
  top: 42px;
  background: var(--avatar-accent);
  opacity: 0.78;
  clip-path: polygon(50% 0, 88% 48%, 61% 100%, 39% 100%, 12% 48%);
}

.avatar-eye {
  position: absolute;
  width: 22px;
  height: 10px;
  top: 61px;
  border-top: 3px solid #202522;
  border-radius: 50%;
}

.avatar-eye::after {
  content: "";
  position: absolute;
  width: 5px;
  height: 7px;
  left: 9px;
  top: -1px;
  border-radius: 50%;
  background: #202522;
}

.avatar-eye.left { left: 18px; transform: rotate(6deg); }
.avatar-eye.right { right: 18px; transform: rotate(-6deg); }

.avatar-muzzle {
  position: absolute;
  width: 54px;
  height: 36px;
  left: 27px;
  bottom: 12px;
  border-radius: 55% 55% 48% 48%;
  background: color-mix(in srgb, var(--avatar-primary) 48%, white);
}

.avatar-nose {
  position: absolute;
  width: 14px;
  height: 10px;
  left: 47px;
  bottom: 34px;
  border-radius: 50% 50% 60% 60%;
  background: #202522;
}

.avatar-tail {
  position: absolute;
  width: 90px;
  height: 154px;
  right: -2px;
  bottom: 7px;
  border: 25px solid var(--avatar-primary);
  border-left-color: transparent;
  border-top-color: transparent;
  border-radius: 0 0 90px 0;
  transform: rotate(-8deg);
}

.avatar-jacket {
  position: absolute;
  width: 73px;
  height: 100px;
  bottom: 0;
  background: #384a45;
  z-index: 5;
}

.avatar-jacket.left {
  left: 53px;
  border-radius: 50px 8px 0 0;
  clip-path: polygon(0 0, 100% 24%, 72% 100%, 0 100%);
}

.avatar-jacket.right {
  right: 53px;
  border-radius: 8px 50px 0 0;
  clip-path: polygon(0 24%, 100% 0, 100% 100%, 28% 100%);
}

.avatar-compass {
  position: absolute;
  width: 34px;
  height: 34px;
  left: 103px;
  bottom: 28px;
  display: grid;
  place-items: center;
  border: 2px solid #332e24;
  border-radius: 50%;
  background: var(--avatar-accent);
  color: #332e24;
  z-index: 7;
}

.avatar-compass svg {
  width: 18px;
  height: 18px;
}

.species-human .avatar-ear,
.species-human .avatar-tail,
.species-construct .avatar-ear,
.species-construct .avatar-tail,
.species-amorphous .avatar-ear,
.species-amorphous .avatar-tail {
  display: none;
}

.species-human .avatar-head {
  border-radius: 48% 48% 43% 43%;
}

.species-avian .avatar-ear {
  width: 33px;
  height: 52px;
  top: -24px;
}

.species-avian .avatar-muzzle {
  width: 62px;
  height: 26px;
  left: 23px;
  bottom: 25px;
  clip-path: polygon(50% 0, 100% 60%, 50% 100%, 0 60%);
  background: var(--avatar-accent);
}

.species-avian .avatar-nose {
  display: none;
}

.species-reptile .avatar-head {
  border-radius: 42% 42% 30% 30%;
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.12);
}

.species-construct .avatar-head,
.species-construct .avatar-neck {
  border-radius: 14px;
  background: #8f9994;
  box-shadow: inset 0 0 0 3px #656e69;
}

.species-construct .avatar-eye::after {
  width: 12px;
  height: 5px;
  background: var(--avatar-accent);
}

.species-construct .avatar-muzzle,
.species-construct .avatar-nose,
.species-construct .avatar-face-mark {
  display: none;
}

.species-construct .avatar-head::after {
  content: "";
  position: absolute;
  width: 30px;
  height: 2px;
  left: 39px;
  bottom: 28px;
  background: #59635e;
  box-shadow: 0 -15px 0 rgba(255, 255, 255, 0.08);
}

.species-amorphous .avatar-head,
.species-amorphous .avatar-body,
.species-amorphous .avatar-neck {
  border-radius: 50% 45% 48% 42%;
  background: color-mix(in srgb, var(--avatar-primary) 70%, transparent);
}

.species-amorphous .avatar-hair,
.species-amorphous .avatar-muzzle,
.species-amorphous .avatar-nose,
.species-amorphous .avatar-jacket,
.species-amorphous .avatar-compass {
  display: none;
}

.species-tag {
  position: absolute;
  left: 12px;
  bottom: 12px;
  max-width: calc(100% - 24px);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 8px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--ink);
  font-size: 9px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
  backdrop-filter: blur(8px);
}

.preview-identity {
  align-items: center;
  padding: 18px 2px 14px;
  border-bottom: 1px solid var(--line);
}

.preview-identity h2 {
  margin: 0;
  font-family: "Unbounded", sans-serif;
  font-size: 17px;
  letter-spacing: 0;
}

.preview-identity p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 10px;
  text-transform: capitalize;
}

.mood-dot {
  width: 11px;
  height: 11px;
  flex: 0 0 auto;
  border: 2px solid white;
  border-radius: 50%;
  background: var(--coral);
  box-shadow: 0 0 0 1px var(--coral);
}

.preview-panel blockquote {
  margin: 0;
  padding: 16px 2px;
  border-bottom: 1px solid var(--line);
  color: #444c47;
  font-size: 11px;
  font-weight: 600;
  font-style: italic;
  line-height: 1.55;
}

.preview-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.preview-stats div {
  padding: 0 9px;
  border-right: 1px solid var(--line);
}

.preview-stats div:last-child {
  border-right: 0;
}

.preview-stats span,
.preview-stats strong {
  display: block;
  text-align: center;
}

.preview-stats span {
  min-height: 25px;
  color: var(--muted);
  font-size: 7px;
  text-transform: uppercase;
}

.preview-stats strong {
  color: var(--teal);
  font-family: "Unbounded", sans-serif;
  font-size: 14px;
}

.preview-section {
  padding: 14px 2px;
  border-bottom: 1px solid var(--line);
}

.preview-section p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.55;
}

.compact-section {
  border: 0;
  padding-bottom: 2px;
}

.quality-row {
  align-items: center;
  color: var(--muted);
  font-size: 9px;
  font-weight: 800;
}

.quality-row strong {
  color: var(--ink);
}

.progress-track {
  height: 5px;
  margin-top: 8px;
  overflow: hidden;
  border-radius: 3px;
  background: #e2e5e0;
}

.progress-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--mustard));
  transition: width 180ms ease;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 60;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  border-radius: 6px;
  background: var(--charcoal);
  color: white;
  box-shadow: 0 12px 28px rgba(0,0,0,0.2);
  font-size: 11px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast svg {
  width: 16px;
  height: 16px;
  color: var(--mustard);
}

@media (max-width: 1180px) {
  :root {
    --sidebar-width: 70px;
    --preview-width: 310px;
  }

  .step-link {
    grid-template-columns: 1fr;
    justify-items: center;
    padding: 7px 4px;
    gap: 3px;
  }

  .step-number {
    display: none;
  }

  .step-link span:last-child {
    font-size: 8px;
  }

  .workspace {
    gap: 14px;
    padding: 14px;
  }

  .form-step {
    padding: 30px;
  }

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

  .avatar-workbench {
    grid-template-columns: 1fr;
  }

  .avatar-result {
    position: relative;
    top: auto;
    width: min(100%, 430px);
    min-height: 380px;
    margin: 0 auto;
  }
}

@media (max-width: 940px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: 64px auto minmax(0, 1fr);
  }

  .topbar {
    height: 64px;
    padding: 0 14px;
  }

  .brand small,
  .save-status,
  #topGenerateButton span {
    display: none;
  }

  .step-nav {
    grid-column: 1;
    grid-row: 2;
    height: auto;
    position: sticky;
    top: 64px;
    z-index: 25;
    display: flex;
    gap: 4px;
    padding: 8px;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .step-link {
    min-width: 92px;
    min-height: 42px;
    margin: 0;
    display: flex;
    justify-content: center;
    padding: 0 10px;
  }

  .step-link span:last-child {
    font-size: 9px;
  }

  .workspace {
    grid-column: 1;
    grid-row: 3;
    grid-template-columns: minmax(0, 1fr);
    padding: 12px;
  }

  .preview-panel {
    width: 100%;
    position: static;
    grid-row: 1;
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    gap: 0 16px;
  }

  .preview-topline {
    grid-column: 1 / -1;
  }

  .avatar-stage {
    grid-row: 2 / span 5;
    height: 270px;
  }

  .preview-identity,
  .preview-panel blockquote,
  .preview-stats,
  .preview-section {
    grid-column: 2;
  }

  .preview-panel.collapsed {
    width: 100%;
    min-height: 48px;
    display: block;
  }

  .preview-panel.collapsed .preview-topline .eyebrow {
    display: block;
  }
}

@media (max-width: 680px) {
  .brand strong {
    font-size: 12px;
  }

  .topbar-actions .button {
    width: 40px;
    padding: 0;
  }

  .workspace {
    padding: 8px;
  }

  .editor-panel {
    grid-row: 1;
  }

  .preview-panel {
    grid-row: 2;
    display: block;
    padding: 12px;
  }

  .avatar-stage {
    height: 260px;
  }

  .preview-identity,
  .preview-panel blockquote,
  .preview-stats,
  .preview-section {
    grid-column: auto;
  }

  .form-step {
    padding: 24px 18px;
  }

  .section-heading {
    display: block;
    padding-bottom: 20px;
    margin-bottom: 20px;
  }

  .section-heading h1 {
    font-size: 20px;
  }

  .section-badge {
    margin-top: 14px;
  }

  .form-grid.two-col,
  .form-grid.three-col,
  .dynamic-species-fields,
  .trait-ranges,
  .state-voice-grid,
  .relation-ranges,
  .mode-controls {
    grid-template-columns: 1fr;
  }

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

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

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

  .avatar-result {
    min-height: 340px;
  }

  .mode-card {
    min-height: 112px;
  }

  .prompt-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .prompt-format {
    width: 100%;
  }

  .prompt-format label {
    flex: 1;
  }

  .prompt-format span {
    padding: 0 6px;
    font-size: 9px;
  }

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

  .prompt-output {
    min-height: 420px;
  }

  .editor-footer {
    padding: 10px 12px;
  }

  .step-dots {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
