:root{
  --cream:#fbf3e6; --paper:#fffaf0; --ink:#4a3328; --muted:#a58f80;
  --coral:#e0685a; --blush:#f2b8b0; --sage:#9db59a; --green:#2f5d50; --mustard:#d9a93b;
  --shadow:0 2px 0 rgba(74,51,40,.06),0 6px 16px rgba(74,51,40,.12);
}
*{box-sizing:border-box;-webkit-tap-highlight-color:transparent}
html,body{height:100%;margin:0;background:var(--cream);color:var(--ink);
  font-family:"DM Sans",system-ui,sans-serif;overscroll-behavior:none;overflow:hidden;
  -webkit-user-select:none;user-select:none;-webkit-touch-callout:none}
button{font:inherit;color:inherit;border:0;background:none;cursor:pointer;padding:0}
#app{height:100vh;height:100dvh;display:flex;flex-direction:column;max-width:720px;margin:0 auto}

#topbar{display:flex;align-items:center;justify-content:space-between;height:44px;padding:0 14px;flex:none;
  padding-top:env(safe-area-inset-top);box-sizing:content-box}
#topbar h1{margin:0;font:700 28px/1 Caveat,cursive;color:var(--coral)}
#selActions{display:flex;gap:6px}
.ib{width:40px;height:40px;border-radius:50%;background:var(--paper);box-shadow:var(--shadow);display:grid;place-items:center}
.ib svg{width:22px;height:22px;fill:none;stroke:var(--ink);stroke-width:2;stroke-linecap:round;stroke-linejoin:round}
.ib.danger svg{stroke:var(--coral)}
.ib:active{transform:scale(.94)}
[hidden]{display:none!important}

#stageWrap{flex:1;min-height:0;position:relative;margin:0 10px;border-radius:18px;overflow:hidden;box-shadow:inset 0 0 0 1px rgba(74,51,40,.1)}
#stage{position:absolute;inset:0;touch-action:none}

#tabs{display:flex;flex:none;margin:10px 10px 0}
#tabs button{flex:1;padding:12px 0 10px;font-weight:700;font-size:14px;color:var(--muted);border-bottom:3px solid transparent}
#tabs button.on{color:var(--ink);border-bottom-color:var(--coral)}

#tray{flex:none;height:176px;padding:12px 10px calc(12px + env(safe-area-inset-bottom));
  overflow-x:auto;overflow-y:hidden;-webkit-overflow-scrolling:touch;scrollbar-width:none;
  display:grid;grid-auto-flow:column;grid-template-rows:repeat(2,72px);grid-auto-columns:72px;gap:10px;align-content:start}
#tray::-webkit-scrollbar{display:none}
#tray.textTray{display:flex;flex-direction:column;gap:10px;overflow:hidden;align-content:unset}

.tile{position:relative;width:72px;height:72px;border-radius:14px;background:var(--paper);box-shadow:var(--shadow);
  display:grid;place-items:center;padding:7px;overflow:hidden}
.tile img{max-width:100%;max-height:100%;display:block;pointer-events:none;-webkit-user-drag:none}
.tile.bgTile{padding:0}.tile.bgTile img{width:100%;height:100%;object-fit:cover}
.tile.active{outline:3px solid var(--coral);outline-offset:-3px}
.lock{position:absolute;top:4px;right:4px;width:22px;height:22px;border-radius:50%;background:var(--mustard);
  display:grid;place-items:center;box-shadow:0 1px 3px rgba(0,0,0,.25)}
.lock svg{width:13px;height:13px;fill:none;stroke:#fff;stroke-width:2.4;stroke-linecap:round;stroke-linejoin:round}
.tile:active{transform:scale(.95)}

.row{display:flex;gap:10px;align-items:center}
.btn{height:46px;padding:0 22px;border-radius:23px;background:var(--coral);color:#fff;font-weight:700;font-size:16px;box-shadow:var(--shadow)}
.btn.ghost{background:var(--paper);color:var(--ink)}
.chip{height:40px;min-width:76px;padding:0 14px;border-radius:20px;background:var(--paper);box-shadow:var(--shadow);font-size:22px;line-height:1}
.chip.active{outline:3px solid var(--coral);outline-offset:-3px}
.sw{width:34px;height:34px;border-radius:50%;box-shadow:inset 0 0 0 2px rgba(0,0,0,.12),var(--shadow);flex:none}
.sw.active{outline:3px solid var(--coral);outline-offset:2px}
.colors{overflow-x:auto;scrollbar-width:none;padding:3px}

#sheetBack{position:fixed;inset:0;background:rgba(40,25,18,.45);z-index:10}
#sheet{position:fixed;left:0;right:0;bottom:0;max-width:720px;margin:0 auto;z-index:11;background:var(--paper);
  border-radius:24px 24px 0 0;padding:22px 20px calc(22px + env(safe-area-inset-bottom));box-shadow:0 -8px 30px rgba(0,0,0,.25);
  animation:up .22s ease-out}
@keyframes up{from{transform:translateY(40px);opacity:0}}
#sheet h2{margin:0 0 6px;font:700 30px/1.1 Caveat,cursive;color:var(--coral)}
#sheet p{margin:0 0 16px;line-height:1.45}
#sheet .thumb{width:72px;height:72px;float:right;margin:0 0 8px 12px;background:var(--cream);border-radius:14px;padding:6px;display:grid;place-items:center}
#sheet .thumb img{max-width:100%;max-height:100%}
#sheet textarea{width:100%;height:110px;border:2px solid var(--blush);border-radius:14px;padding:12px;font:700 26px/1.15 Caveat,cursive;
  background:#fff;color:var(--ink);resize:none;margin-bottom:14px;-webkit-user-select:text;user-select:text}
#sheet .row{justify-content:flex-end}

/* text editing: tabs + tray are swapped for a docked editor, the app fits the visible viewport (keyboard) */
#editBar{flex:none;display:flex;gap:10px;align-items:flex-end;padding:10px 10px calc(10px + env(safe-area-inset-bottom));background:var(--cream)}
#editBar[hidden]{display:none}
#editBar textarea{flex:1;min-width:0;height:92px;border:2px solid var(--blush);border-radius:14px;padding:10px 12px;
  font:600 18px/1.25 "DM Sans",system-ui,sans-serif;background:#fff;color:var(--ink);resize:none;-webkit-user-select:text;user-select:text}
#editBar textarea:focus{outline:none;border-color:var(--coral)}
body.editing #tabs,body.editing #tray{display:none}
#tray.textTray{gap:8px;padding-top:8px}
.range{display:flex;align-items:center;gap:12px;font-weight:700;font-size:13px;color:var(--muted)}
.range input{flex:1;accent-color:var(--coral);height:28px}
.chip{font-size:20px}

#toolbar{display:flex;align-items:center;justify-content:space-between;height:48px;padding:0 10px;flex:none}
#historyActions,#selActions{display:flex;gap:6px}
.ib[disabled]{opacity:.35;box-shadow:none;pointer-events:none}

.topActions{display:flex;gap:6px}
#btnNames{position:relative}
.dot{position:absolute;top:3px;right:3px;width:10px;height:10px;border-radius:50%;background:var(--coral);border:2px solid var(--paper)}
#sheet label{display:block;font-weight:700;font-size:13px;color:var(--muted);margin:0 0 4px}
#sheet input[type=text]{width:100%;height:46px;border:2px solid var(--blush);border-radius:14px;padding:0 12px;margin-bottom:14px;
  font:600 17px "DM Sans",system-ui,sans-serif;background:#fff;color:var(--ink);-webkit-user-select:text;user-select:text}
#sheet input[type=text]:focus{outline:none;border-color:var(--coral)}
#sheet .hint{font-size:13px;color:var(--muted);margin:-4px 0 16px}
.btn.warn{background:#b8453a}

/* while typing: give the canvas all the room above the keyboard */
body.editing #topbar,body.editing #toolbar{display:none}
body.editing #stageWrap{margin-top:max(8px,env(safe-area-inset-top))}
#editBar textarea{height:72px}

.alignGroup{display:flex;gap:4px;flex:none}
.ab{width:36px;height:36px;border-radius:10px;background:var(--paper);box-shadow:var(--shadow);display:grid;place-items:center}
.ab svg{width:20px;height:20px;fill:none;stroke:var(--ink);stroke-width:2;stroke-linecap:round}
.ab.active{outline:3px solid var(--coral);outline-offset:-3px}

.topActions{align-items:center}
.btn.small{height:40px;padding:0 20px;font-size:15px;margin-left:2px}
a.btn{display:inline-flex;align-items:center;justify-content:center;text-decoration:none}
a.btn.wa{background:#2f9b58}
.shareBtns{display:flex;flex-wrap:wrap;gap:10px;margin:0 0 16px}
#sheet .row.spread{justify-content:space-between}
.linkBtn{color:var(--coral);font-weight:700;font-size:15px}
#sheet input[readonly]{background:var(--cream);font-weight:500;font-size:15px}
#sheet .hint.err{color:#b8453a;font-weight:700;margin-top:-8px}
.spinner{width:34px;height:34px;border-radius:50%;border:4px solid var(--blush);border-top-color:var(--coral);animation:spin .8s linear infinite;margin:6px 0 4px}
@keyframes spin{to{transform:rotate(360deg)}}

/* "Pick your confetti": replaces the tabs and tray as the last step before sending; the card stays visible for the live preview */
body.picking #tabs,body.picking #tray{display:none}
#confettiBar{flex:none;padding:8px 10px calc(10px + env(safe-area-inset-bottom));background:var(--cream)}
#confettiBar[hidden]{display:none}
.cbTitle{margin:0 2px 6px;font:700 26px/1 Caveat,cursive;color:var(--coral)}
.cbRow{display:flex;gap:10px;overflow-x:auto;padding:4px 2px 10px;scrollbar-width:none;-webkit-overflow-scrolling:touch}
.cbRow::-webkit-scrollbar{display:none}
.ctile{position:relative;flex:none;width:78px;height:86px;border-radius:14px;background:var(--paper);box-shadow:var(--shadow);display:flex;flex-direction:column;align-items:center;justify-content:center;gap:5px;padding:6px 4px}
.ctile canvas{display:block}
.ctile span.name{font-size:11px;font-weight:700;line-height:1.1;text-align:center;color:var(--ink)}
.ctile[aria-checked=true]{outline:3px solid var(--coral);outline-offset:-3px}
.ctile.off{opacity:.45}
.ctile:active{transform:scale(.96)}
.cbActions{display:flex;gap:10px;justify-content:flex-end}
.cbHint{margin:-4px 2px 8px;font-size:12px;color:var(--muted)}

/* premium preview banner (top of the screen) */
#premiumBanner{flex:none;display:flex;align-items:center;gap:8px;width:100%;min-height:36px;padding:6px 14px;padding-top:calc(6px + env(safe-area-inset-top));border:0;background:#f7e2a8;color:#5e4311;font:700 13px/1.2 "DM Sans",system-ui,sans-serif;text-align:left;cursor:pointer}
#premiumBanner[hidden]{display:none}
#premiumBanner #pbText{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
#premiumBanner .pbStar{color:#b88a1e;font-size:15px}
#premiumBanner .pbMore{flex:none;text-decoration:underline;font-weight:500}
#premiumBanner:not([hidden])+#topbar{padding-top:0}
#sheet .premList{margin:0 0 12px;padding-left:20px;line-height:1.5}
#sheet .stack{display:flex;flex-direction:column;gap:10px}
#sheet .stack .btn{width:100%}

/* finishing step: envelope + confetti tabs, preview of the opening */
.cbHead{display:flex;align-items:center;justify-content:space-between;gap:10px;margin:0 2px 4px}
.cbHead .cbTitle{margin:0}
.fbTabs{display:flex;gap:4px;background:#f1e5d2;border-radius:18px;padding:3px}
.fbTabs button{height:30px;padding:0 14px;border-radius:15px;font-weight:700;font-size:13px;color:var(--muted)}
.fbTabs button.on{background:var(--paper);color:var(--ink);box-shadow:var(--shadow)}
.cbActions .btn{padding:0 16px;font-size:15px;white-space:nowrap}
.ctile.env canvas{margin-bottom:2px}
#previewLayer{position:fixed;inset:0;z-index:60;background:var(--cream)}
#previewLayer[hidden]{display:none}
#previewFrame{position:absolute;inset:0;width:100%;height:100%;border:0;background:var(--cream)}
#previewLayer .btn{position:absolute;top:max(12px,env(safe-area-inset-top));z-index:2;height:38px;font-size:14px;padding:0 14px}
#pvClose{left:12px}
#pvReplay{right:12px}

/* "Add photo" (premium, not built yet) */
.tile.photoTile{flex-direction:column;gap:3px;padding:22px 4px 5px;color:var(--ink)}
.tile.photoTile svg{width:25px;height:25px;fill:none;stroke:var(--coral);stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round}
.tile.photoTile .name{font-size:11px;font-weight:700;line-height:1.1;text-align:center}
.tile.photoTile{display:flex;align-items:center;justify-content:center}
