:root {
  --bg: #111010;
  --panel: #181717;
  --panel-elev: #211f1f;
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.22);
  --text: #f5f3f1;
  --muted: #9a9490;
  --accent: #e8ded6;
  --accent-strong: #ffffff;
  --accent-ink: #121111;
  --danger: #f87171;
  --radius: 14px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px;
  border-bottom: 1px solid var(--border);
  background: rgba(17, 16, 16, 0.9);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-logo {
  height: 36px;
  width: auto;
  display: block;
  object-fit: contain;
}

.brand h1 {
  font-family: "Cormorant Garamond", serif;
  font-size: 1.55rem;
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: 0.02em;
  color: var(--text);
}

.brand h1 em {
  font-style: italic;
  font-weight: 500;
  color: var(--muted);
}

.brand span {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin-top: 2px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.status-pill {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
  border: 1px solid var(--border);
}

.status-pill.ok {
  background: rgba(74, 222, 128, 0.1);
  color: #86efac;
  border-color: rgba(74, 222, 128, 0.25);
}

.layout {
  display: grid;
  grid-template-columns: 444px 1fr;
  gap: 24px;
  max-width: 1460px;
  margin: 0 auto;
  padding: 24px 32px 48px;
}

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

.controls-panel {
  display: flex;
  flex-direction: column;
  gap: 22px;
  height: fit-content;
}

.step-block {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.step-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.step-num {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  font-size: 0.82rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.step-header h2 {
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--text);
}

.step-header p {
  font-size: 0.79rem;
  color: var(--muted);
  margin-top: 2px;
}

.dropzone {
  position: relative;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--panel-elev);
  min-height: 168px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  overflow: hidden;
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.04);
}

.dropzone-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
  padding: 24px;
}

.upload-icon {
  font-size: 1.7rem;
}

.dropzone-empty strong {
  font-size: 0.9rem;
  color: var(--text);
}

.dropzone-empty span {
  font-size: 0.78rem;
  color: var(--muted);
}

.dropzone-preview {
  position: relative;
  width: 100%;
  height: 220px;
}

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

.dropzone-preview .icon-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(17, 16, 16, 0.82);
  color: var(--text);
}

.scenario-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  border-radius: 12px;
  background: var(--panel-elev);
  border: 1px solid var(--border);
}

.scenario-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 12px;
  border-radius: 9px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s, color 0.18s;
}

.scenario-tab:hover {
  color: var(--text);
}

.scenario-tab.active {
  background: var(--accent);
  color: var(--accent-ink);
}

.tab-count {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: inherit;
}

.scenario-tab.active .tab-count {
  background: rgba(18, 17, 17, 0.14);
}

.scenario-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  max-height: 360px;
  overflow-y: auto;
  padding-right: 4px;
}

.scenario-grid::-webkit-scrollbar {
  width: 6px;
}

.scenario-grid::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 999px;
}

.scenario-card {
  position: relative;
  border-radius: 13px;
  border: 1.5px solid var(--border);
  background: var(--panel-elev);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.2s, box-shadow 0.2s;
  text-align: left;
  color: var(--text);
}

.scenario-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-strong);
}

.scenario-card.selected {
  border-color: var(--accent-strong);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.18);
}

.scenario-thumb {
  height: 70px;
  width: 100%;
  position: relative;
  background-size: cover;
  background-position: center;
}

.scenario-card.has-photo .scenario-thumb {
  height: 112px;
}

.scenario-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  font-size: 0.64rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(17, 16, 16, 0.72);
  color: #f5f3f1;
  backdrop-filter: blur(6px);
}

.scenario-delete {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: rgba(17, 16, 16, 0.78);
  color: #fff;
  font-size: 0.68rem;
  cursor: pointer;
}

.scenario-delete:hover {
  background: var(--danger);
}

.scenario-info {
  padding: 9px 10px 10px;
}

.scenario-info strong {
  display: block;
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 3px;
}

.scenario-info span {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.35;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

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

.field-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: #d7d2ce;
}

.field-hint {
  font-size: 0.73rem;
  color: var(--muted);
  line-height: 1.35;
}

.ratio-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pill {
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel-elev);
  color: var(--muted);
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.pill:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.pill.active {
  border-color: var(--accent);
  color: var(--accent-ink);
  background: var(--accent);
}

.select-input,
.text-input,
.file-input {
  width: 100%;
  background: var(--panel-elev);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 10px 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.15s;
}

.select-input:focus,
.text-input:focus {
  border-color: var(--accent);
}

.pro-pose-toggle {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 12px 13px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel-elev);
  cursor: pointer;
  transition: border-color 0.18s, background 0.18s;
}

.pro-pose-toggle:hover {
  border-color: var(--border-strong);
}

.pro-pose-toggle:has(input:checked) {
  border-color: var(--accent);
  background: rgba(232, 222, 214, 0.08);
}

.pro-pose-toggle input[type="checkbox"] {
  width: 17px;
  height: 17px;
  margin-top: 2px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.pro-pose-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.pro-pose-text strong {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text);
}

.pro-pose-text span {
  font-size: 0.73rem;
  color: var(--muted);
  line-height: 1.38;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 11px;
  border: none;
  font-family: inherit;
  font-size: 0.87rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.15s, opacity 0.2s, background 0.2s, border-color 0.2s;
}

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

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-strong);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--panel-elev);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  border-color: var(--border-strong);
  background: #292727;
}

.btn-generate {
  width: 100%;
  padding: 14px;
  font-size: 0.94rem;
}

.icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--panel-elev);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover {
  border-color: var(--border-strong);
}

.error-box {
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.3);
  color: #fca5a5;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.8rem;
  line-height: 1.4;
}

/* Right stage */
.stage-panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.stage-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.stage-header h2 {
  font-family: "Cormorant Garamond", serif;
  font-size: 1.55rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.1;
}

.stage-header p {
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 3px;
}

.stage-frame {
  min-height: 540px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: #131212;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  position: relative;
  overflow: hidden;
}

.stage-placeholder,
.stage-loading {
  text-align: center;
  max-width: 350px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.sparkle {
  font-size: 1.9rem;
  color: var(--accent);
}

.stage-placeholder h3,
.stage-loading h3 {
  font-size: 1.05rem;
  color: var(--text);
}

.stage-placeholder p,
.stage-loading p {
  font-size: 0.84rem;
  color: var(--muted);
  line-height: 1.5;
}

.spinner {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.14);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

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

.result-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.result-img {
  max-width: 100%;
  max-height: 620px;
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55);
  object-fit: contain;
  cursor: zoom-in;
  transition: transform 0.18s, box-shadow 0.18s;
}

.result-img:hover {
  box-shadow: 0 22px 54px rgba(255, 255, 255, 0.08);
}

.history-section {
  border-top: 1px solid var(--border);
  padding-top: 18px;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.history-header h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

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

.history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 10px;
}

.history-item {
  border-radius: 11px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--panel-elev);
  cursor: pointer;
  aspect-ratio: 4 / 5;
  position: relative;
  transition: transform 0.15s, border-color 0.15s;
}

.history-item:hover {
  transform: translateY(-2px);
  border-color: var(--border-strong);
}

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

.history-item span {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 5px 6px;
  font-size: 0.66rem;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.85));
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-loader {
  text-align: center;
  padding: 16px 8px 6px;
  font-size: 0.8rem;
  color: var(--muted);
}

.history-sentinel {
  width: 100%;
  height: 16px;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.74);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}

.modal-card {
  width: 100%;
  max-width: 500px;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  padding: 22px;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.modal-header h3 {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text);
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 6px;
}

/* Crop & Zoom Modal */
.crop-modal-card {
  max-width: 620px;
}

.crop-stage-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0e0d0d;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 14px;
  min-height: 360px;
}

.crop-viewport {
  position: relative;
  overflow: hidden;
  border-radius: 10px;
  border: 2px solid var(--accent);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.6);
  cursor: grab;
  touch-action: none;
  user-select: none;
  background: #141212;
}

.crop-viewport.dragging {
  cursor: grabbing;
}

.crop-viewport img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform-origin: center center;
  pointer-events: none;
  user-select: none;
}

.crop-grid {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(to right, rgba(255, 255, 255, 0.18) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.18) 1px, transparent 1px);
  background-size: 33.333% 33.333%;
  background-position: -1px -1px;
}

.crop-controls {
  margin-bottom: 14px;
}

.crop-zoom-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.crop-zoom-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  cursor: pointer;
}

.hidden {
  display: none !important;
}

@media (max-width: 980px) {
  .topbar {
    padding: 14px 18px;
  }

  .layout {
    grid-template-columns: 1fr;
    padding: 16px;
  }
}
