:root{
  --bg:#000; --card:#0e0e10; --card2:#161618; --line:#26262a;
  --txt:#fff; --dim:#9a9aa2; --blue:#0a7cff; --blue2:#1fa1ff;
  --gray:#e9e9eb; --graytxt:#000;
  --radius:18px;
}
*{box-sizing:border-box;-webkit-tap-highlight-color:transparent}
[hidden]{display:none!important}
html,body{margin:0;padding:0;background:var(--bg);color:var(--txt)}
body{
  font-family:-apple-system,BlinkMacSystemFont,"SF Pro Text","Segoe UI",Roboto,Helvetica,Arial,sans-serif;
  min-height:100dvh;
  -webkit-font-smoothing:antialiased;
}
.app{
  max-width:480px;margin:0 auto;padding:18px 16px calc(20px + env(safe-area-inset-bottom));
  display:flex;flex-direction:column;gap:16px;min-height:100dvh;
}

/* Header */
.top{text-align:center;padding-top:8px}
.brand{display:flex;align-items:center;justify-content:center;gap:8px}
.logo{font-size:26px}
.top h1{font-size:24px;font-weight:700;letter-spacing:-.02em;margin:0}
.tag{margin:6px 0 0;color:var(--dim);font-size:14px}

/* Cards */
.card{background:var(--card);border:1px solid var(--line);border-radius:20px;padding:16px;display:flex;flex-direction:column;gap:14px}
.card.center{align-items:center;text-align:center;gap:16px;padding:34px 16px}

/* Drop zone */
.drop{
  border:2px dashed #34343a;border-radius:16px;background:var(--card2);
  padding:30px 16px;text-align:center;cursor:pointer;transition:.15s border-color,.15s background;
}
.drop:focus-visible{outline:none;border-color:var(--blue)}
.drop.drag{border-color:var(--blue);background:#10202f}
.drop-ico{font-size:34px;line-height:1}
.drop-title{font-weight:600;font-size:16px;margin-top:8px}
.drop-sub{color:var(--dim);font-size:13px;margin-top:3px}

/* Thumbs */
.thumbs{display:flex;flex-wrap:wrap;gap:8px}
.thumb{position:relative;width:62px;height:62px;border-radius:10px;overflow:hidden;border:1px solid var(--line)}
.thumb img{width:100%;height:100%;object-fit:cover;display:block}
.thumb button{position:absolute;top:2px;right:2px;width:20px;height:20px;border:none;border-radius:50%;
  background:rgba(0,0,0,.65);color:#fff;font-size:13px;line-height:20px;cursor:pointer;padding:0}

/* Text input */
.link-btn{background:none;border:none;color:var(--blue2);font-size:14px;padding:2px;cursor:pointer;align-self:flex-start}
.text-wrap textarea{
  width:100%;min-height:130px;resize:vertical;background:var(--card2);color:var(--txt);
  border:1px solid var(--line);border-radius:12px;padding:12px;font-size:15px;font-family:inherit;line-height:1.4;
}
.text-wrap textarea::placeholder{color:#5e5e66}

/* Buttons */
.primary{
  background:linear-gradient(180deg,var(--blue2),var(--blue));color:#fff;border:none;border-radius:14px;
  padding:15px;font-size:16px;font-weight:600;cursor:pointer;transition:.15s opacity,.1s transform;
}
.primary:active{transform:translateY(1px)}
.primary:disabled{opacity:.4;cursor:default}
.ghost{
  background:var(--card2);color:var(--txt);border:1px solid var(--line);border-radius:14px;
  padding:14px;font-size:15px;font-weight:500;cursor:pointer;
}
.ghost:active{transform:translateY(1px)}

.err{color:#ff6b6b;font-size:14px;margin:0;text-align:center}
.hint{color:var(--dim);font-size:13px;margin:2px 0 0;text-align:center}

/* Spinner */
.spinner{width:38px;height:38px;border:3px solid #2a2a30;border-top-color:var(--blue);border-radius:50%;animation:spin .8s linear infinite}
@keyframes spin{to{transform:rotate(360deg)}}

/* Result */
.count{color:var(--dim);font-size:13px;text-align:center;margin:0}
.pages{display:flex;flex-direction:column;gap:16px;background:var(--card2);border-radius:14px;padding:14px;border:1px solid var(--line)}
.page-card{display:flex;flex-direction:column;align-items:center;gap:8px}
.page-card img{max-width:78%;border-radius:10px;box-shadow:0 8px 30px rgba(0,0,0,.5);display:block}
.page-card.single img{max-width:100%}
.card-actions{display:flex;gap:8px;justify-content:center;flex-wrap:wrap}
.page-save{padding:9px 16px;font-size:13px}
.trunc{margin:0;text-align:center;color:var(--dim);font-size:13px;line-height:1.4}
.trunc b{color:#ffd479}
.actions{display:grid;grid-template-columns:1fr auto auto;gap:10px}
/* Multi-card: only Save-all + New remain — split them so New fills the space */
.actions.two{grid-template-columns:2fr 1fr}

/* Copy confirmation animation */
.ghost.copied,.primary.copied{
  background:#34c759!important;border-color:#34c759!important;color:#fff!important;
  animation:copiedPop .32s ease;
}
@keyframes copiedPop{0%{transform:scale(1)}40%{transform:scale(1.07)}100%{transform:scale(1)}}

/* Pro teaser */
.pro{border:1px solid var(--line);border-radius:14px;padding:14px;background:var(--card2)}
.pro-head{font-weight:600;font-size:14px;display:flex;align-items:center;gap:6px}
.lock{filter:grayscale(1)}
.pro-grid{display:grid;grid-template-columns:1fr 1fr;gap:8px;margin-top:10px;color:var(--dim);font-size:13px}
.pro-grid span{background:#0c0c0e;border:1px solid var(--line);border-radius:9px;padding:8px 10px}

.foot{text-align:center;color:#46464c;font-size:12px;margin-top:auto;padding-top:8px}

/* ───────── Off-screen iMessage render stage ───────── */
#stageHost{position:fixed;left:-99999px;top:0;width:0;height:0;overflow:hidden}
.imsg{
  width:430px;background:#fff;color:#000;
  font-family:-apple-system,BlinkMacSystemFont,"SF Pro Text","Helvetica Neue",Helvetica,Arial,sans-serif;
  display:flex;flex-direction:column;
}
.imsg-header{
  display:flex;align-items:center;padding:10px 14px 8px;
  background:rgba(245,245,247,.96);border-bottom:1px solid #d9d9de;
}
.imsg-back{color:#0a7cff;font-size:30px;line-height:1;width:26px;font-weight:300}
.imsg-spacer{width:26px}
.imsg-contact{flex:1;display:flex;flex-direction:column;align-items:center;gap:3px}
.imsg-avatar{
  width:50px;height:50px;border-radius:50%;background:linear-gradient(180deg,#c9c9cf,#a7a7af);
  display:flex;align-items:center;justify-content:center;font-size:26px;overflow:hidden;
}
.imsg-avatar img{width:100%;height:100%;object-fit:cover}
.imsg-name{font-size:12px;color:#000;font-weight:500;display:flex;align-items:center;gap:2px}
.imsg-meta{text-align:center;color:#86868b;font-size:11px;padding:10px 0 4px}
.imsg-meta b{color:#86868b;font-weight:600}

.imsg-thread{display:flex;flex-direction:column;padding:4px 14px 10px;gap:2px}
/* When cards are height-equalized, the thread grows so the watermark pins to the bottom */
.imsg.fixed{overflow:hidden}
.imsg.fixed .imsg-thread{flex:1 0 auto}
.row{display:flex;margin-top:2px}
.row.gap{margin-top:9px}
.row.user{justify-content:flex-end}
.row.assistant{justify-content:flex-start}
.bubble{
  max-width:78%;padding:8px 13px;font-size:17px;line-height:1.32;
  border-radius:19px;word-wrap:break-word;white-space:pre-wrap;position:relative;
}
.row.assistant .bubble{background:#e9e9eb;color:#000;border-bottom-left-radius:7px}
.row.user .bubble{background:linear-gradient(180deg,#27a1ff,#0a7cff);color:#fff;border-bottom-right-radius:7px}
/* middle bubbles in a run get fully rounded */
.row.mid.assistant .bubble{border-bottom-left-radius:19px}
.row.mid.user .bubble{border-bottom-right-radius:19px}

.imsg-watermark{text-align:center;color:#9b9ba1;font-size:11.5px;padding:9px 0 15px;letter-spacing:.01em}
.imsg-watermark b{color:#0a7cff;font-weight:600}
.imsg-more{text-align:center;color:#86868b;font-size:12.5px;line-height:1.4;padding:12px 16px 4px;margin-top:6px;border-top:1px solid #ececef}
.imsg-more b{color:#0a7cff;font-weight:600}

/* ───────────────── Pro UI ───────────────── */
.top{position:relative}
.pro-badge{
  position:absolute;right:0;top:4px;z-index:2;
  display:inline-flex;align-items:center;gap:5px;
  border:1px solid var(--line);background:var(--card2);color:var(--dim);
  border-radius:999px;padding:6px 12px;font-size:12px;font-weight:600;cursor:pointer;
}
.pro-badge .tb-ico{width:15px;height:15px;display:block}
.pro-badge.locked .tb-ico{color:#8a8a92}
.pro-badge.unlocked{background:linear-gradient(180deg,#ffe08a,#f5c451);color:#3a2c00;border-color:#f5c451}
.pro-badge.unlocked .tb-ico{color:#3a2c00}

/* Studio */
.studio-head{font-size:17px;font-weight:700;letter-spacing:-.01em}
.studio-sub{margin:-6px 0 2px;color:var(--dim);font-size:13px}
.lbl-note{color:#5e5e66;font-weight:400}
.field{display:flex;flex-direction:column;gap:7px}
.field label{font-size:13px;color:var(--dim);font-weight:600}
.field input[type=text]{
  background:var(--card2);color:var(--txt);border:1px solid var(--line);
  border-radius:11px;padding:11px 12px;font-size:15px;font-family:inherit;
}
.avatar-row{display:flex;align-items:center;gap:8px;flex-wrap:wrap}
.avatar-preview{
  width:42px;height:42px;border-radius:50%;background:linear-gradient(180deg,#c9c9cf,#a7a7af);
  display:flex;align-items:center;justify-content:center;font-size:22px;overflow:hidden;flex-shrink:0;
}
.avatar-preview img{width:100%;height:100%;object-fit:cover}
.avatar-presets{display:flex;gap:4px;flex-wrap:wrap}
.avatar-presets button{
  width:34px;height:34px;border-radius:9px;border:1px solid var(--line);background:var(--card2);
  font-size:18px;cursor:pointer;padding:0;line-height:1;
}
.avatar-presets button:active{transform:scale(.92)}
.avatar-row input[type=text]{width:64px;background:var(--card2);color:var(--txt);border:1px solid var(--line);border-radius:9px;padding:8px;font-size:16px;text-align:center}
.tiny{padding:8px 12px;font-size:13px}

.theme-row{display:flex;gap:8px;flex-wrap:wrap}
.theme-btn{
  flex:1;min-width:72px;border:1px solid var(--line);background:var(--card2);color:var(--txt);
  border-radius:11px;padding:10px;font-size:13px;font-weight:600;cursor:pointer;
}
.theme-btn.selected{border-color:var(--blue);background:#10202f;color:#fff}

.checkbox{display:flex;align-items:center;gap:9px;font-size:14px;color:var(--txt);cursor:pointer}
.checkbox input{width:18px;height:18px;accent-color:var(--blue)}

.editor-head{font-size:14px;font-weight:600;margin-top:2px;display:flex;flex-direction:column;gap:2px}
.editor-head .hint{font-weight:400;color:var(--dim);font-size:12px}
.editor{display:flex;flex-direction:column;gap:8px}
.ed-row{display:flex;gap:8px;align-items:flex-start;background:var(--card2);border:1px solid var(--line);border-radius:12px;padding:8px}
.ed-side{flex-shrink:0;width:54px;border:none;border-radius:9px;padding:9px 0;font-size:12px;font-weight:700;cursor:pointer}
.ed-side.user{background:linear-gradient(180deg,#27a1ff,#0a7cff);color:#fff}
.ed-side.assistant{background:#3a3a40;color:#fff}
.ed-row textarea{flex:1;background:transparent;color:var(--txt);border:none;resize:none;font-family:inherit;font-size:15px;line-height:1.35;padding:6px 2px;min-height:24px}
.ed-row textarea:focus{outline:none}
.ed-del{flex-shrink:0;background:none;border:none;color:#ff6b6b;font-size:20px;cursor:pointer;padding:4px 6px;line-height:1}
.full{width:100%}
.studio-actions{grid-template-columns:1fr auto}

/* Modal */
.modal{position:fixed;inset:0;z-index:50;background:rgba(0,0,0,.72);display:flex;align-items:center;justify-content:center;padding:20px}
.modal-box{position:relative;width:100%;max-width:380px;background:var(--card);border:1px solid var(--line);border-radius:20px;padding:22px 18px 18px;display:flex;flex-direction:column;gap:12px}
.modal-close{position:absolute;right:12px;top:10px;background:none;border:none;color:var(--dim);font-size:24px;cursor:pointer;line-height:1}
.modal-title{font-size:19px;font-weight:700;text-align:center}
.modal-sub{margin:0;color:var(--dim);font-size:13.5px;text-align:center;line-height:1.45}
.modal-or{margin:4px 0 0;text-align:center;color:#5e5e66;font-size:12px}
.code-row{display:flex;gap:8px}
.code-row input{flex:1;background:var(--card2);color:var(--txt);border:1px solid var(--line);border-radius:11px;padding:11px;font-size:15px;text-transform:uppercase}
.modal-msg{margin:0;text-align:center;font-size:13px}
.modal-msg.ok{color:#34c759}
.modal-msg.bad{color:#ff6b6b}

/* ───────────────── Render themes ───────────────── */
/* iMessage dark */
.imsg.theme-imessage-dark{background:#000}
.imsg.theme-imessage-dark .imsg-header{background:#1c1c1e;border-bottom-color:#2c2c2e}
.imsg.theme-imessage-dark .imsg-name{color:#fff}
.imsg.theme-imessage-dark .imsg-meta,.imsg.theme-imessage-dark .imsg-meta b{color:#8e8e93}
.imsg.theme-imessage-dark .row.assistant .bubble{background:#26252a;color:#fff}
.imsg.theme-imessage-dark .imsg-more{color:#8e8e93;border-top-color:#2c2c2e}
.imsg.theme-imessage-dark .imsg-watermark{color:#6b6b70}

/* WhatsApp */
.imsg.theme-whatsapp{background:#e5ddd5}
.imsg.theme-whatsapp .imsg-header{background:#008069;border-bottom:none}
.imsg.theme-whatsapp .imsg-back{color:#fff}
.imsg.theme-whatsapp .imsg-name{color:#fff}
.imsg.theme-whatsapp .imsg-meta{color:#5b6b63}
.imsg.theme-whatsapp .imsg-meta b{color:#5b6b63}
.imsg.theme-whatsapp .row.assistant .bubble{background:#fff;color:#111;border-radius:8px;border-bottom-left-radius:2px}
.imsg.theme-whatsapp .row.user .bubble{background:#d9fdd3;color:#111;border-radius:8px;border-bottom-right-radius:2px}
.imsg.theme-whatsapp .row.mid.assistant .bubble{border-bottom-left-radius:8px}
.imsg.theme-whatsapp .row.mid.user .bubble{border-bottom-right-radius:8px}
.imsg.theme-whatsapp .imsg-more{color:#5b6b63;border-top-color:#cfc7bf}
.imsg.theme-whatsapp .imsg-watermark{color:#7a8a80}

/* Telegram */
.imsg.theme-telegram{background:#cfe3f3}
.imsg.theme-telegram .imsg-header{background:#527da3;border-bottom:none}
.imsg.theme-telegram .imsg-back{color:#fff}
.imsg.theme-telegram .imsg-name{color:#fff;font-weight:600}
.imsg.theme-telegram .imsg-avatar{background:linear-gradient(180deg,#7ab3e0,#4a90c4);color:#fff}
.imsg.theme-telegram .imsg-meta{padding:12px 0 6px}
.imsg.theme-telegram .imsg-meta span{background:rgba(0,0,0,.28);color:#fff;font-weight:600;border-radius:999px;padding:3px 11px}
.imsg.theme-telegram .imsg-meta b{color:#fff}
.imsg.theme-telegram .row.assistant .bubble{background:#fff;color:#0e0e0e;border-radius:13px;border-bottom-left-radius:4px;box-shadow:0 1px 1px rgba(0,0,0,.08)}
.imsg.theme-telegram .row.user .bubble{background:#effdde;color:#0e0e0e;border-radius:13px;border-bottom-right-radius:4px;box-shadow:0 1px 1px rgba(0,0,0,.08)}
.imsg.theme-telegram .row.mid.assistant .bubble{border-bottom-left-radius:13px}
.imsg.theme-telegram .row.mid.user .bubble{border-bottom-right-radius:13px}
.imsg.theme-telegram .imsg-more{color:#4a6a82;border-top-color:#b5cfe2}
.imsg.theme-telegram .imsg-more b{color:#2b7bbf}
.imsg.theme-telegram .imsg-watermark{color:#5a7d96}
.imsg.theme-telegram .imsg-watermark b{color:#2b7bbf}

/* Watermark removal (Pro) */
.imsg.no-watermark .imsg-watermark{display:none}
