:root {
  --bg: #eaf2ff; --panel: #ffffff; --text: #0f2a55; --muted: #5b6f94;
  --border: #d9e6fb; --accent: #2f6fed; --accent-text: #ffffff; --accent-soft: #e3edff; --accent-ink: #1f4fbf;
  --field: #f5f9ff; --hero: #2f6fed; --hero-a: #4a85f5; --hero-b: #5b93f7;
  --ok: #0e7a4b; --ok-bg: #ddf5e9; --warn: #a15c07; --warn-bg: #fdf0d8; --bad: #b91c1c; --bad-bg: #fde4e4;
  --switch-off: #c7d5ee; --shadow: 0 1px 2px rgba(31,79,191,.06), 0 6px 18px rgba(31,79,191,.07);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a1428; --panel: #111e3a; --text: #e6eeff; --muted: #93a5c8;
    --border: #223558; --accent: #4c86f5; --accent-text: #ffffff; --accent-soft: #1a2b50; --accent-ink: #a9c4ff;
    --field: #0d1930; --hero: #1e47a8; --hero-a: #2a58c2; --hero-b: #3567d6;
    --ok: #4ade80; --ok-bg: #123524; --warn: #fbbf24; --warn-bg: #3a2c0c; --bad: #f87171; --bad-bg: #3d1717;
    --switch-off: #34486f; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 18px rgba(0,0,0,.25);
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }

.hero { background: var(--hero); position: relative; overflow: hidden; padding: 26px 16px 28px; }
.hero::before { content: ""; position: absolute; right: -50px; top: -80px; width: 240px; height: 240px; border-radius: 50%; background: var(--hero-a); }
.hero::after { content: ""; position: absolute; right: 190px; bottom: -100px; width: 170px; height: 170px; border-radius: 50%; background: var(--hero-b); opacity: .6; }
.hero-in { max-width: 1150px; margin: 0 auto; position: relative; z-index: 1; }
.brand { display: flex; align-items: center; gap: 14px; }
.logo { width: 48px; height: 48px; border-radius: 14px; background: #fff; color: #2f6fed; display: grid; place-items: center; flex: none; }
h1 { font-size: 24px; line-height: 1.2; margin: 0; color: #fff; font-weight: 600; }
.hero p { margin: 3px 0 0; color: #dce8ff; font-size: 14px; }
.pill { display: inline-flex; align-items: center; gap: 6px; background: rgba(255,255,255,.18); color: #fff;
  font-size: 12px; padding: 5px 12px; border-radius: 999px; margin-top: 14px; }

main { max-width: 1150px; margin: 0 auto; padding: 18px 16px 8px;
  display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
@media (max-width: 820px) { main { grid-template-columns: minmax(0, 1fr); } h1 { font-size: 20px; } }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 18px; padding: 16px; box-shadow: var(--shadow); }
.card + .card, aside .card + .card { margin-top: 14px; }

.head { display: flex; align-items: center; gap: 11px; margin: 0; cursor: pointer; color: var(--text); font-size: 15px; }
.head.static { cursor: default; margin-bottom: 10px; }
.ic { width: 32px; height: 32px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; flex: none; }
.ic svg { width: 18px; height: 18px; }
.h { flex: 1; font-weight: 600; }
.sw { appearance: none; -webkit-appearance: none; width: 38px; height: 22px; border-radius: 999px; background: var(--switch-off);
  position: relative; cursor: pointer; flex: none; margin: 0; transition: background .2s; }
.sw::after { content: ""; position: absolute; left: 2px; top: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: left .2s; }
.sw:checked { background: var(--accent); }
.sw:checked::after { left: 18px; }
.sw:focus-visible, button:focus-visible, select:focus-visible, input:focus-visible, #drop:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#drop { border: 2px dashed #a9c4f5; background: var(--field); border-radius: 16px; min-height: 170px;
  display: flex; align-items: center; justify-content: center; text-align: center; color: var(--accent);
  cursor: pointer; padding: 16px; transition: border-color .15s, background .15s; }
@media (prefers-color-scheme: dark) { #drop { border-color: #34518f; } }
#drop:hover, #drop.over { border-color: var(--accent); background: var(--accent-soft); }
#drop svg { width: 32px; height: 32px; }
#drop strong { display: block; font-size: 16px; font-weight: 600; }
#drop p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.has-items #drop { min-height: 76px; padding: 8px; }
.has-items #drop p, .has-items #drop svg { display: none; }
.has-items #drop strong { font-size: 14px; }

#summary { display: none; margin: 14px 2px 8px; font-size: 13px; color: var(--muted); }
.has-items #summary { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
#bar { display: none; height: 6px; background: var(--accent-soft); border-radius: 3px; overflow: hidden; margin-bottom: 10px; }
#bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 3px; transition: width .15s; }
.running #bar { display: block; }

#list { max-height: 640px; overflow-y: auto; display: none; padding-right: 2px; }
.has-items #list { display: block; }
.item { display: grid; grid-template-columns: 48px 1fr auto auto; gap: 10px; align-items: center;
  padding: 8px; border: 1px solid var(--border); border-radius: 14px; margin-bottom: 8px; background: var(--panel); }
.thumb { width: 48px; height: 48px; border-radius: 10px; background: var(--accent-soft) center/cover; border: 0; cursor: pointer; padding: 0; }
.thumb:disabled { cursor: default; }
.name { font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meta { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.st { font-size: 12px; white-space: nowrap; color: var(--muted); background: var(--accent-soft); padding: 2px 10px; border-radius: 999px; }
.st.ok { color: var(--ok); background: var(--ok-bg); } .st.warn { color: var(--warn); background: var(--warn-bg); } .st.bad { color: var(--bad); background: var(--bad-bg); }
.icons { display: flex; gap: 4px; }
.icon { border: 0; background: var(--accent-soft); color: var(--accent-ink); border-radius: 9px; width: 30px; height: 30px; cursor: pointer; font-size: 14px; line-height: 1; }
.icon:hover:not(:disabled) { background: var(--accent); color: #fff; }
.icon:disabled { opacity: .35; cursor: default; }
@media (max-width: 520px) { .item { grid-template-columns: 48px 1fr auto; } .st { display: none; } }

label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
label.head, label.radio { font-size: inherit; margin-bottom: 0; }
input[type=number], select { width: 100%; padding: 9px 11px; border: 1px solid var(--border);
  border-radius: 11px; background: var(--field); color: var(--text); font: inherit; font-size: 14px; }
input[type=number]:focus, select:focus { border-color: var(--accent); }
input[type=color] { width: 44px; height: 32px; border: 1px solid var(--border); border-radius: 9px; padding: 2px; background: var(--field); }
.row { display: flex; gap: 8px; align-items: end; }
.row > div { flex: 1; }
.row .x { flex: 0 0 auto; padding-bottom: 9px; color: var(--muted); }
.field { margin-bottom: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip { border: 0; background: var(--accent-soft); color: var(--accent-ink);
  padding: 4px 11px; border-radius: 999px; cursor: pointer; font: 500 12px inherit; }
.chip:hover { background: var(--accent); color: #fff; }
.radio { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; margin: 0 0 8px; cursor: pointer; }
.radio small { color: var(--muted); }
.radio input[type=radio] { accent-color: var(--accent); }
.hint { font-size: 12px; color: var(--muted); margin: 8px 0 0; }

button.primary, button.secondary { width: 100%; padding: 12px; border-radius: 13px; font: 600 15px inherit; cursor: pointer; transition: transform .06s, background .15s; }
button.primary { border: 0; background: var(--accent); color: var(--accent-text); box-shadow: 0 4px 12px rgba(47,111,237,.28); }
button.primary:hover:not(:disabled) { filter: brightness(1.07); }
button.secondary { border: 0; background: var(--accent-soft); color: var(--accent-ink); margin-top: 8px; }
button.secondary:hover:not(:disabled) { background: var(--accent); color: #fff; }
button:active:not(:disabled) { transform: scale(.985); }
button:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }
#msg { margin-top: 10px; font-size: 13px; min-height: 1.4em; }
#msg.ok { color: var(--ok); } #msg.warn { color: var(--warn); }
footer { text-align: center; font-size: 13px; color: var(--muted); padding: 10px 16px 28px; }

dialog { border: 1px solid var(--border); border-radius: 18px; background: var(--panel); color: var(--text);
  padding: 14px; max-width: min(92vw, 900px); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(10,20,40,.55); }
dialog img { max-width: 100%; max-height: 70vh; display: block; margin: 10px auto; border-radius: 10px;
  background-image: linear-gradient(45deg,#8883 25%,transparent 25%,transparent 75%,#8883 75%),
    linear-gradient(45deg,#8883 25%,transparent 25%,transparent 75%,#8883 75%);
  background-size: 16px 16px; background-position: 0 0, 8px 8px; }
.dlghead { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.tab { border: 0; background: var(--accent-soft); color: var(--accent-ink); padding: 5px 14px; border-radius: 999px; cursor: pointer; font: 500 13px inherit; }
.tab[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }

/* ---- shared controls for the cropper and background tools ---- */
input[type=range] { width: 100%; accent-color: var(--accent); margin: 2px 0 0; }
.slider { margin-bottom: 12px; }
.slider label { display: flex; justify-content: space-between; }
.slider output { color: var(--text); font-weight: 500; }
.seg { display: flex; background: var(--accent-soft); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; color: var(--accent-ink); padding: 7px 6px; border-radius: 9px;
  font: 500 13px inherit; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; margin: 2px 0 10px; }
.swatch { width: 32px; height: 32px; border-radius: 10px; border: 2px solid var(--border); cursor: pointer; padding: 0; }
.swatch[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.swatch.checker { background: #fff linear-gradient(45deg,#ccc 25%,transparent 25%,transparent 75%,#ccc 75%) 0 0/10px 10px,
  linear-gradient(45deg,#ccc 25%,#fff 25%,#fff 75%,#ccc 75%) 5px 5px/10px 10px; }
.note { font-size: 12px; color: var(--muted); background: var(--accent-soft); border-radius: 12px; padding: 8px 12px; margin-top: 10px; }
.note b { color: var(--text); font-weight: 600; }
.ai-status { display: none; font-size: 12px; color: var(--accent-ink); background: var(--accent-soft); border-radius: 999px; padding: 4px 12px; margin: 10px 2px 0; }
.ai-status.show { display: inline-block; }
.stage { position: relative; background: var(--field); border-radius: 12px; min-height: 120px; display: grid; place-items: center; }
.stage canvas { max-width: 100%; max-height: 62vh; border-radius: 10px; display: block; }
.checker-bg { background-image: linear-gradient(45deg,#8883 25%,transparent 25%,transparent 75%,#8883 75%),
  linear-gradient(45deg,#8883 25%,transparent 25%,transparent 75%,#8883 75%); background-size: 16px 16px; background-position: 0 0, 8px 8px; }
.dlgbody { display: grid; grid-template-columns: minmax(0, 1fr) 230px; gap: 14px; margin-top: 10px; min-width: min(80vw, 760px); }
@media (max-width: 640px) { .dlgbody { grid-template-columns: minmax(0, 1fr); min-width: 0; } }
.dlgactions { display: flex; gap: 8px; margin-top: 8px; }
.dlgactions button { flex: 1; margin: 0; padding: 9px; }

/* ---- feature cards: switch (on/off) + arrow (expand/collapse) ---- */
.feature .head { cursor: default; gap: 10px; }
.ttl { flex: 1; min-width: 0; display: flex; align-items: center; gap: 11px; background: none; border: 0; padding: 0;
  text-align: left; cursor: pointer; color: var(--text); font: inherit; }
.ttl .txt { display: flex; flex-direction: column; min-width: 0; }
.ttl .h { flex: none; font-weight: 600; font-size: 15px; line-height: 1.25; }
.ttl .desc { font-size: 12px; color: var(--muted); font-weight: 400; line-height: 1.3; }
.chev { width: 30px; height: 30px; border: 0; border-radius: 9px; background: var(--accent-soft); color: var(--accent-ink);
  cursor: pointer; display: grid; place-items: center; flex: none; }
.chev svg { width: 16px; height: 16px; transition: transform .2s; }
.feature.open .chev svg { transform: rotate(180deg); }
.feature.on { border-color: var(--accent); }
.feature.on .ic { background: var(--accent); color: #fff; }
.cbody { display: none; margin: 14px 0 0; padding: 14px 0 0; border: 0; border-top: 1px solid var(--border); min-width: 0; }
.feature.open .cbody { display: block; }
.feature:not(.on) .cbody { opacity: .6; }

/* sections inside a card, each with its own small switch */
.sub { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.sub:first-of-type, .sub[hidden] + .sub { margin-top: 0; padding-top: 0; border-top: 0; }
.subhead { display: flex; align-items: center; gap: 10px; margin: 0 0 4px; font-size: 14px; font-weight: 600; color: var(--text); cursor: pointer; }
.subhead span { flex: 1; }
.subbody { display: none; margin-top: 10px; }
.sub.on .subbody { display: block; }

/* colour picker + hex code */
.colorpick { display: flex; align-items: center; gap: 8px; }
.colorpick input[type=text] { width: 92px; padding: 7px 9px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--field); color: var(--text); font: 500 13px ui-monospace, Consolas, monospace; text-transform: uppercase; }
.colorpick input[type=text]:focus { border-color: var(--accent); }
.colorpick input[type=text].bad { border-color: var(--bad); }
.colorrow { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.colorrow > label { margin: 0; flex: 1; }

/* ---- action buttons: first card in the column, sticky on desktop ---- */
.btnrow { display: grid; grid-template-columns: 1fr; gap: 8px; margin-top: 8px; }
.btnrow:has(#folder:not([hidden])) { grid-template-columns: 1fr 1fr; }
.btnrow .secondary { margin-top: 0; padding: 10px 8px; font-size: 14px; }
.actions .hint { margin: 8px 0 0; }
.actions #msg { margin-top: 8px; }
@media (min-width: 821px) { .actions { position: sticky; top: 12px; z-index: 5; } }
