@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

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

:root {
  --bg:           #FAFAF9;
  --panel-bg:     #FFFFFF;
  --border:       #F0EDE8;
  --border-med:   #E8E3DC;
  --ink:          #111827;
  --ink-2:        #374151;
  --muted:        #6B7280;
  --muted-light:  #9CA3AF;
  --orange-50:    #FFF7F0;
  --orange-100:   #FFEAD8;
  --orange-400:   #FF9F5A;
  --orange-500:   #FF8C42;
  --orange-600:   #FF7A29;
  --orange-700:   #E86A18;
  --blue:         #0064FF;
  --red:          #DC2626;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-weight: 400;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

.app { display: flex; height: 100vh; overflow: hidden; }

/* ══════════ LEFT PANEL ══════════ */
.left-panel {
  width: 302px;
  min-width: 302px;
  height: 100vh;
  background: var(--panel-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 1px 0 8px rgba(0,0,0,0.04);
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 11px;
}

/* ── Upload Zone ── */
.upload-zone {
  width: 100%;
  height: 134px;
  border: 1.5px dashed #E8C9A8;
  border-radius: 12px;
  position: relative;
  cursor: pointer;
  overflow: hidden;
  background: var(--orange-50);
  transition: border-color 0.2s, background 0.2s;
  flex-shrink: 0;
}
.upload-zone:hover    { border-color: var(--orange-500); background: #FFF3E8; }
.upload-zone.dragging { border-color: var(--orange-500); background: #FFF3E8; }

.upload-inner {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 6px; pointer-events: none;
}
.upload-inner.hidden { display: none; }

.upload-icon { width: 24px; height: 24px; color: var(--orange-500); }
.upload-hint { font-size: 0.72rem; font-weight: 600; color: var(--ink-2); }
.upload-sub  { font-size: 0.6rem; color: var(--muted); }

.upload-preview {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: contain; display: none;
  background: var(--panel-bg);
  border-radius: 10px;
}
.upload-preview.visible { display: block; }
#fileInput { display: none; }

/* ── Mode Selector ── */
.mode-selector {
  display: flex;
  gap: 7px;
  flex-shrink: 0;
}

.mode-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  padding: 9px 10px;
  background: var(--panel-bg);
  border: 1.5px solid var(--border-med);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s;
  text-align: left;
  font-family: 'Inter', sans-serif;
}
.mode-btn:hover {
  border-color: var(--orange-400);
  background: var(--orange-50);
}
.mode-btn.active {
  border-color: var(--orange-500);
  background: linear-gradient(135deg, var(--orange-50), #FFF3E8);
  box-shadow: 0 0 0 1px var(--orange-200, #FFD4B0);
}

.mode-title {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--ink-2);
  line-height: 1.2;
  pointer-events: none;
}
.mode-btn.active .mode-title { color: var(--orange-700); }

.mode-sub {
  font-size: 0.56rem;
  font-weight: 400;
  color: var(--muted);
  line-height: 1.4;
  pointer-events: none;
}
.mode-btn.active .mode-sub { color: var(--orange-600); opacity: 0.8; }

/* ── Divider ── */
.lp-divider { height: 1px; background: var(--border); flex-shrink: 0; }

/* ── Buttons ── */
.btn {
  width: 100%;
  padding: 9px 14px;
  font-family: 'Inter', sans-serif;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  border-radius: 10px;
  transition: all 0.2s;
  outline: none;
  text-align: center;
  border: none;
  flex-shrink: 0;
}

.btn-dark {
  background: linear-gradient(to right, var(--orange-400), var(--orange-600));
  color: #fff;
  box-shadow: 0 2px 8px rgba(255,140,66,0.30);
}
.btn-dark:hover {
  background: linear-gradient(to right, var(--orange-500), var(--orange-700));
  box-shadow: 0 3px 12px rgba(255,140,66,0.40);
  transform: translateY(-1px);
}
.btn-dark:active { transform: translateY(0); }
.btn-dark:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
  box-shadow: none;
  transform: none;
}

.btn-ghost {
  background: var(--orange-50);
  color: var(--orange-600);
  border: 1px solid var(--orange-100);
  font-weight: 500;
}
.btn-ghost:hover {
  background: var(--orange-100);
  border-color: #F5C9A0;
  color: var(--orange-700);
}

/* ── Status ── */
.status-section {
  display: flex; flex-direction: column;
  align-items: center; gap: 9px; padding: 4px 0;
  flex-shrink: 0;
}
.status-section.hidden { display: none; }

.spinner {
  width: 22px; height: 22px;
  border: 2.5px solid var(--orange-100);
  border-top-color: var(--orange-500);
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
  flex-shrink: 0;
}
.spinner-sm { width: 12px; height: 12px; border-width: 1.5px; }

.status-text {
  font-size: 0.65rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.65;
}
.status-text strong { color: var(--orange-600); font-weight: 600; }

/* ── Tools ── */
.tools-section { display: flex; flex-direction: column; gap: 11px; }
.tools-section.hidden { display: none; }

.section-label {
  font-size: 0.59rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}

.mask-ready-msg {
  font-size: 0.65rem;
  line-height: 1.65;
  color: var(--ink-2);
  background: linear-gradient(135deg, var(--orange-50), #FFF8F0);
  border: 1px solid var(--orange-100);
  border-radius: 10px;
  padding: 9px 11px;
}

.pan-hint {
  display: flex; align-items: flex-start; gap: 5px;
  font-size: 0.62rem; color: var(--muted-light); line-height: 1.55;
}
.pan-hint svg { flex-shrink: 0; opacity: 0.4; margin-top: 1px; }
kbd {
  display: inline-block;
  padding: 0 5px;
  font-family: inherit;
  font-size: 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border-med);
  border-radius: 4px;
  color: var(--ink-2);
  line-height: 1.7;
}

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

.field-label {
  font-size: 0.59rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}
.field-row { display: flex; justify-content: space-between; align-items: center; }
.field-val {
  font-size: 0.65rem;
  color: var(--orange-600);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ── Tool Buttons ── */
.tool-btn-row { display: flex; gap: 6px; }

.tool-btn {
  flex: 1;
  display: flex; align-items: center; justify-content: center; gap: 5px;
  padding: 7px 8px;
  background: var(--panel-bg);
  border-radius: 8px;
  font-family: 'Inter', sans-serif;
  font-size: 0.62rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.tool-btn svg { flex-shrink: 0; width: 13px; height: 13px; }

.tool-add { border: 1.5px solid var(--blue); color: var(--blue); }
.tool-add:hover  { background: rgba(0,100,255,0.06); }
.tool-add.active { background: var(--blue); color: #fff; border-color: var(--blue); }

.tool-remove { border: 1.5px solid var(--red); color: var(--red); }
.tool-remove:hover  { background: rgba(220,38,38,0.06); }
.tool-remove.active { background: var(--red); color: #fff; border-color: var(--red); }

.tool-neutral { border: 1.5px solid var(--border-med); color: var(--muted); }
.tool-neutral:hover { border-color: var(--orange-400); color: var(--orange-600); background: var(--orange-50); }
.tool-neutral:disabled { opacity: 0.3; cursor: not-allowed; pointer-events: none; }

/* ── Sliders ── */
.slider { width: 100%; height: 3px; accent-color: var(--orange-500); cursor: pointer; display: block; }

/* ── PSD Status ── */
.psd-status { display: flex; align-items: center; gap: 7px; padding: 3px 0; flex-shrink: 0; }
.psd-status.hidden { display: none; }
#psdStatusText { font-size: 0.6rem; color: var(--muted); }

/* ── Error ── */
.error-box {
  padding: 9px 11px;
  border: 1px solid rgba(220,38,38,0.2);
  background: rgba(220,38,38,0.04);
  border-radius: 10px;
  flex-shrink: 0;
}
.error-box.hidden { display: none; }
.error-box p { font-size: 0.65rem; line-height: 1.65; color: var(--red); }

/* ══════════ RIGHT PANEL ══════════ */
.right-panel {
  flex: 1; height: 100vh;
  background: var(--bg);
  display: flex; align-items: stretch;
  overflow: hidden; position: relative;
}

.placeholder {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 12px; pointer-events: none;
  background: linear-gradient(135deg, #FFF7F0, #FFFBF0, #FFF8F0);
}
.placeholder.hidden { display: none; }
.placeholder-icon { width: 46px; height: 46px; color: #E8C4A0; }
.placeholder p {
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #C8A882;
}

.canvas-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.canvas-area.hidden { display: none; }

.canvas-wrapper {
  flex: 1; position: relative; overflow: hidden; background: #F0EBE3;
}
.canvas-wrapper.editing { cursor: none; }
.canvas-wrapper.panning { cursor: grabbing !important; }

.canvas-inner {
  position: absolute; transform-origin: 0 0; line-height: 0;
  box-shadow: 0 8px 32px rgba(0,0,0,0.12);
  border-radius: 2px;
}
#bgCanvas   { display: block; }
#maskCanvas { position: absolute; top: 0; left: 0; display: block; }

/* ── Brush Cursor ── */
.brush-cursor {
  position: fixed; border-radius: 50%;
  pointer-events: none; transform: translate(-50%, -50%);
  display: none; z-index: 9999;
  border: 1.5px solid rgba(0,100,255,0.85);
}
.brush-cursor.mode-remove { border-color: rgba(220,38,38,0.85); }
.brush-cursor::after {
  content: ''; position: absolute; top: 50%; left: 50%;
  width: 3px; height: 3px; background: rgba(0,100,255,0.85);
  border-radius: 50%; transform: translate(-50%, -50%);
}
.brush-cursor.mode-remove::after { background: rgba(220,38,38,0.85); }

/* ── Crown badge & locked state ── */
.crown-badge {
  display: none;
  position: absolute;
  top: 6px;
  right: 7px;
  color: var(--orange-500);
  line-height: 0;
}

.mode-btn { position: relative; }

.mode-btn.locked {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: auto; /* keep hover active for tooltip */
}
.mode-btn.locked .crown-badge { display: block; }
.mode-btn.locked:hover {
  border-color: var(--border-med);
  background: var(--panel-bg);
}

/* ── AI Tips ── */
.ai-tips {
  background: linear-gradient(135deg, var(--orange-50), #FFF8F0);
  border: 1px solid var(--orange-100);
  border-radius: 10px;
  padding: 10px 12px;
  flex-shrink: 0;
}
.ai-tips.hidden { display: none; }

.ai-tips-title {
  font-size: 0.59rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--orange-700);
  margin-bottom: 6px;
}

.ai-tips-list {
  list-style: disc;
  padding-left: 13px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.ai-tips-list li {
  font-size: 0.62rem;
  line-height: 1.6;
  color: var(--ink-2);
}

/* ── Creations counter ── */
.creations-counter {
  font-size: 0.62rem;
  color: var(--muted);
  text-align: center;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.creations-counter.hidden { display: none; }

/* ── Scrollbar ── */
.panel-body::-webkit-scrollbar { width: 3px; }
.panel-body::-webkit-scrollbar-track { background: transparent; }
.panel-body::-webkit-scrollbar-thumb { background: var(--border-med); border-radius: 2px; }

/* ── Animations ── */
@keyframes spin { to { transform: rotate(360deg); } }
/* ── Init loading overlay ── */
.init-overlay {
  position: fixed;
  inset: 0;
  background: #FAFAF9;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
.spinner-init {
  width: 36px;
  height: 36px;
  border-width: 3px;
}