:root {
  --bg: #0f172a;
  --panel: #0b1220;
  --panel2: #111b31;
  --text: #e5e7eb;
  --muted: rgba(229, 231, 235, 0.7);
  --border: rgba(255, 255, 255, 0.12);
  --accent: #60a5fa;
  --accent2: #34d399;
  --error: #ef4444;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(1200px 600px at 50% 0%, #172554, var(--bg));
  color: var(--text);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(10px);
}

.topbar__title { font-weight: 700; letter-spacing: 0.2px; }
.topbar__actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

.layout {
  display: grid;
  grid-template-columns: 280px 1fr 280px;
  gap: 14px;
  padding: 14px;
  align-items: start;
}

.layout {
  min-height: 100vh;
}

.panel {
  background: linear-gradient(180deg, rgba(17, 27, 49, 0.85), rgba(11, 18, 32, 0.85));
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.panel__header {
  padding: 12px 12px 10px;
  border-bottom: 1px solid var(--border);
}

.panel__title { font-weight: 700; }
.panel__subtitle { font-size: 0.85rem; color: var(--muted); margin-top: 2px; }
.panel__content { padding: 10px; }

.panel--right {
  max-height: calc(100vh - 28px);
  display: flex;
  flex-direction: column;
}

.panel--right .panel__content {
  overflow: auto;
}

.btn--camera {
  margin-left: 10px;
  padding: 6px 10px;
  border-radius: 10px;
  font-size: 16px;
  line-height: 1;
}

.portraits-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.portraits-title-row__actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.thumb, .recent-card, .set-slot__apply {
  position: relative;
}

.trash-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(0,0,0,0.4);
  color: rgba(255,255,255,0.9);
  display: grid;
  place-items: center;
  cursor: pointer;
  z-index: 2;
}

.trash-btn:hover {
  border-color: rgba(96,165,250,0.7);
}

.thumb-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.thumb {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: rgba(255,255,255,0.03);
  cursor: pointer;
}

.thumb:hover { border-color: rgba(96, 165, 250, 0.6); }

.thumb__img {
  width: 100%;
  display: block;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background: rgba(255,255,255,0.04);
}

.thumb__label {
  padding: 8px 10px;
  font-size: 0.85rem;
  color: var(--text);
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.thumb__meta { color: var(--muted); font-size: 0.8rem; }

.stage {
  background: linear-gradient(180deg, rgba(17,27,49,0.6), rgba(11,18,32,0.6));
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.stage__toolbar {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.stage__canvasWrap {
  position: relative;
  display: grid;
  place-items: center;
  padding: 12px;
  flex: 0 0 auto;
}

.canvas-overlay {
  position: relative;
  display: inline-block;
  line-height: 0;
  overflow: hidden;
  border-radius: 12px;
}

#composeCanvas {
  touch-action: none;
}

#composeCanvas {
  width: 100%;
  height: auto;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(255,255,255,0.03);
  touch-action: none;
}

.stage__hint {
  position: absolute;
  bottom: 18px;
  left: 18px;
  right: 18px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(0,0,0,0.45);
  border: 1px solid rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.92);
  font-size: 0.9rem;
}

.brush-cursor {
  position: absolute;
  left: 0;
  top: 0;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  border: 2px solid rgba(255,255,255,0.9);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.45);
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 5;
}

.stage__footer {
  padding: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.stage__footerLeft {
  display: flex;
  align-items: center;
  gap: 10px;
}

.stage__footerRight {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.saved-row {
  border-top: 1px solid var(--border);
  padding: 10px 12px 12px;
}

.chk {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  user-select: none;
  font-weight: 700;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255,255,255,0.06);
  cursor: pointer;
}

.chk input { accent-color: var(--accent); }

.chk:hover { border-color: rgba(96, 165, 250, 0.7); }

.set-slot__controls {
  display: grid;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid rgba(255,255,255,0.1);
 }

 .set-slot__controls[hidden] {
  display: none;
 }

 .set-slot__controlsRow {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
 }

 .set-slot__actionsRow {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
 }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.06);
  color: var(--text);
  cursor: pointer;
  user-select: none;
  font-weight: 600;
}

.btn:hover { border-color: rgba(96, 165, 250, 0.7); }

.btn--primary {
  background: linear-gradient(180deg, rgba(96,165,250,0.35), rgba(96,165,250,0.18));
  border-color: rgba(96, 165, 250, 0.6);
}

.btn--secondary {
  background: rgba(52, 211, 153, 0.12);
  border-color: rgba(52, 211, 153, 0.35);
}

.btn--tool { padding: 8px 10px; font-weight: 700; }
.btn--mini { padding: 6px 8px; font-weight: 800; min-width: 34px; }
.btn--active { border-color: rgba(96,165,250,0.9); background: rgba(96,165,250,0.14); }

.btn--icon { padding: 8px 10px; }

.field {
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--muted);
  min-width: 140px;
}

.field input, .field select {
  width: 100%;
  accent-color: var(--accent);
}

.field input.value-input {
  width: 56px;
  text-align: center;
}

.spacer { flex: 1 1 auto; }

.muted { color: var(--muted); font-size: 0.85rem; margin-top: 8px; }

.control-row { margin-top: 10px; }

.set-slot {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: rgba(255,255,255,0.03);
}

.set-slot__header {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.set-slot__title { font-weight: 800; font-size: 0.9rem; }
.set-slot__meta { font-size: 0.8rem; color: var(--muted); }

.set-slot__body { padding: 10px; display: grid; gap: 8px; }

.set-slot__apply {
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 12px;
  overflow: hidden;
  cursor: grab;
  background: rgba(0,0,0,0.2);
}

.set-slot__apply:active { cursor: grabbing; }

.set-slot__apply img {
  width: 100%;
  display: block;
  aspect-ratio: 16 / 9;
  object-fit: cover;
}

.set-slot__apply[data-logo="1"] img {
  aspect-ratio: auto;
  object-fit: contain;
  background: transparent;
}

.set-slot__uploads {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.mini-upload {
  border: 1px dashed rgba(255,255,255,0.22);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  background: rgba(255,255,255,0.02);
}

.mini-upload:hover { border-color: rgba(96, 165, 250, 0.6); }

.mini-upload__img {
  width: 100%;
  display: block;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background: rgba(255,255,255,0.04);
}

.mini-upload__label {
  padding: 7px 9px;
  font-size: 0.82rem;
  color: var(--muted);
  border-top: 1px solid rgba(255,255,255,0.08);
}

.recent-row {
  margin: 0 14px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(17,27,49,0.55), rgba(11,18,32,0.55));
  overflow: hidden;
}

.recent-row__header {
  padding: 12px 12px 10px;
  border-bottom: 1px solid var(--border);
}

.recent-row__title { font-weight: 800; }
.recent-row__subtitle { margin-top: 2px; font-size: 0.85rem; color: var(--muted); }

.recent-row__list {
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.recent-card {
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  background: rgba(255,255,255,0.03);
}

.recent-card:hover { border-color: rgba(96, 165, 250, 0.6); }

.recent-card img {
  width: 100%;
  display: block;
  aspect-ratio: 1 / 1;
  object-fit: cover;
}

.thumb__badge {
  position: absolute;
  left: 10px;
  top: 10px;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.3px;
  color: rgba(255,255,255,0.95);
  border: 1px solid rgba(255,255,255,0.22);
  background: linear-gradient(180deg, rgba(96,165,250,0.55), rgba(96,165,250,0.22));
  box-shadow: 0 10px 22px rgba(0,0,0,0.28);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 3;
}

.thumb__badge--number {
  left: auto;
  top: auto;
  right: 10px;
  bottom: 10px;
  min-width: 52px;
  text-align: center;
  border-color: rgba(52,211,153,0.42);
  background: linear-gradient(180deg, rgba(52,211,153,0.42), rgba(52,211,153,0.18));
}

.thumb__badge--canvas {
  left: 10px;
  top: 10px;
  right: auto;
  bottom: auto;
  border-color: rgba(52, 211, 153, 0.45);
  background: linear-gradient(180deg, rgba(52,211,153,0.55), rgba(52,211,153,0.22));
}

.set-picker {
  margin-top: 10px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.set-picker__title { font-weight: 700; margin-bottom: 8px; }
.set-picker__zones { display: grid; gap: 10px; }

.drop-zone {
  border: 1px dashed rgba(255,255,255,0.25);
  border-radius: 10px;
  padding: 8px;
  background: rgba(255,255,255,0.03);
}

.drop-zone__title { font-size: 0.85rem; color: var(--muted); margin-bottom: 8px; }

.asset-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.asset {
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.12);
  cursor: pointer;
}

.asset:hover { border-color: rgba(96,165,250,0.7); }

.asset img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
}

.modal {
  border: none;
  padding: 0;
  width: min(680px, 96vw);
  border-radius: 14px;
  background: rgba(11,18,32,0.9);
  color: var(--text);
}

.modal::backdrop { background: rgba(0,0,0,0.6); }

.modal__content { padding: 0; margin: 0; }
.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.modal__title { font-weight: 800; }
.modal__body { padding: 12px 14px; display: grid; gap: 10px; }
.modal__footer { padding: 12px 14px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

.password-modal {
  width: min(400px, 90vw);
}

.password-modal .modal__body {
  text-align: center;
}

.password-modal input[type="password"] {
  width: 100%;
  padding: 8px 12px;
  margin-top: 8px;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 16px;
}

.password-modal input[type="password"]:focus {
  outline: none;
  border-color: var(--accent);
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .panel--right { order: 1; }
  .stage { order: 2; }
  .panel--left { order: 3; }

  .portraits-title-row {
    justify-content: center;
    flex-direction: column;
    gap: 10px;
  }

  .portraits-title-row__actions {
    justify-content: center;
  }

  .btn--camera {
    margin-left: 0;
    padding: 12px 18px;
    border-radius: 14px;
    font-size: 22px;
  }

  .portraits-refresh {
    display: none;
  }

  #composeCanvas { width: 100%; }

  .asset-grid { grid-template-columns: repeat(4, 1fr); }

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

@media (min-width: 981px) {
  .portraits-refresh {
    display: inline-flex;
    align-items: center;
    gap: 8px;
  }
}
