/* BG Studio — original styles. Light/dark via [data-theme] set pre-paint by theme.js */
:root, [data-theme="dark"] {
  --bg: #0f1115; --bg2: #161a22; --panel: #1b2029; --line: #2a3140;
  --text: #e8ecf3; --muted: #9aa5b5; --accent: #4f8cff; --accent2: #7c5cff;
  --ok: #34c98e; --warn: #f0b429; --danger: #ef5f6b;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
}
[data-theme="light"] {
  --bg: #f5f7fb; --bg2: #ffffff; --panel: #ffffff; --line: #dde3ee;
  --text: #1c2330; --muted: #5b6678; --accent: #2f6fe4; --accent2: #6a4fd8;
  --shadow: 0 10px 30px rgba(23,32,64,.12);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text); min-height: 100vh;
  display: flex; flex-direction: column;
}
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.hidden { display: none !important; }

/* top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px; border-bottom: 1px solid var(--line); background: var(--bg2);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { display: block; }
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: .2px; }
.badge {
  font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 20px;
  border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
}
.badge-privacy { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.top-link { color: var(--muted); text-decoration: none; font-size: 13px; }
.top-link:hover { color: var(--text); }

main { flex: 1; width: 100%; max-width: 1240px; margin: 0 auto; padding: 22px 18px 40px; }

/* landing */
.stage-landing { text-align: center; }
.hero-title { font-size: clamp(26px, 4.4vw, 42px); margin: 40px 0 10px; }
.hero-sub { color: var(--muted); max-width: 640px; margin: 0 auto 30px; }
.hero-actions { margin-bottom: 30px; }
.btn-hero { font-size: 17px; padding: 14px 44px; border-radius: 12px; }
.hero-hint { color: var(--muted); font-size: 14px; margin-top: 12px; }
kbd {
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px;
  padding: 1px 6px; font-size: 12px; background: var(--bg2);
}
.hero-art { margin: 40px auto 10px; color: var(--text); opacity: .9; }
.page-drop { display: none; }
body.dropping::after {
  content: "Drop the image anywhere";
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 700; color: #fff;
  background: color-mix(in srgb, var(--accent) 55%, rgba(10, 14, 22, .75));
  border: 4px dashed rgba(255, 255, 255, .8); pointer-events: none;
}
.demo-row { margin: 6px 0 10px; display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap; }
.demo-label { color: var(--muted); font-size: 13px; text-align: right; line-height: 1.35; }
.demo-strip { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }
.demo-row .mini-note { flex-basis: 100%; text-align: center; }
.demo-btn {
  width: 74px; height: 74px; padding: 0; border-radius: 12px; overflow: hidden; cursor: pointer;
  border: 2px solid var(--line); background: var(--bg2); transition: transform .12s, border-color .12s;
}
.demo-btn:hover { border-color: var(--accent); transform: translateY(-2px) scale(1.04); }
.demo-btn img { width: 100%; height: 100%; object-fit: cover; display: block; }
.demo-btn.loading { opacity: .5; pointer-events: none; }
.demo-art { font-size: 34px; line-height: 70px; }
/* buttons */
.btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  border-radius: 10px; padding: 9px 16px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: linear-gradient(120deg, var(--accent), var(--accent2)); border: none; color: #fff; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.icon-btn {
  border: 1px solid var(--line); background: transparent; color: var(--text);
  border-radius: 8px; width: 32px; height: 32px; font-size: 15px; cursor: pointer; line-height: 1;
}
.icon-btn:hover { border-color: var(--accent); }
.icon-btn:disabled { opacity: .4; cursor: not-allowed; }

/* full-screen editing mode: the editor fills everything below the header */
body.editing { height: 100vh; overflow: hidden; }
body.editing main { flex: 1; max-width: none; width: 100%; padding: 0; margin: 0; display: flex; flex-direction: column; min-height: 0; }
body.editing #stage-editor { flex: 1; display: flex; flex-direction: column; min-height: 0; }
body.editing .editor-shell { flex: 1; min-height: 0; border-radius: 0; border-left: none; border-right: none; }
body.editing .side-panel { max-height: none; }
body.editing .canvas-area { min-height: 0; overflow: hidden; }
body.editing .canvas-wrap { max-height: 100%; max-width: 100%; }
body.editing #preview-canvas { max-height: calc(100vh - 150px); }
body.editing .statusbar { border-radius: 0; border-bottom: none; }
body.editing .footer { display: none; }

/* editor layout: icon rail | contextual panel | canvas */
.editor-shell {
  display: grid; grid-template-columns: 64px 300px minmax(0, 1fr);
  gap: 0; align-items: stretch; min-height: 74vh;
  border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--bg2);
}
@media (max-width: 900px) {
  .editor-shell { grid-template-columns: 56px minmax(0, 1fr); }
  .side-panel { grid-column: 1 / -1; order: 3; border-right: none; border-top: 1px solid var(--line); }
}
.rail {
  display: flex; flex-direction: column; border-right: 1px solid var(--line);
  background: var(--bg2); padding: 4px 0;
}
.rail-btn {
  background: transparent; border: none; color: var(--muted); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 10px 2px; font-size: 10.5px; font-weight: 600; border-left: 3px solid transparent;
}
.rail-btn svg { display: block; }
.rail-btn:hover { color: var(--text); }
.rail-btn.active { color: var(--accent); border-left-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.side-panel { border-right: 1px solid var(--line); overflow-y: auto; max-height: 80vh; }
.panel-heading { font-weight: 700; font-size: 15px; margin-bottom: 12px; }
.canvas-area {
  background: color-mix(in srgb, var(--muted) 22%, var(--bg));
  display: flex; align-items: center; justify-content: center; padding: 14px; min-height: 300px;
}
.demo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.demo-grid .demo-btn { width: 100%; height: auto; aspect-ratio: 1; }

/* status bar under the editor */
.statusbar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  border: 1px solid var(--line); border-top: none; border-radius: 0 0 12px 12px;
  background: var(--bg2); padding: 8px 14px; font-size: 13px; color: var(--muted);
}
.sb-note { flex: 1; min-width: 180px; }
.sb-view { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.sb-view-btn {
  background: transparent; border: none; color: var(--muted); cursor: pointer;
  padding: 5px 14px; font-size: 13px; font-weight: 600;
}
.sb-view-btn.active { background: var(--accent); color: #fff; }
.sb-zoom { font-variant-numeric: tabular-nums; }

.canvas-wrap {
  position: relative; display: flex; align-items: center; justify-content: center;
  max-width: 100%; touch-action: none;
}
.checker {
  background-image: linear-gradient(45deg, rgba(127,127,127,.18) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(127,127,127,.18) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(127,127,127,.18) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(127,127,127,.18) 75%);
  background-size: 22px 22px; background-position: 0 0, 0 11px, 11px -11px, -11px 0;
}
#preview-canvas { max-width: 100%; max-height: 72vh; display: block; }
.canvas-note { color: var(--muted); font-size: 12px; margin-top: 8px; }
.brush-cursor {
  position: absolute; border: 1.5px solid #fff; outline: 1.5px solid rgba(0,0,0,.6);
  border-radius: 50%; pointer-events: none; transform: translate(-50%, -50%);
}

/* panels */
.panel { padding: 14px; }
.ctl-group { margin-bottom: 16px; }
.ctl-label { display: flex; justify-content: space-between; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.ctl-label .ctl-val { color: var(--muted); font-weight: 500; font-variant-numeric: tabular-nums; }
.slider { width: 100%; accent-color: var(--accent); }
.seg-row { display: flex; gap: 6px; flex-wrap: wrap; }
.seg-btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--text); cursor: pointer;
  border-radius: 8px; padding: 7px 10px; font-size: 13px; flex: 1; min-width: 70px;
}
.seg-btn.active { border-color: var(--accent); color: var(--accent); font-weight: 700; }
.swatch-row { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.swatch {
  aspect-ratio: 1; border-radius: 8px; border: 2px solid var(--line); cursor: pointer; padding: 0;
}
.swatch.active { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 45%, transparent); }
.swatch-custom { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.swatch-custom input[type="color"] { width: 42px; height: 30px; border: 1px solid var(--line); border-radius: 6px; background: none; padding: 2px; }
.grad-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.backdrop-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.backdrop-btn {
  border: 2px solid var(--line); background: var(--panel); border-radius: 10px; cursor: pointer;
  padding: 4px 4px 2px; display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.backdrop-btn img { width: 100%; aspect-ratio: 4/3; object-fit: cover; border-radius: 6px; display: block; }
.backdrop-btn span { font-size: 11px; color: var(--muted); }
.backdrop-btn:hover { border-color: var(--accent); }
.backdrop-btn.active { border-color: var(--accent); }
.backdrop-btn.active span { color: var(--accent); font-weight: 700; }
.backdrop-btn.loading { opacity: .5; pointer-events: none; }
.grad {
  aspect-ratio: 16/10; border-radius: 8px; border: 2px solid var(--line); cursor: pointer; padding: 0;
}
.grad.active { border-color: var(--accent); }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mini-note { color: var(--muted); font-size: 12px; margin-top: 4px; }
.check-row { display: flex; align-items: center; gap: 8px; font-size: 14px; margin-bottom: 12px; }
.check-row input { accent-color: var(--accent); width: 16px; height: 16px; }
.panel .btn-block { width: 100%; margin-top: 4px; }
.select, .panel select {
  width: 100%; background: var(--panel); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 8px 10px; font-size: 14px;
}
.bg-thumb { max-width: 100%; border-radius: 8px; border: 1px solid var(--line); display: block; margin-top: 8px; }

/* progress overlay */
.overlay {
  position: fixed; inset: 0; background: rgba(8, 10, 14, .62); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.progress-card {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
  padding: 22px 26px; width: min(92vw, 380px);
}
.progress-title { font-weight: 700; margin-bottom: 12px; }
.progress-steps { list-style: none; margin: 0; padding: 0; }
.progress-steps li {
  padding: 7px 0 7px 26px; color: var(--muted); position: relative; font-size: 14px;
}
.progress-steps li::before {
  content: ""; position: absolute; left: 4px; top: 12px; width: 10px; height: 10px;
  border-radius: 50%; border: 2px solid var(--line);
}
.progress-steps li.active { color: var(--text); }
.progress-steps li.active::before { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 35%, transparent); }
.progress-steps li.done { color: var(--text); }
.progress-steps li.done::before { border-color: var(--ok); background: var(--ok); }
.step-extra { color: var(--muted); font-size: 12px; }
.progress-foot { color: var(--muted); font-size: 12px; margin-top: 12px; }

/* toast + footer */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--bg2); color: var(--text); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow); padding: 10px 16px; font-size: 14px; z-index: 60; max-width: 88vw;
}
.toast.toast-error { border-color: var(--danger); }
.footer {
  border-top: 1px solid var(--line); background: var(--bg2); color: var(--muted);
  padding: 14px 18px; font-size: 13px; display: flex; gap: 16px; flex-wrap: wrap;
}
.footer a { color: var(--muted); }
.footer a:hover { color: var(--text); }
