:root{
  --bg:#F7F1E6;--surface:#FFFFFF;--surface2:#FBF6EC;--surface3:#F0E2D0;
  --border:#E9DFCC;--border2:#DCC9A8;
  --text:#201D1B;--text2:#6E6156;--text3:#A79C8C;
  --accent:#C4798A;--accent2:#8B5D67;--accent-bg:#F5E4E7;
  --ink:#171513;
  --green:#5C7A5A;--green-bg:#EAF0E4;
  --red:#B2483F;--red-bg:#F8E9E5;
  --amber:#A47417;--amber-bg:#F6EAD2;
  --shadow-sm:0 2px 10px rgba(60,45,20,0.07);
  --shadow-md:0 10px 30px rgba(60,45,20,0.12);
  --r-sm:10px;--r-md:16px;--r-lg:20px;
  --safe-top:env(safe-area-inset-top,0px);
  --safe-bot:env(safe-area-inset-bottom,0px);
}
@media (prefers-color-scheme: dark){
  :root:not([data-theme="light"]){
    --bg:#17140F;--surface:#221E17;--surface2:#2A251C;--surface3:#382F22;
    --border:#3D3527;--border2:#4E4330;
    --text:#F5EEE1;--text2:#C4B8A3;--text3:#8C8071;
    --accent:#E39BAB;--accent2:#F0B8C4;--accent-bg:#3A2A2E;
    --ink:#F5EEE1;
    --green:#8FB08A;--green-bg:#22301F;
    --red:#E08A80;--red-bg:#3A2420;
    --amber:#D9B25E;--amber-bg:#382E17;
    --shadow-sm:0 2px 10px rgba(0,0,0,0.3);
    --shadow-md:0 10px 30px rgba(0,0,0,0.4);
  }
}
:root[data-theme="dark"]{
  --bg:#17140F;--surface:#221E17;--surface2:#2A251C;--surface3:#382F22;
  --border:#3D3527;--border2:#4E4330;
  --text:#F5EEE1;--text2:#C4B8A3;--text3:#8C8071;
  --accent:#E39BAB;--accent2:#F0B8C4;--accent-bg:#3A2A2E;
  --ink:#F5EEE1;
  --green:#8FB08A;--green-bg:#22301F;
  --red:#E08A80;--red-bg:#3A2420;
  --amber:#D9B25E;--amber-bg:#382E17;
  --shadow-sm:0 2px 10px rgba(0,0,0,0.3);
  --shadow-md:0 10px 30px rgba(0,0,0,0.4);
}

*,*::before,*::after{box-sizing:border-box;margin:0;padding:0;}
html{height:100%;-webkit-text-size-adjust:100%;}
body{
  font-family:'Inter',system-ui,-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;
  background:var(--bg);color:var(--text);
  min-height:100vh;min-height:100dvh;
  -webkit-font-smoothing:antialiased;
  overscroll-behavior:none;
}
h1,h2{font-family:'Playfair Display',Georgia,serif;font-weight:600;}
button{font-family:inherit;}
input,textarea,select{font-family:inherit;color:var(--text);background:var(--surface2);border:1px solid var(--border);border-radius:var(--r-sm);padding:11px 13px;font-size:15px;width:100%;outline:none;}
input:focus,textarea:focus,select:focus{border-color:var(--accent);}
textarea{resize:vertical;line-height:1.5;}
.visually-hidden{position:absolute;width:1px;height:1px;overflow:hidden;opacity:0;}
.script-accent{font-family:'Petit Formal Script',cursive;font-style:normal;color:var(--accent);font-weight:400;}

.app-shell{max-width:640px;margin:0 auto;min-height:100vh;min-height:100dvh;display:flex;flex-direction:column;}

/* ===== Topbar ===== */
.topbar{
  position:sticky;top:0;z-index:20;
  display:flex;align-items:center;justify-content:space-between;
  padding:calc(16px + var(--safe-top)) 18px 16px;
  background:var(--bg);
}
.brand{display:flex;align-items:center;gap:8px;}
.brand-mark{font-size:15px;color:var(--accent);}
.brand-text{display:flex;flex-direction:column;line-height:1;}
.brand-name{font-family:'Playfair Display',Georgia,serif;font-weight:600;font-size:21px;letter-spacing:0.01em;color:var(--ink);}
.brand-script{font-family:'Petit Formal Script',cursive;font-weight:400;color:var(--accent);font-size:1.15em;margin-left:1px;}
.brand-by{font-size:9.5px;letter-spacing:0.1em;text-transform:uppercase;color:var(--text3);font-weight:600;margin-top:2px;}
.topbar-actions{display:flex;gap:18px;align-items:center;}
.nav-link-btn{
  background:none;border:none;color:var(--ink);cursor:pointer;
  font-size:11px;font-weight:600;letter-spacing:0.11em;text-transform:uppercase;
  padding:4px 0;border-bottom:1px solid transparent;
}
.nav-link-btn:active{border-bottom-color:var(--accent);}
.icon-btn{
  background:var(--surface2);border:1px solid var(--border);border-radius:12px;
  width:40px;height:40px;font-size:18px;display:flex;align-items:center;justify-content:center;
  cursor:pointer;color:var(--text);
}
.icon-btn:active{transform:scale(0.94);}

/* ===== Layout ===== */
.content{flex:1;padding:0 16px calc(112px + var(--safe-bot));display:flex;flex-direction:column;gap:16px;}

.output-placeholder{display:none;}

/* ===== Intro ===== */
.intro-card{
  background:var(--surface);
  border:1px solid var(--border);border-radius:var(--r-lg);
  padding:24px 22px;display:flex;flex-direction:column;gap:12px;
  box-shadow:var(--shadow-sm);
}
.intro-card h1{font-size:25px;line-height:1.35;letter-spacing:0.005em;font-weight:600;}
.intro-card p{color:var(--text2);font-size:14.5px;line-height:1.6;}
.intro-card p strong{color:var(--ink);}
.intro-free{color:var(--text)!important;font-weight:500;font-size:13.5px;}
.intro-free strong{color:var(--accent2);font-weight:700;}

/* ===== Banner ===== */
.banner{display:flex;align-items:center;justify-content:space-between;gap:10px;padding:12px 14px;border-radius:var(--r-md);font-size:14px;}
.banner-warn{background:var(--amber-bg);border:1px solid var(--amber);color:var(--amber);}
.banner-warn .btn{background:var(--ink);color:var(--bg);flex-shrink:0;}

/* ===== Cards ===== */
.card{background:var(--surface);border:1px solid var(--border);border-radius:var(--r-lg);padding:18px;box-shadow:var(--shadow-sm);}
.card-head{display:flex;align-items:center;justify-content:space-between;gap:10px;margin-bottom:12px;}
.card-head h2{font-size:17px;font-weight:600;display:flex;align-items:center;gap:8px;flex-wrap:wrap;}
.card-head .hint{font-size:11.5px;color:var(--text3);white-space:nowrap;letter-spacing:0.01em;}
.card-head-actions{display:flex;align-items:center;gap:10px;flex-wrap:wrap;}
.btn-link-sm{font-size:11.5px;padding:0;text-decoration:underline;white-space:nowrap;}
.step-num{
  display:inline-flex;align-items:center;justify-content:center;
  width:22px;height:22px;border-radius:50%;background:var(--ink);color:var(--bg);
  font-size:11px;font-weight:700;font-family:'Inter',sans-serif;
}
.optional-tag{font-size:10px;font-weight:600;letter-spacing:0.08em;text-transform:uppercase;color:var(--accent2);background:var(--accent-bg);padding:3px 9px;border-radius:20px;}
.collapsible{cursor:pointer;user-select:none;}
.chevron{transition:transform .2s;color:var(--text3);}
.chevron.open{transform:rotate(180deg);}
.card-body{display:flex;flex-direction:column;gap:14px;}
.card-body.collapsed{display:none;}

/* ===== Photo grid ===== */
.photo-grid{display:grid;grid-template-columns:repeat(4,1fr);gap:10px;}
.photo-add,.photo-thumb{
  aspect-ratio:1;border-radius:var(--r-md);position:relative;overflow:hidden;
}
.photo-add{
  border:1.5px dashed var(--border2);display:flex;flex-direction:column;align-items:center;justify-content:center;gap:4px;
  cursor:pointer;color:var(--text2);background:var(--surface2);
}
.photo-add-icon{font-size:22px;line-height:1;color:var(--accent);font-weight:300;}
.photo-add-label{font-size:9px;text-align:center;padding:0 4px;line-height:1.2;letter-spacing:0.06em;text-transform:uppercase;font-weight:600;}
.photo-thumb{border:1px solid var(--border);}
.photo-thumb img{width:100%;height:100%;object-fit:cover;display:block;}
.photo-thumb .remove-photo{
  position:absolute;top:4px;right:4px;width:22px;height:22px;border-radius:50%;
  background:rgba(23,21,19,0.72);color:#fff;border:none;font-size:13px;display:flex;align-items:center;justify-content:center;cursor:pointer;
}
.photo-thumb .primary-tag{
  position:absolute;bottom:0;left:0;right:0;background:rgba(23,21,19,0.72);color:#fff;
  font-size:8.5px;text-align:center;padding:3px 0;font-weight:600;letter-spacing:0.08em;text-transform:uppercase;
}

/* ===== Fields ===== */
.field{display:flex;flex-direction:column;gap:6px;flex:1;min-width:0;}
.field label{font-size:12px;font-weight:600;color:var(--text2);}
.field-row{display:flex;gap:10px;}
.field-row .field{width:50%;}
@media (max-width:400px){.field-row{flex-direction:column;}.field-row .field{width:100%;}}

.switch-row{display:flex;align-items:center;justify-content:space-between;font-size:14px;cursor:pointer;padding:2px 0;}
.switch-row input{display:none;}
.switch{width:42px;height:24px;border-radius:20px;background:var(--surface3);border:1px solid var(--border2);position:relative;flex-shrink:0;transition:.2s;}
.switch::after{content:'';position:absolute;top:2px;left:2px;width:18px;height:18px;border-radius:50%;background:var(--text3);transition:.2s;}
.switch-row input:checked + .switch{background:var(--accent);border-color:var(--accent);}
.switch-row input:checked + .switch::after{transform:translateX(18px);background:#fff;}

/* ===== Buttons ===== */
.btn{
  border:none;border-radius:999px;padding:13px 20px;font-size:12.5px;font-weight:700;
  letter-spacing:0.09em;text-transform:uppercase;
  cursor:pointer;display:inline-flex;align-items:center;justify-content:center;gap:6px;
  transition:transform .08s, opacity .2s;
}
.btn:active{transform:scale(0.97);}
.btn:disabled{opacity:.45;cursor:not-allowed;}
.btn-primary{background:var(--ink);color:var(--bg);}
.btn-secondary{background:var(--surface);color:var(--ink);border:1px solid var(--ink);}
.btn-sm{padding:9px 14px;font-size:11px;}
.btn-lg{padding:17px;font-size:13.5px;}
.btn-block{width:100%;}
.btn-link{background:none;border:none;color:var(--text2);font-size:13px;font-weight:500;text-decoration:underline;cursor:pointer;padding:6px 0;text-align:center;}
.btn-link-danger{color:var(--red);}

.generate-bar{
  position:fixed;left:0;right:0;bottom:0;z-index:10;
  max-width:640px;margin:0 auto;
  display:flex;flex-direction:column;gap:7px;align-items:center;
  padding:14px 16px calc(14px + var(--safe-bot));
  background:linear-gradient(180deg, transparent, var(--bg) 35%);
}
.generate-sub{font-size:12px;color:var(--text3);text-align:center;}

/* ===== Loading ===== */
.loading-card{display:flex;flex-direction:column;align-items:center;gap:14px;padding:32px 18px;text-align:center;color:var(--text2);}
.spinner{width:32px;height:32px;border-radius:50%;border:2.5px solid var(--border2);border-top-color:var(--accent);animation:spin 0.8s linear infinite;}
@keyframes spin{to{transform:rotate(360deg);}}

/* ===== Results ===== */
.results{display:flex;flex-direction:column;gap:14px;}
.result-card .card-head h2{font-size:16px;}
.result-title-input{font-weight:600;font-size:15.5px;font-family:'Playfair Display',Georgia,serif;}
.result-textarea{width:100%;}
.chip-btn{
  background:var(--accent-bg);border:1px solid var(--border2);color:var(--accent2);
  border-radius:999px;padding:6px 14px;font-size:10.5px;font-weight:700;letter-spacing:0.08em;text-transform:uppercase;
  cursor:pointer;flex-shrink:0;
}
.chip-btn:active{transform:scale(0.95);}
.bullet-list{display:flex;flex-direction:column;gap:8px;list-style:none;}
.bullet-list li{
  display:flex;gap:9px;font-size:14px;line-height:1.5;background:var(--surface2);
  border-radius:10px;padding:9px 11px;align-items:flex-start;
}
.bullet-list li .bullet-dot{color:var(--accent);flex-shrink:0;font-size:12px;padding-top:2px;}
.bullet-list li[contenteditable]{outline:none;}
.tag-list{display:flex;flex-wrap:wrap;gap:8px;}
.tag-pill{
  background:var(--surface3);color:var(--ink);border:1px solid var(--border2);
  border-radius:999px;padding:6px 13px;font-size:11.5px;font-weight:600;letter-spacing:0.02em;
}
.result-actions{display:flex;flex-wrap:wrap;gap:10px;justify-content:center;padding-top:4px;}

/* ===== Toast ===== */
.toast{
  position:fixed;left:16px;right:16px;bottom:calc(20px + var(--safe-bot));z-index:100;
  max-width:608px;margin:0 auto;background:var(--ink);color:var(--bg);
  border:1px solid var(--ink);border-radius:14px;padding:13px 16px;font-size:13.5px;font-weight:500;
  box-shadow:var(--shadow-md);animation:toastIn .2s ease;
}
.toast.toast-error{background:var(--red-bg);border-color:var(--red);color:var(--red);}
.toast.toast-success{background:var(--surface2);border-color:var(--accent);color:var(--accent2);}
@keyframes toastIn{from{opacity:0;transform:translateY(10px);}to{opacity:1;transform:translateY(0);}}

/* ===== Sheets (modal bottom sheets) ===== */
.sheet-overlay{
  position:fixed;inset:0;background:rgba(23,21,19,0.55);z-index:200;
  display:flex;align-items:flex-end;justify-content:center;
}
.sheet{
  width:100%;max-width:640px;max-height:88vh;overflow-y:auto;
  background:var(--surface);border-radius:22px 22px 0 0;
  padding:10px 20px calc(26px + var(--safe-bot));
  display:flex;flex-direction:column;gap:14px;
  animation:sheetUp .22s ease;
}
@keyframes sheetUp{from{transform:translateY(30px);opacity:.6;}to{transform:translateY(0);opacity:1;}}
.sheet-handle{width:40px;height:4px;border-radius:4px;background:var(--border2);margin:4px auto 6px;}
.sheet h2{font-size:19px;font-weight:600;}
.sheet-desc{font-size:13px;color:var(--text2);line-height:1.55;}
.sheet-actions{display:flex;gap:10px;}
.sheet-actions .btn{flex:1;}
.key-input-row{display:flex;gap:8px;}
.key-input-row input{flex:1;}
.get-key-box{background:var(--surface2);border:1px solid var(--border);border-radius:12px;padding:12px 14px;font-size:13px;color:var(--text2);line-height:1.6;}
.get-key-box a{color:var(--accent2);font-weight:600;}
.get-key-box ol{padding-left:18px;margin-top:4px;}
.pin-lock-field{border-top:1px solid var(--border);padding-top:14px;margin-top:4px;}
.pin-error{color:var(--red);font-size:13px;text-align:center;min-height:18px;}

/* ===== History ===== */
.history-list{display:flex;flex-direction:column;gap:10px;max-height:50vh;overflow-y:auto;}
.history-item{
  display:flex;gap:12px;align-items:center;background:var(--surface2);border:1px solid var(--border);
  border-radius:14px;padding:10px;cursor:pointer;text-align:left;width:100%;
}
.history-item img{width:48px;height:48px;border-radius:10px;object-fit:cover;flex-shrink:0;background:var(--surface3);}
.history-item .hi-text{flex:1;min-width:0;}
.history-item .hi-title{font-size:14px;font-weight:600;font-family:'Playfair Display',Georgia,serif;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
.history-item .hi-date{font-size:11px;color:var(--text3);}
.history-empty{color:var(--text3);font-size:14px;text-align:center;padding:20px 0;}

/* ===== Ad slot ===== */
.ad-slot{
  background:var(--surface2);border:1px solid var(--border);border-radius:var(--r-md);
  padding:10px;display:flex;flex-direction:column;gap:6px;align-items:center;
  min-height:60px;justify-content:center;
}
.ad-slot-label{font-size:9px;letter-spacing:0.1em;text-transform:uppercase;color:var(--text3);align-self:flex-start;}

/* ===== Footer ===== */
.app-footer{padding:10px 16px calc(24px + var(--safe-bot));text-align:center;display:flex;align-items:center;justify-content:center;gap:8px;flex-wrap:wrap;}
.app-footer a{font-size:12px;color:var(--text3);text-decoration:underline;}
.app-footer .footer-dot{font-size:12px;color:var(--border2);}

.hidden{display:none!important;}

/* On mobile these wrappers must be invisible to layout — their children
   flow directly into .content's flex column exactly as if the wrapper
   didn't exist. display:contents does that. */
.col-input-group,.col-output-group{display:contents;}

/* ===== Desktop layout ===== */
/* Below this width the app is the single-column, fixed-bottom-button mobile
   flow above. Above it, it reads as a real website tool: a bordered header,
   a wider frame, and a two-pane layout — inputs on the left, a live output
   pane on the right that stays in view (position:sticky) while you edit.
   Each side is grouped into a single flex container that IS one grid cell,
   rather than giving every card its own grid-column — CSS Grid's default
   auto-placement advances one row per DOM item regardless of column, so
   interleaved single-item placement produces a staircase, not two aligned
   columns.
   This block must stay LAST in the file: at matching viewport widths it
   needs to win over the unconditional rules above it (e.g. .generate-bar's
   position:fixed) at equal specificity, and a media query alone doesn't
   grant priority — source order still decides ties. */
@media (min-width:900px){
  .app-shell{max-width:1120px;}
  .topbar{border-bottom:1px solid var(--border);}
  .content{
    display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);
    gap:20px 36px;align-items:start;
    padding:32px 32px 56px;
  }
  .col-input-group,.col-output-group{display:flex;flex-direction:column;gap:16px;}
  .app-footer{grid-column:1 / -1;}

  .generate-bar{position:static;background:none;padding:8px 0 0;}

  .output-placeholder{
    display:flex;flex-direction:column;align-items:center;justify-content:center;gap:10px;
    min-height:360px;text-align:center;color:var(--text3);font-size:13.5px;padding:32px;
  }
  .output-placeholder-icon{font-size:26px;color:var(--accent);}

  .results{position:sticky;top:24px;}
  .loading-card{position:sticky;top:24px;}
}
