:root {
  --bg: #f3f4f8; --panel: #ffffff; --panel2: #f0f1f6; --text: #16171d; --muted: #6b7080; --line: #e2e4ec;
  --accent: #7c5cff; --accent-soft: rgba(124, 92, 255, .12); --danger: #e5484d; --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 22, 40, .06), 0 8px 24px rgba(20, 22, 40, .08);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0e0f14; --panel: #171821; --panel2: #1f2130; --text: #eceef6; --muted: #8b90a5; --line: #292c3d;
  --accent: #8f74ff; --accent-soft: rgba(143, 116, 255, .18); --shadow: 0 8px 28px rgba(0, 0, 0, .45);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 13.5px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); display: flex; flex-direction: column; overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.ic { width: 17px; height: 17px; flex: none; }
.muted { color: var(--muted); } .small { font-size: 12px; } .trunc { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin: 0 0 8px; }
.warn { color: #b45309; }

.topbar { height: 56px; flex: none; display: flex; align-items: center; gap: 14px; padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-size: 15px; margin: 0; font-weight: 400; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.logo { width: 28px; height: 28px; border-radius: 8px; background: url(../icon.svg) center / cover no-repeat; box-shadow: 0 1px 4px rgba(124, 92, 255, .35); }
.tools { margin-inline-start: auto; display: flex; align-items: center; gap: 8px; }

.btn, .icon, .chip, .auto { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; transition: background .15s, border-color .15s, transform .05s; }
.btn { display: inline-flex; align-items: center; gap: 7px; padding: 7px 12px; font-weight: 500; }
.btn.sm { padding: 5px 9px; font-size: 12.5px; }
.icon { width: 34px; height: 34px; display: inline-grid; place-items: center; padding: 0; }
.btn:hover, .icon:hover, .chip:hover { background: var(--panel2); }
.btn:active, .icon:active { transform: translateY(1px); }
.btn:disabled, .icon:disabled { opacity: .4; pointer-events: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn.danger { color: var(--danger); }
.btn.busy { opacity: .6; pointer-events: none; }
.btnrow { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.btnrow.big .btn { flex: 1; justify-content: center; padding: 10px 12px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.seg { display: inline-flex; background: var(--panel2); border-radius: 9px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 5px 14px; border-radius: 7px; font-weight: 500; color: var(--muted); }
.seg button.on { background: var(--panel); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.seg.full { display: flex; } .seg.full button { flex: 1; padding: 7px 4px; }
.seg.scale button { display: flex; flex-direction: column; line-height: 1.15; } .seg.scale small { font-size: 10px; color: var(--muted); font-weight: 400; } .seg.scale button:disabled { opacity: .35; cursor: not-allowed; }

.app { flex: 1; min-height: 0; display: grid; grid-template-columns: 330px 1fr 290px; }
.side, .inspector { background: var(--panel); overflow: auto; }
.side { border-inline-end: 1px solid var(--line); display: flex; flex-direction: column; }
.inspector { border-inline-start: 1px solid var(--line); padding: 16px; }
.inspector h3 { margin: 0 0 6px; font-size: 14px; }
.foot { margin-top: auto; position: sticky; bottom: 0; z-index: 2; background: var(--panel); flex: none; padding: 10px 14px; border-top: 1px solid var(--line); display: flex; align-items: center; gap: 10px; font-size: 11px; line-height: 1.35; color: var(--muted); }
.foot .lock { flex: none; }
.foot span { flex: 1; }
.foot a { color: var(--muted); display: grid; opacity: .7; } .foot a:hover { opacity: 1; color: var(--text); }
.tabs { display: flex; padding: 8px; gap: 4px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 2; }
.tabs button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; border: 0; background: transparent; color: var(--muted); padding: 7px 2px; border-radius: 8px; font-size: 11.5px; font-weight: 500; }
.tabs button.on { background: var(--accent-soft); color: var(--accent); }
.pane { display: none; padding: 14px; } .pane.on { display: block; }
.sub { margin: 16px 0 8px; font-size: 11.5px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.pane > .sub:first-child { margin-top: 0; }

.drop { width: 100%; border: 2px dashed var(--line); background: var(--panel2); border-radius: 14px; padding: 20px 14px; display: grid; justify-items: center; gap: 4px; text-align: center; }
.drop:hover { border-color: var(--accent); background: var(--accent-soft); }
.drop b { font-size: 14px; } .drop small { color: var(--muted); font-size: 12px; }
.dz-ic .ic { width: 28px; height: 28px; color: var(--accent); }
.tray { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.thumb { position: relative; aspect-ratio: 1; border-radius: 9px; overflow: hidden; background: var(--panel2); cursor: grab; border: 2px solid transparent; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.used { border-color: var(--accent); }
.thumb i { position: absolute; inset-inline-start: 4px; bottom: 4px; font-style: normal; font-size: 10px; background: var(--accent); color: #fff; width: 16px; height: 16px; border-radius: 50%; display: grid; place-items: center; }
.thumb .x { position: absolute; top: 4px; inset-inline-end: 4px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: rgba(0, 0, 0, .6); color: #fff; display: none; place-items: center; padding: 0; }
.thumb:hover .x { display: grid; } .thumb .x .ic { width: 12px; height: 12px; }

.row { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.row > span { width: 92px; flex: none; color: var(--muted); }
.row input[type=range] { flex: 1; min-width: 0; accent-color: var(--accent); }
.row output { width: 46px; text-align: end; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; }
.row select, .row input[type=text], .row2 input[type=number], textarea { flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 6px 8px; }
.row input[type=color] { width: 44px; height: 30px; border: 1px solid var(--line); border-radius: 8px; padding: 2px; background: var(--panel); }
.row input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }
textarea { width: 100%; resize: vertical; margin: 6px 0; }
.row2 { display: flex; align-items: center; gap: 8px; margin: 8px 0; } .row2 label { display: flex; align-items: center; gap: 6px; flex: 1; color: var(--muted); }
.stepper { justify-content: space-between; } .stepper b { min-width: 60px; text-align: center; }
.stepper span { color: var(--muted); margin-inline-end: auto; }

.auto { width: 100%; display: flex; gap: 12px; align-items: center; text-align: start; padding: 11px 12px; margin-bottom: 4px; }
.auto .ic { width: 22px; height: 22px; color: var(--accent); }
.auto small { display: block; color: var(--muted); font-size: 11.5px; line-height: 1.3; }
.auto.on { border-color: var(--accent); background: var(--accent-soft); }
.tpls { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 8px; }
.tpl { aspect-ratio: 1; border: 1px solid var(--line); background: var(--panel); border-radius: 9px; color: #b8bccb; display: grid; place-items: center; padding: 0; }
:root[data-theme="dark"] .tpl { color: #4b5068; }
.tpl:hover { color: var(--accent); border-color: var(--accent); } .tpl.on { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.freeonly { display: none; } body[data-mode="free"] .freeonly { display: block; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.chip { padding: 5px 11px; border-radius: 99px; font-size: 12.5px; }
.chip.on, .chip:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chip.chk { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; } .chip.chk input { accent-color: var(--accent); }
.sws { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin: 8px 0; }
.sw { aspect-ratio: 1; border-radius: 50%; border: 2px solid var(--panel); box-shadow: 0 0 0 1px var(--line); padding: 0; } .sw:hover { box-shadow: 0 0 0 2px var(--accent); }
[hidden] { display: none !important; }
.themes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.theme { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 6px; display: grid; gap: 5px; }
.theme:hover { border-color: var(--accent); }
.theme em { font-style: normal; font-size: 11.5px; color: var(--muted); }
.tp { display: grid; grid-template-columns: 1fr 1fr; aspect-ratio: 1.3; border-radius: 6px; } .tp i { background: #8b90a5; opacity: .75; }
.stickers { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.stickers button { border: 0; background: transparent; font-size: 22px; padding: 6px 0; border-radius: 8px; } .stickers button:hover { background: var(--panel2); }

.stat { background: var(--accent-soft); border-radius: 12px; padding: 12px; margin-bottom: 12px; } .stat b { font-size: 24px; color: var(--accent); display: block; } .stat span { font-size: 12px; color: var(--muted); }
.tips { padding-inline-start: 18px; color: var(--muted); font-size: 12.5px; } .tips li { margin: 6px 0; }
kbd { background: var(--panel2); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; font: 11px ui-monospace, monospace; }

.stagearea { direction: ltr; position: relative; display: flex; overflow: auto; background: var(--bg); background-image: radial-gradient(var(--line) 1px, transparent 1px); background-size: 20px 20px; }
.stagewrap { margin: auto; padding: 28px 28px 70px; }
#stage { box-shadow: var(--shadow); border-radius: 2px; line-height: 0; }
.checker #stage, .prev.checker img { background: repeating-conic-gradient(#d9d9e0 0 25%, #f4f4f8 0 50%) 0 0 / 18px 18px; }
.viewbar { position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 4px 6px; padding-inline-start: 14px; box-shadow: var(--shadow); font-size: 12px; color: var(--muted); }
.viewbar .icon { width: 30px; height: 30px; border: 0; }
.veil { position: absolute; inset: 0; background: rgba(124, 92, 255, .18); border: 3px dashed var(--accent); display: none; place-items: center; font-size: 22px; font-weight: 600; color: var(--accent); z-index: 5; pointer-events: none; }
.veil.on { display: grid; }

dialog { border: 0; padding: 0; border-radius: 18px; background: var(--panel); color: var(--text); box-shadow: 0 30px 80px rgba(0, 0, 0, .4); width: min(880px, 94vw); max-height: 92vh; overflow: auto; }
dialog::backdrop { background: rgba(10, 10, 20, .55); backdrop-filter: blur(3px); }
.dlg { display: grid; grid-template-columns: 1fr 1fr; position: relative; }
.dlg .close, .infobox .close { position: absolute; top: 10px; inset-inline-end: 10px; border: 0; z-index: 2; }
.prev { background: var(--panel2); display: grid; place-items: center; padding: 24px; min-height: 340px; }
.prev img { max-width: 100%; max-height: 62vh; border-radius: 4px; box-shadow: var(--shadow); }
.opts { padding: 22px; } .opts h2 { margin: 0 0 4px; font-size: 18px; }

#toast { position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 20px); background: #1f2130; color: #fff; padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none; transition: .25s; z-index: 50; max-width: 90vw; box-shadow: var(--shadow); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 1100px) { .app { grid-template-columns: 300px 1fr; } .inspector { position: fixed; inset-inline-end: 0; bottom: 0; top: auto; width: min(340px, 100vw); max-height: 45vh; border: 1px solid var(--line); border-radius: 14px 14px 0 0; box-shadow: var(--shadow); z-index: 20; } }

@media (max-width: 1100px) { .inspector.idle { display: none; } }

.mobile-only, #doneBtn { display: none; }
.more-menu { display: contents; }
#themeBtn span { display: none; }
@media (hover: none) { .thumb .x { display: grid; } }

/* ---- phones: full-height canvas, bottom tab bar, slide-up sheets ---- */
@media (max-width: 760px) {
  :root { --tabh: calc(58px + env(safe-area-inset-bottom)); --sheet: 42vh; }
  html, body { height: 100dvh; } body { overflow: hidden; }
  .mobile-only { display: inline-grid; }
  input, select, textarea { font-size: 16px; }
  .topbar { height: 52px; padding: 0 10px; gap: 8px; position: relative; }
  .brand b { display: none; }
  .tools { gap: 6px; }
  .tools .btn span { display: none; } .btn.primary span { display: inline !important; }
  .icon { width: 40px; height: 40px; }
  .more-menu { display: none; position: absolute; top: calc(100% + 6px); inset-inline-end: 10px; flex-direction: column; gap: 4px; padding: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); z-index: 60; min-width: 170px; }
  .tools.open .more-menu { display: flex; }
  .more-menu .btn, .more-menu .icon { width: 100%; height: auto; justify-content: flex-start; display: flex; gap: 10px; padding: 10px 12px; border: 0; }
  .more-menu .btn span, .more-menu .icon span { display: inline !important; }

  .app { display: flex; flex-direction: column; padding-bottom: var(--tabh); }
  body[data-sheet="open"] .app, body.has-sel:not([data-sheet="open"]) .app { padding-bottom: calc(var(--tabh) + var(--sheet)); }
  .stagearea { flex: 1; min-height: 0; height: auto; }
  .stagewrap { padding: 12px 12px 56px; }
  .viewbar { bottom: 8px; }

  .side { display: contents; }
  .foot { order: 2; position: static; padding: 6px 12px; font-size: 10.5px; }
  .tabs { position: fixed; left: 0; right: 0; bottom: 0; top: auto; height: var(--tabh); padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); border-bottom: 0; z-index: 40; }
  .tabs button { font-size: 11px; }
  .pane, .inspector { position: fixed; left: 0; right: 0; bottom: var(--tabh); height: var(--sheet); width: auto; max-height: none; overflow: auto; background: var(--panel); border: 0; border-top: 1px solid var(--line); border-radius: 18px 18px 0 0; box-shadow: 0 -10px 30px rgba(0, 0, 0, .18); padding: 16px 14px 24px; overscroll-behavior: contain; }
  .pane { z-index: 30; } .inspector { z-index: 31; display: none; }
  body:not([data-sheet="open"]) .pane.on { display: none; }
  body.has-sel:not([data-sheet="open"]) .inspector { display: block; }
  body.has-sel:not([data-sheet="open"]) #doneBtn { display: inline-flex; position: fixed; inset-inline-end: 12px; bottom: calc(var(--tabh) + var(--sheet) - 44px); z-index: 32; }
  .inspector h3 { padding-inline-end: 70px; }
  .tray { grid-template-columns: repeat(4, 1fr); } .tpls { grid-template-columns: repeat(5, 1fr); }
  #toast { bottom: calc(var(--tabh) + 14px); }

  dialog { width: 100vw; max-width: 100vw; max-height: 94dvh; margin: auto 0 0; border-radius: 18px 18px 0 0; }
  .dlg { grid-template-columns: 1fr; } .prev { min-height: 0; padding: 14px; } .prev img { max-height: 26vh; } .opts { padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
}
@media (max-width: 760px) { .btn.primary { white-space: nowrap; } .btn.primary .lg { display: none !important; } .btn.primary .sh { display: inline; } }

/* export button label: long form on wide screens, short on phones */
.btn.primary .sh { display: none; }
/* footer icon buttons */
.foot .fbtn { border: 0; background: transparent; color: var(--muted); display: grid; padding: 0; opacity: .7; cursor: pointer; } .foot .fbtn:hover { opacity: 1; color: var(--text); }
/* about and language dialogs */
dialog.info { width: min(640px, 94vw); }
.infobox { position: relative; padding: 24px 26px 28px; line-height: 1.55; }
.infobox h2 { margin: 0 34px 10px 0; font-size: 19px; } .infobox h3 { margin: 22px 0 6px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.infobox h4 { margin: 14px 0 2px; font-size: 14px; } .infobox p { margin: 0; color: var(--muted); } .infobox .faq p { color: var(--text); opacity: .85; }
.langs { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.langs a { display: block; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; color: var(--text); text-decoration: none; font-weight: 500; }
.langs a:hover { background: var(--panel2); } .langs a[aria-current] { border-color: var(--accent); background: var(--accent-soft); }
[dir="rtl"] .infobox h2 { margin: 0 0 10px 34px; }
.row output { direction: ltr; unicode-bidi: isolate; } [dir="rtl"] .row output { text-align: left; }
@media (max-width: 760px) { dialog.info { width: 100vw; } }
.guides { margin: 0; padding-inline-start: 18px; } .guides a { color: var(--accent); }
