/* BoothCraft Studio */
:root {
  --bg: #0b0d11;
  --bg-2: #11141a;
  --bg-3: #171b23;
  --line: #242a35;
  --line-soft: #1c212a;
  --ink: #eef1f6;
  --ink-2: #a8b1c0;
  --ink-3: #6f7889;
  --gold: #e2b65c;
  --gold-soft: rgba(226, 182, 92, 0.14);
  --violet: #8b7bf0;
  --ok: #4ec98b;
  --warn: #e8795a;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
  --topbar-h: 56px;
  --aibar-h: 92px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 400 14px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body { display: flex; flex-direction: column; }

h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
.hidden { display: none !important; }
.muted { color: var(--ink-2); }
.small { font-size: 12px; line-height: 1.45; }

/* ---------------------------------------------------------------- boot */
.boot {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  background: radial-gradient(1200px 600px at 50% -10%, #1b2030, var(--bg));
}
.boot-card {
  width: min(380px, 90vw);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--bg-2);
  box-shadow: var(--shadow);
  text-align: center;
}
.boot-card p { color: var(--ink-2); }
.brand-lg { justify-content: center; font-size: 20px; margin-bottom: 14px; }

/* -------------------------------------------------------------- topbar */
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  height: var(--topbar-h);
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
  flex: 0 0 auto;
}
.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
}
.brand em { color: var(--gold); font-style: normal; font-weight: 500; }
.brand-mark {
  width: 18px;
  height: 22px;
  border-radius: 4px;
  background: linear-gradient(170deg, var(--gold) 0 62%, #f2f4f8 62% 100%);
  display: inline-block;
}
.name-input {
  flex: 1;
  min-width: 80px;
  max-width: 420px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
  padding: 7px 10px;
}
.name-input:hover { border-color: var(--line); }
.name-input:focus { outline: none; border-color: var(--gold); background: var(--bg-3); }
.topbar-actions { display: flex; gap: 8px; margin-left: auto; }

/* -------------------------------------------------------------- buttons */
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg-3);
  color: var(--ink);
  padding: 8px 13px;
  border-radius: var(--radius);
  font: 500 13px/1.1 inherit;
  cursor: pointer;
  transition: border-color 0.14s, background 0.14s, transform 0.08s;
  white-space: nowrap;
}
.btn:hover { border-color: #39414f; }
.btn:active { transform: translateY(1px); }
.btn small { display: block; font-size: 10px; font-weight: 400; opacity: 0.75; margin-top: 2px; }
.btn-primary { background: var(--gold); border-color: var(--gold); color: #1a1405; font-weight: 600; }
.btn-primary:hover { background: #eec475; border-color: #eec475; }
.btn-ghost { background: transparent; }
.btn-ai { background: linear-gradient(135deg, rgba(139, 123, 240, 0.22), rgba(226, 182, 92, 0.16)); border-color: #3b3560; }
.btn-ai:hover { border-color: var(--violet); }
.btn-icon { padding: 7px 10px; min-width: 34px; }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-block { display: block; width: 100%; margin-top: 8px; }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.btn-danger { color: var(--warn); border-color: rgba(232, 121, 90, 0.35); }

/* --------------------------------------------------------------- ai bar */
.aibar {
  flex: 0 0 auto;
  padding: 12px 16px 10px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #141822, var(--bg-2));
}
.aibar-main { display: flex; gap: 8px; align-items: center; min-width: 0; }
.cmd-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  padding: 11px 13px;
  font-size: 13.5px;
  min-width: 0;
}
.cmd-input:focus { outline: none; border-color: var(--violet); box-shadow: 0 0 0 3px rgba(139, 123, 240, 0.12); }
.mic {
  position: relative;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--bg-3);
  color: var(--ink);
  font-size: 16px;
  cursor: pointer;
}
.mic:hover { border-color: var(--violet); }
.mic.live { border-color: var(--warn); background: rgba(232, 121, 90, 0.18); }
.mic.live .mic-dot {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid rgba(232, 121, 90, 0.5);
  animation: pulse 1.3s ease-out infinite;
}
@keyframes pulse { 0% { transform: scale(0.9); opacity: 0.9; } 100% { transform: scale(1.3); opacity: 0; } }
.aibar-foot { display: flex; gap: 12px; align-items: center; margin-top: 8px; }

/* chat composer: text area, attachment chip, send, intent */
.aibar { position: relative; }
.aibar.drop { box-shadow: inset 0 0 0 2px var(--violet); }
.composer { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
textarea.cmd-input {
  display: block;
  width: 100%;
  resize: none;
  line-height: 1.4;
  max-height: 150px;
  overflow-y: auto;
  font-family: inherit;
}
.attach-btn.on { border-color: var(--violet); color: var(--violet); }
.chat-toggle { position: relative; }
.chat-count {
  position: absolute;
  top: -5px;
  right: -5px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--gold);
  color: #1a1405;
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
}
.aibar-main .select.intent { width: 124px; flex: 0 0 auto; }
.aibar-main .select.provider { width: 150px; flex: 0 0 auto; }
#btnSend { flex: 0 0 auto; min-width: 72px; }
#btnSend:disabled { opacity: 0.6; cursor: wait; }
.attach-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  width: max-content;
  max-width: 100%;
  padding: 3px 8px 3px 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-3);
  font-size: 12px;
  color: var(--ink-2);
}
.attach-chip img { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; }
.attach-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.swatches { display: flex; gap: 3px; }
.swatch { width: 12px; height: 12px; border-radius: 50%; border: 1px solid rgba(255, 255, 255, 0.18); }
.attach-x {
  border: none;
  background: none;
  color: var(--ink-3);
  cursor: pointer;
  font-size: 12px;
  padding: 0 2px;
}
.attach-x:hover { color: var(--warn); }

/* floating conversation panel, drops below the bar without moving the workspace */
.chat-panel {
  position: absolute;
  left: 16px;
  right: 16px;
  top: calc(100% + 6px);
  z-index: 40;
  display: flex;
  flex-direction: column;
  max-height: min(56vh, 520px);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.chat-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 12px 9px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-3);
}
.chat-head-actions { display: flex; gap: 6px; align-items: center; }
.chat-log {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chat-empty { color: var(--ink-3); font-size: 13px; margin: 4px 0; line-height: 1.5; }
.msg {
  max-width: 82%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 9px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-3);
  font-size: 13px;
  line-height: 1.45;
}
.msg-user { align-self: flex-end; background: rgba(139, 123, 240, 0.16); border-color: #3b3560; }
.msg-assistant { align-self: flex-start; }
.msg-text { white-space: pre-wrap; word-break: break-word; }
.msg-note { font-size: 11px; color: var(--gold); }
.msg-thumb { width: 96px; height: 96px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }

.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; flex: 1; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  border: 1px solid var(--line-soft);
  background: var(--bg);
  color: var(--ink-2);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 11.5px;
  cursor: pointer;
}
.chip:hover { color: var(--ink); border-color: var(--gold); }
.ai-status { font-size: 11.5px; color: var(--ink-3); white-space: nowrap; }
.ai-status.busy { color: var(--violet); }
.ai-status.err { color: var(--warn); }

/* ------------------------------------------------------------ workspace */
.workspace {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 268px minmax(0, 1fr) 284px;
}
.panel {
  background: var(--bg-2);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 0 0 40px;
}
.panel-right { border-right: none; border-left: 1px solid var(--line); padding: 16px 14px 60px; }
.panel::-webkit-scrollbar { width: 10px; }
.panel::-webkit-scrollbar-thumb { background: #262c38; border-radius: 8px; border: 3px solid var(--bg-2); }

.tabs { display: flex; position: sticky; top: 0; background: var(--bg-2); border-bottom: 1px solid var(--line); z-index: 2; }
.tab {
  flex: 1;
  padding: 11px 6px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--ink-3);
  font: 500 12.5px inherit;
  cursor: pointer;
}
.tab.active { color: var(--ink); border-bottom-color: var(--gold); }

.group { padding: 14px; border-bottom: 1px solid var(--line-soft); }
.group h3 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.09em; color: var(--ink-3); margin-bottom: 10px; }

.field { display: block; margin-bottom: 9px; }
.field > span { display: block; font-size: 11.5px; color: var(--ink-2); margin-bottom: 4px; }
.field.row { display: flex; align-items: center; gap: 8px; }
.field.row > span { flex: 0 0 82px; margin: 0; }
.field.row > input, .field.row > select { flex: 1; min-width: 0; }
input[type="text"], input[type="number"], input[type="password"], textarea, .select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  padding: 8px 9px;
  font: 400 13px inherit;
}
textarea { resize: vertical; }
input:focus, textarea:focus, .select:focus { outline: none; border-color: var(--gold); }
.select-sm { padding: 6px 7px; font-size: 12px; }
input[type="color"] {
  width: 100%;
  height: 30px;
  padding: 2px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 7px;
  cursor: pointer;
}
input[type="range"] { accent-color: var(--gold); height: 22px; }
input[type="checkbox"] { accent-color: var(--gold); width: 15px; height: 15px; }

.pill-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.pill {
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink-2);
  border-radius: 8px;
  padding: 7px 8px;
  font-size: 11.5px;
  cursor: pointer;
  text-align: left;
}
.pill:hover { border-color: #3a4250; color: var(--ink); }
.pill.active { border-color: var(--gold); background: var(--gold-soft); color: var(--ink); }

.layout-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 10px; }
.layout-btn {
  aspect-ratio: 3 / 4;
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 7px;
  cursor: pointer;
  padding: 4px;
  display: grid;
  gap: 2px;
}
.layout-btn:hover { border-color: #3a4250; }
.layout-btn.active { border-color: var(--gold); background: var(--gold-soft); }
.layout-btn i { background: #3c4553; border-radius: 2px; display: block; }
.layout-btn.active i { background: var(--gold); }

.palette-row { display: flex; gap: 6px; }
.palette-row input[type="color"] { flex: 1; height: 34px; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg-btn {
  flex: 1;
  padding: 7px 8px;
  background: var(--bg);
  border: none;
  border-right: 1px solid var(--line);
  color: var(--ink-3);
  font: 500 12px inherit;
  cursor: pointer;
}
.seg-btn:last-child { border-right: none; }
.seg-btn.active { background: var(--gold-soft); color: var(--ink); }

.sticker-row { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 9px; }
.sticker {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 8px;
  font-size: 17px;
  cursor: pointer;
  line-height: 1;
}
.sticker:hover { border-color: var(--gold); }

.ideas { margin-top: 9px; display: grid; gap: 6px; }
.idea {
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 8px;
  padding: 8px 9px;
  cursor: pointer;
  text-align: left;
  color: var(--ink);
}
.idea:hover { border-color: var(--gold); }
.idea b { display: block; font-size: 12.5px; }
.idea span { font-size: 11px; color: var(--ink-3); }

.layer-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.layer-item {
  display: flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line-soft);
  background: var(--bg);
  border-radius: 8px;
  padding: 7px 8px;
  cursor: pointer;
  font-size: 12px;
}
.layer-item:hover { border-color: #39414f; }
.layer-item.active { border-color: var(--gold); background: var(--gold-soft); }
.layer-item .lname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-item .lbtn {
  background: none;
  border: none;
  color: var(--ink-3);
  cursor: pointer;
  font-size: 12px;
  padding: 2px 3px;
}
.layer-item .lbtn:hover { color: var(--ink); }
.layer-kind { font-size: 13px; width: 16px; text-align: center; opacity: 0.8; }

/* ---------------------------------------------------------------- stage */
.stage-wrap { display: flex; flex-direction: column; min-width: 0; background: #06070a; }
.stage-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
  flex-wrap: wrap;
}
.stage-info { font-size: 12px; color: var(--ink-3); }
.stage-tools { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.zoom-label { font-size: 11.5px; color: var(--ink-3); min-width: 42px; text-align: center; }

.stage-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  display: grid;
  place-items: center;
  padding: 26px;
  background-image: radial-gradient(circle at 1px 1px, #161a22 1px, transparent 0);
  background-size: 22px 22px;
}
.stage {
  position: relative;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.7);
  background-color: #fff;
  background-image: linear-gradient(45deg, #d7dbe2 25%, transparent 25%, transparent 75%, #d7dbe2 75%),
    linear-gradient(45deg, #d7dbe2 25%, transparent 25%, transparent 75%, #d7dbe2 75%);
  background-size: 18px 18px;
  background-position: 0 0, 9px 9px;
}
#canvas { display: block; touch-action: none; }
.overlay-layer { position: absolute; inset: 0; pointer-events: none; }
.sel-box { position: absolute; border: 1.5px solid var(--gold); pointer-events: none; }
.handle {
  position: absolute;
  width: 11px;
  height: 11px;
  margin: -6px 0 0 -6px;
  background: #fff;
  border: 1.5px solid var(--gold);
  border-radius: 2px;
  pointer-events: auto;
  touch-action: none;
}
.handle.rot { border-radius: 50%; background: var(--gold); }
.guide { position: absolute; background: rgba(139, 123, 240, 0.9); }

.exportbar {
  display: flex;
  gap: 8px;
  padding: 11px 14px;
  border-top: 1px solid var(--line);
  background: var(--bg-2);
  overflow-x: auto;
  flex: 0 0 auto;
}

/* ----------------------------------------------------------- inspector */
.inspector { margin-top: 12px; }
.insp-group { border-top: 1px solid var(--line-soft); padding-top: 10px; margin-top: 10px; }
.insp-group:first-child { border-top: none; margin-top: 0; padding-top: 0; }
.insp-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.insp-label { font-size: 11px; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.07em; margin-bottom: 7px; }
.align-row { display: flex; gap: 5px; }
.align-row .btn { flex: 1; padding: 6px 4px; font-size: 12px; }

/* -------------------------------------------------------------- modal */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(4, 5, 8, 0.72); display: grid; place-items: center; padding: 20px; }
.modal-card {
  width: min(760px, 96vw);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 16px; overflow-y: auto; }
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.lib-card { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--bg); cursor: pointer; }
.lib-card:hover { border-color: var(--gold); }
.lib-thumb { aspect-ratio: 2 / 3; background: #0c0e13 center/contain no-repeat; display: grid; place-items: center; color: var(--ink-3); font-size: 11px; }
.lib-meta { padding: 8px 9px; }
.lib-meta b { display: block; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-meta span { font-size: 10.5px; color: var(--ink-3); }
.lib-actions { display: flex; gap: 5px; padding: 0 9px 9px; }
.lib-actions .btn { flex: 1; padding: 5px; font-size: 11px; }

/* --------------------------------------------------------------- toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  z-index: 70;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-left: 3px solid var(--gold);
  border-radius: var(--radius);
  padding: 11px 16px;
  font-size: 13px;
  box-shadow: var(--shadow);
  max-width: 90vw;
}
.toast.err { border-left-color: var(--warn); }
.toast.ok { border-left-color: var(--ok); }

/* ---------------------------------------------------------- responsive */
@media (max-width: 1100px) {
  .workspace { grid-template-columns: 232px minmax(0, 1fr) 250px; }
}
@media (max-width: 900px) {
  .aibar-main .select.intent { width: 96px; }
  .aibar-main .select.provider { width: 118px; }
  .chat-panel { left: 8px; right: 8px; }
  .workspace { grid-template-columns: 1fr; grid-template-rows: auto minmax(320px, 1fr) auto; }
  .panel { max-height: 40vh; border-right: none; border-bottom: 1px solid var(--line); }
  .panel-right { border-left: none; border-top: 1px solid var(--line); }
  .name-input { max-width: 150px; }
  .topbar-actions .btn-ghost { display: none; }
}

/* compare: one button per design */
.candidates { display: flex; flex-direction: column; gap: 6px; }
.candidate {
  display: flex;
  flex-direction: column;
  gap: 3px;
  text-align: left;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink-2);
  font-size: 12px;
  cursor: pointer;
}
.candidate strong { color: var(--ink); font-weight: 600; font-size: 12.5px; }
.candidate:hover:not(:disabled) { border-color: var(--gold); }
.candidate.chosen { border-color: var(--ok); }
.candidate:disabled { cursor: default; opacity: 0.75; }

.mask-tools, .mask-actions {display:flex;align-items:end;gap:12px;flex-wrap:wrap}
.mask-tools label {display:grid;gap:5px;font-size:12px;color:var(--ink-2)}
.mask-tools output {display:contents}
.mask-stage {display:grid;place-items:center;position:relative;overflow:hidden;background:#242730;border-radius:8px;margin:14px 0}
.mask-stage canvas {display:block;max-width:100%;max-height:49vh;width:auto;height:auto;touch-action:none;cursor:none;background:repeating-conic-gradient(#8d9097 0 25%,#bcc0c7 0 50%) 0 0 / 16px 16px}
.mask-stage i {position:absolute;pointer-events:none;transform:translate(-50%,-50%);border:1px solid white;border-radius:100%;box-shadow:0 0 0 1px #333}
.mask-actions [data-cancel] {margin-left:auto}
.frame-gallery {display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:5px;margin-bottom:12px}
.frame-gallery button {display:grid;justify-items:center;gap:4px;padding:7px 1px;background:var(--bg);color:var(--ink-2);font:inherit;font-size:10px;border-radius:6px;border:1px solid var(--line);cursor:pointer}
.frame-gallery canvas {width:32px;height:24px}
.frame-gallery button:hover,.frame-gallery button[aria-pressed=true] {border-color:var(--gold);color:var(--ink)}
.frame-gallery button[aria-pressed=true] {background:var(--bg-3)}
