:root{
    --paper:#F2E7E1;
    --paper-2:#EAD9D2;
    --ink:#2B2129;
    --ink-soft:#6A5A62;
    --rose:#9E3B54;
    --rose-deep:#7C2C41;
    --rose-soft:#C97E8C;
    --gold:#B08D57;
    --card:#FBF5F2;
    --shadow:rgba(74,40,50,0.14);
  }
  *{box-sizing:border-box; -webkit-tap-highlight-color:transparent;}
  html,body{margin:0; height:100%;}
  body{
    background:var(--paper);
    color:var(--ink);
    font-family:"Instrument Sans", system-ui, sans-serif;
    overflow:hidden;
  }
  .serif{ font-family:"Fraunces", Georgia, serif; }

  #app{ height:100dvh; width:100vw; position:relative; overflow:hidden; }
  .screen{
    position:absolute; inset:0;
    display:flex; flex-direction:column;
    padding:calc(env(safe-area-inset-top) + 26px) 22px calc(env(safe-area-inset-bottom) + 22px);
    opacity:0; pointer-events:none;
    transform:translateY(10px);
    transition:opacity .32s ease, transform .32s ease;
    overflow-y:auto;
  }
  .screen.active{ opacity:1; pointer-events:auto; transform:none; }

  /* Landing */
  #landing{ justify-content:center; align-items:center; text-align:center; }
  .brandmark{
    width:60px; height:60px; margin-bottom:26px;
  }
  #landing .kicker{
    font-size:12px; letter-spacing:.28em; text-transform:uppercase;
    color:var(--rose); margin-bottom:18px;
  }
  #landing h1{
    font-family:"Fraunces", serif; font-weight:400;
    font-size:clamp(38px, 12vw, 54px); line-height:1.02;
    margin:0 0 22px; letter-spacing:-.01em;
  }
  #landing .tagline{
    font-family:"Fraunces", serif; font-style:italic;
    font-size:clamp(17px,5vw,20px); color:var(--ink-soft);
    max-width:20ch; margin:0 auto 40px; line-height:1.4;
  }
  .btn-primary{
    background:var(--rose); color:#FBF5F2; border:none;
    font-family:"Instrument Sans",sans-serif; font-weight:600; font-size:16px;
    padding:16px 40px; border-radius:100px; cursor:pointer;
    box-shadow:0 8px 22px -8px var(--rose-deep);
    transition:transform .15s ease, background .2s ease;
    letter-spacing:.01em;
  }
  .btn-primary:active{ transform:scale(.96); background:var(--rose-deep); }

  /* Header shared */
  .topline{
    display:flex; align-items:center; justify-content:space-between;
    margin-bottom:22px; min-height:34px;
  }
  .back{
    background:none; border:none; cursor:pointer; color:var(--ink);
    font-size:15px; font-weight:500; display:flex; align-items:center; gap:6px;
    padding:6px 4px; margin-left:-4px; font-family:inherit;
  }
  .back svg{ width:17px; height:17px; }
  .fav-open{
    background:none; border:none; cursor:pointer; color:var(--rose);
    display:flex; align-items:center; gap:5px; font-weight:500; font-size:14px;
    font-family:inherit; padding:6px;
  }
  .fav-open svg{ width:18px; height:18px; }

  /* Category grid */
  #grid h2, #favorites h2{
    font-family:"Fraunces",serif; font-weight:400; font-size:30px;
    margin:2px 0 4px;
  }
  #grid .sub, #favorites .sub{
    color:var(--ink-soft); font-size:14px; margin:0 0 24px;
  }
  .cats{ display:grid; grid-template-columns:1fr 1fr; gap:14px; }
  .cat{
    background:var(--card); border:1px solid rgba(158,59,84,.10);
    border-radius:20px; padding:20px 18px; cursor:pointer; text-align:left;
    font-family:inherit; color:var(--ink);
    box-shadow:0 6px 16px -12px var(--shadow);
    transition:transform .15s ease, box-shadow .2s ease;
    display:flex; flex-direction:column; gap:10px; min-height:118px;
    justify-content:space-between;
  }
  .cat:active{ transform:scale(.97); }
  .cat .emoji{ font-size:26px; }
  .cat .name{ font-family:"Fraunces",serif; font-size:18px; line-height:1.1; }
  .cat .count{ font-size:12px; color:var(--ink-soft); letter-spacing:.02em; }

  /* Browser */
  #browser{ }
  #browser .cat-title{
    font-family:"Fraunces",serif; font-size:24px; text-align:center;
    margin:0 0 4px; display:flex; align-items:center; justify-content:center; gap:8px;
  }
  .size-toggle{
    display:flex; gap:6px; justify-content:center; margin:16px 0 6px;
    background:var(--paper-2); padding:5px; border-radius:100px; align-self:center;
  }
  .pill{
    border:none; background:none; cursor:pointer; font-family:inherit;
    font-size:13px; font-weight:600; color:var(--ink-soft);
    padding:8px 16px; border-radius:100px; transition:all .18s ease;
    letter-spacing:.02em;
  }
  .pill.on{ background:var(--rose); color:#FBF5F2; box-shadow:0 4px 10px -5px var(--rose-deep); }

  .card-wrap{
    flex:1; display:flex; align-items:center; justify-content:center;
    min-height:0; padding:14px 0;
  }
  .msg-card{
    background:var(--card); border-radius:24px;
    padding:38px 30px; width:100%; max-width:520px;
    box-shadow:0 18px 40px -22px var(--shadow);
    border:1px solid rgba(158,59,84,.08);
    position:relative; display:flex; align-items:center; justify-content:center;
    min-height:min(46dvh, 320px);
    transition:opacity .18s ease, transform .18s ease;
  }
  .msg-card.swap{ opacity:0; transform:translateY(6px); }
  .msg-text{
    font-family:"Fraunces", serif; font-weight:400;
    font-size:clamp(21px, 6vw, 27px); line-height:1.42; text-align:center;
    color:var(--ink); letter-spacing:-.005em;
  }
  .heart-save{
    position:absolute; top:16px; right:16px;
    background:none; border:none; cursor:pointer; padding:6px;
  }
  .heart-save svg{ width:24px; height:24px; }
  .heart-save.saved svg path{ fill:var(--rose); stroke:var(--rose); }

  .controls{ display:flex; align-items:center; gap:12px; margin-top:16px; }
  .nav-btn{
    background:var(--card); border:1px solid rgba(158,59,84,.14);
    width:52px; height:52px; border-radius:50%; cursor:pointer;
    display:flex; align-items:center; justify-content:center; flex-shrink:0;
    box-shadow:0 6px 14px -10px var(--shadow); transition:transform .14s ease;
    color:var(--ink);
  }
  .nav-btn:active{ transform:scale(.92); }
  .nav-btn svg{ width:20px; height:20px; }
  .shuffle-btn{
    flex:1; background:var(--rose); color:#FBF5F2; border:none;
    height:52px; border-radius:100px; cursor:pointer;
    font-family:inherit; font-weight:600; font-size:15px;
    display:flex; align-items:center; justify-content:center; gap:9px;
    box-shadow:0 8px 20px -9px var(--rose-deep); transition:transform .14s ease;
    letter-spacing:.01em;
  }
  .shuffle-btn:active{ transform:scale(.97); }
  .shuffle-btn svg{ width:18px; height:18px; }
  .copy-btn{
    margin-top:12px; width:100%; max-width:520px; align-self:center;
    background:var(--ink); color:var(--paper); border:none;
    height:54px; border-radius:100px; cursor:pointer;
    font-family:inherit; font-weight:600; font-size:16px;
    display:flex; align-items:center; justify-content:center; gap:9px;
    transition:transform .14s ease, background .25s ease;
    letter-spacing:.01em;
  }
  .copy-btn:active{ transform:scale(.98); }
  .copy-btn.copied{ background:var(--rose); }
  .copy-btn svg{ width:18px; height:18px; }

  .counter{ text-align:center; font-size:12px; color:var(--ink-soft); margin-top:12px; letter-spacing:.04em; }

  /* Favorites */
  #favorites .fav-list{ display:flex; flex-direction:column; gap:12px; padding-bottom:10px; }
  .fav-item{
    background:var(--card); border-radius:18px; padding:18px 18px 16px;
    border:1px solid rgba(158,59,84,.08); box-shadow:0 6px 16px -14px var(--shadow);
  }
  .fav-item .fav-cat{ font-size:11px; letter-spacing:.16em; text-transform:uppercase; color:var(--rose); margin-bottom:8px; }
  .fav-item .fav-msg{ font-family:"Fraunces",serif; font-size:17px; line-height:1.4; margin-bottom:14px; }
  .fav-actions{ display:flex; gap:10px; }
  .fav-actions button{
    flex:1; border:none; cursor:pointer; font-family:inherit; font-weight:600; font-size:13px;
    padding:10px; border-radius:100px;
  }
  .fav-copy{ background:var(--ink); color:var(--paper); }
  .fav-remove{ background:var(--paper-2); color:var(--ink-soft); }
  .empty-fav{
    text-align:center; color:var(--ink-soft); margin-top:40px;
    font-family:"Fraunces",serif; font-style:italic; font-size:18px; line-height:1.5;
  }
  .empty-fav .heart-illo{ font-size:34px; margin-bottom:14px; }

  .toast{
    position:fixed; left:50%; bottom:calc(env(safe-area-inset-bottom) + 26px);
    transform:translateX(-50%) translateY(20px);
    background:var(--ink); color:var(--paper); padding:12px 22px;
    border-radius:100px; font-size:14px; font-weight:500;
    opacity:0; pointer-events:none; transition:all .28s ease; z-index:50;
    box-shadow:0 10px 30px -10px rgba(0,0,0,.4);
  }
  .toast.show{ opacity:1; transform:translateX(-50%) translateY(0); }

  @media (prefers-reduced-motion: reduce){
    .screen,.msg-card,.toast{ transition:opacity .01s; }
  }
