/* ---- shadcn-inspired design tokens ---- */
:root {
  --background: #0b0b0f;
  --card: #16161c;
  --card-2: #1d1d25;
  --border: #2a2a33;
  --foreground: #e7e7ea;
  --muted: #9b9ba3;
  --muted-2: #6f6f78;
  --primary: #6366f1;
  --primary-hover: #5457e5;
  --primary-fg: #ffffff;
  --ring: #6366f1;
  --radius: 8px;
  --shadow: 0 10px 40px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }

html, body { height: 100%; }
body {
  margin: 0;
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--background);
  color: var(--foreground);
  display: flex;
  flex-direction: column;
  height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ---- surfaces ---- */
.panel {
  background: var(--card);
  border: 1px solid var(--border);
}
.card {
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}
.card + .card { margin-top: 12px; }
.card-title {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---- top bar ---- */
header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-left: 0; border-right: 0; border-top: 0;
}
.brand { flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-logo {
  display: inline-flex; align-items: center; gap: 9px;
  background: none; border: 0; padding: 4px 6px; margin: 0;
  color: inherit; cursor: pointer; border-radius: var(--radius);
  transition: background .12s;
}
.brand-logo:hover { background: var(--card-2); }
.brand-logo:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.logo-mark { width: 22px; height: 22px; flex: 0 0 auto; }
.wordmark { font-weight: 700; font-size: 15px; letter-spacing: .09em; }

/* ---- project menu ---- */
.project { position: relative; min-width: 0; }
.project-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; max-width: 260px; padding: 0 10px;
  font: inherit; color: var(--foreground);
  background: var(--card-2); border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer; transition: background .12s, border-color .12s;
}
.project-btn:hover { background: #262630; }
.project-btn:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.project-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted-2); flex: 0 0 auto; }
.project-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-sep { color: var(--muted-2); }
.project-status { color: var(--muted); white-space: nowrap; }
.project-caret { width: 14px; height: 14px; color: var(--muted); flex: 0 0 auto; }
/* unsaved accent */
.project-btn.is-dirty .project-dot { background: var(--primary); }
.project-btn.is-dirty .project-status { color: var(--foreground); }

.project-menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 30;
  min-width: 180px; padding: 4px;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 2px;
}
.project-menu.hidden { display: none; }
.project-menu-item {
  display: block; width: 100%; text-align: left;
  height: 32px; padding: 0 10px;
  font: inherit; color: var(--foreground);
  background: transparent; border: 0; border-radius: 6px; cursor: pointer;
  transition: background .12s;
}
.project-menu-item:hover { background: var(--card-2); }
.project-menu-item[disabled] { opacity: .45; cursor: not-allowed; }
.project-menu-item[disabled]:hover { background: transparent; }
.actions { flex: 1; display: flex; gap: 6px; align-items: center; justify-content: flex-end; }

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 12px;
  font: inherit; font-weight: 500;
  color: var(--foreground);
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .12s, border-color .12s, opacity .12s;
  white-space: nowrap;
}
.btn:hover { background: #262630; }
.btn:active { transform: translateY(.5px); }
.btn:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn--primary { background: var(--primary); border-color: var(--primary); color: var(--primary-fg); }
.btn--primary:hover { background: var(--primary-hover); }
.btn--ghost { background: transparent; border-color: transparent; }
.btn--ghost:hover { background: var(--card-2); }
.btn--icon { width: 32px; padding: 0; }
.btn--icon svg { width: 16px; height: 16px; }
.btn svg { width: 15px; height: 15px; flex: 0 0 auto; }

/* stepper (layer count) */
.stepper {
  display: inline-flex; align-items: center; gap: 2px;
  background: var(--card-2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 2px;
}
.stepper button {
  width: 26px; height: 26px; border: 0; border-radius: 6px;
  background: transparent; color: var(--foreground); cursor: pointer; font-size: 16px; line-height: 1;
}
.stepper button:hover { background: #2c2c36; }
.stepper .count { min-width: 24px; text-align: center; font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---- segmented control ---- */
.segmented {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--card-2); border: 1px solid var(--border); border-radius: var(--radius);
}
.segmented.full { display: flex; width: 100%; }
.segmented button {
  height: 26px; padding: 0 12px;
  border: 0; border-radius: 6px;
  background: transparent; color: var(--muted);
  font: inherit; font-weight: 500; cursor: pointer;
  transition: background .12s, color .12s;
  white-space: nowrap;
}
.segmented.full button { flex: 1; min-width: 0; padding: 0 8px; overflow: hidden; text-overflow: ellipsis; }
.segmented.vertical { flex-direction: column; }
.segmented.vertical button { flex: none; width: 100%; }
.segmented button:hover { color: var(--foreground); }
.segmented button.is-active { background: var(--primary); color: var(--primary-fg); }
.segmented button:focus-visible { outline: 2px solid var(--ring); outline-offset: 1px; }

/* ---- sliders ---- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field + .field { margin-top: 12px; }
.field-head { display: flex; justify-content: space-between; align-items: baseline; }
.field-head .label { color: var(--muted); font-size: 12px; }
.field-head .value { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 12px; }

.slider {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 4px; border-radius: 999px;
  background: var(--border); outline: none; cursor: pointer;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--foreground); border: 2px solid var(--primary);
  box-shadow: 0 1px 4px rgba(0,0,0,.5); cursor: pointer;
  transition: transform .1s;
}
.slider::-webkit-slider-thumb:hover { transform: scale(1.12); }
.slider::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--foreground); border: 2px solid var(--primary); cursor: pointer;
}
.slider:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px rgba(99,102,241,.35); }

/* ---- main layout ---- */
main { flex: 1; display: flex; min-height: 0; }
#stage {
  flex: 1; display: flex; align-items: center; justify-content: center;
  overflow: hidden; padding: 20px; position: relative;
}
.canvas-wrap { position: relative; display: flex; max-width: 100%; max-height: 100%; transform-origin: 0 0; }
#stage.pannable #cv { cursor: grab; }
#cv, #overlay {
  display: block; max-width: 100%; max-height: 100%;
  border-radius: var(--radius);
}
#cv { box-shadow: var(--shadow); }
#overlay { position: absolute; inset: 0; width: 100%; height: 100%; opacity: .55; pointer-events: none; }
#stage:not(.image) #overlay { display: none; }
#stage.image #cv { cursor: none; }
#stage.depth #cv { cursor: default; }
#stage.preview #cv { cursor: grab; }

/* brush-size cursor (edit mode) */
.brush-cursor {
  position: absolute; left: 0; top: 0; z-index: 5;
  border: 1.5px solid rgba(255,255,255,.92); border-radius: 50%;
  transform: translate(-50%, -50%); pointer-events: none;
  box-shadow: 0 0 0 1px rgba(0,0,0,.5);
}
.brush-cursor::after {
  content: ''; position: absolute; left: 50%; top: 50%;
  width: 2px; height: 2px; border-radius: 50%;
  background: rgba(255,255,255,.92); transform: translate(-50%, -50%);
}
.brush-cursor.erase { border-style: dashed; border-color: #ff6b6b; }
.brush-cursor.erase::after { background: #ff6b6b; }

/* ---- sidebars ---- */
aside { padding: 12px; overflow-y: auto; }
.side-left { width: 260px; flex: 0 0 260px; border-top: 0; border-bottom: 0; border-left: 0; }
.side-right { width: 280px; flex: 0 0 280px; border-top: 0; border-bottom: 0; border-right: 0; display: flex; flex-direction: column; }
.depth-card { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
#wizard { flex: 0 0 auto; }
.hidden { display: none !important; }

/* layer list */
.layers { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.layer-row {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 8px; border-radius: 6px; cursor: pointer;
  border: 1px solid transparent;
  transition: background .1s;
}
.layer-row:hover { background: var(--card); }
.layer-row.is-sel { background: var(--card); border-color: var(--primary); }
.layer-row .name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.layer-row .name.muted { color: var(--muted); }
.layer-name-input { flex: 1; min-width: 0; background: var(--background); border: 1px solid var(--primary); border-radius: 4px; color: var(--foreground); font: inherit; padding: 2px 6px; outline: none; }

.swatch {
  width: 16px; height: 16px; border-radius: 4px;
  display: inline-block; box-shadow: inset 0 0 0 1px rgba(0,0,0,.4);
}
.brush-target { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.brush-target .swatch { width: 18px; height: 18px; }

/* ---- depth map panel (right) ---- */
.hist-wrap { position: relative; flex: 1 1 auto; min-height: 140px; }
#hist { width: 100%; height: 100%; display: block; cursor: ns-resize; }
#histTip {
  position: absolute; top: 0; transform: translate(-100%, -50%);
  background: var(--primary); color: var(--primary-fg);
  font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums;
  padding: 2px 7px; border-radius: 6px; pointer-events: none;
  opacity: 0; transition: opacity .1s; white-space: nowrap;
}
#histTip.show { opacity: 1; }
.hint { margin: 10px 0 0; font-size: 12px; color: var(--muted-2); }
.depth-actions { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.depth-actions .btn { width: 100%; }

/* ---- onboarding wizard ---- */
.step { display: flex; align-items: flex-start; gap: 10px; padding: 8px; border-radius: 6px; cursor: pointer; border: 1px solid transparent; }
.step + .step { margin-top: 4px; }
.step:hover { background: var(--card); }
.step.is-active { border-color: var(--primary); background: var(--card); }
.step.is-done { opacity: .6; }
.step-badge { width: 20px; height: 20px; flex: 0 0 auto; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; background: var(--card-2); color: var(--muted); }
.step.is-active .step-badge { background: var(--primary); color: var(--primary-fg); }
.step.is-done .step-badge { background: #2e7d52; color: #fff; }
.step-title { font-size: 13px; font-weight: 500; }
.step-hint { font-size: 11px; color: var(--muted-2); margin-top: 1px; }

/* ---- upload modal ---- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, .6); display: flex; align-items: center; justify-content: center;
}
.modal {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px; width: 320px; max-width: 90vw;
  display: flex; flex-direction: column; gap: 12px; text-align: center; box-shadow: var(--shadow);
}
.modal h3 { margin: 0; font-size: 15px; }
.modal p { margin: 0; color: var(--muted); font-size: 13px; }
.modal-actions { display: flex; flex-direction: column; gap: 8px; }
.modal-actions .btn { width: 100%; }

/* ---- empty state ---- */
#stage.is-empty .canvas-wrap { display: none; }
#stage.is-empty #cv { box-shadow: none; }
#stage:not(.is-empty) #emptyState { display: none; }
.empty-state {
  position: absolute; inset: 20px; z-index: 4;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; border-radius: 14px;
}
.empty-inner {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px;
  width: min(440px, 80%); padding: 40px 28px;
  border: 1.5px dashed var(--border); border-radius: 16px;
  background:
    radial-gradient(120% 120% at 50% 0%, rgba(99,102,241,.06), transparent 60%),
    var(--card);
  transition: border-color .15s, background .15s, transform .15s;
}
.empty-state:hover .empty-inner { border-color: #3a3a47; transform: translateY(-1px); }
.empty-icon {
  width: 56px; height: 56px; margin-bottom: 8px;
  display: flex; align-items: center; justify-content: center;
  color: var(--primary); border-radius: 14px;
  background: rgba(99,102,241,.12); border: 1px solid rgba(99,102,241,.28);
}
.empty-icon svg { width: 28px; height: 28px; }
.empty-title { margin: 0; font-size: 16px; font-weight: 600; }
.empty-sub { margin: 0 0 8px; font-size: 13px; color: var(--muted); }
.empty-inner .btn { pointer-events: auto; }

/* ---- drag-over hint (covers stage in both empty + loaded states) ---- */
.drop-hint {
  position: absolute; inset: 12px; z-index: 20;
  display: none; align-items: center; justify-content: center;
  border-radius: 16px; pointer-events: none;
  background: rgba(99,102,241,.10);
  border: 2px dashed var(--primary);
  backdrop-filter: blur(1px);
}
#stage.is-dragover .drop-hint { display: flex; }
#stage.is-dragover.is-empty .empty-inner { border-color: var(--primary); }
.drop-hint-inner {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  color: var(--foreground); font-weight: 600; font-size: 14px;
}
.drop-hint-inner svg { width: 34px; height: 34px; color: var(--primary); }

/* ---- loading overlay ---- */
.loading {
  position: absolute; inset: 0; z-index: 30;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: rgba(11, 11, 15, .62); backdrop-filter: blur(2px);
}
.spinner {
  width: 38px; height: 38px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.14);
  border-top-color: var(--primary);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-label { font-size: 13px; color: var(--foreground); font-weight: 500; }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 1.6s; } }

/* ---- toast ---- */
#toast {
  position: fixed; bottom: 168px; left: 50%; transform: translateX(-50%);
  background: var(--card-2); border: 1px solid var(--border);
  padding: 9px 16px; border-radius: 999px; font-size: 12px;
  box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }
