:root {
  --bg: #121214; --s1: #1E1F23; --s2: #2A2B30; --s3: #3A3B41; --line: #2E2F35;
  --tx: #F4F4F5; --mut: #A1A1AA; --acc: #FFD43B; --danger: #FF8080;
  font-family: Heebo, system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--tx); -webkit-text-size-adjust: 100%; }
body { min-height: 100dvh; -webkit-tap-highlight-color: transparent; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
a { color: var(--acc); }
:focus-visible { outline: 2px solid var(--acc); outline-offset: 2px; }

.screen { max-width: 560px; margin: 0 auto; min-height: 100dvh; }

/* ---------- Home ---------- */
#home { padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 18px; }
.home-head { display: flex; align-items: center; height: 56px; }
.brand { display: flex; align-items: flex-end; gap: 6px; }
.brand a { display: block; line-height: 0; }
.brand img { height: 30px; width: auto; display: block; }
.brand-word { font-family: Rubik, sans-serif; font-weight: 500; font-size: 53px; line-height: 0.74; color: #fff; position: relative; top: 2px; }
.tagline { margin: -6px 0 0; color: var(--mut); font-size: 15px; }
.card { display: flex; gap: 16px; align-items: center; min-height: 104px; padding: 20px; border-radius: 20px; background: var(--s1); border: 1px solid var(--line); color: var(--tx); text-decoration: none; cursor: pointer; }
.card-primary { background: var(--acc); border-color: var(--acc); color: #121214; }
.card h2 { margin: 0; font-family: Rubik, sans-serif; font-weight: 900; font-size: 24px; }
.card p { margin: 4px 0 0; font-size: 14px; color: var(--mut); }
.card-primary p { color: #121214; font-weight: 500; }
.card svg { flex-shrink: 0; }
.row-link { display: flex; align-items: center; gap: 14px; min-height: 58px; padding: 0 18px; border-radius: 16px; background: var(--s1); border: 1px solid var(--line); color: var(--tx); text-decoration: none; font-weight: 700; font-size: 17px; width: 100%; text-align: start; }
.row-link small { margin-inline-start: auto; font-weight: 400; font-size: 13px; color: var(--mut); }
.drafts-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
.drafts-head h2 { margin: 0; font-size: 18px; }
.drafts-head span { font-size: 13px; color: var(--mut); }
.draft-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.draft, .tile { position: relative; }
.draft-open { display: block; width: 100%; aspect-ratio: 1; padding: 0; border: 0; border-radius: 12px; overflow: hidden; background: var(--s2); }
.draft-open img { width: 100%; height: 100%; object-fit: cover; display: block; }
.draft-del, .tile-del { position: absolute; top: -6px; left: -6px; width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--bg); background: var(--s3); color: var(--tx); display: flex; align-items: center; justify-content: center; padding: 0; }
.empty { grid-column: 1 / -1; color: var(--mut); font-size: 14px; margin: 8px 0; line-height: 1.5; }

/* ---------- Bars & buttons ---------- */
.bar { display: flex; align-items: center; gap: 4px; height: 56px; padding: 0 8px; flex-shrink: 0; }
.bar h1 { margin: 0; font-family: Rubik, sans-serif; font-weight: 900; font-size: 20px; }
.spacer { flex: 1; }
.icon-btn { width: 44px; height: 44px; border: 0; background: none; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center; color: var(--tx); padding: 0; text-decoration: none; }
.icon-btn:disabled { opacity: .3; cursor: default; }
.btn-primary, .btn-outline { min-height: 44px; padding: 0 18px; border-radius: 12px; font-weight: 700; font-size: 15px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; }
.btn-primary { border: 0; background: var(--acc); color: #121214; }
.btn-outline { border: 1px solid var(--acc); background: none; color: var(--acc); }
.wide { width: 100%; }

/* ---------- Editor / collage shared ---------- */
#editor, #collage, #library { display: flex; flex-direction: column; height: 100dvh; min-height: 0; }
.stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.stage canvas { touch-action: none; border-radius: 4px; box-shadow: 0 0 0 1px var(--line); display: block; }
.panel { background: var(--s1); border-radius: 20px 20px 0 0; padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; max-height: 44dvh; overflow-y: auto; flex-shrink: 0; }
#colPanel { padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
.toolbar { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); height: calc(64px + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: #18191C; border-top: 1px solid var(--s2); flex-shrink: 0; }
.toolbar button { border: 0; background: none; color: var(--mut); font-size: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; }
.toolbar button.on { color: var(--acc); font-weight: 700; }
.hint { margin: 0; font-size: 13px; color: var(--mut); line-height: 1.5; }
.panel textarea { width: 100%; min-height: 52px; resize: vertical; background: var(--s2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; font-size: 16px; color: var(--tx); }
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex-shrink: 0; height: 40px; padding: 0 14px; border-radius: 10px; border: 2px solid var(--s2); background: var(--s2); font-size: 16px; display: inline-flex; align-items: center; gap: 6px; }
.chip.on { border-color: var(--acc); }
.range { display: flex; align-items: center; gap: 12px; font-size: 14px; color: var(--mut); }
.range input { flex: 1; accent-color: var(--acc); min-width: 0; }
.range output { width: 36px; color: var(--tx); text-align: center; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.lbl { font-size: 14px; color: var(--mut); min-width: 40px; }
.btns .tog { flex: 1; }
.tog { min-height: 44px; padding: 0 12px; border-radius: 10px; border: 2px solid var(--s2); background: var(--s2); font-size: 14px; font-weight: 500; }
.tog.on { background: var(--acc); border-color: var(--acc); color: #121214; font-weight: 700; }
.tog.danger { color: var(--danger); }
.sq { background: var(--s2); border: 2px solid var(--s2); flex-shrink: 0; }
.sq.on { border-color: var(--acc); }
.swatches { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.sw { width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--s3); padding: 0; position: relative; flex-shrink: 0; }
.sw.on { border: 3px solid var(--acc); }
.sw[data-val="transparent"] { background: repeating-conic-gradient(#666 0 25%, #333 0 50%) 0 0 / 12px 12px !important; }
.sw-custom { display: inline-flex; align-items: center; justify-content: center; background: var(--s2); border-style: dashed; font-size: 18px; overflow: hidden; cursor: pointer; }
.sw-custom input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; border: 0; padding: 0; }
.layer-row { display: flex; align-items: center; gap: 4px; background: var(--s2); border-radius: 12px; padding: 4px; padding-inline-start: 12px; min-height: 52px; border: 2px solid transparent; cursor: pointer; }
.layer-row.on { border-color: var(--acc); }
.layer-row span { flex: 1; font-size: 14px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

/* ---------- Collage ---------- */
.layouts { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.lay { aspect-ratio: 1; border-radius: 10px; border: 2px solid var(--s2); background: var(--s2); padding: 7px; display: flex; align-items: center; justify-content: center; color: var(--mut); }
.lay.on { border-color: var(--acc); }
.lay-box { position: relative; width: 100%; }
.lay-box i { position: absolute; border: 1.5px solid var(--s2); background: #6B6C73; border-radius: 3px; }
.lay.on .lay-box i { background: var(--acc); }

/* ---------- Library ---------- */
.lib-top { padding: 4px 16px 0; display: flex; flex-direction: column; gap: 12px; flex-shrink: 0; }
.search { height: 48px; border-radius: 14px; background: var(--s1); border: 1px solid var(--line); display: flex; align-items: center; gap: 10px; padding: 0 14px; color: var(--mut); }
.search input { flex: 1; border: 0; background: none; font-size: 16px; color: var(--tx); outline: none; min-width: 0; }
.tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); background: var(--s1); border-radius: 12px; padding: 4px; gap: 4px; }
.tabs button { height: 38px; border: 0; border-radius: 9px; background: none; color: #D4D4D8; font-size: 15px; font-weight: 500; }
.tabs button.on { background: var(--acc); color: #121214; font-weight: 700; }
.lib-note { margin: 0; font-size: 12px; color: var(--mut); }
.lib-grid { flex: 1; min-height: 0; overflow-y: auto; padding: 12px 16px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 10px; align-content: start; }
.tile-btn { width: 100%; border: 0; background: none; padding: 0; display: flex; flex-direction: column; gap: 6px; color: var(--tx); }
.tile-img { display: block; aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: var(--s2); width: 100%; }
.tile-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile-name { font-size: 12px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; width: 100%; }
.lib-foot { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--s2); display: flex; flex-direction: column; gap: 10px; flex-shrink: 0; }
.lib-foot p { margin: 0; font-size: 13px; color: var(--mut); }
.lib-foot .row > * { flex: 1; }

/* ---------- Dialogs & toast ---------- */
.sheet { border: 0; padding: 16px; border-radius: 20px; background: var(--s1); color: var(--tx); width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); }
.sheet::backdrop { background: rgba(0, 0, 0, .65); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sheet-head h2 { margin: 0; font-size: 18px; }
#expPreview { display: block; max-width: 100%; max-height: 55dvh; margin: 0 auto 14px; border-radius: 6px; }
.sheet-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.sheet-btns > * { flex: 1; }
.note { font-size: 12px; color: var(--mut); margin: 12px 0 0; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--mut); margin-bottom: 12px; }
.field input { height: 46px; border-radius: 12px; border: 1px solid var(--line); background: var(--s2); padding: 0 12px; font-size: 16px; color: var(--tx); }
#toast { position: fixed; bottom: calc(92px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); background: #F4F4F5; color: #121214; padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 500; z-index: 50; max-width: calc(100vw - 32px); box-shadow: 0 6px 24px rgba(0, 0, 0, .4); text-align: center; }
