.app-shell {
  min-height: 100vh;
  overflow: hidden;
}

.studio-header {
  position: relative;
  z-index: 30;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 26px;
  align-items: center;
  min-height: var(--header-height);
  border-bottom: 1px solid var(--line);
  background: var(--white);
  padding: 0 32px;
}

.brand,
.product-title,
.header-controls,
.brand-copy,
.product-title > span:last-child,
.key-status,
.batch-summary,
.storage-status,
.selected-meta {
  display: flex;
  align-items: center;
}

.brand {
  width: max-content;
  min-width: 0;
  color: var(--ink);
  text-decoration: none;
}

.brand img {
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
}

.brand-copy,
.product-title > span:last-child {
  align-items: flex-start;
  flex-direction: column;
  min-width: 0;
  margin-left: 11px;
}

.brand-copy strong {
  font-size: 20px;
  line-height: 1.1;
}

.brand-copy small,
.product-title small {
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

.product-title {
  min-width: max-content;
  border-left: 1px solid var(--line);
  padding-left: 26px;
}

.product-mark {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--deep);
  color: var(--cyan);
}

.product-mark svg {
  width: 21px;
  height: 21px;
}

.product-title strong {
  font-size: 17px;
  line-height: 1.1;
}

.product-heading {
  display: inline-flex;
  align-items: baseline;
  gap: 7px;
  white-space: nowrap;
}

.studio-version {
  color: var(--blue);
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 11px;
  font-weight: 850;
  line-height: 1;
}

.header-controls {
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
}

.preview-badge {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  border: 1px solid var(--line);
  border-color: #eed6a7;
  border-radius: 999px;
  padding: 0 12px;
  background: var(--amber-soft);
  color: var(--amber);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.key-status.is-ready {
  border-color: #bfe8d8;
  background: var(--green-soft);
  color: var(--green);
}

.key-status {
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--muted);
  padding: 0 9px;
  font-size: 11px;
  font-weight: 750;
  white-space: nowrap;
}

.status-dot {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #aab4c2;
  box-shadow: 0 0 0 3px rgba(170, 180, 194, 0.13);
}

.is-ready .status-dot,
.storage-status[data-mode="compatible"] .status-dot {
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(22, 143, 100, 0.12);
}

.storage-status[data-mode="compat-readonly"] .status-dot {
  background: var(--amber);
  box-shadow: 0 0 0 3px rgba(184, 108, 18, 0.12);
}

.storage-status[data-mode="unavailable"] .status-dot {
  background: var(--red);
  box-shadow: 0 0 0 3px rgba(189, 63, 80, 0.12);
}

.key-status .status-dot {
  margin-right: 7px;
}

.icon-button,
.tool-button,
.field-icon-button {
  display: inline-grid;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--white);
  color: var(--ink-soft);
  padding: 0;
  text-decoration: none;
}

.icon-button {
  grid-auto-flow: column;
  width: 42px;
  height: 42px;
  gap: 3px;
}

.icon-button svg,
.tool-button svg,
.field-icon-button svg,
.command-button svg,
.generate-button svg,
.dialog-icon svg {
  width: 17px;
  height: 17px;
}

.icon-button:hover,
.tool-button:hover,
.field-icon-button:hover {
  border-color: #96a8bd;
  background: var(--paper);
  color: var(--ink);
}

#language-label {
  font-size: 11px;
  font-weight: 850;
}

.history-trigger {
  position: relative;
}

.history-count {
  position: absolute;
  top: -6px;
  right: -6px;
  display: grid;
  min-width: 18px;
  height: 18px;
  place-items: center;
  border: 2px solid var(--white);
  border-radius: 999px;
  background: var(--blue);
  color: var(--white);
  padding: 0 4px;
  font-size: 9px;
  font-weight: 850;
}

.mobile-view-tabs,
.mobile-generate-bar {
  display: none;
}

.studio-layout {
  position: relative;
  display: grid;
  grid-template-columns: var(--composer-width) minmax(0, 1fr);
  height: calc(100vh - var(--header-height));
  min-height: 540px;
}

.composer-panel {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: var(--white);
  overflow: hidden;
}

#generation-form {
  display: block;
  min-height: 0;
  padding: 4px 28px 38px;
  overflow: auto;
  scrollbar-gutter: stable;
}

.form-section {
  padding: 25px 0;
  border-bottom: 1px solid var(--line);
}

.form-section:last-of-type {
  border-bottom: 0;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 30px;
  margin-bottom: 16px;
}

.section-heading > div,
.section-actions {
  display: flex;
  align-items: center;
}

.section-heading > div {
  align-items: baseline;
  min-width: 0;
}

.section-actions {
  gap: 10px;
}

.section-index {
  margin-right: 11px;
  color: var(--blue);
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 11px;
  font-weight: 850;
}

.section-heading h2,
.workspace-header h1,
.history-header h2,
.confirm-dialog h2 {
  margin: 0;
  color: var(--ink);
  letter-spacing: 0;
}

.section-heading h2 {
  font-size: 16px;
  line-height: 1.2;
}

.text-button {
  min-height: 30px;
  border: 0;
  background: transparent;
  color: var(--blue);
  padding: 4px 0;
  font-size: 12px;
  font-weight: 800;
}

.danger-text {
  color: var(--red);
}

.input-with-actions {
  position: relative;
}

.input-icon {
  position: absolute;
  top: 50%;
  left: 13px;
  width: 17px;
  height: 17px;
  color: var(--muted);
  transform: translateY(-50%);
  pointer-events: none;
}

input[type="password"],
input[type="text"],
input[type="url"],
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--white);
  color: var(--ink);
  outline: 0;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

input[type="password"],
input[type="text"],
input[type="url"],
select {
  min-height: 46px;
  padding: 9px 12px;
  font-size: 14px;
}

#api-key {
  padding-right: 48px;
  padding-left: 40px;
  font-family: ui-monospace, "Cascadia Code", monospace;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(50, 103, 214, 0.12);
}

input::placeholder,
textarea::placeholder {
  color: #95a0b0;
}

.field-icon-button {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 36px;
  height: 36px;
  border-color: transparent;
}

.check-control,
.switch-control {
  display: grid;
  align-items: center;
  cursor: pointer;
}

.check-control {
  grid-template-columns: auto auto minmax(0, 1fr);
  gap: 8px;
  margin-top: 12px;
  color: var(--ink-soft);
  font-size: 12px;
}

.check-control input {
  width: 17px;
  height: 17px;
  margin: 0;
  accent-color: var(--blue);
}

.check-control small {
  justify-self: end;
  color: var(--muted);
  font-size: 11px;
}

.counter {
  color: var(--muted);
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 11px;
}

textarea {
  min-height: 172px;
  resize: vertical;
  padding: 14px 15px;
  font-size: 14px;
  line-height: 1.62;
}

input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  overflow: hidden;
  white-space: nowrap;
}

.reference-actions,
.result-commands,
.workspace-actions,
.dialog-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.command-button,
.small-button,
.danger-button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--white);
  color: var(--ink-soft);
  padding: 8px 13px;
  font-size: 13px;
  font-weight: 750;
  text-decoration: none;
  white-space: nowrap;
}

.command-button:hover,
.small-button:hover {
  border-color: var(--blue);
  background: var(--blue-soft);
  color: var(--blue);
}

.command-button.compact {
  min-height: 32px;
  padding: 5px 9px;
}

.danger-button {
  border-color: #efc4ca;
  background: var(--red-soft);
  color: var(--red);
}

.reference-url-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-top: 12px;
}

.reference-preview {
  display: block;
  min-height: 78px;
  margin-top: 14px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--paper);
  padding: 9px;
  overflow: hidden;
}

.reference-preview.is-empty {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  align-items: center;
  gap: 13px;
}

.reference-preview:not(.is-empty) {
  border-style: solid;
  background: var(--white);
}

.reference-thumbnail img,
.reference-placeholder {
  width: 58px;
  height: 58px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--white);
}

.reference-thumbnail img {
  display: block;
  object-fit: cover;
}

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

.reference-item {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.reference-item + .reference-item {
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.reference-thumbnail {
  position: relative;
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  padding: 0;
  overflow: hidden;
  cursor: zoom-in;
}

.reference-thumbnail:hover img {
  border-color: var(--blue);
}

.reference-index {
  position: absolute;
  top: 3px;
  left: 3px;
  display: grid;
  width: 20px;
  height: 20px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 4px;
  background: rgba(11, 18, 32, 0.82);
  color: #fff;
  font-size: 11px;
  font-weight: 850;
}

.reference-preview-mark {
  position: absolute;
  right: 3px;
  bottom: 3px;
  display: grid;
  width: 20px;
  height: 20px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 4px;
  background: rgba(11, 18, 32, 0.82);
  color: #fff;
  pointer-events: none;
}

.reference-preview-mark svg {
  width: 12px;
  height: 12px;
}

.reference-item-copy {
  min-width: 0;
}

.reference-remove {
  width: 32px;
  height: 32px;
  min-width: 32px;
}

.reference-placeholder {
  display: grid;
  place-items: center;
  color: var(--muted);
}

.reference-placeholder svg {
  width: 20px;
  height: 20px;
}

.reference-preview div {
  min-width: 0;
}

.reference-preview strong,
.reference-preview small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reference-preview strong {
  font-size: 13px;
}

.reference-preview small {
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
}

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

.model-field > span,
.option-field legend,
.select-grid label > span {
  display: block;
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.model-field select {
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-weight: 750;
}

.option-field {
  min-width: 0;
  margin: 0 0 18px;
  border: 0;
  padding: 0;
}

.segmented {
  display: grid;
  grid-auto-columns: 1fr;
  grid-auto-flow: column;
  gap: 1px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--line-strong);
  overflow: hidden;
}

.segmented label {
  position: relative;
  min-width: 0;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: grid;
  min-height: 42px;
  place-items: center;
  background: var(--white);
  color: var(--ink-soft);
  padding: 8px;
  font-size: 13px;
  font-weight: 750;
  white-space: nowrap;
}

.segmented input:checked + span {
  background: var(--deep);
  color: var(--white);
}

.segmented input:focus-visible + span {
  box-shadow: inset 0 0 0 2px var(--cyan);
}

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

.select-grid label {
  min-width: 0;
}

.select-grid select {
  font-size: 13px;
}

.advanced-settings {
  margin-top: 16px;
  border-top: 1px solid var(--line);
  padding-top: 13px;
}

.advanced-settings summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
  list-style: none;
}

.advanced-settings summary::-webkit-details-marker {
  display: none;
}

.advanced-settings summary svg {
  width: 15px;
  height: 15px;
  transition: transform 150ms ease;
}

.advanced-settings[open] summary svg {
  transform: rotate(180deg);
}

.switch-control {
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0 10px;
  margin-top: 14px;
}

.switch-control input {
  position: absolute;
  opacity: 0;
}

.switch-track {
  position: relative;
  grid-row: 1;
  width: 36px;
  height: 20px;
  border-radius: 999px;
  background: #b9c3d0;
  transition: background 150ms ease;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--white);
  box-shadow: 0 1px 4px rgba(18, 23, 34, 0.2);
  transition: transform 150ms ease;
}

.switch-control input:checked + .switch-track {
  background: var(--blue);
}

.switch-control input:checked + .switch-track::after {
  transform: translateX(16px);
}

.switch-control > span:last-child {
  grid-column: 2;
  grid-row: 1;
}

.switch-control strong,
.switch-control small {
  display: block;
}

.switch-control strong {
  font-size: 13px;
}

.switch-control small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.form-alert {
  margin: 4px 0 12px;
  border: 1px solid #efc4ca;
  border-radius: var(--radius);
  background: var(--red-soft);
  color: var(--red);
  padding: 10px 11px;
  font-size: 12px;
  line-height: 1.45;
}

.generate-button {
  display: flex;
  width: 100%;
  min-height: 52px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 1px solid #24b8d0;
  border-radius: var(--radius);
  background: var(--cyan);
  color: #06232a;
  padding: 10px 14px;
  font-size: 15px;
  font-weight: 850;
  box-shadow: 0 8px 20px rgba(66, 214, 236, 0.2);
}

.generate-button:hover {
  background: #57def1;
  box-shadow: 0 10px 24px rgba(66, 214, 236, 0.28);
}

.generate-button:disabled {
  box-shadow: none;
}

.button-quantity {
  display: grid;
  min-width: 25px;
  height: 25px;
  place-items: center;
  border-radius: 999px;
  background: rgba(8, 12, 19, 0.12);
  padding: 0 6px;
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 11px;
}

.composer-footer {
  border-top: 1px solid var(--line);
  background: var(--white);
  padding: 16px 24px;
  box-shadow: 0 -8px 24px rgba(18, 23, 34, 0.05);
}

.workspace-panel {
  display: grid;
  min-width: 0;
  min-height: 0;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  background: var(--paper);
  overflow: hidden;
}

.workspace-header { grid-row: 1; }
.batch-strip { grid-row: 2; }
.understanding-panel { grid-row: 3; }
.result-stage { grid-row: 4; }
.result-toolbar { grid-row: 5; }

.workspace-header {
  display: flex;
  min-height: 86px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(244, 247, 250, 0.96);
  padding: 18px 28px;
}

.workspace-heading-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.workspace-eyebrow {
  display: block;
  margin-bottom: 7px;
  color: var(--blue);
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 10px;
  font-weight: 850;
}

.workspace-header h1,
.history-header h2 {
  font-size: 22px;
  line-height: 1.15;
}

.tool-button {
  width: 38px;
  height: 38px;
}

.toolbar-divider {
  width: 1px;
  height: 24px;
  background: var(--line-strong);
}

.zoom-value {
  min-width: 42px;
  color: var(--muted);
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 11px;
  text-align: center;
}

.batch-strip {
  display: grid;
  grid-template-columns: auto minmax(120px, 1fr) auto auto;
  align-items: center;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  background: var(--white);
  padding: 10px 24px;
}

.batch-spinner {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  margin-right: 10px;
  border: 2px solid #c7edf3;
  border-top-color: var(--cyan-dark);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

.batch-strip.is-complete .batch-spinner {
  border-color: var(--green);
  background: var(--green-soft);
  animation: none;
}

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

.batch-summary strong,
.batch-summary small {
  display: block;
}

.batch-summary strong {
  font-size: 13px;
}

.batch-summary small {
  margin-top: 3px;
  color: var(--muted);
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 10px;
}

.batch-progress {
  height: 6px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.batch-progress span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--cyan-dark);
  transition: width 180ms ease;
}

.result-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 26px 28px;
  overflow: auto;
}

.empty-state {
  position: absolute;
  inset: 26px 28px;
  display: grid;
  place-content: center;
  justify-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

.empty-mark {
  display: grid;
  width: 78px;
  height: 78px;
  place-items: center;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--white);
  color: var(--cyan-dark);
  box-shadow: var(--shadow-sm);
}

.empty-mark svg {
  width: 32px;
  height: 32px;
}

.empty-state strong {
  color: var(--ink);
  font-size: 19px;
}

.empty-state small {
  margin-top: 8px;
  font-size: 13px;
}

.empty-stats {
  display: flex;
  gap: 7px;
  margin-top: 20px;
}

.empty-stats span {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--white);
  padding: 6px 10px;
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 10px;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  min-height: 100%;
}

.result-grid[data-count="1"] {
  grid-template-columns: minmax(0, 1fr);
  height: 100%;
  min-height: 0;
  place-items: center;
}

.result-grid[data-count="1"] .result-card {
  width: min(100%, 820px);
  height: min(100%, 600px);
  min-height: 0;
}

.result-card {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 260px;
  grid-template-rows: minmax(0, 1fr) auto;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--white);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
}

.result-card.is-selected {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(50, 103, 214, 0.14), var(--shadow-sm);
}

.result-image-wrap {
  position: relative;
  display: grid;
  min-height: 0;
  place-items: center;
  background-color: #eef2f6;
  background-image: linear-gradient(45deg, #e3e8ee 25%, transparent 25%), linear-gradient(-45deg, #e3e8ee 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #e3e8ee 75%), linear-gradient(-45deg, transparent 75%, #e3e8ee 75%);
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
  overflow: hidden;
}

.result-card img {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  object-fit: contain;
  transform: scale(var(--image-scale, 1));
  transform-origin: center;
  transition: transform 150ms ease;
}

.result-card footer {
  display: flex;
  min-height: 42px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding: 8px 10px;
}

.result-number {
  color: var(--ink);
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 10px;
  font-weight: 800;
}

.result-state {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--green);
  font-size: 9px;
  font-weight: 800;
}

.result-state::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.result-placeholder {
  display: grid;
  place-items: center;
  min-height: 240px;
  color: var(--muted);
}

.result-placeholder.is-error {
  color: var(--red);
}

.result-placeholder .batch-spinner {
  margin: 0 0 10px;
}

.result-placeholder svg {
  width: 28px;
  height: 28px;
  margin-bottom: 10px;
}

.result-placeholder strong,
.result-placeholder small {
  display: block;
  text-align: center;
}

.result-placeholder small {
  max-width: 220px;
  margin-top: 5px;
  font-size: 9px;
  line-height: 1.4;
}

.result-toolbar {
  display: flex;
  min-height: 64px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-top: 1px solid var(--line);
  background: var(--white);
  padding: 10px 24px;
}

.selected-meta {
  min-width: 0;
  align-items: flex-start;
  flex-direction: column;
}

.selected-meta strong {
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 10px;
}

.selected-meta span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 9px;
}

.history-drawer {
  position: absolute;
  z-index: 50;
  top: 0;
  right: 0;
  bottom: 0;
  display: grid;
  width: min(420px, 92vw);
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  border-left: 1px solid var(--line);
  background: var(--white);
  box-shadow: -16px 0 40px rgba(18, 23, 34, 0.12);
  transform: translateX(105%);
  transition: transform 180ms ease;
}

.history-drawer.is-open {
  transform: translateX(0);
}

.drawer-scrim {
  position: absolute;
  z-index: 40;
  inset: 0;
  border: 0;
  background: rgba(8, 12, 19, 0.35);
}

.history-header {
  display: flex;
  min-height: 75px;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding: 15px 18px;
}

.storage-status {
  gap: 10px;
  margin: 14px 18px 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  padding: 10px 11px;
}

.storage-status > div {
  min-width: 0;
}

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

.storage-status strong {
  font-size: 11px;
}

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

.history-list {
  display: grid;
  align-content: start;
  gap: 1px;
  min-height: 0;
  margin-top: 12px;
  background: var(--line);
  overflow: auto;
}

.history-empty {
  min-height: 220px;
  display: grid;
  place-items: center;
  background: var(--white);
  color: var(--muted);
  font-size: 11px;
}

.history-item {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr) auto;
  gap: 11px;
  align-items: center;
  min-height: 94px;
  background: var(--white);
  padding: 10px 12px;
}

.history-item img,
.history-corrupt-thumb {
  width: 74px;
  height: 74px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--paper);
  object-fit: cover;
}

.history-corrupt-thumb {
  display: grid;
  place-items: center;
  color: var(--red);
}

.history-item-copy {
  min-width: 0;
}

.history-item-copy strong,
.history-item-copy span,
.history-item-copy small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item-copy strong {
  font-size: 11px;
}

.history-item-copy span {
  margin-top: 5px;
  color: var(--muted);
  font-size: 9px;
}

.history-item-copy small {
  margin-top: 4px;
  color: var(--blue);
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 8px;
}

.history-item-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.history-item-actions .tool-button {
  width: 30px;
  height: 30px;
}

.history-footer {
  display: flex;
  min-height: 52px;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--line);
  padding: 10px 18px;
}

.history-footer span {
  color: var(--muted);
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 9px;
}

.toast-region {
  position: fixed;
  z-index: 100;
  right: 18px;
  bottom: 18px;
  display: grid;
  width: min(360px, calc(100vw - 36px));
  gap: 8px;
  pointer-events: none;
}

.toast {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 9px;
  align-items: start;
  border: 1px solid var(--line-strong);
  border-left: 3px solid var(--blue);
  border-radius: var(--radius);
  background: var(--white);
  color: var(--ink-soft);
  padding: 11px 12px;
  box-shadow: var(--shadow-md);
  font-size: 11px;
  line-height: 1.45;
  animation: toast-in 160ms ease-out;
}

.toast > svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.toast.is-error { border-left-color: var(--red); }
.toast.is-success { border-left-color: var(--green); }
.toast.is-warning { border-left-color: var(--amber); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
}

.reference-lightbox {
  width: min(1080px, calc(100vw - 40px));
  height: min(820px, calc(100dvh - 40px));
  max-width: none;
  max-height: none;
  border: 1px solid #2c3543;
  border-radius: var(--radius);
  background: #0d121a;
  color: #f4f7fa;
  padding: 0;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.4);
  overflow: hidden;
}

.reference-lightbox::backdrop {
  background: rgba(8, 12, 19, 0.78);
}

.reference-lightbox-shell {
  display: grid;
  width: 100%;
  height: 100%;
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.reference-lightbox-header {
  display: flex;
  min-height: 68px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid #2c3543;
  background: #141b25;
  padding: 11px 14px 11px 20px;
}

.reference-lightbox-header > div {
  min-width: 0;
}

.reference-lightbox-header span,
.reference-lightbox-header strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reference-lightbox-header span {
  color: #73dfee;
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 10px;
  font-weight: 800;
}

.reference-lightbox-header strong {
  margin-top: 5px;
  font-size: 13px;
}

.reference-lightbox-stage {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
  background: #090d13;
  padding: 18px 70px;
  overflow: hidden;
}

.reference-lightbox-stage img {
  display: block;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  object-fit: contain;
}

.lightbox-tool-button {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid #394454;
  border-radius: var(--radius);
  background: #1a2330;
  color: #f4f7fa;
  padding: 0;
}

.lightbox-tool-button:hover {
  border-color: #73dfee;
  color: #73dfee;
}

.lightbox-tool-button:disabled {
  opacity: 0.28;
}

.lightbox-tool-button svg {
  width: 19px;
  height: 19px;
}

.reference-lightbox-nav {
  position: absolute;
  z-index: 1;
  top: 50%;
  transform: translateY(-50%);
}

.reference-lightbox-nav.is-previous {
  left: 14px;
}

.reference-lightbox-nav.is-next {
  right: 14px;
}

.reference-lightbox footer {
  min-height: 44px;
  border-top: 1px solid #2c3543;
  background: #141b25;
  color: #aab4c2;
  padding: 13px 20px;
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 10px;
}

.confirm-dialog {
  width: min(390px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--white);
  color: var(--ink);
  padding: 0;
  box-shadow: var(--shadow-md);
}

.confirm-dialog::backdrop {
  background: rgba(8, 12, 19, 0.5);
}

.confirm-dialog form {
  padding: 22px;
}

.dialog-icon {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: var(--radius);
  background: var(--amber-soft);
  color: var(--amber);
}

.confirm-dialog h2 {
  margin-top: 14px;
  font-size: 16px;
}

.confirm-dialog p {
  margin: 9px 0 20px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

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

body.workspace-maximized .studio-header,
body.workspace-maximized .composer-panel,
body.workspace-maximized .mobile-view-tabs,
body.workspace-maximized .mobile-generate-bar {
  display: none !important;
}

body.workspace-maximized .studio-layout {
  grid-template-columns: minmax(0, 1fr);
  height: 100vh;
}

body.workspace-maximized .workspace-panel {
  display: grid !important;
}

body.workspace-maximized .result-stage {
  padding: 14px;
}

body.workspace-maximized .result-toolbar {
  min-height: 56px;
}

/* v3.2: model hint, aspect ratio, drag & drop, history search */
.model-hint {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.option-field legend {
  display: flex;
  width: 100%;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.size-preview {
  color: var(--blue);
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 11px;
  font-weight: 700;
}

.ratio-segments span {
  min-height: 38px;
  padding: 6px 2px;
  font-size: 12px;
}

.ratio-segments.is-disabled span {
  background: var(--paper);
  color: #a3adbb;
  cursor: not-allowed;
}

.ratio-segments.is-disabled input:checked + span {
  background: var(--line-strong);
  color: var(--ink-soft);
}

.reference-section {
  position: relative;
}

.reference-drop-hint {
  display: none;
}

.reference-section.is-dragover .reference-drop-hint {
  position: absolute;
  z-index: 5;
  inset: 6px;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 8px;
  border: 2px dashed var(--blue);
  border-radius: var(--radius);
  background: rgba(237, 243, 255, 0.94);
  color: var(--blue);
  font-size: 13px;
  font-weight: 800;
  pointer-events: none;
}

.reference-drop-hint svg {
  width: 26px;
  height: 26px;
}

.history-search {
  margin: 12px 18px 0;
}

.history-search input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--white);
  color: var(--ink);
  padding: 7px 11px;
  font-size: 13px;
  outline: 0;
}

.history-search input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(50, 103, 214, 0.12);
}

.result-state.is-warning {
  margin-left: auto;
  color: var(--amber);
}

.result-state.is-warning::before {
  background: var(--amber);
}

.result-toolbar {
  flex-wrap: wrap;
  row-gap: 8px;
}

.selected-meta {
  flex: 1 1 150px;
}

.selected-meta strong,
.selected-meta span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-commands {
  flex-wrap: wrap;
}

/* v3.3: prompt understanding */
.understand-switch {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  padding: 10px 12px;
}

.understand-switch code {
  color: var(--blue);
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 10px;
  font-weight: 700;
}

.effort-field {
  display: block;
  margin-top: 14px;
}

.effort-field > span {
  display: block;
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

/* Indeterminate sweep while waiting on the understanding model or on the first image bytes. */
.batch-strip.is-understanding .batch-progress,
.batch-strip.is-waiting .batch-progress {
  position: relative;
}

.batch-strip.is-understanding .batch-progress::after,
.batch-strip.is-waiting .batch-progress::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 38%;
  border-radius: inherit;
  background: linear-gradient(90deg, transparent, var(--cyan), var(--blue), transparent);
  animation: understanding-sweep 1.5s ease-in-out infinite;
}

@keyframes understanding-sweep {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(270%); }
}

.understanding-panel {
  border-bottom: 1px solid var(--line);
  background: var(--white);
}

.understanding-panel summary {
  display: flex;
  min-height: 46px;
  align-items: center;
  gap: 10px;
  padding: 8px 24px;
  cursor: pointer;
  list-style: none;
}

.understanding-panel summary::-webkit-details-marker {
  display: none;
}

.understanding-badge {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 5px;
  border-radius: 999px;
  background: var(--blue-soft);
  color: var(--blue);
  padding: 4px 10px 4px 8px;
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.understanding-badge svg {
  width: 13px;
  height: 13px;
}

.understanding-summary {
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
  color: var(--ink-soft);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.understanding-chevron {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
  color: var(--muted);
  transition: transform 150ms ease;
}

.understanding-panel[open] .understanding-chevron {
  transform: rotate(180deg);
}

.understanding-panel.is-loading summary {
  cursor: default;
}

.understanding-panel.is-loading .understanding-chevron {
  display: none;
}

.understanding-panel.is-loading .understanding-summary::after {
  content: "…";
}

.understanding-body {
  display: grid;
  max-height: min(46vh, 420px);
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px 20px;
  border-top: 1px solid var(--line);
  padding: 14px 24px 16px;
  overflow: auto;
}

.understanding-block h3 {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.understanding-block ul {
  margin: 0;
  padding-left: 18px;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.6;
}

.understanding-final {
  grid-column: 1 / -1;
}

.understanding-final-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.understanding-prompt {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.7;
  white-space: pre-wrap;
}

.understanding-meta {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 10px;
}

.understanding-dialog {
  width: min(680px, calc(100vw - 32px));
  max-height: calc(100dvh - 40px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--white);
  color: var(--ink);
  padding: 0;
  box-shadow: var(--shadow-md);
}

.understanding-dialog::backdrop {
  background: rgba(8, 12, 19, 0.5);
}

.understanding-dialog form {
  display: grid;
  gap: 14px;
  padding: 22px;
}

.understanding-dialog h2 {
  margin: 10px 0 6px;
  font-size: 18px;
}

.understanding-dialog header p {
  margin: 0;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.6;
}

.understanding-dialog-points {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px 18px;
}

.understanding-dialog-points:empty {
  display: none;
}

.understanding-dialog-editor > span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.understanding-dialog-editor textarea {
  min-height: 200px;
  font-size: 13px;
}

.understanding-dialog .dialog-actions {
  justify-content: flex-end;
}

.compact-generate {
  width: auto;
  min-height: 42px;
  padding: 0 18px;
}

/* v3.4: reference actions and popover menu */
.reference-actions-row {
  display: flex;
  align-items: center;
  gap: 2px;
}

.reference-action {
  width: 28px;
  height: 28px;
  min-width: 28px;
  border-color: transparent;
  background: transparent;
}

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

.reference-action:hover:not(:disabled) {
  border-color: var(--line-strong);
  background: var(--white);
}

.reference-action.reference-remove:hover:not(:disabled) {
  color: var(--red);
}

.popover-menu {
  position: fixed;
  z-index: 200;
  display: grid;
  min-width: 190px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--white);
  padding: 5px;
  box-shadow: var(--shadow-md);
}

.popover-menu button {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: center;
  gap: 2px 9px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--ink);
  padding: 8px 10px;
  font-size: 13px;
  font-weight: 650;
  text-align: left;
}

.popover-menu button:hover:not(:disabled),
.popover-menu button:focus-visible {
  background: var(--blue-soft);
  color: var(--blue);
  outline: 0;
}

.popover-menu button svg {
  width: 16px;
  height: 16px;
}

.popover-menu button small {
  grid-column: 2;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}

/* v3.4: prompt library */
.library-trigger {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--blue);
}

.library-trigger svg {
  width: 14px;
  height: 14px;
}

.transparent-switch.is-disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.library-dialog,
.editor-dialog {
  width: min(1180px, calc(100vw - 32px));
  height: min(860px, calc(100dvh - 32px));
  max-width: none;
  max-height: none;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--white);
  color: var(--ink);
  padding: 0;
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.library-dialog::backdrop,
.editor-dialog::backdrop {
  background: rgba(8, 12, 19, 0.55);
}

.library-shell,
.editor-shell {
  position: relative;
  display: grid;
  width: 100%;
  height: 100%;
  min-height: 0;
}

.library-shell {
  grid-template-rows: auto auto minmax(0, 1fr) auto;
}

.library-header,
.editor-header {
  display: flex;
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  padding: 14px 20px;
}

.library-heading h2,
.editor-header h2 {
  margin: 2px 0 0;
  font-size: 18px;
}

.library-search {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
}

.library-search svg {
  position: absolute;
  top: 50%;
  left: 12px;
  width: 16px;
  height: 16px;
  color: var(--muted);
  transform: translateY(-50%);
}

.library-search input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 8px 12px 8px 36px;
  font-size: 14px;
  outline: 0;
}

.library-search input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(50, 103, 214, 0.12);
}

#library-source {
  width: auto;
  max-width: 220px;
  min-height: 40px;
}

.library-cats {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--line);
  padding: 10px 20px;
  overflow-x: auto;
  scrollbar-width: thin;
}

.library-chip {
  flex: 0 0 auto;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--white);
  color: var(--ink-soft);
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.library-chip:hover {
  border-color: var(--blue);
  color: var(--blue);
}

.library-chip.is-active {
  border-color: var(--deep);
  background: var(--deep);
  color: var(--white);
}

.library-body {
  min-height: 0;
  background: var(--paper);
  padding: 16px 20px;
  overflow: auto;
}

.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px;
}

.library-card {
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--white);
  color: var(--ink);
  padding: 0 0 10px;
  text-align: left;
  overflow: hidden;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

.library-card:hover {
  border-color: var(--blue);
  box-shadow: var(--shadow-sm);
}

.library-cover {
  display: block;
  aspect-ratio: 4 / 3;
  background: linear-gradient(135deg, var(--cyan-soft), var(--blue-soft));
  overflow: hidden;
}

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

.library-card strong,
.library-card small,
.library-card-meta {
  padding: 0 10px;
}

.library-card strong {
  display: -webkit-box;
  overflow: hidden;
  font-size: 13px;
  line-height: 1.4;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.library-card small {
  display: -webkit-box;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.library-card-meta {
  align-self: end;
  color: var(--blue);
  font-size: 10px;
  font-weight: 800;
}

.library-empty {
  grid-column: 1 / -1;
  padding: 60px 0;
  color: var(--muted);
  text-align: center;
}

.library-more-row {
  display: flex;
  justify-content: center;
  padding-top: 16px;
}

.library-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 6px 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  padding: 10px 20px;
  font-size: 11px;
}

.library-detail {
  position: absolute;
  z-index: 5;
  inset: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: var(--white);
}

.library-detail > header {
  border-bottom: 1px solid var(--line);
  padding: 12px 20px;
}

.library-detail > header .text-button {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.library-detail > header svg {
  width: 15px;
  height: 15px;
}

.library-detail-body {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 24px;
  min-height: 0;
  padding: 20px;
  overflow: auto;
}

.library-detail-body > img {
  width: 100%;
  max-height: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  object-fit: contain;
  background: var(--paper);
}

.library-detail-copy h3 {
  margin: 0 0 6px;
  font-size: 20px;
}

.library-detail-copy a {
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
}

.library-detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 12px 0;
}

.library-detail-tags span {
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink-soft);
  padding: 3px 9px;
  font-size: 11px;
}

.library-detail-description,
.library-detail-placeholder {
  margin: 0 0 10px;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.6;
}

.library-detail-placeholder {
  border-left: 3px solid var(--amber);
  background: var(--amber-soft);
  padding: 8px 10px;
}

.library-detail-prompt {
  max-height: 360px;
  margin: 0 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  padding: 12px 14px;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.7;
  white-space: pre-wrap;
  overflow: auto;
}

.library-detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* v3.4: image tools dialog */
.editor-shell {
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.editor-header {
  justify-content: space-between;
}

.editor-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  min-height: 0;
}

.editor-stage {
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
  background:
    linear-gradient(45deg, #e8edf3 25%, transparent 25%, transparent 75%, #e8edf3 75%),
    linear-gradient(45deg, #e8edf3 25%, transparent 25%, transparent 75%, #e8edf3 75%);
  background-color: #f5f7fa;
  background-position: 0 0, 10px 10px;
  background-size: 20px 20px;
  overflow: hidden;
}

.editor-canvas-wrap {
  position: relative;
  box-shadow: var(--shadow-md);
}

.editor-canvas-wrap img,
.editor-canvas-wrap canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.editor-canvas-wrap canvas {
  touch-action: none;
}

.editor-canvas-wrap canvas.is-mask {
  opacity: 0.5;
}

.editor-side {
  display: grid;
  align-content: start;
  min-height: 0;
  border-left: 1px solid var(--line);
  padding: 16px;
  overflow: auto;
}

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

.editor-tools {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.editor-tools button {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--white);
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 750;
}

.editor-tools button svg {
  width: 15px;
  height: 15px;
}

.editor-tools button.is-active {
  border-color: var(--deep);
  background: var(--deep);
  color: var(--white);
}

.editor-range {
  display: grid;
  gap: 8px;
}

.editor-range > span,
.editor-field > span,
.editor-label {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.editor-range b {
  color: var(--blue);
  font-family: ui-monospace, "Cascadia Code", monospace;
}

.editor-range input {
  width: 100%;
  accent-color: var(--blue);
}

.editor-field {
  display: grid;
  gap: 8px;
}

.editor-field textarea {
  min-height: 0;
  font-size: 13px;
}

.editor-field input[type="number"] {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 14px;
}

.editor-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.editor-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.editor-readout {
  display: flex;
  justify-content: space-between;
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink-soft);
  padding: 9px 11px;
  font-size: 12px;
}

.editor-angle-label b {
  font-weight: 700;
  line-height: 1.5;
}

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

.editor-footer small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

/* v3.4.1: live understanding card */
.thinking-card {
  position: relative;
  max-width: 760px;
  margin: 4vh auto 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--white);
  padding: 22px 24px 20px;
  box-shadow: var(--shadow-md);
  overflow: hidden;
  animation: thinking-enter 260ms ease-out;
}

@keyframes thinking-enter {
  from { opacity: 0; transform: translateY(8px) scale(0.99); }
  to { opacity: 1; transform: none; }
}

.thinking-glow {
  position: absolute;
  top: -120px;
  left: -10%;
  width: 120%;
  height: 220px;
  background:
    radial-gradient(closest-side, rgba(66, 214, 236, 0.22), transparent) 10% 50% / 45% 100% no-repeat,
    radial-gradient(closest-side, rgba(50, 103, 214, 0.18), transparent) 55% 40% / 45% 100% no-repeat,
    radial-gradient(closest-side, rgba(199, 76, 178, 0.14), transparent) 90% 60% / 40% 100% no-repeat;
  filter: blur(10px);
  pointer-events: none;
  animation: thinking-aurora 7s ease-in-out infinite alternate;
}

@keyframes thinking-aurora {
  from { transform: translateX(-6%) rotate(-2deg); }
  to { transform: translateX(6%) rotate(2deg); }
}

.thinking-header {
  position: relative;
  display: flex;
  align-items: center;
  gap: 16px;
}

.thinking-orb {
  position: relative;
  display: grid;
  width: 54px;
  height: 54px;
  flex: 0 0 auto;
  place-items: center;
}

.thinking-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(from 0deg, var(--cyan), var(--blue), var(--magenta), var(--cyan));
  -webkit-mask: radial-gradient(circle, transparent 58%, #000 60%);
  mask: radial-gradient(circle, transparent 58%, #000 60%);
  animation: spin 1.6s linear infinite;
}

.thinking-core {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 50%;
  background: var(--deep);
  color: var(--cyan);
  animation: thinking-pulse 1.8s ease-in-out infinite;
}

.thinking-core svg {
  width: 20px;
  height: 20px;
  animation: thinking-twinkle 1.8s ease-in-out infinite;
}

@keyframes thinking-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(66, 214, 236, 0.45); }
  50% { box-shadow: 0 0 0 9px rgba(66, 214, 236, 0); }
}

@keyframes thinking-twinkle {
  0%, 100% { transform: scale(1) rotate(0deg); opacity: 1; }
  50% { transform: scale(1.12) rotate(12deg); opacity: 0.75; }
}

.thinking-heading {
  min-width: 0;
  flex: 1 1 auto;
}

.thinking-heading strong {
  display: block;
  background: linear-gradient(90deg, var(--ink) 0%, var(--ink) 40%, var(--blue) 50%, var(--ink) 60%, var(--ink) 100%);
  background-size: 250% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-size: 18px;
  animation: thinking-shine 2.6s linear infinite;
}

@keyframes thinking-shine {
  from { background-position: 100% 0; }
  to { background-position: -150% 0; }
}

.thinking-heading small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.thinking-heading code {
  color: var(--blue);
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 11px;
  font-weight: 700;
}

.thinking-steps {
  position: relative;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 20px 0 16px;
  padding: 0;
  list-style: none;
}

.thinking-steps li {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 7px;
  color: #9aa5b5;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  transition: color 200ms ease;
}

.thinking-steps li::before {
  content: "";
  position: absolute;
  top: 12px;
  right: 50%;
  width: calc(100% - 26px + 8px);
  height: 2px;
  margin-right: 13px;
  background: var(--line);
}

.thinking-steps li:first-child::before {
  display: none;
}

.thinking-steps li.is-done::before,
.thinking-steps li.is-active::before {
  background: linear-gradient(90deg, var(--green), var(--cyan-dark));
}

.thinking-step-mark {
  position: relative;
  display: grid;
  width: 26px;
  height: 26px;
  place-items: center;
  border: 2px solid var(--line-strong);
  border-radius: 50%;
  background: var(--white);
  color: transparent;
  transition: border-color 200ms ease, background 200ms ease;
}

.thinking-step-mark svg {
  width: 14px;
  height: 14px;
  stroke-width: 3;
}

.thinking-steps li.is-active {
  color: var(--blue);
}

.thinking-steps li.is-active .thinking-step-mark {
  border-color: #c9d8f7;
  border-top-color: var(--blue);
  animation: spin 900ms linear infinite;
}

.thinking-steps li.is-done {
  color: var(--green);
}

.thinking-steps li.is-done .thinking-step-mark {
  border-color: var(--green);
  background: var(--green);
  color: var(--white);
  animation: thinking-pop 260ms ease-out;
}

@keyframes thinking-pop {
  from { transform: scale(0.6); }
  60% { transform: scale(1.15); }
  to { transform: scale(1); }
}

.thinking-live {
  position: relative;
  display: grid;
  gap: 10px;
  min-height: 96px;
  border-radius: 8px;
  background: var(--paper);
  padding: 14px 16px;
}

.thinking-task {
  justify-self: start;
  border-radius: 999px;
  background: var(--blue-soft);
  color: var(--blue);
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 800;
  animation: thinking-enter 240ms ease-out;
}

.thinking-hint {
  margin: 0;
  color: var(--ink-soft);
  font-size: 13px;
}

.thinking-hint.is-fresh {
  animation: thinking-fade 420ms ease-out;
}

@keyframes thinking-fade {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.thinking-skeleton {
  display: grid;
  gap: 8px;
}

.thinking-skeleton span {
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(90deg, #e3e9f1 0%, #f4f7fb 45%, #e3e9f1 90%);
  background-size: 200% 100%;
  animation: thinking-skeleton 1.3s ease-in-out infinite;
}

.thinking-skeleton span:nth-child(2) { width: 86%; animation-delay: 120ms; }
.thinking-skeleton span:nth-child(3) { width: 62%; animation-delay: 240ms; }

@keyframes thinking-skeleton {
  from { background-position: 150% 0; }
  to { background-position: -50% 0; }
}

.thinking-summary,
.thinking-prompt {
  margin: 0;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.7;
  white-space: pre-wrap;
}

.thinking-summary:empty {
  display: none;
}

.thinking-card.is-streaming:not(.is-writing) .thinking-summary::after,
.thinking-card.is-writing .thinking-prompt::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: 1.05em;
  margin-left: 2px;
  background: var(--blue);
  vertical-align: -0.15em;
  animation: thinking-caret 900ms steps(1) infinite;
}

@keyframes thinking-caret {
  50% { opacity: 0; }
}

.thinking-prompt-block {
  display: grid;
  gap: 6px;
  border-top: 1px dashed var(--line-strong);
  padding-top: 10px;
}

.thinking-prompt-block > span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.thinking-prompt {
  max-height: 168px;
  color: var(--ink-soft);
  font-size: 13px;
  overflow: auto;
  -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 22px);
  mask-image: linear-gradient(180deg, transparent 0, #000 22px);
}

/* busy generate button */
.generate-button.is-working {
  position: relative;
  overflow: hidden;
  opacity: 0.94;
}

.generate-button.is-working::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, transparent 25%, rgba(255, 255, 255, 0.55) 50%, transparent 75%);
  background-size: 220% 100%;
  animation: thinking-shine 1.6s linear infinite;
  pointer-events: none;
}

.generate-button.is-working svg {
  animation: thinking-twinkle 1.2s ease-in-out infinite;
}

/* waiting image cards */
.result-placeholder.is-working {
  background: linear-gradient(110deg, var(--white) 30%, #eef4fb 50%, var(--white) 70%);
  background-size: 220% 100%;
  animation: thinking-skeleton 1.8s ease-in-out infinite;
}

.job-hint {
  color: #9aa5b5;
  font-size: 10px !important;
}

/* v3.5: embedded inside sub2api (?ui_mode=embedded) */
.is-embedded .brand,
.is-embedded #open-new-window {
  display: none;
}

.is-embedded .studio-header {
  grid-template-columns: minmax(0, 1fr) auto;
}

.is-embedded .product-title {
  border-left: 0;
  padding-left: 0;
}
