:root {
  --bg-dark: #111215;
  --bg-panel: #181a1f;
  --bg-card: #22252b;
  --bg-btn: #2d3139;
  --bg-btn-hover: #383d47;
  --border: #31353e;
  --text: #eef0f4;
  --text-muted: #9aa0ae;
  --accent: #00a8e8;
  --accent-hover: #14b8f5;
  --danger: #e5484d;
  --radius: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  width: 100%; height: 100%; overflow: hidden;
  background: var(--bg-dark); color: var(--text);
  font-family: 'Segoe UI', Inter, system-ui, -apple-system, sans-serif;
  font-size: 13px; user-select: none;
}

.hidden { display: none !important; }
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.accent { color: var(--accent); }

/* Buttons */
.btn {
  border: 1px solid var(--border); background: var(--bg-btn); color: var(--text);
  padding: 9px 16px; border-radius: 999px; cursor: pointer; font-weight: 600;
  font-size: 13px; transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--bg-btn-hover); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #05131a; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: #2a2e37; }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-block { width: 100%; }

.icon-btn {
  width: 30px; height: 30px; border-radius: 6px; border: none;
  background: transparent; color: var(--text-muted); cursor: pointer;
  display: grid; place-items: center; font-size: 15px;
}
.icon-btn:hover { background: var(--bg-btn); color: var(--text); }
.accent-btn { background: var(--accent); color: #05131a; font-weight: 700; }
.accent-btn:hover { background: var(--accent-hover); color: #05131a; }

/* Launcher */
.launcher {
  position: fixed; inset: 0; z-index: 40;
  background: radial-gradient(circle at 20% 20%, #172733 0%, var(--bg-dark) 60%);
  display: grid; place-items: center; padding: 24px;
}
.launcher-card {
  width: min(760px, 100%); background: var(--bg-panel);
  border: 1px solid var(--border); border-radius: 16px; padding: 28px;
  box-shadow: 0 24px 70px rgba(0,0,0,.55);
}
.launcher-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.brand-badge {
  width: 44px; height: 44px; border-radius: 12px; background: var(--accent);
  color: #04131c; font-weight: 800; font-size: 18px; display: grid; place-items: center;
}
.launcher-brand h1 { font-size: 22px; line-height: 1.2; }
.launcher-brand p { color: var(--text-muted); margin-top: 3px; font-size: 12.5px; }

.drop-zone {
  border: 2px dashed #3b4250; border-radius: 14px; padding: 34px 20px;
  text-align: center; background: rgba(255,255,255,.02); transition: .15s;
}
.drop-zone.dragover { border-color: var(--accent); background: rgba(0,168,232,.09); }
.drop-icon { font-size: 38px; margin-bottom: 10px; }
.drop-title { color: var(--text-muted); margin-bottom: 18px; }
.drop-title kbd {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 4px; padding: 1px 6px; color: var(--text);
}
.launcher-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }

.new-project-form { margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--border); }
.new-project-form h3 { margin-bottom: 12px; font-size: 15px; }
.preset-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.chip {
  background: var(--bg-card); border: 1px solid var(--border); color: var(--text-muted);
  padding: 6px 12px; border-radius: 999px; cursor: pointer; font-size: 12px;
}
.chip.active, .chip:hover { border-color: var(--accent); color: var(--text); }
.form-row { display: grid; grid-template-columns: 1.4fr .8fr .8fr 1.2fr; gap: 10px; align-items: end; }
.form-row label { display: flex; flex-direction: column; gap: 4px; color: var(--text-muted); font-size: 12px; }
.form-row input[type="text"], .form-row input[type="number"] {
  background: var(--bg-card); border: 1px solid var(--border); color: var(--text);
  padding: 7px 9px; border-radius: 6px;
}
.toggle-inline { flex-direction: row !important; align-items: center; gap: 8px !important; height: 34px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; }

/* Workspace 5-Region Grid */
.workspace {
  display: grid;
  grid-template-columns: 54px 276px minmax(0, 1fr) 118px;
  grid-template-rows: 1fr 46px;
  width: 100vw; height: 100vh;
}
.workspace.drawer-closed {
  grid-template-columns: 54px 0px minmax(0, 1fr) 118px;
}
@media (max-width: 1020px) {
  .workspace { grid-template-columns: 48px 236px minmax(0, 1fr) 104px; }
  .workspace.drawer-closed { grid-template-columns: 48px 0px minmax(0, 1fr) 104px; }
  .bottom-bar { padding: 0 8px; }
  .bar-btn, .bottom-bar .btn { padding: 5px 8px; font-size: 11px; white-space: nowrap; }
}
.workspace.drawer-closed .tool-drawer { overflow: hidden; border-right: none; }

/* 1. Left Tool Rail */
.tool-rail {
  grid-column: 1; grid-row: 1 / 3;
  background: var(--bg-panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center; padding: 8px 0; gap: 4px;
}
.rail-divider { width: 30px; height: 1px; background: var(--border); margin: 4px 0 6px; }
.rail-btn {
  width: 40px; height: 40px; border-radius: 8px; border: none;
  background: transparent; color: #b5bcc9; cursor: pointer;
  display: grid; place-items: center; position: relative; transition: .12s;
}
.rail-btn svg { width: 21px; height: 21px; fill: currentColor; }
.rail-btn:hover { background: var(--bg-card); color: #fff; }
.rail-btn.active { background: #262b33; color: #fff; }
.rail-btn.active::before {
  content: ""; position: absolute; left: -7px; top: 8px; bottom: 8px;
  width: 3px; border-radius: 0 3px 3px 0; background: var(--accent);
}

/* 2. Tool Drawer */
.tool-drawer {
  grid-column: 2; grid-row: 1 / 3;
  background: var(--bg-panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-width: 0;
}
.drawer-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px 10px;
}
.drawer-header h2 { font-size: 15px; font-weight: 600; flex: 1; text-align: center; padding-left: 24px; }
.drawer-hatch {
  height: 7px;
  background: repeating-linear-gradient(-45deg, transparent, transparent 4px, #2a2e36 4px, #2a2e36 5px);
  border-top: 1px solid #262a31; border-bottom: 1px solid #262a31;
}
.drawer-body { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.drawer-body::-webkit-scrollbar { width: 6px; }
.drawer-body::-webkit-scrollbar-thumb { background: #333843; border-radius: 99px; }
.drawer-footer { padding: 10px 12px; border-top: 1px solid var(--border); }

.panel-card {
  background: var(--bg-card); border: 1px solid #2b2f38;
  border-radius: 10px; padding: 12px;
}
.warn-card { border-color: #6b5220; background: #252018; }
.warn-card p { color: #f0d08a; margin-bottom: 10px; line-height: 1.4; }

.ai-cutout-btn {
  width: 100%; min-height: 40px; padding: 8px 12px; border-radius: 999px;
  border: 1px solid #4a505d; background: linear-gradient(180deg, #252931, #1c1f26);
  color: #fff; font-weight: 600; font-size: 12.5px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 6px; text-align: center;
  transition: border-color .15s, box-shadow .15s;
}
.ai-cutout-btn:hover { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(0,168,232,.2); }
.ai-cutout-btn:disabled { opacity: .65; cursor: wait; }

.ai-progress { margin-top: 8px; }
.ai-progress-bar { height: 6px; background: #2b303a; border-radius: 99px; overflow: hidden; }
.ai-progress-fill { height: 100%; width: 15%; background: var(--accent); transition: width .2s; }
.ai-progress small { display: block; margin-top: 4px; color: var(--text-muted); font-size: 11px; }

.field-label { font-size: 12.5px; color: #d5dae3; font-weight: 600; margin-bottom: 8px; }
.hint-text { font-size: 11.5px; color: var(--text-muted); line-height: 1.4; }

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

.seg-btn {
  height: 34px; border-radius: 6px; border: 1px solid transparent;
  background: var(--bg-btn); color: #d6dbe4; cursor: pointer;
  font-size: 11.5px; font-weight: 600; display: grid; place-items: center;
  transition: .12s;
}
.seg-btn svg { width: 17px; height: 17px; fill: currentColor; }
.seg-btn:hover { background: var(--bg-btn-hover); color: #fff; }
.seg-btn.active { background: var(--accent); color: #fff; }
.seg-btn.danger:hover { background: var(--danger); color: #fff; }

.pill-btn {
  width: 100%; min-height: 34px; padding: 6px 10px; border-radius: 999px;
  border: 1px solid #4a505d; background: transparent; color: var(--text);
  cursor: pointer; font-weight: 600; font-size: 12px; line-height: 1.25; transition: .12s;
}
.pill-btn:hover { border-color: var(--accent); color: #fff; background: rgba(0,168,232,.08); }
.pill-primary { border-color: var(--accent); background: rgba(0,168,232,.18); }

.slider-row { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
input[type="range"] { width: 100%; accent-color: var(--accent); cursor: pointer; }
.text-input {
  width: 100%; background: #16181d; border: 1px solid var(--border);
  color: var(--text); padding: 7px 9px; border-radius: 6px; font-family: inherit;
}
.num-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.num-grid label { display: flex; flex-direction: column; gap: 3px; font-size: 11.5px; color: var(--text-muted); }
.num-grid input {
  background: #16181d; border: 1px solid var(--border); color: var(--text);
  padding: 6px 8px; border-radius: 6px; width: 100%;
}

.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.switch { position: relative; width: 38px; height: 20px; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider-pill {
  position: absolute; inset: 0; background: #3b404c; border-radius: 99px;
  cursor: pointer; transition: .15s;
}
.slider-pill::before {
  content: ""; position: absolute; width: 14px; height: 14px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: .15s;
}
.switch input:checked + .slider-pill { background: var(--accent); }
.switch input:checked + .slider-pill::before { transform: translateX(18px); }

.brush-preview-row { display: flex; gap: 10px; align-items: center; }
#cutout-brush-preview {
  background: #14161a; border: 1px solid var(--border); border-radius: 8px; flex-shrink: 0;
}
.brush-sliders { flex: 1; }

.effect-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.effect-card {
  padding: 10px 6px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--bg-btn); color: var(--text); cursor: pointer; font-size: 12px;
}
.effect-card.active { border-color: var(--accent); background: rgba(0,168,232,.2); }

/* 3. Central Stage */
.stage-wrap {
  grid-column: 3; grid-row: 1;
  position: relative; overflow: hidden;
  background: #0d0e11;
  display: grid; place-items: center;
}
.canvas-stage {
  position: relative;
  box-shadow: 0 12px 48px rgba(0,0,0,.65);
  background-image:
    linear-gradient(45deg, #2a2d34 25%, transparent 25%),
    linear-gradient(-45deg, #2a2d34 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #2a2d34 75%),
    linear-gradient(-45deg, transparent 75%, #2a2d34 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-color: #1e2026;
  transform-origin: center center;
}
#main-canvas, #overlay-canvas { display: block; }
#overlay-canvas { position: absolute; inset: 0; pointer-events: auto; cursor: crosshair; }

.status-pill {
  position: absolute; left: 14px; bottom: 14px;
  background: rgba(20,22,27,.86); border: 1px solid var(--border);
  padding: 5px 10px; border-radius: 999px; font-size: 11.5px; color: var(--text-muted);
}
.ai-float-pill {
  position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%);
}
.ai-float-btn {
  background: linear-gradient(135deg, #1b2735, #171a22);
  border: 1px solid var(--accent); color: #fff; padding: 7px 16px;
  border-radius: 999px; cursor: pointer; font-weight: 600; font-size: 12px;
  box-shadow: 0 0 18px rgba(0,168,232,.3);
}
.ai-float-btn:hover { background: var(--accent); color: #04131c; }

.toast {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  background: #1d222b; border: 1px solid var(--accent); color: #fff;
  padding: 8px 16px; border-radius: 999px; font-size: 12.5px; z-index: 30;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
}

/* 4. Right Layers Strip */
.layerbar {
  grid-column: 4; grid-row: 1 / 3;
  background: var(--bg-panel); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; position: relative;
}
.layerbar-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 8px; border-bottom: 1px solid var(--border);
}
.layerbar-title { font-size: 11px; font-weight: 700; color: var(--text-muted); letter-spacing: .06em; }
.popover {
  position: absolute; top: 44px; right: 8px; width: 168px; z-index: 25;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px; box-shadow: 0 10px 30px rgba(0,0,0,.5);
  display: flex; flex-direction: column; gap: 4px;
}
.popover button {
  background: transparent; border: none; color: var(--text); text-align: left;
  padding: 7px 9px; border-radius: 6px; cursor: pointer; font-size: 12px;
}
.popover button:hover { background: var(--bg-btn); }

.layer-list { flex: 1; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 8px; }
.layer-item {
  border: 2px solid transparent; border-radius: 8px; background: var(--bg-card);
  padding: 5px; cursor: pointer; position: relative;
}
.layer-item.active { border-color: var(--accent); }
.layer-thumb {
  width: 100%; height: 52px; border-radius: 4px; display: block;
  background: repeating-conic-gradient(#2c3038 0% 25%, #1d2026 0% 50%) 50% / 10px 10px;
  object-fit: contain;
}
.layer-item-meta {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 4px; gap: 4px;
}
.layer-item-name {
  font-size: 11px; color: var(--text-muted); overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; flex: 1;
}
.layer-vis-btn {
  background: transparent; border: none; color: var(--text-muted); cursor: pointer; font-size: 12px;
}
.layer-item.hidden-layer { opacity: .45; }

.layer-controls { padding: 8px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 6px; }
.mini-select {
  width: 100%; background: var(--bg-card); border: 1px solid var(--border);
  color: var(--text); border-radius: 6px; padding: 4px; font-size: 11px;
}
.layer-mini-btns { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.layer-mini-btns button {
  background: var(--bg-btn); border: none; color: var(--text);
  border-radius: 5px; height: 26px; cursor: pointer; font-size: 12px;
}
.layer-mini-btns button:hover { background: var(--bg-btn-hover); }

.layerbar-bg { padding: 8px; border-top: 1px solid var(--border); }
.bg-trigger {
  display: flex; align-items: center; justify-content: space-between;
  gap: 4px; font-size: 11.5px; color: var(--text-muted); cursor: pointer;
}
.bg-trigger input[type="color"] { width: 22px; height: 22px; border: none; background: none; cursor: pointer; }

/* 5. Bottom Bar */
.bottom-bar {
  grid-column: 3; grid-row: 2;
  background: var(--bg-panel); border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 10px; gap: 6px; min-width: 0; overflow-x: auto;
}
.bottom-group { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.bar-btn {
  background: var(--bg-card); border: 1px solid var(--border); color: var(--text);
  padding: 5px 10px; border-radius: 6px; cursor: pointer; font-size: 12px; font-weight: 600;
}
.bar-btn:hover { background: var(--bg-btn-hover); }
.bar-btn:disabled { opacity: .4; cursor: not-allowed; }
.zoom-label { min-width: 44px; text-align: center; font-weight: 600; color: var(--text-muted); }

/* Save Modal */
.modal {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.72);
  display: grid; place-items: center; padding: 20px;
}
.modal-card {
  width: min(820px, 100%); background: var(--bg-panel);
  border: 1px solid var(--border); border-radius: 14px; overflow: hidden;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.save-body { display: grid; grid-template-columns: 1.15fr 1fr; gap: 18px; padding: 18px; }
.save-preview-pane {
  background: #101216; border: 1px solid var(--border); border-radius: 10px;
  padding: 14px; display: flex; flex-direction: column; align-items: center; justify-content: center;
}
#save-preview-canvas {
  max-width: 100%; max-height: 300px; border-radius: 6px;
  background: repeating-conic-gradient(#2c3038 0% 25%, #1d2026 0% 50%) 50% / 14px 14px;
}
.save-meta { margin-top: 10px; font-size: 12px; color: var(--text-muted); }
