:root {
  --bg: #0c0e14;
  --card: #161a24;
  --text: #eef1f7;
  --muted: rgba(238, 241, 247, 0.62);
  --accent: #a78bfa;
  --line: rgba(255, 255, 255, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  background-image:
    radial-gradient(circle at 18% 12%, rgba(139, 92, 246, 0.14), transparent 35%),
    radial-gradient(circle at 88% 78%, rgba(59, 130, 246, 0.1), transparent 30%);
}

.wrap {
  max-width: 1220px;
  margin: 0 auto;
  padding: 22px 18px 48px;
}

.head h1 {
  margin: 0 0 10px;
  font-size: clamp(1.35rem, 4vw, 1.85rem);
  letter-spacing: -0.02em;
}

.head-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.portal-link {
  align-self: center;
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
  font-size: 0.95rem;
  white-space: nowrap;
}

.portal-link:hover {
  text-decoration: underline;
}

.head-main {
  flex: 1;
  min-width: min(100%, 280px);
}

.btn-gear {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 12px;
  font-size: 1.35rem;
  line-height: 1;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 16px;
  overflow-y: auto;
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(6px);
}

.modal-backdrop.hidden {
  display: none !important;
}

.modal {
  width: min(440px, 100%);
  margin-top: min(12vh, 80px);
  padding: 20px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--card);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}

.modal-title {
  margin: 0 0 12px;
  font-size: 1.12rem;
  color: var(--accent);
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.btn-modal {
  flex: 1;
  min-width: min(100%, 120px);
}

.kie-status {
  margin: 0 0 10px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}

.chk-row-tight {
  margin-top: 4px;
  margin-bottom: 6px;
}

.canvas-panel.canvas-disabled .toolbar,
.canvas-panel.canvas-disabled .canvas-wrap,
.canvas-panel.canvas-disabled .canvas-underlay-block,
.canvas-panel.canvas-disabled .canvas-4o-block {
  opacity: 0.42;
  pointer-events: none;
}

.lead {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.55;
  max-width: 960px;
}

.lead code {
  font-size: 0.88em;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
}

.lang-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.2);
}

.lang-caption {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--muted);
}

.chk-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 0.9rem;
}

.layout {
  display: grid;
  gap: 20px;
  margin-top: 22px;
}

@media (min-width: 980px) {
  .layout {
    grid-template-columns: minmax(0, 1fr) 400px;
    align-items: start;
  }
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
}

.block-title {
  margin: 0 0 8px;
  font-size: 1.05rem;
  color: var(--accent);
}

.block-title-sm {
  margin-top: 4px;
  font-size: 1rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.lbl {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  color: var(--muted);
}

.canvas-wrap {
  border-radius: 12px;
  overflow: auto;
  max-height: min(72vh, 780px);
  border: 1px solid var(--line);
  background: #222;
}

.canvas-stack {
  position: relative;
  line-height: 0;
}

.canvas-stack #draw-bg {
  display: block;
  vertical-align: top;
  background: #fff;
  cursor: default;
}

.canvas-stack #draw {
  position: absolute;
  left: 0;
  top: 0;
  display: block;
  cursor: crosshair;
  touch-action: none;
  background: transparent;
}

.canvas-underlay-block {
  margin-top: 12px;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.18);
}

.field.field-tight {
  margin-bottom: 10px;
}

.canvas-underlay-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.sep-canvas {
  margin: 18px 0 14px;
}

.block-title-sub {
  margin: 0 0 8px;
  font-size: 1rem;
  font-weight: 600;
}

.btn-go-canvas {
  width: 100%;
  margin-top: 8px;
}

.btn-4o {
  width: 100%;
  margin-top: 8px;
  background: linear-gradient(135deg, #ea580c, #f59e0b);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #0f0f0f;
  font-weight: 600;
}

.btn-4o:hover {
  filter: brightness(1.06);
}

.out-title-4o {
  margin: 12px 0 8px;
  font-size: 0.95rem;
}

.hint {
  margin: 10px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.45;
}

.hint-tight {
  margin-top: 0;
  margin-bottom: 10px;
}

.sep {
  border: none;
  border-top: 1px solid var(--line);
  margin: 16px 0;
}

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

.field-lbl {
  display: block;
  margin-bottom: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}

textarea,
select,
input[type="file"] {
  width: 100%;
  font: inherit;
}

textarea {
  resize: vertical;
  min-height: 62px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
}

.input-url {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  font: inherit;
}

.input-url::placeholder {
  color: rgba(238, 241, 247, 0.38);
}

select {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
}

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

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

@media (max-width: 520px) {
  .row-3 {
    grid-template-columns: 1fr;
  }
}

.field.third {
  margin-bottom: 14px;
}

.chk-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 12px 0 4px;
  cursor: pointer;
  font-size: 0.88rem;
  line-height: 1.45;
  color: var(--text);
}

.chk-row input {
  margin-top: 4px;
  flex-shrink: 0;
}

.cam-box {
  margin-bottom: 12px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.18);
}

.webcam {
  width: 100%;
  max-height: 220px;
  border-radius: 10px;
  background: #000;
  object-fit: cover;
}

.cam-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.face-preview {
  margin-top: 10px;
  max-width: 100%;
  max-height: 180px;
  border-radius: 10px;
  border: 1px solid var(--line);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.idea-upload-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 8px;
}

.btn-compact {
  padding: 8px 12px;
  font-size: 0.82rem;
}

.btn-idea {
  flex: 1;
  min-width: min(100%, 220px);
  padding: 11px 16px;
  border-radius: 12px;
  font-weight: 800;
  font-size: 0.88rem;
  cursor: pointer;
  font-family: inherit;
  border: 1px solid rgba(234, 179, 8, 0.55);
  background: linear-gradient(135deg, #facc15, #eab308);
  color: #1c1917;
  box-shadow: 0 8px 22px rgba(234, 179, 8, 0.28);
}

.btn-idea:hover {
  filter: brightness(1.05);
}

.btn-idea:active {
  transform: translateY(1px);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
  font-family: inherit;
}

.btn-primary {
  width: 100%;
  margin-top: 8px;
  padding: 12px 18px;
  font-size: 0.92rem;
  background: linear-gradient(135deg, #8b5cf6, #6d28d9);
  color: #fff;
  border-color: rgba(167, 139, 250, 0.45);
  box-shadow: 0 10px 28px rgba(109, 40, 217, 0.35);
}

.btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border-color: var(--line);
}

.btn-ghost.active {
  border-color: var(--accent);
  color: var(--accent);
}

.status {
  margin-top: 12px;
  font-size: 0.88rem;
  color: var(--muted);
  min-height: 1.4em;
}

.status.err {
  color: #fca5a5;
}

.progress-wrap {
  margin-top: 14px;
}

.progress-wrap.hidden {
  display: none;
}

.progress-track {
  height: 10px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  border: 1px solid var(--line);
}

.progress-fill {
  height: 100%;
  width: 0%;
  min-width: 0;
  background: linear-gradient(90deg, var(--accent), #a78bfa);
  transition: width 0.4s ease;
}

.progress-summary {
  margin: 10px 0 6px;
  font-size: 0.88rem;
  color: var(--muted);
  line-height: 1.35;
}

.progress-log {
  font-size: 0.78rem;
  line-height: 1.45;
  color: rgba(255, 255, 255, 0.72);
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  max-height: 200px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.out-wrap {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.out-wrap h2 {
  margin: 0 0 10px;
  font-size: 1rem;
}

.result-img {
  display: block;
  width: 100%;
  height: auto;
  margin-top: 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
}

.hidden {
  display: none !important;
}
