.painting-character-open {
  overflow: hidden;
}

.painting-character-shell {
  --pc-ink: #18202d;
  --pc-muted: #667085;
  --pc-line: rgba(25, 36, 54, 0.12);
  --pc-panel: rgba(255, 255, 255, 0.94);
  --pc-accent: #4258e8;
  position: fixed;
  inset: 0;
  z-index: 980;
  display: grid;
  place-items: center;
  padding: 22px;
  color: var(--pc-ink);
  background:
    radial-gradient(circle at 14% 0%, rgba(118, 132, 255, 0.22), transparent 31rem),
    rgba(12, 16, 24, 0.68);
  -webkit-backdrop-filter: blur(18px) saturate(1.08);
  backdrop-filter: blur(18px) saturate(1.08);
}

.painting-character-shell[hidden] {
  display: none;
}

.painting-character-window {
  width: min(1560px, calc(100vw - 44px));
  height: min(940px, calc(100vh - 44px));
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 24px;
  background: #f2f4f8;
  box-shadow: 0 32px 90px rgba(4, 10, 22, 0.34), 0 2px 12px rgba(4, 10, 22, 0.12);
  animation: painting-character-enter 180ms cubic-bezier(0.2, 0.78, 0.22, 1);
}

@keyframes painting-character-enter {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.988);
  }
}

.painting-character-head {
  min-height: 84px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 18px 14px 24px;
  border-bottom: 1px solid var(--pc-line);
  background: rgba(255, 255, 255, 0.88);
}

.painting-character-head h2,
.painting-character-head p,
.painting-character-panel h3,
.painting-character-panel p {
  margin: 0;
}

.painting-character-head h2 {
  display: inline;
  margin-right: 12px;
  font-size: 24px;
  line-height: 1.2;
  letter-spacing: -0.03em;
}

.painting-character-head p {
  display: inline;
  color: var(--pc-muted);
  font-size: 13px;
}

.painting-character-kicker {
  display: block;
  margin-bottom: 3px;
  color: var(--pc-accent);
  font: 700 10px/1.2 ui-monospace, SFMono-Regular, Consolas, monospace;
  letter-spacing: 0.14em;
}

.painting-character-head-actions,
.painting-character-panel-actions,
.painting-character-preview-actions,
.painting-character-version-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.painting-character-save-state {
  padding: 5px 9px;
  border-radius: 999px;
  color: #557060;
  background: #e8f5ec;
  font-size: 12px;
  white-space: nowrap;
}

.painting-character-save-state.dirty {
  color: #936217;
  background: #fff2d5;
}

.painting-character-save-state.busy {
  color: #3549c8;
  background: #e8ebff;
}

.painting-character-icon-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--pc-line);
  border-radius: 13px;
  color: #344054;
  background: #fff;
  font-size: 27px;
  font-weight: 300;
  line-height: 1;
}

.painting-character-body {
  height: calc(100% - 84px);
  display: grid;
  grid-template-columns: 224px minmax(0, 1fr);
}

.painting-character-library {
  min-width: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  border-right: 1px solid var(--pc-line);
  background: rgba(247, 248, 251, 0.92);
}

.painting-character-library-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 4px 12px;
}

.painting-character-library-head strong {
  font-size: 15px;
}

.painting-character-library button,
.painting-character-editor button,
.painting-character-file-button {
  min-height: 34px;
  border: 1px solid var(--pc-line);
  border-radius: 10px;
  color: #344054;
  background: rgba(255, 255, 255, 0.88);
  font: 600 12px/1.2 inherit;
  transition: border-color 140ms ease, background 140ms ease, color 140ms ease, transform 140ms ease;
}

.painting-character-library button:hover,
.painting-character-editor button:hover,
.painting-character-file-button:hover {
  border-color: rgba(66, 88, 232, 0.34);
  color: #283dcc;
  background: #f9faff;
}

.painting-character-library button:active,
.painting-character-editor button:active {
  transform: translateY(1px);
}

.painting-character-library button:focus-visible,
.painting-character-editor button:focus-visible,
.painting-character-editor input:focus-visible,
.painting-character-editor textarea:focus-visible,
.painting-character-editor select:focus-visible,
.painting-character-search input:focus-visible {
  outline: 3px solid rgba(66, 88, 232, 0.2);
  outline-offset: 1px;
  border-color: rgba(66, 88, 232, 0.58);
}

.painting-character-library button:disabled,
.painting-character-editor button:disabled,
.painting-character-file-button:has(input:disabled) {
  opacity: 0.46;
  cursor: not-allowed;
  transform: none;
}

.painting-character-search {
  display: grid;
  gap: 5px;
  padding: 0 4px 12px;
  color: var(--pc-muted);
  font-size: 11px;
}

.painting-character-search input,
.painting-character-editor input,
.painting-character-editor textarea,
.painting-character-editor select {
  min-width: 0;
  border: 1px solid var(--pc-line);
  border-radius: 10px;
  color: var(--pc-ink);
  background: rgba(255, 255, 255, 0.94);
  font: 500 13px/1.35 inherit;
}

.painting-character-search input,
.painting-character-editor input:not([type='color']):not([type='range']),
.painting-character-editor select {
  min-height: 36px;
  padding: 7px 10px;
}

.painting-character-list {
  min-height: 0;
  overflow-y: auto;
  display: grid;
  align-content: start;
  gap: 6px;
  padding: 2px 4px 16px;
  scrollbar-width: thin;
}

.painting-character-card {
  width: 100%;
  min-height: 62px !important;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 7px !important;
  text-align: left;
}

.painting-character-card.active {
  border-color: rgba(66, 88, 232, 0.42);
  color: #283dcc;
  background: linear-gradient(135deg, #eef0ff, #f8f9ff);
  box-shadow: inset 3px 0 0 var(--pc-accent);
}

.painting-character-card-thumb {
  width: 44px;
  height: 44px;
  overflow: hidden;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: #e7e9ef;
}

.painting-character-card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.painting-character-avatar-placeholder {
  color: #788195;
  font-size: 15px;
}

.painting-character-card-copy {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.painting-character-card-copy strong,
.painting-character-card-copy small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.painting-character-card-copy strong {
  font-size: 13px;
}

.painting-character-card-copy small {
  color: var(--pc-muted);
  font-size: 11px;
}

.painting-character-list-state,
.painting-character-reference-empty,
.painting-character-history-empty {
  padding: 24px 12px;
  color: var(--pc-muted);
  font-size: 12px;
  text-align: center;
}

.painting-character-editor {
  min-width: 0;
  overflow: auto;
  padding: 16px;
  scrollbar-width: thin;
}

.painting-character-empty {
  height: 100%;
  display: grid;
  place-content: center;
  justify-items: center;
  text-align: center;
}

.painting-character-empty > span {
  color: var(--pc-accent);
  font: 700 11px/1 ui-monospace, SFMono-Regular, Consolas, monospace;
  letter-spacing: 0.14em;
}

.painting-character-empty h3 {
  margin: 12px 0 8px;
  font-size: 24px;
}

.painting-character-empty p {
  max-width: 420px;
  margin: 0 0 18px;
  color: var(--pc-muted);
  font-size: 13px;
}

.painting-character-empty button {
  min-width: 120px;
}

.painting-character-meta-row {
  display: grid;
  grid-template-columns: minmax(180px, 0.75fr) minmax(280px, 1.5fr) auto auto;
  align-items: end;
  gap: 10px;
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid var(--pc-line);
  border-radius: 15px;
  background: rgba(255, 255, 255, 0.76);
}

.painting-character-meta-row label,
.painting-character-prompt {
  min-width: 0;
  display: grid;
  gap: 5px;
  color: var(--pc-muted);
  font-size: 11px;
}

.painting-character-meta-row .danger {
  color: #b42318;
}

.painting-character-grid {
  display: grid;
  grid-template-columns: minmax(500px, 1.28fr) minmax(360px, 0.9fr);
  grid-template-rows: minmax(390px, 1fr) auto auto;
  gap: 12px;
}

.painting-character-panel {
  min-width: 0;
  border: 1px solid var(--pc-line);
  border-radius: 17px;
  background: var(--pc-panel);
  box-shadow: 0 5px 18px rgba(29, 37, 58, 0.04);
}

.painting-character-panel-head {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 13px;
  border-bottom: 1px solid var(--pc-line);
}

.painting-character-panel-head span {
  display: block;
  margin-bottom: 3px;
  color: #727b8f;
  font: 700 9px/1 ui-monospace, SFMono-Regular, Consolas, monospace;
  letter-spacing: 0.12em;
}

.painting-character-panel-head h3 {
  font-size: 15px;
  letter-spacing: -0.01em;
}

.painting-character-pose-panel {
  grid-row: 1 / span 3;
  display: flex;
  flex-direction: column;
}

.painting-character-canvas-toolbar {
  min-height: 48px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px 10px;
  padding: 7px 12px;
  border-bottom: 1px solid var(--pc-line);
  background: #f8f9fb;
}

.painting-character-canvas-toolbar label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--pc-muted);
  font-size: 11px;
  white-space: nowrap;
}

.painting-character-canvas-toolbar input[type='number'] {
  width: 76px;
  min-height: 30px !important;
  padding: 4px 7px !important;
}

.painting-character-canvas-toolbar input[type='color'] {
  width: 28px;
  height: 28px;
  padding: 2px;
}

.painting-character-canvas-toolbar input[type='range'] {
  width: 92px;
  accent-color: var(--pc-accent);
}

.painting-character-canvas-toolbar output {
  min-width: 32px;
  color: #344054;
  font-size: 11px;
}

.painting-character-tool-group {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--pc-line);
  border-radius: 10px;
  background: #fff;
}

.painting-character-tool-group button {
  min-height: 28px;
  border: 0;
  background: transparent;
}

.painting-character-tool-group button.active {
  color: #fff;
  background: var(--pc-accent);
}

.painting-character-file-button {
  position: relative;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  cursor: pointer;
}

.painting-character-file-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.painting-character-canvas-viewport {
  min-height: 0;
  flex: 1;
  overflow: auto;
  display: grid;
  place-items: center;
  padding: 16px;
  background: #dfe3ea;
  scrollbar-width: thin;
}

.painting-character-canvas-frame {
  width: min(100%, calc((100vh - 340px) * var(--character-canvas-ratio)));
  max-height: calc(100vh - 340px);
  aspect-ratio: var(--character-canvas-ratio);
  overflow: hidden;
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #edf0f4 25%, transparent 25%),
    linear-gradient(-45deg, #edf0f4 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #edf0f4 75%),
    linear-gradient(-45deg, transparent 75%, #edf0f4 75%);
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-size: 20px 20px;
  box-shadow: 0 12px 30px rgba(14, 22, 37, 0.18);
}

.painting-character-canvas-frame canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

.painting-character-pose-foot {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  border-top: 1px solid var(--pc-line);
}

.painting-character-pose-foot p,
.painting-character-help {
  color: var(--pc-muted);
  font-size: 11px;
  line-height: 1.5;
}

.painting-character-editor button.primary {
  border-color: transparent;
  color: #fff;
  background: linear-gradient(135deg, #4055e3, #6a48d7);
  box-shadow: 0 7px 18px rgba(66, 88, 232, 0.22);
}

.painting-character-reference-panel,
.painting-character-version-panel,
.painting-character-preview-panel {
  overflow: hidden;
}

.painting-character-reference-panel {
  grid-column: 2;
  grid-row: 2;
}

.painting-character-reference-panel > .painting-character-help {
  padding: 9px 12px 0;
}

.painting-character-reference-list {
  max-height: 214px;
  overflow-y: auto;
  display: grid;
  gap: 6px;
  padding: 9px 10px 12px;
  scrollbar-width: thin;
}

.painting-character-reference {
  min-height: 56px;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  padding: 5px;
  border: 1px solid var(--pc-line);
  border-radius: 11px;
  background: #fafbfc;
  cursor: grab;
}

.painting-character-reference:active {
  cursor: grabbing;
}

.painting-character-reference img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 8px;
  background: #e7e9ef;
}

.painting-character-reference > div:not(.painting-character-reference-actions) {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.painting-character-reference strong,
.painting-character-reference small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.painting-character-reference strong {
  font-size: 12px;
}

.painting-character-reference small {
  color: var(--pc-muted);
  font-size: 10px;
}

.painting-character-reference-actions {
  display: flex;
  gap: 3px;
}

.painting-character-reference-actions button {
  width: 28px;
  min-height: 28px;
  padding: 0;
}

.painting-character-preview-panel {
  grid-column: 2;
  grid-row: 1;
  padding-bottom: 12px;
}

.painting-character-status-pill {
  margin: 0 !important;
  padding: 5px 8px;
  border-radius: 999px;
  font: 600 10px/1.2 inherit !important;
  letter-spacing: 0 !important;
}

.painting-character-status-pill.ready {
  color: #11734b;
  background: #def7ea;
}

.painting-character-status-pill.disabled {
  color: #9a5b14;
  background: #fff0d2;
}

.painting-character-preview {
  height: clamp(172px, 27vh, 300px);
  display: grid;
  place-items: center;
  gap: 5px;
  margin: 12px;
  overflow: hidden;
  border: 1px solid var(--pc-line);
  border-radius: 13px;
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #f1f2f5 25%, transparent 25%),
    linear-gradient(-45deg, #f1f2f5 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f1f2f5 75%),
    linear-gradient(-45deg, transparent 75%, #f1f2f5 75%);
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
}

.painting-character-preview img {
  width: 100%;
  height: calc(100% - 24px);
  min-height: 0;
  object-fit: contain;
}

.painting-character-preview > span {
  width: 100%;
  padding: 5px 8px;
  color: var(--pc-muted);
  background: rgba(255, 255, 255, 0.9);
  font-size: 10px;
  text-align: center;
}

.painting-character-preview-empty {
  padding: 20px;
  color: var(--pc-muted);
  font-size: 12px;
  text-align: center;
}

.painting-character-preview-empty > span {
  display: block;
  margin-bottom: 8px;
  color: #9aa1b0;
  font: 800 22px/1 ui-monospace, SFMono-Regular, Consolas, monospace;
  text-transform: uppercase;
}

.painting-character-prompt,
.painting-character-boundary,
.painting-character-generation-state,
.painting-character-preview-actions {
  margin-right: 12px;
  margin-left: 12px;
}

.painting-character-prompt textarea {
  min-height: 58px;
  resize: vertical;
  padding: 8px 10px;
}

.painting-character-generation-state {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 9px;
  padding: 9px 10px;
  border-radius: 10px;
  color: #3549c8;
  background: #eef0ff;
  font-size: 11px;
}

.painting-character-generation-state[hidden] {
  display: none;
}

.painting-character-spinner {
  width: 14px;
  height: 14px;
  display: inline-block;
  flex: 0 0 auto;
  border: 2px solid rgba(66, 88, 232, 0.18);
  border-top-color: var(--pc-accent);
  border-radius: 50%;
  animation: painting-character-spin 700ms linear infinite;
}

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

.painting-character-boundary {
  margin-top: 9px;
  padding: 8px 10px;
  border-left: 3px solid #c8ceff;
  border-radius: 0 9px 9px 0;
  color: var(--pc-muted);
  background: #f7f8ff;
}

.painting-character-boundary strong {
  display: block;
  margin-bottom: 3px;
  color: #45506a;
  font-size: 11px;
}

.painting-character-boundary p {
  font-size: 10px;
  line-height: 1.45;
}

.painting-character-preview-actions {
  justify-content: flex-end;
  margin-top: 10px;
}

.painting-character-preview-actions button {
  min-width: 126px;
}

.painting-character-version-panel {
  grid-column: 2;
  grid-row: 3;
}

.painting-character-version-controls {
  padding: 10px 12px;
}

.painting-character-version-controls select {
  flex: 1;
}

.painting-character-generation-list {
  max-height: 160px;
  overflow-y: auto;
  display: grid;
  gap: 7px;
  margin: 0;
  padding: 0 12px 12px;
  list-style: none;
}

.painting-character-generation-list li:not(.painting-character-history-empty) {
  display: grid;
  grid-template-columns: 8px minmax(0, 1fr);
  align-items: start;
  gap: 8px;
  color: #475467;
}

.painting-character-generation-list li > span {
  width: 7px;
  height: 7px;
  margin-top: 4px;
  border-radius: 50%;
  background: #98a2b3;
}

.painting-character-generation-list li > span.succeeded {
  background: #25a66a;
}

.painting-character-generation-list li > span.failed {
  background: #e44c42;
}

.painting-character-generation-list li > span.processing {
  background: #4c63ef;
  box-shadow: 0 0 0 4px rgba(76, 99, 239, 0.12);
}

.painting-character-generation-list li > div {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.painting-character-generation-list strong {
  font-size: 11px;
}

.painting-character-generation-list small,
.painting-character-generation-list em {
  overflow: hidden;
  color: var(--pc-muted);
  font-size: 9px;
  font-style: normal;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.painting-character-generation-list em {
  color: #b42318;
}

.painting-character-shell.canvas-fullscreen .painting-character-window {
  width: calc(100vw - 20px);
  height: calc(100vh - 20px);
}

.painting-character-shell.canvas-fullscreen .painting-character-library,
.painting-character-shell.canvas-fullscreen .painting-character-meta-row,
.painting-character-shell.canvas-fullscreen .painting-character-reference-panel,
.painting-character-shell.canvas-fullscreen .painting-character-preview-panel {
  display: none;
}

.painting-character-shell.canvas-fullscreen .painting-character-body,
.painting-character-shell.canvas-fullscreen .painting-character-grid {
  display: block;
}

.painting-character-shell.canvas-fullscreen .painting-character-editor {
  height: 100%;
  padding: 10px;
}

.painting-character-shell.canvas-fullscreen .painting-character-pose-panel {
  height: 100%;
}

.painting-character-shell.canvas-fullscreen .painting-character-canvas-frame {
  width: min(100%, calc((100vh - 245px) * var(--character-canvas-ratio)));
  max-height: calc(100vh - 245px);
}

@media (max-width: 1120px) {
  .painting-character-shell {
    padding: 8px;
  }

  .painting-character-window {
    width: calc(100vw - 16px);
    height: calc(100vh - 16px);
    border-radius: 17px;
  }

  .painting-character-body {
    grid-template-columns: 184px minmax(0, 1fr);
  }

  .painting-character-grid {
    grid-template-columns: minmax(410px, 1.15fr) minmax(310px, 0.85fr);
  }

  .painting-character-meta-row {
    grid-template-columns: minmax(160px, 0.7fr) minmax(220px, 1.3fr) auto;
  }

  .painting-character-meta-row .danger {
    display: none;
  }
}

@media (max-width: 780px) {
  .painting-character-head p,
  .painting-character-library {
    display: none;
  }

  .painting-character-body {
    display: block;
  }

  .painting-character-editor {
    height: 100%;
    padding: 9px;
  }

  .painting-character-meta-row {
    grid-template-columns: 1fr auto;
  }

  .painting-character-description {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .painting-character-grid {
    display: block;
  }

  .painting-character-panel {
    margin-bottom: 9px;
  }

  .painting-character-pose-panel {
    height: 66vh;
  }
}

@media (prefers-reduced-motion: reduce) {
  .painting-character-window,
  .painting-character-spinner {
    animation: none;
  }

  .painting-character-library button,
  .painting-character-editor button,
  .painting-character-file-button {
    transition: none;
  }
}

/* Sketch-stage entry point. The character editor itself stays independent so
   opening it never replaces or resets the active painting workspace. */
.painting-character-entry {
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--accent, #7f75ff) 30%, rgba(255, 255, 255, 0.1));
  border-radius: 12px;
  background: linear-gradient(145deg, rgba(127, 117, 255, 0.12), rgba(255, 255, 255, 0.035));
}

.painting-character-entry > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 52px;
  padding: 10px 12px;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.painting-character-entry > summary::-webkit-details-marker {
  display: none;
}

.painting-character-entry > summary span {
  display: grid;
  gap: 2px;
}

.painting-character-entry > summary strong {
  color: var(--text-strong, #f7f8ff);
  font-size: 13px;
}

.painting-character-entry > summary small {
  color: var(--text-muted, #9ba1b4);
  font-size: 11px;
}

.painting-character-entry > summary b {
  color: var(--accent, #8d85ff);
  font-size: 16px;
  transition: transform 160ms ease;
}

.painting-character-entry[open] > summary b {
  transform: rotate(180deg);
}

.painting-character-entry > div {
  display: grid;
  gap: 9px;
  padding: 0 12px 12px;
}

.painting-character-entry > div p {
  margin: 0;
  color: var(--text-muted, #a4a9ba);
  font-size: 11px;
  line-height: 1.6;
}

.painting-character-entry > div button {
  min-height: 38px;
  border-color: color-mix(in srgb, var(--accent, #7f75ff) 42%, transparent);
  background: color-mix(in srgb, var(--accent, #7f75ff) 18%, rgba(255, 255, 255, 0.045));
  color: var(--text-strong, #f7f8ff);
}
