@import url("https://fonts.googleapis.com/css2?family=Work+Sans:wght@400;500;600&display=swap");

:root {
  --bg: #1e1e1e;
  --bg-panel: #2c2c2c;
  --bg-input: #383838;
  --border: #4a4a4a;
  --border-focus: #31EFB8;
  --text: #e8e8e8;
  --text-muted: #8c8c8c;
  --accent: #31EFB8;
  --accent-strong: #1ac99a;
  --accent-soft: rgba(49, 239, 184, 0.12);
  --success: #31EFB8;
  --error: #ff6b6b;
  --warning: #ffc36c;
  --radius: 6px;
  --font-ui: "Work Sans", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
}

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

.app-shell {
  display: grid;
  gap: 8px;
  padding: 12px;
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}

.panel h2 {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.field-group {
  display: grid;
  gap: 4px;
}

.field-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.field-help {
  margin: 0 0 10px;
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
}

select,
input[type="text"] {
  width: 100%;
  height: 28px;
  padding: 0 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

textarea {
  width: 100%;
  min-height: 100px;
  padding: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  resize: vertical;
  line-height: 1.5;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

select:focus,
input[type="text"]:focus,
textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.toggle {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.35;
}

.toggle input {
  margin-top: 2px;
  accent-color: var(--accent);
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

button {
  height: 28px;
  border: none;
  border-radius: var(--radius);
  padding: 0 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 120ms ease, background 120ms ease;
}

button:hover:not(:disabled) {
  opacity: 0.85;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

.primary {
  background: var(--accent);
  color: #1e1e1e;
}

.secondary {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
}

.status {
  min-height: 18px;
  margin: 10px 0 0;
  font-size: 12px;
  line-height: 1.4;
}

.status[data-kind="info"] {
  color: var(--text-muted);
}

.status[data-kind="loading"] {
  color: var(--warning);
}

.status[data-kind="success"] {
  color: var(--success);
}

.status[data-kind="error"] {
  color: var(--error);
}

.badge {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 8px;
  border-radius: var(--radius);
  font-size: 11px;
  font-weight: 600;
}

.badge.accent {
  background: var(--accent-soft);
  color: var(--accent);
}

.selection-info {
  margin: 8px 0 0;
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
}

.preview-caption {
  margin: 8px 0 0;
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
}

.preview-shell {
  display: grid;
  place-items: center;
  min-height: 200px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  overflow: hidden;
}

.preview-shell img {
  width: 100%;
  height: auto;
  display: block;
}

.preview-shell.empty img {
  display: none;
}

.preview-placeholder {
  max-width: 220px;
  margin: 0;
  padding: 20px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.45;
}

.skeleton {
  display: none;
  width: 100%;
  min-height: 200px;
  border-radius: var(--radius);
  background: linear-gradient(
    90deg,
    var(--bg-input) 25%,
    #454545 50%,
    var(--bg-input) 75%
  );
  background-size: 200% 100%;
}

body.loading .skeleton {
  display: block;
  animation: shimmer 1.6s linear infinite;
}

body.loading .preview-shell.is-loading .skeleton,
.preview-shell.is-loading .skeleton {
  display: block;
  animation: shimmer 1.6s linear infinite;
}

body.loading #previewImage,
body.loading #previewPlaceholder {
  display: none;
}

.preview-shell.is-loading #previewImage,
.preview-shell.is-loading #previewPlaceholder {
  display: none;
}

@keyframes shimmer {
  from {
    background-position: 200% 0;
  }
  to {
    background-position: -200% 0;
  }
}

/* Prompt mode toggle */
.prompt-section-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.prompt-section-label .field-label {
  margin: 0;
}

.prompt-mode-toggle {
  display: flex;
  gap: 2px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2px;
}

.mode-btn {
  flex: 1;
  height: 22px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  border: none;
  padding: 0;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  transition: background 120ms ease, color 120ms ease;
}

.mode-btn.active {
  background: var(--bg-panel);
  color: var(--text);
}

.mode-btn:hover:not(.active) {
  color: var(--text);
}

/* Guided prompt grid */
.guided-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.guided-grid .field-group:first-child,
.guided-grid .field-group:last-child {
  grid-column: 1 / -1;
}

@media (max-width: 420px) {
  .settings-grid,
  .actions,
  .guided-grid {
    grid-template-columns: 1fr;
  }

  .guided-grid .field-group:first-child,
  .guided-grid .field-group:last-child {
    grid-column: 1;
  }
}

/* ── Extend panel ─────────────────────────────────────── */

.extend-help {
  margin-bottom: 12px;
}

.extend-stage {
  --canvas-top: 8%;
  --canvas-bottom: 8%;
  --canvas-left: 8%;
  --canvas-right: 8%;
  --source-top: 0%;
  --source-bottom: 0%;
  --source-left: 0%;
  --source-right: 0%;
  position: relative;
  width: 100%;
  height: 320px;
  margin-bottom: 10px;
  border-radius: 14px;
  overflow: hidden;
  background:
    linear-gradient(45deg, rgba(255, 255, 255, 0.06) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255, 255, 255, 0.06) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(255, 255, 255, 0.06) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(255, 255, 255, 0.06) 75%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0)),
    #f5f5f5;
  background-size: 32px 32px, 32px 32px, 32px 32px, 32px 32px, 100% 100%, 100% 100%;
  background-position: 0 0, 0 16px, 16px -16px, -16px 0, 0 0, 0 0;
  border: 1px solid var(--border);
}

.extend-stage.no-image {
  height: 320px;
}

.extend-canvas {
  position: absolute;
  top: var(--canvas-top);
  right: var(--canvas-right);
  bottom: var(--canvas-bottom);
  left: var(--canvas-left);
  min-width: 0;
  min-height: 0;
}

.extend-zone {
  position: absolute;
  overflow: hidden;
  pointer-events: none;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  background:
    repeating-linear-gradient(
      135deg,
      rgba(49, 239, 184, 0.18),
      rgba(49, 239, 184, 0.18) 10px,
      rgba(49, 239, 184, 0.06) 10px,
      rgba(49, 239, 184, 0.06) 20px
    );
}

.extend-zone--top {
  top: 0;
  left: var(--source-left);
  right: var(--source-right);
  height: var(--source-top);
}

.extend-zone--left {
  top: var(--source-top);
  left: 0;
  bottom: var(--source-bottom);
  width: var(--source-left);
}

.extend-zone--right {
  top: var(--source-top);
  right: 0;
  bottom: var(--source-bottom);
  width: var(--source-right);
}

.extend-zone--bottom {
  left: var(--source-left);
  right: var(--source-right);
  bottom: 0;
  height: var(--source-bottom);
}

.extend-source-frame {
  position: absolute;
  top: var(--source-top);
  right: var(--source-right);
  bottom: var(--source-bottom);
  left: var(--source-left);
  min-width: 0;
  min-height: 0;
  border-radius: 12px;
  overflow: visible;
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.08),
    0 18px 45px rgba(15, 15, 15, 0.12);
}

.extend-source-tag {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 5;
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 10px;
  border-radius: 999px;
  background: rgba(12, 12, 12, 0.74);
  color: #ffffff;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.extend-zone-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 56px;
  height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: rgba(13, 13, 13, 0.72);
  border: 1px solid rgba(49, 239, 184, 0.35);
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.extend-corner {
  position: absolute;
  width: 18px;
  height: 18px;
  border: 3px solid rgba(90, 90, 90, 0.85);
  z-index: 3;
  pointer-events: none;
}

.extend-corner--tl {
  top: -10px;
  left: -10px;
  border-right: 0;
  border-bottom: 0;
}

.extend-corner--tr {
  top: -10px;
  right: -10px;
  border-left: 0;
  border-bottom: 0;
}

.extend-corner--bl {
  bottom: -10px;
  left: -10px;
  border-right: 0;
  border-top: 0;
}

.extend-corner--br {
  right: -10px;
  bottom: -10px;
  border-left: 0;
  border-top: 0;
}

.stage-drag-handle {
  position: absolute;
  border: none;
  border-radius: 999px;
  background: rgba(20, 20, 20, 0.78);
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.24);
  cursor: grab;
  z-index: 4;
}

.stage-drag-handle:active {
  cursor: grabbing;
}

.stage-drag-handle--top,
.stage-drag-handle--bottom {
  left: 50%;
  width: 32px;
  height: 6px;
  transform: translateX(-50%);
}

.stage-drag-handle--top {
  top: -16px;
}

.stage-drag-handle--bottom {
  bottom: -16px;
}

.stage-drag-handle--left,
.stage-drag-handle--right {
  top: 50%;
  width: 6px;
  height: 32px;
  transform: translateY(-50%);
}

.stage-drag-handle--left {
  left: -16px;
}

.stage-drag-handle--right {
  right: -16px;
}

.extend-stage.dragging .stage-drag-handle,
.stage-drag-handle.active,
.stage-drag-handle:hover {
  background: #0d0d0d;
}

.extend-preview-shell {
  width: 100%;
  height: 100%;
  min-height: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0)),
    var(--bg-input);
  display: grid;
  place-items: center;
  overflow: hidden;
}

.extend-preview-shell.is-loading {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0)),
    #1f1f1f;
}

.extend-preview-shell img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.extend-preview-loader {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.14);
  border-top-color: var(--accent);
  animation: spin 900ms linear infinite;
}

.extend-preview-shell.is-loading .extend-preview-loader {
  display: block;
}

.extend-preview-shell.is-loading img {
  opacity: 0;
}

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

.extend-dimensions {
  margin-bottom: 12px;
}

.extend-summary-row {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  margin-bottom: 10px;
}

.extend-summary-row .extend-handle {
  flex: 1 1 0;
  justify-content: space-between;
}

.extend-fine-tuning {
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
}

.extend-fine-tuning summary {
  padding: 10px 12px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-muted);
  list-style: none;
}

.extend-fine-tuning summary::-webkit-details-marker {
  display: none;
}

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

.extend-card {
  display: grid;
  gap: 8px;
  padding: 10px;
  border-radius: 12px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0)),
    #242424;
  border: 1px solid var(--border);
}

.extend-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.extend-side-value {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
}

.extend-handle {
  min-width: 0;
  height: 40px;
  padding: 0 10px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: var(--bg-input);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.extend-handle--icon {
  justify-content: center;
  gap: 6px;
}

.extend-handle-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
}

.extend-handle-icon svg {
  width: 16px;
  height: 16px;
  display: block;
}

.extend-handle--top .extend-handle-icon {
  transform: rotate(90deg);
}

.extend-handle--right .extend-handle-icon {
  transform: rotate(180deg);
}

.extend-handle--bottom .extend-handle-icon {
  transform: rotate(270deg);
}

.extend-handle.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

.extend-range {
  width: 100%;
  accent-color: var(--accent);
}

.extend-range:disabled {
  opacity: 0.35;
}

.extend-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.extend-chip {
  height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid rgba(49, 239, 184, 0.22);
  background: rgba(49, 239, 184, 0.08);
  color: var(--text);
  font-size: 11px;
}

.extend-chip--ghost {
  border-color: var(--border);
  background: transparent;
  color: var(--text-muted);
}

@media (max-width: 420px) {
  .extend-stage,
  .extend-stage.no-image {
    height: 280px;
  }

  .extend-summary-row {
    gap: 6px;
  }

  .extend-handle {
    padding: 0 8px;
  }

  .extend-side-value {
    font-size: 10px;
  }
}

.plugin-mode-toggle {
  display: flex;
  gap: 2px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2px;
  margin-bottom: 12px;
}

@media (max-width: 420px) {
  .extend-summary-row .extend-handle {
    flex: 1 1 100%;
  }

  .extend-controls {
    grid-template-columns: 1fr;
  }
}
