:root {
  --bg: #F6F7FA; --surface: #FFFFFF; --surface2: #EEF1F6; --text: #151821; --muted: #5B6475;
  --line: #E3E7EE; --line2: #CBD1DC; --primary: #2F5BEA; --on-primary: #FFFFFF; --primary-soft: #DDE5FF; --on-primary-soft: #0A2378;
  --danger: #C62839; --danger-soft: #FFE1E4; --ok: #1E9E6A; --shadow: 0 1px 2px rgba(16,24,40,.04), 0 4px 16px rgba(16,24,40,.06);
  --radius: 18px; color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101217; --surface: #171A20; --surface2: #222630; --text: #E3E5EC; --muted: #A9B0C0;
    --line: #2C313C; --line2: #424856; --primary: #B3C4FF; --on-primary: #00267D; --primary-soft: #1F3EA8; --on-primary-soft: #DDE5FF;
    --danger: #FFB3BA; --danger-soft: #8C1022; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #101217; --surface: #171A20; --surface2: #222630; --text: #E3E5EC; --muted: #A9B0C0;
  --line: #2C313C; --line2: #424856; --primary: #B3C4FF; --on-primary: #00267D; --primary-soft: #1F3EA8; --on-primary-soft: #DDE5FF;
  --danger: #FFB3BA; --danger-soft: #8C1022; --shadow: none; color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", sans-serif; }
body { min-height: 100vh; padding-bottom: env(safe-area-inset-bottom); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.wrap { max-width: 980px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 8px) 16px 120px; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.label { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 22px 4px 10px; }
h1 { font-size: 30px; margin: 0; letter-spacing: -.02em; font-weight: 650; }
h2 { font-size: 20px; margin: 0; font-weight: 600; }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; border: 0; background: transparent; display: grid; place-items: center; color: var(--text); flex: none; }
.icon-btn:hover { background: var(--surface2); }
.icon-btn:disabled { opacity: .35; }
svg.i { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.search { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 0 14px; height: 52px; margin-top: 14px; }
.search input { flex: 1; border: 0; background: transparent; outline: none; font-size: 16px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 14px 0 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { border: 1px solid var(--line2); background: transparent; border-radius: 10px; padding: 7px 14px; white-space: nowrap; font-size: 14px; font-weight: 500; }
.chip.on { background: var(--primary-soft); color: var(--on-primary-soft); border-color: transparent; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(158px, 1fr)); gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.tool { text-align: left; padding: 14px; height: 136px; display: flex; flex-direction: column; border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.tool:active { transform: scale(.98); }
.tool b { font-size: 15px; font-weight: 600; margin-top: auto; }
.tool span { font-size: 13px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ticon { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; flex: none; }
.ticon svg { width: 21px; height: 21px; }
.topbar { position: sticky; top: 0; z-index: 5; background: var(--bg); display: flex; align-items: center; gap: 6px; padding: calc(env(safe-area-inset-top) + 6px) 8px 6px; }
.topbar h2 { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.page { max-width: 760px; margin: 0 auto; padding: 0 16px 140px; display: flex; flex-direction: column; gap: 12px; }
.drop { border: 1.5px dashed color-mix(in srgb, var(--primary) 50%, transparent); background: color-mix(in srgb, var(--primary) 6%, transparent); border-radius: 20px; height: 180px; display: grid; place-items: center; text-align: center; color: var(--primary); font-weight: 600; width: 100%; }
.drop.over { background: color-mix(in srgb, var(--primary) 14%, transparent); }
.file { display: flex; align-items: center; gap: 12px; padding: 10px 6px 10px 14px; }
.badge { width: 38px; height: 38px; border-radius: 9px; background: var(--surface2); display: grid; place-items: center; font-size: 11px; font-weight: 700; flex: none; }
.name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.opts { padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.opt > .t { font-size: 14px; font-weight: 600; margin-bottom: 8px; }
.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.field { width: 100%; height: 50px; border: 1px solid var(--line2); border-radius: 12px; padding: 0 14px; background: var(--surface); outline: none; }
.field:focus { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
textarea.field { height: auto; min-height: 90px; padding: 12px 14px; }
.switch { display: flex; align-items: center; gap: 12px; }
.switch input { appearance: none; width: 50px; height: 30px; border-radius: 15px; background: var(--line2); position: relative; transition: .2s; flex: none; margin: 0; }
.switch input::after { content: ""; position: absolute; left: 4px; top: 4px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: .2s; }
.switch input:checked { background: var(--primary); }
.switch input:checked::after { left: 24px; background: var(--on-primary); }
input[type=range] { width: 100%; accent-color: var(--primary); }
.btn { border: 0; border-radius: 16px; padding: 15px 18px; font-weight: 600; font-size: 16px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn.primary { background: var(--primary); color: var(--on-primary); }
.btn.tonal { background: var(--primary-soft); color: var(--on-primary-soft); }
.btn.outline { background: transparent; border: 1px solid var(--line2); color: var(--text); }
.btn:disabled { opacity: .45; }
.btn.block { width: 100%; }
.bottom { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; background: var(--bg); padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
.bottom > * { max-width: 728px; margin: 0 auto; }
.error { background: var(--danger-soft); color: var(--danger); border-radius: 14px; padding: 12px 14px; font-size: 14px; }
:root[data-theme="dark"] .error { color: #FFDADD; }
.progress { height: 6px; border-radius: 3px; background: var(--surface2); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--primary); width: 0; transition: width .2s; }
.progress.indet > i { width: 30%; animation: indet 1.2s infinite ease-in-out; }
@keyframes indet { from { transform: translateX(-100%); } to { transform: translateX(340%); } }
.done-mark { width: 64px; height: 64px; border-radius: 50%; background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); display: grid; place-items: center; margin: 12px auto 8px; }
.diff { border-radius: 10px; padding: 8px 12px; font-size: 13px; display: flex; gap: 10px; }
.diff.add { background: color-mix(in srgb, var(--ok) 12%, transparent); }
.diff.rem { background: color-mix(in srgb, #E0475B 12%, transparent); }
/* drawer */
#drawer-scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; }
#drawer { position: fixed; top: 0; bottom: 0; left: 0; width: min(330px, 88vw); background: var(--surface); z-index: 21; overflow-y: auto; padding: calc(env(safe-area-inset-top) + 18px) 12px 30px; border-radius: 0 22px 22px 0; transform: translateX(-102%); transition: transform .22s ease; }
#drawer.open { transform: none; }
.dcat, .ditem { width: 100%; border: 0; background: transparent; display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 14px; text-align: left; }
.dcat:hover, .ditem:hover { background: var(--surface2); }
.ditem { padding-left: 40px; }
.count { font-size: 12px; background: var(--surface2); border-radius: 20px; padding: 1px 8px; }
.segbtns { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line2); border-radius: 22px; overflow: hidden; margin: 0 12px; }
.segbtns button { border: 0; background: transparent; padding: 9px 4px; font-size: 14px; display: flex; gap: 6px; align-items: center; justify-content: center; }
.segbtns button + button { border-left: 1px solid var(--line2); }
.segbtns button.on { background: var(--primary-soft); color: var(--on-primary-soft); font-weight: 600; }
/* editor */
.ed-stage { display: grid; place-items: center; padding: 8px; }
.ed-page { position: relative; background: #fff; box-shadow: 0 0 0 1px var(--line); touch-action: none; }
.ed-page canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.ed-tools { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0; scrollbar-width: none; }
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--line2); flex: none; }
.swatch.on { outline: 3px solid var(--primary); outline-offset: 1px; }
.pill { pointer-events: none; position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 190px); background: var(--text); color: var(--bg); border-radius: 30px; padding: 8px 16px; font-size: 14px; z-index: 30; max-width: 90vw; text-align: center; }
#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(100px + env(safe-area-inset-bottom)); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 30px; z-index: 40; font-size: 14px; }
/* organize */
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.thumb { padding: 8px; }
.thumb .img { aspect-ratio: .77; background: var(--surface2); border-radius: 10px; display: grid; place-items: center; overflow: hidden; position: relative; }
.thumb img { max-width: 92%; max-height: 92%; background: #fff; }
.thumb .n { position: absolute; top: 6px; left: 6px; background: rgba(0,0,0,.65); color: #fff; font-size: 12px; border-radius: 10px; padding: 1px 8px; }
.thumb .acts { display: flex; justify-content: space-between; }
.thumb .acts .icon-btn { width: 32px; height: 32px; }
.thumb .acts svg.i { width: 17px; height: 17px; }
/* dialog */
dialog { border: 0; border-radius: 24px; padding: 20px; background: var(--surface); color: var(--text); width: min(440px, 92vw); max-height: 86vh; }
dialog::backdrop { background: rgba(0,0,0,.4); }
.install { display: flex; gap: 12px; align-items: center; padding: 12px 14px; margin-top: 12px; background: var(--primary-soft); color: var(--on-primary-soft); border-radius: 16px; font-size: 14px; }
