:root{
  --bg:#0d0d0d;
  --bg-drawer:#181818;
  --surface:#1e1e1e;
  --surface-2:#2a2a2a;
  --line:#272727;
  --text:#ececec;
  --text-dim:#9b9b9b;
  --text-faint:#6b6b6b;
  --accent:#6d5efc;
  --bubble-user:#4338ca;
  --ok:#3fbf6a;
  --warn:#e5a33a;
  --danger:#f36a6a;

  --safe-top:env(safe-area-inset-top,0px);
  --safe-bottom:env(safe-area-inset-bottom,0px);
  --safe-left:env(safe-area-inset-left,0px);
  --safe-right:env(safe-area-inset-right,0px);

  --app-h:100vh;
  --gutter:14px;
  --content-max:720px;
  --fs-base:15px;
}

*{box-sizing:border-box;-webkit-tap-highlight-color:transparent}

[hidden]{display:none !important}

html,body{height:100%;margin:0}
body{
  height:var(--app-h);
  background:var(--bg);color:var(--text);
  font:var(--fs-base)/1.5 -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",sans-serif;
  overscroll-behavior:none;
  padding-left:var(--safe-left);padding-right:var(--safe-right);
}
button{font:inherit;cursor:pointer;color:inherit}
input,textarea{font:inherit}

.screen{display:none;height:100%;min-height:0}
.screen.is-active{display:flex;flex-direction:column}

.round-btn{
  width:38px;height:38px;flex:0 0 auto;display:grid;place-items:center;
  border:0;border-radius:50%;background:var(--surface);color:var(--text);
  transition:background .15s ease;
}
.round-btn:active{background:var(--surface-2)}

.btn-pill{
  border:0;border-radius:999px;padding:9px 16px;background:var(--accent);color:#fff;
  font-weight:600;font-size:13.5px;white-space:nowrap;
}
.btn-pill:active{transform:scale(.97)}
.btn-pill[disabled]{opacity:.5;pointer-events:none}
.btn-ghost{border:0;background:transparent;color:var(--text-dim);padding:9px 14px;border-radius:999px;font-size:13.5px}

.tag{
  margin-left:auto;font-size:10.5px;color:var(--text-faint);
  border:1px solid var(--line);border-radius:999px;padding:2px 7px;white-space:nowrap;
}
.dot{width:7px;height:7px;border-radius:50%;background:var(--warn);margin-left:auto}

.avatar{width:32px;height:32px;border-radius:50%;object-fit:cover;flex:0 0 auto}
.avatar-fallback{display:grid;place-items:center;background:#3a2fa8;color:#d9d4ff;font-weight:600;font-size:14px}

.login-wrap{
  flex:1;min-height:0;overflow-y:auto;
  display:flex;flex-direction:column;align-items:center;justify-content:center;
  padding:clamp(20px,6vw,40px) clamp(18px,6vw,32px) calc(clamp(20px,5vh,34px) + var(--safe-bottom));
  text-align:center;
}
.brand{margin-bottom:clamp(22px,6vh,42px)}
.brand-mark{
  width:clamp(58px,16vw,74px);height:clamp(58px,16vw,74px);
  margin:0 auto clamp(12px,3vh,20px);border-radius:50%;display:grid;place-items:center;
  background:#17152b;color:var(--accent);box-shadow:0 0 0 1px #2a2550;
}
.brand-mark svg{width:52%;height:52%}
.brand h1{margin:0;font-size:clamp(24px,7vw,30px);letter-spacing:-.4px;font-weight:600}
.brand-sub{margin:7px 0 0;color:var(--text-dim);font-size:clamp(13px,3.6vw,14.5px)}

.btn-google{
  width:100%;max-width:340px;display:flex;align-items:center;justify-content:center;gap:10px;
  padding:15px 18px;border:0;border-radius:999px;
  background:#fff;color:#1b1b1b;font-weight:600;font-size:15px;
  transition:transform .12s ease,opacity .12s ease;
}
.btn-google:active{transform:scale(.98)}
.btn-google[disabled]{opacity:.6;pointer-events:none}

.login-status{min-height:20px;margin:16px 0 0;font-size:13px;color:var(--text-dim)}
.login-status.err{color:var(--danger)}
.login-status.ok{color:var(--ok)}
.login-legal{margin:clamp(14px,4vh,28px) 0 0;font-size:11.5px;color:var(--text-faint);max-width:290px;line-height:1.6}
.login-version{margin:10px 0 0;font-size:11px;color:#3d3d3d}

.topbar{
  display:flex;align-items:center;gap:10px;flex:0 0 auto;
  padding:calc(9px + var(--safe-top)) var(--gutter) 9px;
  background:var(--bg);
}
.topbar-mid{flex:1;min-width:0;display:flex;flex-direction:column;align-items:center}
.topbar-mid span{
  max-width:100%;font-size:15px;font-weight:500;
  white-space:nowrap;overflow:hidden;text-overflow:ellipsis;
}
.conn{font-size:11px;color:var(--danger);margin-top:1px}

.scrim{position:fixed;inset:0;background:#0009;z-index:20;animation:fade .18s ease}
@keyframes fade{from{opacity:0}to{opacity:1}}
.drawer{
  position:fixed;top:0;left:0;width:min(86vw,320px);height:var(--app-h);z-index:21;
  background:var(--bg-drawer);display:flex;flex-direction:column;
  transform:translateX(-102%);transition:transform .25s cubic-bezier(.3,.8,.3,1);
  padding-top:var(--safe-top);padding-bottom:var(--safe-bottom);
}
.drawer.open{transform:translateX(0)}

.drawer-head{display:flex;align-items:center;justify-content:space-between;gap:8px;padding:16px 14px 12px;flex:0 0 auto}
.drawer-head h2{margin:0;font-size:clamp(19px,5.5vw,23px);font-weight:600;letter-spacing:-.3px}

.search-wrap{padding:0 12px 10px;flex:0 0 auto}
.search-wrap input{
  width:100%;padding:11px 14px;border:0;border-radius:12px;
  background:var(--surface);color:var(--text);font-size:14px;
}
.search-wrap input:focus{outline:none;background:var(--surface-2)}

.drawer-nav{padding:2px 8px;display:flex;flex-direction:column;gap:1px;flex:0 0 auto}
.drawer-item{
  display:flex;align-items:center;gap:13px;width:100%;text-align:left;
  padding:11px 12px;border:0;border-radius:11px;background:transparent;font-size:14.5px;
}
.drawer-item:active{background:var(--surface)}
.drawer-item svg{color:var(--text);opacity:.9;flex:0 0 auto}

.usage-card{
  margin:10px 12px 2px;padding:12px;border:1px solid var(--line);border-radius:14px;
  background:transparent;text-align:left;display:block;width:calc(100% - 24px);flex:0 0 auto;
}
.usage-card:active{background:var(--surface)}
.usage-top{display:flex;align-items:center;justify-content:space-between;gap:8px;margin-bottom:9px}
.usage-plan{font-size:13px;font-weight:600}
.usage-coins{display:inline-flex;align-items:center;gap:5px;font-size:12.5px;color:#f0c475}
.meter{height:5px;border-radius:999px;background:var(--surface-2);overflow:hidden}
.meter span{display:block;height:100%;width:0;border-radius:999px;background:var(--accent);transition:width .4s ease}
.meter span.hot{background:var(--warn)}
.meter span.full{background:var(--danger)}
.usage-card small{display:block;margin-top:7px;font-size:11.5px;color:var(--text-faint)}

.drawer-divider{height:1px;background:var(--line);margin:12px 14px;flex:0 0 auto}

.conv-wrap{flex:1;min-height:0;overflow-y:auto;padding:0 8px 8px}
.conv-list{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:1px}
.conv-row{display:flex;align-items:center;border-radius:11px;min-width:0}
.conv-row.active,.conv-row:active{background:var(--surface)}
.conv-open{
  flex:1;min-width:0;text-align:left;border:0;background:transparent;
  padding:11px 4px 11px 12px;font-size:14.5px;
  white-space:nowrap;overflow:hidden;text-overflow:ellipsis;
}
.conv-more{
  width:34px;height:34px;flex:0 0 auto;border:0;background:transparent;color:var(--text-faint);
  border-radius:50%;display:grid;place-items:center;font-size:17px;line-height:1;
}
.conv-more:active{background:var(--surface-2)}
.conv-empty{color:var(--text-faint);font-size:13px;padding:10px 14px;margin:0}
.see-all{width:100%;text-align:left;border:0;background:transparent;color:var(--text-faint);padding:11px 12px;font-size:14px;border-radius:11px}

.drawer-foot{
  display:flex;align-items:center;gap:8px;flex:0 0 auto;
  padding:9px 12px calc(12px + var(--safe-bottom));border-top:1px solid var(--line);
}
.foot-user{flex:1;min-width:0;display:flex;align-items:center;gap:10px;border:0;background:transparent;padding:6px;border-radius:12px;text-align:left}
.foot-user:active{background:var(--surface)}
.foot-id{min-width:0;display:flex;flex-direction:column;line-height:1.25}
.foot-id strong{font-size:14px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.foot-id small{font-size:11.5px;color:var(--text-faint);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}

.update-bar{
  display:flex;align-items:center;gap:12px;flex:0 0 auto;
  margin:0 var(--gutter) 6px;padding:11px 14px;
  background:#231d10;border:1px solid #3d2f14;border-radius:14px;
}
.update-bar div{flex:1;min-width:0;display:flex;flex-direction:column}
.update-bar strong{font-size:13.5px;color:#f0c475}
.update-bar small{font-size:11.5px;color:#9b8257;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}

.messages{
  flex:1;min-height:0;overflow-y:auto;-webkit-overflow-scrolling:touch;
  padding:10px var(--gutter) 6px;
  display:flex;flex-direction:column;gap:16px;
}
.messages > *{width:100%;max-width:var(--content-max);margin-inline:auto}

.empty{margin:auto;text-align:center;padding:12px 4px}
.empty-mark{
  width:clamp(48px,13vw,60px);height:clamp(48px,13vw,60px);
  margin:0 auto 14px;border-radius:50%;display:grid;place-items:center;
  background:#17152b;color:#4b4490;
}
.empty-mark svg{width:52%;height:52%}
.empty h2{margin:0 0 18px;font-size:clamp(17px,5vw,21px);font-weight:500}
.chips{display:flex;flex-wrap:wrap;gap:8px;justify-content:center}
.chip{
  border:1px solid var(--line);background:transparent;color:var(--text-dim);
  padding:9px 14px;border-radius:999px;font-size:13px;max-width:100%;
  white-space:nowrap;overflow:hidden;text-overflow:ellipsis;
}
.chip:active{background:var(--surface)}

.msg{animation:pop .18s ease;word-wrap:break-word;overflow-wrap:anywhere;white-space:pre-wrap}
@keyframes pop{from{opacity:0;transform:translateY(5px)}to{opacity:1;transform:none}}
.msg.user{
  align-self:flex-end;width:auto;max-width:min(82%,560px);margin-inline:0;
  background:var(--bubble-user);color:#fff;padding:11px 16px;border-radius:20px;font-size:15px;
}

.msg.bot{font-size:15.5px;line-height:1.65}
.msg.sys{color:var(--text-faint);font-size:12.5px;text-align:center}

.typing{display:flex;gap:5px;padding:4px 2px;max-width:var(--content-max);margin-inline:auto;width:100%}
.typing i{width:7px;height:7px;border-radius:50%;background:#5c5c5c;animation:blink 1.3s infinite}
.typing i:nth-child(2){animation-delay:.18s}
.typing i:nth-child(3){animation-delay:.36s}
@keyframes blink{0%,60%,100%{opacity:.25;transform:translateY(0)}30%{opacity:1;transform:translateY(-3px)}}

.composer{
  flex:0 0 auto;background:var(--bg);
  padding:6px var(--gutter) calc(10px + var(--safe-bottom));
}
.composer-card{
  width:100%;max-width:var(--content-max);margin-inline:auto;
  background:var(--surface);border:1px solid var(--line);border-radius:22px;
  padding:8px 8px 6px;display:flex;flex-direction:column;gap:2px;
}
.composer-top{display:flex;align-items:center;gap:6px;padding:2px 2px 0;overflow-x:auto;scrollbar-width:none}
.composer-top::-webkit-scrollbar{display:none}
.opt-pill{
  display:inline-flex;align-items:center;gap:6px;flex:0 0 auto;max-width:60%;
  border:0;background:transparent;color:var(--text-dim);
  padding:6px 9px;border-radius:999px;font-size:12.5px;
}
.opt-pill:active{background:var(--surface-2)}
.opt-pill span{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.opt-pill .caret{opacity:.7;flex:0 0 auto}

.attach-row{display:flex;flex-wrap:wrap;gap:6px;padding:4px 4px 2px}
.attach-chip{
  display:inline-flex;align-items:center;gap:6px;max-width:100%;
  background:var(--surface-2);border-radius:10px;padding:6px 8px;font-size:12px;color:var(--text-dim);
}
.attach-chip b{font-weight:500;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:120px}
.attach-chip button{border:0;background:transparent;color:var(--text-faint);line-height:1;padding:0 2px}

.composer textarea{
  width:100%;resize:none;max-height:min(42vh,170px);min-height:36px;
  padding:7px 8px;border:0;background:transparent;color:var(--text);line-height:1.45;
}
.composer textarea:focus{outline:none}
.composer textarea::placeholder{color:var(--text-faint)}

.composer-bottom{display:flex;align-items:center;gap:2px;padding-top:2px}
.icon-sm{
  width:36px;height:36px;flex:0 0 auto;display:grid;place-items:center;
  border:0;border-radius:50%;background:transparent;color:var(--text-dim);
}
.icon-sm:active{background:var(--surface-2)}
.token-chip{
  margin-left:auto;margin-right:6px;font-size:11px;color:var(--text-faint);
  border:1px solid var(--line);border-radius:999px;padding:3px 8px;white-space:nowrap;
}
.send{
  width:36px;height:36px;flex:0 0 auto;margin-left:auto;display:grid;place-items:center;
  border:0;border-radius:50%;background:#fff;color:#111;transition:opacity .15s,transform .1s;
}
.token-chip:not([hidden]) + .send{margin-left:0}  
.send:active{transform:scale(.94)}
.send[disabled]{background:var(--surface-2);color:#777;pointer-events:none}

.plans-wrap{
  flex:1;min-height:0;overflow-y:auto;display:flex;flex-direction:column;
  align-items:center;justify-content:center;text-align:center;
  padding:28px var(--gutter) calc(28px + var(--safe-bottom));
}
.plans-mark{
  width:66px;height:66px;border-radius:50%;display:grid;place-items:center;
  background:#2a2210;color:#f0c475;margin-bottom:18px;
}
.plans-wrap h2{margin:0 0 8px;font-size:clamp(19px,5.5vw,23px);font-weight:600}
.plans-wrap p{margin:0;color:var(--text-dim);font-size:14px;max-width:300px;line-height:1.7}

.toast{
  position:fixed;left:50%;bottom:calc(96px + var(--safe-bottom));transform:translateX(-50%);
  background:#2d2d2d;color:var(--text);padding:11px 18px;border-radius:999px;
  font-size:13.5px;z-index:60;max-width:86vw;text-align:center;animation:pop .18s ease;
  box-shadow:0 10px 30px -12px #000;
}

.sheet-back{position:fixed;inset:0;background:#0009;z-index:45;display:flex;align-items:flex-end;justify-content:center}
.sheet{
  width:100%;max-width:520px;max-height:82vh;overflow-y:auto;
  background:var(--bg-drawer);border-radius:20px 20px 0 0;
  padding:8px 10px calc(14px + var(--safe-bottom));animation:up .2s ease;
}
@keyframes up{from{transform:translateY(16px);opacity:.6}to{transform:none;opacity:1}}
.sheet-grip{width:38px;height:4px;border-radius:999px;background:#3a3a3a;margin:4px auto 10px}
.sheet-title{margin:0 10px 8px;font-size:13px;color:var(--text-faint);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.sheet-body{display:flex;flex-direction:column;gap:2px}
.sheet-item{
  display:flex;align-items:center;gap:12px;width:100%;text-align:left;border:0;background:transparent;
  padding:13px 14px;border-radius:12px;font-size:14.5px;
}
.sheet-item:active{background:var(--surface)}
.sheet-item[disabled]{opacity:.45}
.sheet-item.danger{color:var(--danger)}
.sheet-item.cancel{color:var(--text-dim);justify-content:center;margin-top:4px;border-top:1px solid var(--line);border-radius:0}
.sheet-item .si-ico{width:22px;flex:0 0 auto;display:grid;place-items:center;color:var(--text-dim)}
.sheet-item .si-text{min-width:0;display:flex;flex-direction:column}
.sheet-item .si-text b{font-weight:500}
.sheet-item .si-text small{color:var(--text-faint);font-size:11.5px}
.sheet-item .si-right{margin-left:auto;display:flex;align-items:center;gap:7px}
.sheet-item .check{color:var(--accent)}

.modal{position:fixed;inset:0;background:#000b;z-index:50;display:grid;place-items:center;padding:24px}
.modal-card{background:var(--bg-drawer);border-radius:18px;padding:22px;max-width:380px;width:100%;max-height:84vh;overflow-y:auto}
.modal-card h3{margin:0 0 12px;font-size:17px;font-weight:600}
.modal-card > div{font-size:13.5px;color:var(--text-dim);line-height:1.8;margin-bottom:16px}
.modal-card b{color:var(--text);font-weight:500}
.modal-card input{width:100%;padding:12px 14px;border:0;border-radius:12px;background:var(--surface);color:var(--text);font-size:14.5px;margin-bottom:14px}
.modal-card input:focus{outline:none;background:var(--surface-2)}
.modal-actions{display:flex;justify-content:flex-end;gap:6px}

html[data-size="compact"]{--gutter:10px;--fs-base:14.5px}
html[data-size="compact"] .opt-pill{font-size:12px;padding:6px 8px}
html[data-size="compact"] .round-btn{width:35px;height:35px}
html[data-size="compact"] .chips{flex-direction:column;align-items:center}

html[data-size="wide"]{--gutter:22px}
html[data-size="wide"] .drawer{border-right:1px solid var(--line)}

html[data-h="short"] .empty-mark{display:none}
html[data-h="short"] .chips{display:none}
html[data-h="short"] .empty h2{margin-bottom:0;font-size:16px}
html[data-h="short"] .composer textarea{max-height:84px}
html[data-h="short"] .messages{gap:12px}

html[data-keyboard="open"] .update-bar{display:none}

@media (min-width:760px){
  body{background:#070707}
  .screen.is-active{max-width:760px;margin:0 auto;background:var(--bg)}
  
  .drawer{left:0}
  .drawer.open{transform:translateX(max(0px,calc(50vw - 380px)))}
  .chip{font-size:13.5px}
}

@media (prefers-reduced-motion:reduce){
  *{animation-duration:.01ms !important;transition-duration:.01ms !important}
}
